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.

290 lines
8.4 KiB

  1. // Copyright (c) 1996-1999 Microsoft Corporation
  2. ------ state of the system ---------
  3. Each parsing of an open brace should change
  4. the state of the system.
  5. As a feature, option, switch(feature), case(option)
  6. or other construct is parsed this is noted.
  7. this construct stack allows us to select the appropriate
  8. context for parsing:
  9. is this a local keyword to this option (construct) or is it
  10. EXTERN:?
  11. What tree structure should be built for this construct?
  12. then the parsing code should continue parsing
  13. tokens as normal.
  14. There will be tables that state what the
  15. local keywords are for each situation.
  16. constructs:
  17. UIGroup, Feature, Option, Switch, Case,
  18. Commands, Font, OEM
  19. state stack:
  20. each state is of the form: state / symbol
  21. The stack is empty at the root level.
  22. state allowed transitions may contain
  23. root UIGroup any global attributes
  24. Feature
  25. Switch
  26. Commands
  27. Font
  28. OEM
  29. UIGroup Feature none
  30. UIGroup
  31. Feature Switch feature attributes
  32. Options
  33. Switch Case none
  34. Options Switch option attributes
  35. relocatable Global Attributes
  36. Case Switch
  37. relocatable local Attributes
  38. of immediately enclosing
  39. construct outside of Switch.
  40. relocatable Global Attributes
  41. Commands none command attributes
  42. ShortCommands none cmdName:invocation
  43. Font none font attributes
  44. OEM none oem attributes
  45. Note: Commands and Fonts are considered
  46. relocatable Global Attributes
  47. Tables: root attributes (divide into relocatable and non)
  48. feature attributes ()
  49. option attributes ()
  50. command attributes
  51. font attributes
  52. oem attributes
  53. Tables of allowed transitions:
  54. Rules: how to construct a tree and where to plant the tree
  55. for a local or global attribute
  56. ---- implementation of this state machine -------
  57. typedef enum {CONSTRUCT, LOCAL, GLOBAL,
  58. INVALID_CONSTRUCT, INVALID_LOCAL, INVALID_GLOBAL,
  59. INVALID_UNRECOGNIZED, COMMENT, EOF } keywordClass ;
  60. GroundState()
  61. {
  62. STATE StateStack[] ;
  63. for(1)
  64. {
  65. extract Keyword(keyword)
  66. class = ClassifyKeyword(keyword)
  67. switch (class)
  68. {
  69. case (CONSTRUCT):
  70. parseSymbol(symbol) ;
  71. parseOpenBrace() ; // somewhere we need to register symbol
  72. // and allocate memory for structure
  73. // and return ptr or index to new
  74. // or existing structure
  75. changeState(keyword) ;
  76. case (COMMENT):
  77. absorbCommentLine() ;
  78. case (LOCAL) :
  79. ProcessLocalAttribute(keyword) ;
  80. case (GLOBAL) :
  81. ProcessGlobalAttribute(keyword) ;
  82. case (SPECIAL) :
  83. ProcessSpecialAttribute(keyword) ;
  84. case (EOF)
  85. return(1);
  86. default:
  87. ErrorHandling() ;
  88. }
  89. if(rc == FATAL)
  90. return(1);
  91. }
  92. }
  93. class = ClassifyKeyword(keyword)
  94. {
  95. if(commentline)
  96. return(COMMENT) ;
  97. if(EOF)
  98. return(EOF) ;
  99. The current state determines which sets of
  100. keywords are allowed.
  101. state = DetermineCurrentState()
  102. implement this table:
  103. for each state there is a list of all the keywords
  104. arranged in a fixed order (by keyword ID) each keyword
  105. is assigned a classification:
  106. Valid Constructs
  107. InValid Constructs
  108. Valid Local Attribute
  109. InValid Local Attribute
  110. Valid Global Attribute
  111. InValid Global Attribute
  112. Valid Special Attribute
  113. InValid Special Attribute
  114. if(keyword not found it table)
  115. return(INVALID_UNRECOGNIZED) ;
  116. return(classTable[keyword][state]) ;
  117. }
  118. typedef enum {ROOT, UIGROUP, FEATURE, SWITCH, OPTIONS, CASE_ROOT,
  119. CASE_FEATURE, CASE_OPTION, COMMAND, SHORT_COMMAND,
  120. FONT, OEM, any other passive construct} STATES ;
  121. Sample Table
  122. KEYWORD STATES ---->
  123. *Command
  124. *UIGroup *Switch *CaseRoot *CaseOption *Font
  125. *Root *Feature *Options *CaseFeature *ShortCmd *OEM
  126. UIGroup : VC VC IC IC IC IC IC IC IC IC IC IC
  127. Feature : VC VC IC IC IC IC IC IC IC IC IC IC
  128. Switch : VC IC VC IC VC VC VC VC IC IC IC IC
  129. Options : IC IC VC IC IC IC IC IC IC IC IC IC
  130. Case : IC IC IC VC IC IC IC IC IC IC IC IC
  131. Command : VC IC IC IC VC VC VC VC IC IC IC IC
  132. Font : VC IC IC IC VC VC VC VC IC IC IC IC
  133. OEM : VC IC IC IC IC IC IC IC IC IC IC IC
  134. UIConstraints : IS IS VS IS VS IS IS IS IS IS IS IS
  135. note: UIConstraints appearing in a Feature is treated differently
  136. than appearing under Options. The processing of UIConstraints
  137. causes one, two or many elements to be added to the Constraints
  138. Array. This is in stark contrast to normal keywords hence
  139. the classification of Special.
  140. state stack:
  141. each state is of the form: state / symbol
  142. DetermineCurrentState()
  143. {
  144. // this state is only used to determine
  145. // which catagories of keywords are
  146. // assigned which TYPES in ClassifyKeyword().
  147. if(CurState == 0)
  148. return(ROOT) ; // No further processing needed.
  149. return(stateStack[CurState - 1].state) ;
  150. }
  151. changeState(keyword, symbol, mode)
  152. {
  153. // Change needed: shortcut *Command
  154. // does not initiate a state change. This should
  155. // be treated as a special keyword.
  156. // mode determines if the *Command keyword
  157. // introduces a normal command construct or
  158. // the short version.
  159. switch(keyword)
  160. {
  161. case (*UIGroup):
  162. addState(UIGROUP, symbol);
  163. case (*Feature):
  164. addState(FEATURE, symbol);
  165. case (*Switch):
  166. addState(SWITCH, symbol);
  167. case (*Option):
  168. addState(OPTIONS, symbol);
  169. case (*Font):
  170. addState(FONT, symbol);
  171. case (*OEM):
  172. addState(OEM, symbol);
  173. case (*Command):
  174. {
  175. if(mode == short)
  176. addState(SHORT_CMD, symbol);
  177. else
  178. addState(COMMAND, symbol);
  179. }
  180. case (*Case):
  181. {
  182. if(stateStack[CurState - 2].state == ROOT ||
  183. stateStack[CurState - 2].state == CASE_ROOT)
  184. addState(CASE_ROOT, symbol);
  185. if(stateStack[CurState - 2].state == FEATURE ||
  186. stateStack[CurState - 2].state == CASE_FEATURE)
  187. addState(CASE_FEATURE, symbol);
  188. if(stateStack[CurState - 2].state == OPTIONS ||
  189. stateStack[CurState - 2].state == CASE_OPTIONS)
  190. addState(CASE_OPTIONS, symbol);
  191. }
  192. }
  193. }
  194. // these two functions will grow an appropriate
  195. // tree for each keyword based on the StateStack
  196. // and plant the tree in the appropriate attribute
  197. // field in the appropriate structure, (index) etc.
  198. // or add a branch to an existing tree,
  199. // and set the value at the node of the tree.
  200. ProcessLocalAttribute(keyword) ;
  201. ProcessGlobalAttribute(keyword, lpvalue)
  202. {
  203. locate entry in Dglobals corresponding
  204. to keyword.
  205. OR the current branch (constructed using the state stack)
  206. with any existing tree pointed to by entry in Dglobals.
  207. if this branch exists in the existing tree, locate the offset
  208. in heap and overwrite that by
  209. (lptype)(lpRef + attributeTree[i].offset) = (lptype)lpvalue ;
  210. otherwise
  211. offset = lpCurHeapPos - lpRef ;
  212. lpCurHeapPos += sizeof(datatype) ;
  213. Note: an attribute tree should not be constructed
  214. piecemeal. It is an error if the tree is subsequently
  215. redefined/elaborated using a different feature nesting
  216. order.
  217. }
  218. may need to keep a table for each keyword
  219. with the following info per keyword.
  220. keyword, datastructure, offset within datastructure, sizeof(data)