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.

183 lines
6.9 KiB

  1. // Copyright (c) 1996-1999 Microsoft Corporation
  2. A quick tour of the GPD parser:
  3. A GPD source file is consists of a series of
  4. statements. Each statement typically consists of
  5. a Keyword - value pair separated by a colon delimiter.
  6. The parser classifies keywords into Attribute and
  7. non-Attribute keywords. Attribute keywords require
  8. a context before they can be defined. They are used
  9. to define the value for individual attributes.
  10. Non-Attribute keywords establish the context for
  11. the other keywords. Construct keywords are examples
  12. of Non-Attribute keywords.
  13. BcreateGPDbinary() - framwrk1.c: current entry point for
  14. parsing of GPD source file. Calls functions to initialize
  15. gMasterTable[] which contains almost all allocated buffers.
  16. Then calls other functions to process the GPD file.
  17. BcreateTokenMap() - token1.c : memory maps root file, SOURCEBUFFER holds
  18. pointers to memory address and current position.
  19. They are accessed via the macros mpubSrcRef and mdwSrcInd.
  20. The source file is parsed into Keywords and Values.
  21. Since a variety of syntax rules are allowed for the different
  22. value types, the parsing is very liberal with little syntax
  23. checking.
  24. All arbitrary whitespace is discarded (replaced by space chars).
  25. This includes all comments and continuation lines.
  26. One TKMAP structure is initialized for each
  27. GPD statement parsed. If the keyword is found to be
  28. a non-Attribute keyword, its keywordID is stored in the
  29. TKMAP, else it is marked as an "Unidentified" keyword.
  30. BevaluateMacros() Macro replacement stage: Not implemented yet.
  31. This is where macro substitution and shortcut expansion
  32. occurs. Some token map entries are deleted and new ones
  33. are added.
  34. First pass of BInterpretTokens():
  35. *Feature: PaperSize
  36. {
  37. *Option: Letter
  38. {
  39. }
  40. }
  41. *Command: CmdStartJob
  42. {
  43. }
  44. Each entry in the Tokenmap is examined.
  45. If the entry is a Construct keyword (a subset of non-Attribute
  46. keyword), the associated symbolname value is registered in the
  47. appropriate symboltree. For example, BlockMacroNames, FontCartridge names,
  48. and FeatureNames occupy different symboltrees (and hence different
  49. namespaces). OptionNames occupy subtrees branching from the
  50. associated FeatureName.
  51. Each Construct keyword encountered causes a statemachine change.
  52. The previous state is restored when the closing brace is encountered.
  53. If the entry is an attribute keyword, the current state
  54. is used to determine which construct they are a part of
  55. and hence which dictionary to use. The EXTERN_GLOBAL
  56. prefix will override this for global attributes, permitting
  57. globals to be used within other constructs.
  58. The dictionary defines
  59. the name of the keyword, what type of keyword it is, if
  60. it is an Attribute, the subtype determines what structure
  61. the value is stored in and what state the keyword
  62. may legally appear in, the offset determines the location within
  63. the structure, the AllowedValue determines the syntax of the value
  64. and the format it is stored. The namespaces of attributes belonging
  65. to different constructs are separate. Hence the attribute *Name used in
  66. a *Feature construct is not confused with *Name used within an *Option
  67. construct.
  68. BallocateCountableObjects():
  69. By counting the number of symbols registered in the first pass
  70. of BInterpretTokens() we know how many structures of each type
  71. to alloc. Now we can actually store the values associated
  72. with the attribute keywords.
  73. Second pass of BInterpretTokens():
  74. Construct keywords are again parsed to establish the current
  75. state.
  76. Attribute Keywords are checked against the current state.
  77. Does this Keyword belong in this state?
  78. If the attribute is legal, the parser proceeds to
  79. a) locate the root of attribute.
  80. b) create or identify an existing branch in the attribute
  81. tree which corresponds to the set of states defined by
  82. the nested constructs.
  83. c) parse the value token associated with the attribute
  84. and store its value in the appropriate format.
  85. d) write a link into the appropriate node at the end of the
  86. branch in the attribute tree.
  87. example, a string referenced from GlobalAttributes structure:
  88. typedef struct
  89. {
  90. ....
  91. ATREEREF atrModelName ; contains index of an
  92. ATTRIB_TREE structure in the array of structures
  93. ...
  94. } GLOBALATTRIB, * PGLOBALATTRIB ; // the prefix tag shall be 'ga'
  95. The field dwOffset in a ATTRIB_TREE leaf node contains
  96. a heap offset which contains a STRINGREF (aka ARRAYREF)
  97. which contains the heap offset and byte count of the
  98. actual string.
  99. BInterpretTokens()
  100. BidentifyAttributeKeyword(ptkmap + wEntry) )
  101. BprocessAttribute(ptkmap + wEntry) ;
  102. BstoreGlobalAttrib(ptkmap) ; // different function for each construct
  103. // identifies which structure and offset contains ATREEREF
  104. // (root of tree)
  105. BaddBranchToTree(ptkmap, (PATREEREF)(pub + dwOffset)) ;
  106. // navigates or adds branch to tree
  107. BaddValueToHeap() ;
  108. // if value is stored in dedicated structure,
  109. // accesses or allocates that element, provides
  110. // address of that memory location to
  111. BparseAndWrite((PBYTE)pcmd + dwOffset, ptkmap,
  112. FALSE, NULL ) )
  113. // else the address of the dwOffset field is provided.
  114. // this function determines the type of value
  115. // to be parsed and calls the appropriate
  116. // function to parse the token and to store
  117. // it in the proper format.
  118. BparseAndTerminateString(&aarValue, (PARRAYREF)pubTmp) ;
  119. Special cases:
  120. Is the attribute value stored in a dedicated structure ?
  121. ie does the value in the node of the attribute tree reference
  122. a heap offset or a dedicated structure?
  123. Does the root of the tree reference a heap offset or a
  124. ATTRIB_TREE structure?
  125. Does the attribute tree have a global default initializer node?
  126. Does each feature level in the attribute tree have a default
  127. initializer corresponding to the *default keyword?
  128. AddBranchToTree() - token2.c
  129. The loop uses the state stack to navigate or create a
  130. particular branch of the attribute tree,
  131. then after exiting the loop, the value is parsed
  132. and its heap offset is written to the node in the
  133. attribute tree.
  134. Value1.c : this module contains functions to parse
  135. the different value types defined in the GPD spec.
  136. integers, POINT, RECT, Constants, Symbols, strings,
  137. commands, LISTS, QualifiedNames, OrderDependency,
  138. Constraints and InvalidCombinations. (found in constrnt.c)
  139. Functions that parse Command invocations are found in command.c
  140. BconsolidateBuffers() this function copies portions of
  141. some buffers listed in gMasterTable[] into a new consolidated
  142. buffer. This buffer is saved as the *.BUD binary file.
  143. Code to create a snapshot and other helper functions.
  144. Not completed at this time.