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.

421 lines
11 KiB

  1. /* Copyright (C) Boris Nikolaus, Germany, 1996-1997. All rights reserved. */
  2. /* Copyright (C) Microsoft Corporation, 1997-1998. All rights reserved. */
  3. #include "precomp.h"
  4. #include "hackdir.h"
  5. #ifdef MS_DIRECTIVE
  6. int g_fPrivateDir_FieldNameToken = 0;
  7. int g_fPrivateDir_TypeNameToken = 0;
  8. int g_fPrivateDir_ValueNameToken = 0;
  9. int g_fPrivateDir_SLinked = 0;
  10. int g_fPrivateDir_DLinked = 0;
  11. int g_fPrivateDir_Public = 0;
  12. int g_fPrivateDir_Intx = 0;
  13. int g_fPrivateDir_LenPtr = 0;
  14. int g_fPrivateDir_Pointer = 0;
  15. int g_fPrivateDir_Array = 0;
  16. int g_fPrivateDir_NoCode = 0;
  17. int g_fPrivateDir_NoMemCopy = 0;
  18. int g_fPrivateDir_OidPacked = 0;
  19. int g_fPrivateDir_OidArray = 0;
  20. char g_szPrivateDirectedFieldName[64];
  21. char g_szPrivateDirectedTypeName[64];
  22. char g_szPrivateDirectedValueName[64];
  23. int My_toupper ( int ch )
  24. {
  25. if ('a' <= ch && ch <= 'z')
  26. {
  27. ch = (ch - 'a' + 'A');
  28. }
  29. return ch;
  30. }
  31. int PrivateDirectives_MatchSymbol ( int *p, char *psz )
  32. {
  33. int c = *p;
  34. int fMatched = 1;
  35. while (*psz != '\0')
  36. {
  37. if (My_toupper(c) != *psz++)
  38. {
  39. fMatched = 0;
  40. break;
  41. }
  42. c = PrivateDirectives_Input();
  43. }
  44. *p = c;
  45. return fMatched;
  46. }
  47. void PrivateDirectives_SkipSpace ( int *p )
  48. {
  49. int c = *p;
  50. while (isspace(c))
  51. {
  52. c = PrivateDirectives_Input();
  53. }
  54. *p = c;
  55. }
  56. void PrivateDirectives_GetSymbol ( int *p, char *psz )
  57. {
  58. int c = *p;
  59. while (c == '_' || isalnum(c))
  60. {
  61. *psz++ = (char)c;
  62. c = PrivateDirectives_Input();
  63. }
  64. *psz = '\0';
  65. *p = c;
  66. }
  67. void PrivateDirectives_IgnoreSymbol ( int *p )
  68. {
  69. int c = *p;
  70. while (c == '_' || isalnum(c))
  71. {
  72. c = PrivateDirectives_Input();
  73. }
  74. *p = c;
  75. }
  76. void GetMicrosoftDirective ( int *p )
  77. {
  78. int c = *p;
  79. // loop through to get all directives
  80. while (c != g_chDirectiveEnd)
  81. {
  82. if (c == g_chDirectiveAND)
  83. {
  84. c = PrivateDirectives_Input();
  85. PrivateDirectives_SkipSpace(&c);
  86. }
  87. switch (My_toupper(c))
  88. {
  89. case 'A': // possible ARRAY
  90. if (PrivateDirectives_MatchSymbol(&c, "ARRAY"))
  91. {
  92. g_fPrivateDir_Array = 1;
  93. }
  94. break;
  95. case 'D': // possible DLINKED
  96. if (PrivateDirectives_MatchSymbol(&c, "DLINKED"))
  97. {
  98. g_fPrivateDir_DLinked = 1;
  99. }
  100. break;
  101. case 'F': // possible FNAME
  102. if (PrivateDirectives_MatchSymbol(&c, "FIELD"))
  103. {
  104. // c should be a space now
  105. PrivateDirectives_SkipSpace(&c);
  106. // c should be a double quote now
  107. if (c == '"')
  108. {
  109. c = PrivateDirectives_Input();
  110. }
  111. // c should be the first char of name
  112. PrivateDirectives_GetSymbol(&c, &g_szPrivateDirectedFieldName[0]);
  113. g_fPrivateDir_FieldNameToken = 0;
  114. }
  115. break;
  116. case 'I': // possible INTX
  117. if (PrivateDirectives_MatchSymbol(&c, "INTX"))
  118. {
  119. g_fPrivateDir_Intx = 1;
  120. }
  121. break;
  122. case 'L': // possible LENPTR
  123. if (PrivateDirectives_MatchSymbol(&c, "LENPTR"))
  124. {
  125. g_fPrivateDir_LenPtr = 1;
  126. }
  127. break;
  128. case 'N': // possible NO MEMCPY (or NOMEMCPY) or NO CODE (or NOCODE)
  129. if (PrivateDirectives_MatchSymbol(&c, "NO"))
  130. {
  131. // skip over possible spaces
  132. PrivateDirectives_SkipSpace(&c);
  133. switch (My_toupper(c))
  134. {
  135. case 'C':
  136. if (PrivateDirectives_MatchSymbol(&c, "CODE")) // CODE
  137. {
  138. g_fPrivateDir_NoCode = 1;
  139. }
  140. break;
  141. case 'M':
  142. if (PrivateDirectives_MatchSymbol(&c, "MEMCPY")) // MEMCPY
  143. {
  144. g_fPrivateDir_NoMemCopy = 1;
  145. }
  146. break;
  147. }
  148. }
  149. break;
  150. case 'O': // possible OID ARRAY (or OIDARRAY) or OID PACKED (or OIDPACKED)
  151. if (PrivateDirectives_MatchSymbol(&c, "OID"))
  152. {
  153. // skip over possible spaces
  154. PrivateDirectives_SkipSpace(&c);
  155. switch (My_toupper(c))
  156. {
  157. case 'A':
  158. if (PrivateDirectives_MatchSymbol(&c, "ARRAY")) // ARRAY
  159. {
  160. g_fPrivateDir_OidArray = 1;
  161. }
  162. break;
  163. case 'P':
  164. if (PrivateDirectives_MatchSymbol(&c, "PACKED")) // PACKED
  165. {
  166. g_fPrivateDir_OidPacked = 1;
  167. }
  168. break;
  169. }
  170. }
  171. break;
  172. case 'P': // possible POINTER or PUBLIC
  173. c = PrivateDirectives_Input();
  174. switch (My_toupper(c))
  175. {
  176. case 'O':
  177. if (PrivateDirectives_MatchSymbol(&c, "OINTER")) // POINTER
  178. {
  179. g_fPrivateDir_Pointer = 1;
  180. }
  181. break;
  182. case 'U':
  183. if (PrivateDirectives_MatchSymbol(&c, "UBLIC")) // PUBLIC
  184. {
  185. g_fPrivateDir_Public = 1;
  186. }
  187. break;
  188. }
  189. break;
  190. case 'S': // possible SLINKED
  191. if (PrivateDirectives_MatchSymbol(&c, "SLINKED"))
  192. {
  193. g_fPrivateDir_SLinked = 1;
  194. }
  195. break;
  196. case 'T': // possible TNAME
  197. if (PrivateDirectives_MatchSymbol(&c, "TYPE"))
  198. {
  199. // c should be a space now
  200. PrivateDirectives_SkipSpace(&c);
  201. // c should be a double quote now
  202. if (c == '"')
  203. {
  204. c = PrivateDirectives_Input();
  205. }
  206. // c should be the first char of name
  207. PrivateDirectives_GetSymbol(&c, &g_szPrivateDirectedTypeName[0]);
  208. g_fPrivateDir_TypeNameToken = 0;
  209. }
  210. break;
  211. case 'V': // possible VNAME
  212. if (PrivateDirectives_MatchSymbol(&c, "VALUE"))
  213. {
  214. // c should be a space now
  215. PrivateDirectives_SkipSpace(&c);
  216. // c should be a double quote now
  217. if (c == '"')
  218. {
  219. c = PrivateDirectives_Input();
  220. }
  221. // c should be the first char of name
  222. PrivateDirectives_GetSymbol(&c, &g_szPrivateDirectedValueName[0]);
  223. g_fPrivateDir_ValueNameToken = 0;
  224. }
  225. break;
  226. default:
  227. goto MyExit;
  228. }
  229. // determine if we should stay in the loop
  230. // skip over the ending double quote
  231. if (c == '"')
  232. {
  233. c = PrivateDirectives_Input();
  234. }
  235. // skip over unknown directives
  236. PrivateDirectives_IgnoreSymbol(&c);
  237. // skip over possible spaces
  238. PrivateDirectives_SkipSpace(&c);
  239. }
  240. // now, c is >. we need to advance to --
  241. c = PrivateDirectives_Input();
  242. // now, c should be -
  243. MyExit:
  244. // return the current character
  245. *p = c;
  246. }
  247. void GetPrivateDirective ( int *p )
  248. {
  249. GetMicrosoftDirective(p);
  250. }
  251. typedef struct Verbatim_s
  252. {
  253. struct Verbatim_s *next;
  254. char pszVerbatim[1];
  255. }
  256. Verbatim_t;
  257. Verbatim_t *g_VerbatimList = NULL;
  258. void RememberVerbatim(char *pszVerbatim)
  259. {
  260. int cb = strlen(pszVerbatim) + 1;
  261. Verbatim_t *p = (Verbatim_t *) malloc(sizeof(Verbatim_t) + cb);
  262. if (p)
  263. {
  264. memcpy(p->pszVerbatim, pszVerbatim, cb);
  265. p->next = NULL;
  266. if (g_VerbatimList)
  267. {
  268. Verbatim_t *q;
  269. for (q = g_VerbatimList; q->next; q = q->next)
  270. ;
  271. q->next = p;
  272. }
  273. else
  274. {
  275. g_VerbatimList = p;
  276. }
  277. }
  278. }
  279. void PrintVerbatim(void)
  280. {
  281. Verbatim_t *p;
  282. for (p = g_VerbatimList; p; p = p->next)
  283. {
  284. output("/* %s */\n", p->pszVerbatim);
  285. }
  286. if (g_VerbatimList)
  287. {
  288. output("\n");
  289. }
  290. }
  291. int CompareDirective(char *pszDirective, char *pszInput)
  292. {
  293. int rc;
  294. int len = strlen(pszDirective);
  295. char ch = pszInput[len];
  296. pszInput[len] = '\0';
  297. rc = strcmpi(pszDirective, pszInput);
  298. pszInput[len] = ch;
  299. return rc;
  300. }
  301. void SetDirective(char *pszInput)
  302. {
  303. // verbatim strings
  304. const char szComment[] = "COMMENT";
  305. if (! CompareDirective((char *) &szComment[0], pszInput))
  306. {
  307. pszInput += sizeof(szComment) - 1;
  308. if (isspace(*pszInput))
  309. {
  310. pszInput++;
  311. if ('"' == *pszInput++)
  312. {
  313. char *pszEnd = strchr(pszInput, '"');
  314. if (pszEnd)
  315. {
  316. *pszEnd = '\0';
  317. RememberVerbatim(pszInput);
  318. *pszEnd = '"';
  319. }
  320. }
  321. }
  322. return;
  323. }
  324. // object identifier
  325. if (! CompareDirective("OID ARRAY", pszInput))
  326. {
  327. g_fOidArray = 1;
  328. return;
  329. }
  330. // set of/sequence of w/o size constraint
  331. if (! CompareDirective("SS.basic SLINKED", pszInput))
  332. {
  333. g_eDefTypeRuleSS_NonSized = eTypeRules_SinglyLinkedList;
  334. return;
  335. }
  336. if (! CompareDirective("SS.basic DLINKED", pszInput))
  337. {
  338. g_eDefTypeRuleSS_NonSized = eTypeRules_DoublyLinkedList;
  339. return;
  340. }
  341. if (! CompareDirective("SS.basic LENPTR", pszInput))
  342. {
  343. g_eDefTypeRuleSS_NonSized = eTypeRules_LengthPointer;
  344. return;
  345. }
  346. if (! CompareDirective("SS.basic ARRAY", pszInput))
  347. {
  348. g_eDefTypeRuleSS_NonSized = eTypeRules_FixedArray;
  349. return;
  350. }
  351. // set of/sequence of w/ size constraint
  352. if (! CompareDirective("SS.sized SLINKED", pszInput))
  353. {
  354. g_eDefTypeRuleSS_Sized = eTypeRules_SinglyLinkedList;
  355. return;
  356. }
  357. if (! CompareDirective("SS.sized DLINKED", pszInput))
  358. {
  359. g_eDefTypeRuleSS_Sized = eTypeRules_DoublyLinkedList;
  360. return;
  361. }
  362. if (! CompareDirective("SS.sized LENPTR", pszInput))
  363. {
  364. g_eDefTypeRuleSS_Sized = eTypeRules_LengthPointer;
  365. return;
  366. }
  367. if (! CompareDirective("SS.sized ARRAY", pszInput))
  368. {
  369. g_eDefTypeRuleSS_Sized = eTypeRules_FixedArray;
  370. return;
  371. }
  372. // set extra pointer type for SS construct, its struct name will be postfixed with _s
  373. if (! CompareDirective("SS.struct EXTRA-PTR-TYPE", pszInput))
  374. {
  375. g_fExtraStructPtrTypeSS = 1;
  376. return;
  377. }
  378. }
  379. #endif // MS_DIRECTIVE