Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

477 lines
14 KiB

  1. // Copyright (c) 1996-1999 Microsoft Corporation
  2. /* shortcut.c - functions that expand shortcuts */
  3. #include "gpdparse.h"
  4. // ---- functions defined in shortcut.c ---- //
  5. BOOL BInitKeywordField(
  6. PTKMAP pNewtkmap,
  7. PGLOBL pglobl) ;
  8. BOOL BExpandMemConfig(
  9. PTKMAP ptkmap,
  10. PTKMAP pNewtkmap,
  11. DWORD dwTKMindex,
  12. PGLOBL pglobl) ;
  13. BOOL BExpandCommand(
  14. PTKMAP ptkmap,
  15. PTKMAP pNewtkmap,
  16. DWORD dwTKMindex,
  17. PGLOBL pglobl) ;
  18. BOOL BexpandShortcuts(
  19. PGLOBL pglobl) ;
  20. BOOL BSsyncTokenMap(
  21. PTKMAP ptkmap,
  22. PTKMAP pNewtkmap,
  23. PGLOBL pglobl) ;
  24. // ---------------------------------------------------- //
  25. BOOL BInitKeywordField(
  26. PTKMAP pNewtkmap,
  27. PGLOBL pglobl)
  28. /* all synthesized entries must have aarKeyword initialized
  29. via mainkeyword table since ERR code may want to print
  30. it out if a parsing error occurs further downstream. */
  31. {
  32. ABSARRAYREF aarKeywordName ;
  33. DWORD dwKeyID ;
  34. dwKeyID = pNewtkmap->dwKeywordID ;
  35. aarKeywordName.pub = mMainKeywordTable[dwKeyID].pstrKeyword ;
  36. aarKeywordName.dw = strlen(aarKeywordName.pub) ;
  37. pNewtkmap->aarKeyword.dw = 0 ; // copy mode
  38. if(!BCatToTmpHeap( &pNewtkmap->aarKeyword,
  39. &aarKeywordName, pglobl) )
  40. {
  41. vIdentifySource(pNewtkmap, pglobl) ;
  42. ERR(("Internal error - unable to store keyword name.\n"));
  43. return(FALSE) ;
  44. }
  45. return(TRUE) ;
  46. }
  47. BOOL BExpandMemConfig(
  48. PTKMAP ptkmap,
  49. PTKMAP pNewtkmap,
  50. DWORD dwTKMindex,
  51. PGLOBL pglobl)
  52. /* this function is pretty lax about syntax checking.
  53. It just assumes the existence of some non trivial string
  54. between open parent and a comma. It assumes this is the
  55. amount of installed memory. The value parser will rigorously
  56. determine if the syntax is conforming.
  57. */
  58. {
  59. DWORD dwNewTKMindex, dwDelim ;
  60. BOOL bMB = FALSE ; // KB otherwise
  61. ABSARRAYREF aarTmpValue, aarToken, aarNewValue, aarUnits, aarDQuote;
  62. aarUnits.pub = "KB" ; // hardcode strings
  63. aarUnits.dw = 2 ;
  64. aarDQuote.pub = "\"" ;
  65. aarDQuote.dw = 1 ;
  66. if(ptkmap[dwTKMindex].dwKeywordID == gdwMemConfigMB)
  67. {
  68. aarUnits.pub = "MB" ;
  69. bMB = TRUE ;
  70. }
  71. if(!BallocElementFromMasterTable(
  72. MTI_NEWTOKENMAP, &dwNewTKMindex, pglobl) )
  73. {
  74. geErrorSev = ERRSEV_RESTART ;
  75. geErrorType = ERRTY_MEMORY_ALLOCATION ;
  76. gdwMasterTabIndex = MTI_NEWTOKENMAP ;
  77. return(FALSE);
  78. }
  79. // parse out the amount of installed memory
  80. aarTmpValue = ptkmap[dwTKMindex].aarValue ;
  81. if(!BdelimitToken(&aarTmpValue, "(", &aarToken, &dwDelim ) ||
  82. dwDelim ||
  83. !BdelimitToken(&aarTmpValue, ",", &aarToken, &dwDelim ) ||
  84. dwDelim || !BeatSurroundingWhiteSpaces(&aarToken) )
  85. {
  86. vIdentifySource(ptkmap + dwTKMindex, pglobl) ;
  87. ERR(("Syntax error in value of *MemConfig shortcut: %0.*s.\n",
  88. ptkmap[dwTKMindex].aarValue.dw ,
  89. ptkmap[dwTKMindex].aarValue.pub ));
  90. return(FALSE);
  91. }
  92. aarNewValue.dw = 0 ; // initialize so BCatToTmpHeap
  93. // will overwrite instead of append
  94. pNewtkmap[dwNewTKMindex].dwKeywordID = gdwOptionConstruct ;
  95. if(!BInitKeywordField(pNewtkmap + dwNewTKMindex, pglobl) ||
  96. !BCatToTmpHeap(&aarNewValue, &aarToken, pglobl) ||
  97. !BCatToTmpHeap(&aarNewValue, &aarUnits, pglobl))
  98. {
  99. vIdentifySource(ptkmap + dwTKMindex, pglobl) ;
  100. ERR(("Concatenation to synthesize Memory option name failed.\n"));
  101. return(FALSE) ;
  102. }
  103. pNewtkmap[dwNewTKMindex].aarValue = aarNewValue ;
  104. pNewtkmap[dwNewTKMindex].dwFileNameIndex =
  105. ptkmap[dwTKMindex].dwFileNameIndex ;
  106. pNewtkmap[dwNewTKMindex].dwLineNumber =
  107. ptkmap[dwTKMindex].dwLineNumber ;
  108. // -- synthesize entry for open brace
  109. if(!BallocElementFromMasterTable(
  110. MTI_NEWTOKENMAP, &dwNewTKMindex, pglobl) )
  111. {
  112. geErrorSev = ERRSEV_RESTART ;
  113. geErrorType = ERRTY_MEMORY_ALLOCATION ;
  114. gdwMasterTabIndex = MTI_NEWTOKENMAP ;
  115. return(FALSE);
  116. }
  117. pNewtkmap[dwNewTKMindex].dwKeywordID = gdwOpenBraceConstruct ;
  118. pNewtkmap[dwNewTKMindex].aarValue.dw = 0 ;
  119. if(!BInitKeywordField(pNewtkmap + dwNewTKMindex, pglobl) )
  120. return(FALSE);
  121. pNewtkmap[dwNewTKMindex].dwFileNameIndex =
  122. ptkmap[dwTKMindex].dwFileNameIndex ;
  123. pNewtkmap[dwNewTKMindex].dwLineNumber =
  124. ptkmap[dwTKMindex].dwLineNumber ;
  125. // -- synthesize *Name entry
  126. if(!BallocElementFromMasterTable(
  127. MTI_NEWTOKENMAP, &dwNewTKMindex, pglobl) )
  128. {
  129. geErrorSev = ERRSEV_RESTART ;
  130. geErrorType = ERRTY_MEMORY_ALLOCATION ;
  131. gdwMasterTabIndex = MTI_NEWTOKENMAP ;
  132. return(FALSE);
  133. }
  134. pNewtkmap[dwNewTKMindex].dwKeywordID = gdwOptionName ;
  135. pNewtkmap[dwNewTKMindex].aarValue.dw = 0 ; // initialize so
  136. // BCatToTmpHeap will overwrite instead of append
  137. if(!BInitKeywordField(pNewtkmap + dwNewTKMindex, pglobl) ||
  138. !BCatToTmpHeap(&pNewtkmap[dwNewTKMindex].aarValue, &aarDQuote, pglobl) ||
  139. !BCatToTmpHeap(&pNewtkmap[dwNewTKMindex].aarValue, &aarNewValue, pglobl) ||
  140. !BCatToTmpHeap(&pNewtkmap[dwNewTKMindex].aarValue, &aarDQuote, pglobl) )
  141. {
  142. vIdentifySource(ptkmap + dwTKMindex, pglobl) ;
  143. ERR(("Concatenation to synthesize Memory option name failed.\n"));
  144. return(FALSE) ;
  145. }
  146. pNewtkmap[dwNewTKMindex].dwFileNameIndex =
  147. ptkmap[dwTKMindex].dwFileNameIndex ;
  148. pNewtkmap[dwNewTKMindex].dwLineNumber =
  149. ptkmap[dwTKMindex].dwLineNumber ;
  150. // -- synthesize *MemoryConfigX entry
  151. if(!BallocElementFromMasterTable(
  152. MTI_NEWTOKENMAP, &dwNewTKMindex, pglobl) )
  153. {
  154. geErrorSev = ERRSEV_RESTART ;
  155. geErrorType = ERRTY_MEMORY_ALLOCATION ;
  156. gdwMasterTabIndex = MTI_NEWTOKENMAP ;
  157. return(FALSE);
  158. }
  159. pNewtkmap[dwNewTKMindex].dwKeywordID =
  160. (bMB) ? gdwMemoryConfigMB : gdwMemoryConfigKB ;
  161. pNewtkmap[dwNewTKMindex].aarValue = ptkmap[dwTKMindex].aarValue ;
  162. if(!BInitKeywordField(pNewtkmap + dwNewTKMindex, pglobl) )
  163. return(FALSE);
  164. pNewtkmap[dwNewTKMindex].dwFileNameIndex =
  165. ptkmap[dwTKMindex].dwFileNameIndex ;
  166. pNewtkmap[dwNewTKMindex].dwLineNumber =
  167. ptkmap[dwTKMindex].dwLineNumber ;
  168. // -- synthesize entry for close brace
  169. if(!BallocElementFromMasterTable(
  170. MTI_NEWTOKENMAP, &dwNewTKMindex, pglobl) )
  171. {
  172. geErrorSev = ERRSEV_RESTART ;
  173. geErrorType = ERRTY_MEMORY_ALLOCATION ;
  174. gdwMasterTabIndex = MTI_NEWTOKENMAP ;
  175. return(FALSE);
  176. }
  177. pNewtkmap[dwNewTKMindex].dwKeywordID = gdwCloseBraceConstruct ;
  178. pNewtkmap[dwNewTKMindex].aarValue.dw = 0 ;
  179. if(!BInitKeywordField(pNewtkmap + dwNewTKMindex, pglobl) )
  180. return(FALSE);
  181. pNewtkmap[dwNewTKMindex].dwFileNameIndex =
  182. ptkmap[dwTKMindex].dwFileNameIndex ;
  183. pNewtkmap[dwNewTKMindex].dwLineNumber =
  184. ptkmap[dwTKMindex].dwLineNumber ;
  185. return(TRUE) ;
  186. }
  187. BOOL BExpandCommand(
  188. PTKMAP ptkmap,
  189. PTKMAP pNewtkmap,
  190. DWORD dwTKMindex,
  191. PGLOBL pglobl)
  192. /* this function is pretty lax about syntax checking.
  193. It just assumes the existence of some non trivial string
  194. between the two colons. It assumes this is the
  195. name of the command. The portion after the 2nd colon is
  196. the actual command invocation. The value parser will rigorously
  197. determine if the syntax is conforming.
  198. */
  199. {
  200. DWORD dwNewTKMindex, dwDelim ;
  201. ABSARRAYREF aarTmpValue, aarToken, aarNewValue, aarUnits ;
  202. if(!BallocElementFromMasterTable(
  203. MTI_NEWTOKENMAP, &dwNewTKMindex, pglobl) )
  204. {
  205. geErrorSev = ERRSEV_RESTART ;
  206. geErrorType = ERRTY_MEMORY_ALLOCATION ;
  207. gdwMasterTabIndex = MTI_NEWTOKENMAP ;
  208. return(FALSE);
  209. }
  210. pNewtkmap[dwNewTKMindex] = ptkmap[dwTKMindex] ;
  211. // parse out the command name
  212. aarTmpValue = ptkmap[dwTKMindex].aarValue ;
  213. if(!BdelimitToken(&aarTmpValue, ":", &aarToken, &dwDelim ) ||
  214. dwDelim )
  215. {
  216. vIdentifySource(ptkmap + dwTKMindex, pglobl) ;
  217. ERR(("Syntax error in *Command shortcut: %0.*s.\n",
  218. ptkmap[dwTKMindex].aarValue.dw ,
  219. ptkmap[dwTKMindex].aarValue.pub ));
  220. return(FALSE);
  221. }
  222. pNewtkmap[dwNewTKMindex].aarValue = aarToken ;
  223. // -- synthesize entry for open brace
  224. if(!BallocElementFromMasterTable(
  225. MTI_NEWTOKENMAP, &dwNewTKMindex, pglobl) )
  226. {
  227. geErrorSev = ERRSEV_RESTART ;
  228. geErrorType = ERRTY_MEMORY_ALLOCATION ;
  229. gdwMasterTabIndex = MTI_NEWTOKENMAP ;
  230. return(FALSE);
  231. }
  232. pNewtkmap[dwNewTKMindex].dwKeywordID = gdwOpenBraceConstruct ;
  233. pNewtkmap[dwNewTKMindex].aarValue.dw = 0 ;
  234. if(!BInitKeywordField(pNewtkmap + dwNewTKMindex, pglobl) )
  235. return(FALSE);
  236. pNewtkmap[dwNewTKMindex].dwFileNameIndex =
  237. ptkmap[dwTKMindex].dwFileNameIndex ;
  238. pNewtkmap[dwNewTKMindex].dwLineNumber =
  239. ptkmap[dwTKMindex].dwLineNumber ;
  240. // -- synthesize *Cmd entry
  241. if(!BallocElementFromMasterTable(
  242. MTI_NEWTOKENMAP, &dwNewTKMindex, pglobl) )
  243. {
  244. geErrorSev = ERRSEV_RESTART ;
  245. geErrorType = ERRTY_MEMORY_ALLOCATION ;
  246. gdwMasterTabIndex = MTI_NEWTOKENMAP ;
  247. return(FALSE);
  248. }
  249. pNewtkmap[dwNewTKMindex].dwKeywordID = gdwCommandCmd ;
  250. pNewtkmap[dwNewTKMindex].aarValue = aarTmpValue ;
  251. if(!BInitKeywordField(pNewtkmap + dwNewTKMindex, pglobl) )
  252. return(FALSE);
  253. pNewtkmap[dwNewTKMindex].dwFileNameIndex =
  254. ptkmap[dwTKMindex].dwFileNameIndex ;
  255. pNewtkmap[dwNewTKMindex].dwLineNumber =
  256. ptkmap[dwTKMindex].dwLineNumber ;
  257. // -- synthesize entry for close brace
  258. if(!BallocElementFromMasterTable(
  259. MTI_NEWTOKENMAP, &dwNewTKMindex, pglobl) )
  260. {
  261. geErrorSev = ERRSEV_RESTART ;
  262. geErrorType = ERRTY_MEMORY_ALLOCATION ;
  263. gdwMasterTabIndex = MTI_NEWTOKENMAP ;
  264. return(FALSE);
  265. }
  266. pNewtkmap[dwNewTKMindex].dwKeywordID = gdwCloseBraceConstruct ;
  267. pNewtkmap[dwNewTKMindex].aarValue.dw = 0 ;
  268. if(!BInitKeywordField(pNewtkmap + dwNewTKMindex, pglobl) )
  269. return(FALSE);
  270. pNewtkmap[dwNewTKMindex].dwFileNameIndex =
  271. ptkmap[dwTKMindex].dwFileNameIndex ;
  272. pNewtkmap[dwNewTKMindex].dwLineNumber =
  273. ptkmap[dwTKMindex].dwLineNumber ;
  274. return(TRUE) ;
  275. }
  276. BOOL BexpandShortcuts(
  277. PGLOBL pglobl)
  278. // this function scans through the TokenMap
  279. // making a copy to NewTokenMap without
  280. // the shortcuts. At the end transfers
  281. // all NewTokenMap entries back to TokenMap so
  282. // subsequent passes can work.
  283. // This function assumes the temp heap is availible for
  284. // storage of strings.
  285. {
  286. PTKMAP ptkmap, pNewtkmap ; // start of tokenmap
  287. DWORD dwNewTKMindex, dwEntry, dwKeywordID ;
  288. BOOL bStatus = TRUE ;
  289. // this function is called before resolveMacros.
  290. // it will leave the result on ptkmap.
  291. // source
  292. ptkmap = (PTKMAP)gMasterTable[MTI_TOKENMAP].pubStruct ;
  293. // dest
  294. pNewtkmap = (PTKMAP)gMasterTable[MTI_NEWTOKENMAP].pubStruct ;
  295. for(dwEntry = 0 ; geErrorSev < ERRSEV_RESTART ; dwEntry++)
  296. {
  297. // These ID's must be processed separately
  298. // because they do not index into the mainKeyword table.
  299. // The code for generic ID's will fail.
  300. dwKeywordID = ptkmap[dwEntry].dwKeywordID ;
  301. if (dwKeywordID == gdwID_IgnoreBlock)
  302. {
  303. VIgnoreBlock(ptkmap + dwEntry, TRUE, pglobl) ;
  304. continue ;
  305. }
  306. if (dwKeywordID == ID_EOF)
  307. {
  308. // transfer all tokenmap fields to newTokenMap
  309. if(!BallocElementFromMasterTable(
  310. MTI_NEWTOKENMAP, &dwNewTKMindex, pglobl) )
  311. {
  312. geErrorSev = ERRSEV_RESTART ;
  313. geErrorType = ERRTY_MEMORY_ALLOCATION ;
  314. gdwMasterTabIndex = MTI_NEWTOKENMAP ;
  315. return(FALSE);
  316. }
  317. pNewtkmap[dwNewTKMindex] = ptkmap[dwEntry] ;
  318. // must reset tokenmap so it can be reused.
  319. gMasterTable[MTI_TOKENMAP].dwCurIndex = 0 ;
  320. if(bStatus)
  321. bStatus = BSsyncTokenMap(ptkmap, pNewtkmap , pglobl) ;
  322. return(bStatus) ;
  323. }
  324. if (dwKeywordID == ID_NULLENTRY)
  325. {
  326. continue ; // skip to next entry.
  327. }
  328. else if (dwKeywordID == gdwMemConfigMB ||
  329. dwKeywordID == gdwMemConfigKB)
  330. {
  331. if(!BExpandMemConfig(ptkmap, pNewtkmap, dwEntry, pglobl))
  332. return(FALSE);
  333. }
  334. else if (dwKeywordID == gdwCommandConstruct &&
  335. ptkmap[dwEntry].dwFlags & TKMF_COLON)
  336. {
  337. if(!BExpandCommand(ptkmap, pNewtkmap, dwEntry, pglobl))
  338. return(FALSE);
  339. }
  340. else
  341. {
  342. // transfer all tokenmap fields to newTokenMap
  343. if(!BallocElementFromMasterTable(
  344. MTI_NEWTOKENMAP, &dwNewTKMindex, pglobl) )
  345. {
  346. geErrorSev = ERRSEV_RESTART ;
  347. geErrorType = ERRTY_MEMORY_ALLOCATION ;
  348. gdwMasterTabIndex = MTI_NEWTOKENMAP ;
  349. return(FALSE);
  350. }
  351. pNewtkmap[dwNewTKMindex] = ptkmap[dwEntry] ;
  352. }
  353. }
  354. return(FALSE); // failsafe derail.
  355. }
  356. BOOL BSsyncTokenMap(
  357. PTKMAP ptkmap,
  358. PTKMAP pNewtkmap,
  359. PGLOBL pglobl )
  360. {
  361. DWORD dwTKMindex, dwEntry, dwKeywordID ;
  362. for(dwEntry = 0 ; geErrorSev < ERRSEV_RESTART ; dwEntry++)
  363. {
  364. // transfer all newTokenMap fields back to tokenmap
  365. if(!BallocElementFromMasterTable(
  366. MTI_TOKENMAP, &dwTKMindex, pglobl) )
  367. {
  368. geErrorSev = ERRSEV_RESTART ;
  369. geErrorType = ERRTY_MEMORY_ALLOCATION ;
  370. gdwMasterTabIndex = MTI_TOKENMAP ;
  371. return(FALSE); // failsafe derail.
  372. }
  373. ptkmap[dwTKMindex] = pNewtkmap[dwEntry] ;
  374. if (pNewtkmap[dwEntry].dwKeywordID == ID_EOF)
  375. {
  376. gMasterTable[MTI_NEWTOKENMAP].dwCurIndex = 0 ;
  377. return(TRUE) ;
  378. }
  379. }
  380. return(FALSE); // failsafe derail.
  381. }