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.

295 lines
6.6 KiB

  1. /********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1987-1990 **/
  4. /********************************************************************/
  5. #ifndef DEBUG
  6. #ifndef NDEBUG // for assert()
  7. #define NDEBUG // for assert()
  8. #endif
  9. #endif
  10. #define INCL_NOCOMMON
  11. #include <os2.h>
  12. #include <stdio.h>
  13. #include <assert.h>
  14. #include <process.h>
  15. #include "netcmds.h"
  16. #include "interpre.h"
  17. #include <msystem.h>
  18. #include "os2incl.h"
  19. #include "os2cmd.h"
  20. #define STACKSIZE 20
  21. #define RECURSE 10
  22. /*
  23. * XXSTKCHECK - checks the given expression. if true, then the stack
  24. * is ok, else stack overflow will occur.
  25. */
  26. #define xxstkcheck(cond) if(!(cond))xxovfl()
  27. TOKSTACK *Tokptr, *Tokmax;
  28. TOKSTACK Tokstack[STACKSIZE];
  29. int Condition = FALSE;
  30. int S_orstack[INTER_OR * 3 * RECURSE];
  31. XX_USERTYPE S_frstack[INTER_FRAME * RECURSE];
  32. extern TCHAR *xxswitch[];
  33. /* Function Prototypes. */
  34. XX_USERTYPE xx_parser(int, int *, int);
  35. int XX_USERLEX(TOKSTACK *);
  36. void xxinit(void);
  37. void xxovfl(void);
  38. int xxnext(void);
  39. int (*XXulex)(TOKSTACK *) = XX_USERLEX;
  40. int XXtoken = 0;
  41. XX_USERTYPE XXnode = 0;
  42. extern TCHAR *Rule_strings[];
  43. extern SHORT Index_strings[];
  44. /*
  45. ** XX_USERPARSE : this is what the user calls to parse a tree.
  46. */
  47. XX_USERTYPE XX_USERPARSE(VOID)
  48. {
  49. xxinit();
  50. return(xx_parser(XX_START,S_orstack,0));
  51. }
  52. /*
  53. ** xx_parser : this is what we call to actually parse the tree
  54. */
  55. XX_USERTYPE xx_parser(pc,or_ptr,fp)
  56. register int pc;
  57. register int *or_ptr;
  58. register int fp;
  59. {
  60. register int type;
  61. register TOKSTACK *ptok;
  62. int *or_start = or_ptr;
  63. int fp_start = fp;
  64. S_frstack[fp] = (XX_USERTYPE) 1;
  65. while(1)
  66. {
  67. #ifdef DEBUG
  68. WriteToCon(TEXT("Current PC = %3d value = %4d type is "),pc,XXvalues[pc]);
  69. #endif
  70. switch(XXtype[pc])
  71. {
  72. case X_RULE :
  73. #ifdef DEBUG
  74. WriteToCon( TEXT("X_RULE\n"));
  75. #endif
  76. break;
  77. case X_OR :
  78. #ifdef DEBUG
  79. WriteToCon( TEXT("X_OR\n"));
  80. #endif
  81. type = XXtype[pc + 1];
  82. /*
  83. ** before we go through the bother of pushing a backup place,
  84. ** if the a token or a check and the current token
  85. ** does not match the value, then immediately update the pc
  86. ** to have the value of the X_OR.
  87. ** otherwise, save all the current info.
  88. */
  89. if( ((type == X_TOKEN) || (type == X_CHECK))
  90. &&
  91. (XXvalues[pc + 1] != (SHORT) XXtoken))
  92. {
  93. pc = XXvalues[pc];
  94. continue;
  95. }
  96. xxstkcheck(or_ptr < &S_orstack[DIMENSION(S_orstack) - 3]);
  97. *(or_ptr++) = XXvalues[pc]; /* link to next subsection */
  98. *(or_ptr++) = fp; /* the current frame ptr */
  99. *(or_ptr++) = (int)(Tokptr - Tokstack); /* the Tokstack index */
  100. break;
  101. case X_PROC :
  102. #ifdef DEBUG
  103. WriteToCon( TEXT("X_PROC\n"));
  104. #endif
  105. xxstkcheck(fp < (DIMENSION(S_frstack) - 1));
  106. if( ! (S_frstack[fp] = xx_parser(XXvalues[pc],or_ptr,fp)))
  107. {
  108. goto backout;
  109. }
  110. fp++;
  111. break;
  112. case X_CHECK :
  113. #ifdef DEBUG
  114. WriteToCon( TEXT("X_CHECK\n"));
  115. #endif
  116. if(XXtoken != XXvalues[pc])
  117. {
  118. goto backout;
  119. }
  120. break;
  121. case X_SWITCH :
  122. #ifdef DEBUG
  123. WriteToCon( TEXT("X_SWITCH\n"));
  124. #endif
  125. /* if "/anything" was in the grammar, we call this
  126. * routine for an implementation defined switch
  127. * check, passing the text of the string as an argument.
  128. */
  129. if(!CheckSwitch(xxswitch[XXvalues[pc]]))
  130. {
  131. goto backout;
  132. }
  133. break;
  134. case X_ANY :
  135. #ifdef DEBUG
  136. WriteToCon( TEXT("X_ANY\n"));
  137. #endif
  138. /* match anything */
  139. xxstkcheck(fp < DIMENSION(S_frstack));
  140. S_frstack[fp++] = XXnode; /* must be here, read comment */
  141. if (XXtoken == EOS)
  142. goto backout;
  143. else
  144. xxnext();
  145. break;
  146. case X_TOKEN :
  147. #ifdef DEBUG
  148. WriteToCon( TEXT("X_TOKEN\n"));
  149. #endif
  150. xxstkcheck(fp < DIMENSION(S_frstack));
  151. /*
  152. ** we first save the node, then check the token, since
  153. ** if the tokens match, xxlex will get the next one and we'll
  154. ** lose the current one of interest.
  155. */
  156. S_frstack[fp++] = XXnode; /* must be here, read comment */
  157. if(XXvalues[pc] != (SHORT) XXtoken)
  158. {
  159. goto backout;
  160. }
  161. else
  162. xxnext();
  163. break;
  164. case X_CONDIT :
  165. #ifdef DEBUG
  166. WriteToCon( TEXT("X_CONDIT\n"));
  167. #endif
  168. if( ! xxcondition(XXvalues[pc], &S_frstack[fp_start]))
  169. {
  170. goto backout;
  171. }
  172. break;
  173. case X_ACTION :
  174. #ifdef DEBUG
  175. WriteToCon( TEXT("X_ACTION\n"));
  176. #endif
  177. xxaction(XXvalues[pc],&S_frstack[fp_start]);
  178. break;
  179. case X_ACCEPT :
  180. #ifdef DEBUG
  181. WriteToCon( TEXT("X_ACCEPT\n"));
  182. #endif
  183. return(S_frstack[fp_start]);
  184. case X_DEFINE :
  185. #ifdef DEBUG
  186. WriteToCon( TEXT("X_DEFINE\n"));
  187. #endif
  188. break;
  189. /*
  190. **case X_PUSH :
  191. #ifdef DEBUG
  192. WriteToCon( TEXT("X_PUSH\n"));
  193. #endif
  194. ** ppush(XXvalues[pc],S_frstack[fp_start]);
  195. ** break;
  196. */
  197. default :
  198. #ifdef DEBUG
  199. WriteToCon( TEXT("UNKNOWN\n"));
  200. #endif
  201. assert(FALSE);
  202. break;
  203. }
  204. pc++;
  205. continue;
  206. backout: /* BACK OUT !!! recover an earlier state */
  207. if(or_ptr != or_start)
  208. {
  209. /*
  210. ** reset the 'or' stack
  211. */
  212. Tokptr = ptok = Tokstack + *(--or_ptr);
  213. XXtoken = ptok->token;
  214. XXnode = ptok->node;
  215. fp = *(--or_ptr);
  216. pc = *(--or_ptr);
  217. }
  218. else
  219. {
  220. return((XX_USERTYPE) 0);
  221. }
  222. }
  223. }
  224. /*
  225. ** xxinit - Clear the input stack and get the first token.
  226. **/
  227. VOID
  228. xxinit(VOID)
  229. {
  230. register TOKSTACK *ptok;
  231. /* fill the first one with a token */
  232. Tokmax = Tokptr = ptok = &Tokstack[0];
  233. (*XXulex)(ptok);
  234. XXtoken = ptok->token;
  235. XXnode = ptok->node;
  236. #ifdef DEBUG
  237. WriteToCon( TEXT("xxinit, new token value is %d\n"),XXtoken);
  238. #endif
  239. }
  240. /*
  241. ** XXOVFL - a common subexpression, used in xxstkcheck macro above
  242. **/
  243. VOID
  244. xxovfl(VOID)
  245. {
  246. WriteToCon(TEXT("PANIC: expression too complex, please simplify;"));
  247. }
  248. /*
  249. * XXLEX - If a match occurs, get the next input token and return TRUE.
  250. * Otherwise return FALSE. If backup has occured, the token will be
  251. * fetched from the token stack. Otherwise the user routine will be called.
  252. */
  253. int
  254. xxnext(VOID)
  255. {
  256. register TOKSTACK *ptok;
  257. ptok = ++Tokptr;
  258. xxstkcheck(ptok < &Tokstack[DIMENSION(Tokstack)]);
  259. if (ptok > Tokmax)
  260. {
  261. (*XXulex)(ptok);
  262. Tokmax++;
  263. }
  264. XXtoken = ptok->token;
  265. XXnode = ptok->node;
  266. #ifdef DEBUG
  267. WriteToCon( TEXT("xxnext, new token value is %d\n"),XXtoken);
  268. #endif
  269. return(1);
  270. }
  271. #if XX_XACCLEX
  272. XXlex(VOID)
  273. {
  274. }
  275. #endif