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.

726 lines
19 KiB

  1. /*++
  2. Copyright (c) 1996-1997 Microsoft Corporation
  3. Module Name:
  4. ppdparse.h
  5. Abstract:
  6. Declarations for PPD parser
  7. Environment:
  8. PostScript driver, PPD parser
  9. Revision History:
  10. 08/20/96 -davidx-
  11. Common coding style for NT 5.0 drivers.
  12. 03/26/96 -davidx-
  13. Created it.
  14. --*/
  15. #ifndef _PPDPARSE_H_
  16. #define _PPDPARSE_H_
  17. //
  18. // PPD parser memory management functions
  19. //
  20. // NOTE: newly allocated memory is always zero initialized
  21. // The parser allocates its working memory from the heap and
  22. // everything is freed at the end when the heap is destroyed.
  23. //
  24. #define ALLOC_PARSER_MEM(pParserData, size) \
  25. ((PVOID) HeapAlloc((pParserData)->hHeap, HEAP_ZERO_MEMORY, (size)))
  26. //
  27. // Character constants
  28. //
  29. #define KEYWORD_CHAR '*'
  30. #define COMMENT_CHAR '%'
  31. #define SYMBOL_CHAR '^'
  32. #define SEPARATOR_CHAR ':'
  33. #define XLATION_CHAR '/'
  34. #define QUERY_CHAR '?'
  35. #define QUOTE_CHAR '"'
  36. #define TAB '\t'
  37. #define SPACE ' '
  38. #define CR '\r'
  39. #define LF '\n'
  40. #define IS_SPACE(c) ((c) == SPACE || (c) == TAB)
  41. #define IS_NEWLINE(c) ((c) == CR || (c) == LF)
  42. //
  43. // Masks to indicate which characters can appear in what fields
  44. //
  45. #define KEYWORD_MASK 0x01
  46. #define XLATION_MASK 0x02
  47. #define QUOTED_MASK 0x04
  48. #define STRING_MASK 0x08
  49. #define DIGIT_MASK 0x10
  50. #define HEX_DIGIT_MASK 0x20
  51. extern const BYTE gubCharMasks[256];
  52. #define IS_VALID_CHAR(ch) (gubCharMasks[(BYTE) (ch)] != 0)
  53. #define IS_MASKED_CHAR(ch, mask) (gubCharMasks[(BYTE) (ch)] & (mask))
  54. #define IS_DIGIT(ch) (gubCharMasks[(BYTE) (ch)] & DIGIT_MASK)
  55. #define IS_HEX_DIGIT(ch) (gubCharMasks[(BYTE) (ch)] & (DIGIT_MASK|HEX_DIGIT_MASK))
  56. #define IS_KEYWORD_CHAR(ch) ((ch) == KEYWORD_CHAR)
  57. //
  58. // Tags to identify various data types
  59. //
  60. #define VALUETYPE_NONE 0x01
  61. #define VALUETYPE_STRING 0x02
  62. #define VALUETYPE_QUOTED 0x04
  63. #define VALUETYPE_SYMBOL 0x08
  64. #define VALUETYPE_MASK 0xff
  65. //
  66. // Error code constants
  67. //
  68. #define PPDERR_NONE 0
  69. #define PPDERR_MEMORY (-1)
  70. #define PPDERR_FILE (-2)
  71. #define PPDERR_SYNTAX (-3)
  72. #define PPDERR_EOF (-4)
  73. typedef INT PPDERROR;
  74. //
  75. // Special length value to indicate that an invocation string is defined by a symbol.
  76. // Normal invocation strings must be shorter than this length.
  77. //
  78. #define SYMBOL_INVOCATION_LENGTH 0x80000000
  79. #define MARK_SYMBOL_INVOC(pInvoc) ((pInvoc)->dwLength |= SYMBOL_INVOCATION_LENGTH)
  80. #define CLEAR_SYMBOL_INVOC(pInvoc) ((pInvoc)->dwLength &= ~SYMBOL_INVOCATION_LENGTH)
  81. #define IS_SYMBOL_INVOC(pInvoc) ((pInvoc)->dwLength & SYMBOL_INVOCATION_LENGTH)
  82. typedef struct _INVOCOBJ {
  83. DWORD dwLength; // length of invocation string
  84. PVOID pvData; // points to invocation string data
  85. } INVOCOBJ, *PINVOCOBJ;
  86. //
  87. // Data structure for representing a data buffer
  88. //
  89. typedef struct _BUFOBJ {
  90. DWORD dwMaxLen;
  91. DWORD dwSize;
  92. PBYTE pbuf;
  93. } BUFOBJ, *PBUFOBJ;
  94. //
  95. // Always reserve one byte in a buffer so that we can append a zero byte at the end.
  96. //
  97. #define IS_BUFFER_FULL(pbo) ((pbo)->dwSize + 1 >= (pbo)->dwMaxLen)
  98. #define IS_BUFFER_EMPTY(pbo) ((pbo)->dwSize == 0)
  99. #define CLEAR_BUFFER(pbo) { (pbo)->dwSize = 0; (pbo)->pbuf[0] = 0; }
  100. #define ADD_CHAR_TO_BUFFER(pbo, c) (pbo)->pbuf[(pbo)->dwSize++] = (BYTE)(c)
  101. #define SET_BUFFER(pbo, buf) \
  102. { (pbo)->pbuf = (PBYTE) (buf); (pbo)->dwMaxLen = sizeof(buf); (pbo)->dwSize = 0; }
  103. //
  104. // Maximum length for keyword, option, and translation strings.
  105. // NOTE: we are being very lenient here because these limits are arbitrary and
  106. // there is nothing that prevents us from handling longer lengths.
  107. //
  108. #define MAX_KEYWORD_LEN 64
  109. #define MAX_OPTION_LEN 64
  110. #define MAX_XLATION_LEN 256
  111. //
  112. // Constants to indicate whether an input slot requires PageRegion invocation
  113. //
  114. #define REQRGN_UNKNOWN 0
  115. #define REQRGN_TRUE 1
  116. #define REQRGN_FALSE 2
  117. //
  118. // Data structure for representing a mapped file object
  119. //
  120. typedef struct _FILEOBJ {
  121. HFILEMAP hFileMap;
  122. PBYTE pubStart;
  123. PBYTE pubEnd;
  124. PBYTE pubNext;
  125. DWORD dwFileSize;
  126. PTSTR ptstrFileName;
  127. INT iLineNumber;
  128. BOOL bNewLine;
  129. } FILEOBJ, *PFILEOBJ;
  130. #define END_OF_FILE(pFile) ((pFile)->pubNext >= (pFile)->pubEnd)
  131. #define END_OF_LINE(pFile) ((pFile)->bNewLine)
  132. //
  133. // Data structure for representing a singly-linked list
  134. //
  135. typedef struct _LISTOBJ {
  136. PVOID pNext; // pointer to next node
  137. PSTR pstrName; // item name
  138. } LISTOBJ, *PLISTOBJ;
  139. //
  140. // Data structure for representing symbol information
  141. //
  142. typedef struct _SYMBOLOBJ {
  143. PVOID pNext; // pointer to the next symbol
  144. PSTR pstrName; // symbol name
  145. INVOCOBJ Invocation; // symbol data
  146. } SYMBOLOBJ, *PSYMBOLOBJ;
  147. //
  148. // Data structure for representing job patch file information
  149. //
  150. typedef struct _PATCHFILEOBJ {
  151. PVOID pNext; // pointer to the next patch
  152. PSTR pstrName; // string of the patch number
  153. LONG lPatchNo; // number of the patch as set in the PPD file
  154. INVOCOBJ Invocation; // symbol data
  155. } JOBPATCHFILEOBJ, *PJOBPATCHFILEOBJ;
  156. //
  157. // Data structure for representing a default font substitution entry
  158. //
  159. typedef struct _TTFONTSUB {
  160. PVOID pNext; // pointer to the next entry
  161. PSTR pstrName; // TT font family name
  162. INVOCOBJ Translation; // TT font family name translation
  163. INVOCOBJ PSName; // PS font family name
  164. } TTFONTSUB, *PTTFONTSUB;
  165. //
  166. // Data structure for representing printer feature option information
  167. //
  168. // Need to change translation string field to make it ready for Unicode encoding.
  169. //
  170. typedef struct _OPTIONOBJ {
  171. PVOID pNext; // pointer to the next option
  172. PSTR pstrName; // option name
  173. INVOCOBJ Translation; // translation string
  174. INVOCOBJ Invocation; // invocation string
  175. DWORD dwConstraint; // list of UIConstraints associated with this option
  176. } OPTIONOBJ, *POPTIONOBJ;
  177. //
  178. // Data structure for representing paper size information
  179. //
  180. typedef struct _PAPEROBJ {
  181. OPTIONOBJ Option; // generic option information
  182. SIZE szDimension; // paper dimension
  183. RECT rcImageArea; // imageable area
  184. } PAPEROBJ, *PPAPEROBJ;
  185. //
  186. // Default paper size when the information in the PPD file is invalid
  187. //
  188. #define DEFAULT_PAPER_WIDTH 215900 // 8.5 inch measured in microns
  189. #define DEFAULT_PAPER_LENGTH 279400 // 11 inch measured in microns
  190. //
  191. // paper size values for Letter and A4
  192. //
  193. #define LETTER_PAPER_WIDTH 215900 // 8.5 inch measured in microns
  194. #define LETTER_PAPER_LENGTH 279400 // 11 inch measured in microns
  195. #define A4_PAPER_WIDTH 210058 // 8.27 inch measured in microns
  196. #define A4_PAPER_LENGTH 296926 // 11.69 inch measured in microns
  197. //
  198. // Data structure for representing input slot information
  199. //
  200. typedef struct _TRAYOBJ {
  201. OPTIONOBJ Option; // generic option information
  202. DWORD dwReqPageRgn; // whether PageRegion invocation is required
  203. DWORD dwTrayIndex; // index used for DEVMODE.dmDefaultSource field
  204. } TRAYOBJ, *PTRAYOBJ;
  205. //
  206. // Data structure for representing output bin information
  207. //
  208. typedef struct _BINOBJ {
  209. OPTIONOBJ Option; // generic option information
  210. BOOL bReversePrint; // first page comes out at bottom?
  211. } BINOBJ, *PBINOBJ;
  212. //
  213. // Data structure for representing memory configuration information
  214. //
  215. typedef struct _MEMOBJ {
  216. OPTIONOBJ Option; // generic option information
  217. DWORD dwFreeVM; // amount of free VM
  218. DWORD dwFontMem; // size of font cache memory
  219. } MEMOBJ, *PMEMOBJ;
  220. //
  221. // Data structure for representing memory configuration information
  222. //
  223. typedef struct _RESOBJ {
  224. OPTIONOBJ Option; // generic option information
  225. FIX_24_8 fxScreenAngle; // suggested screen angle
  226. FIX_24_8 fxScreenFreq; // suggested screen frequency
  227. } RESOBJ, *PRESOBJ;
  228. //
  229. // Data structure for representing printer feature information
  230. //
  231. typedef struct _FEATUREOBJ {
  232. PVOID pNext; // pointer to next printer feature
  233. PSTR pstrName; // feature name
  234. INVOCOBJ Translation; // translation string
  235. PSTR pstrDefault; // default option name
  236. DWORD dwFeatureID; // predefined feature identifier
  237. BOOL bInstallable; // whether the feature is an installble option
  238. DWORD dwUIType; // type of feature option list
  239. INVOCOBJ QueryInvoc; // query invocation string
  240. DWORD dwConstraint; // list of UIConstraints associated with this feature
  241. DWORD dwOptionSize; // size of each option item
  242. POPTIONOBJ pOptions; // pointer to list of options
  243. } FEATUREOBJ, *PFEATUREOBJ;
  244. //
  245. // Data structure for representing device font information
  246. //
  247. // NOTE: The first three fields of this structure must match the
  248. // first three fields of OPTIONOBJ structure.
  249. //
  250. typedef struct {
  251. PVOID pNext; // pointer to next device font
  252. PSTR pstrName; // font name
  253. INVOCOBJ Translation; // translation string
  254. PSTR pstrEncoding; // font encoding information
  255. PSTR pstrCharset; // charsets supported
  256. PSTR pstrVersion; // version string
  257. DWORD dwStatus; // status
  258. } FONTREC, *PFONTREC;
  259. //
  260. // Data structure for maintain information used by the parser
  261. //
  262. typedef struct _PARSERDATA {
  263. PVOID pvStartSig; // signature used for debugging
  264. HANDLE hHeap; // memory heap used by the parser
  265. PFILEOBJ pFile; // pointer to current file object
  266. PDWORD pdwKeywordHashs; // precomputed hash values for built-in keywords
  267. PBYTE pubKeywordCounts; // count the occurrence of built-in keywords
  268. BOOL bErrorFlag; // semantic error flag
  269. INT iIncludeLevel; // current include level
  270. PFEATUREOBJ pOpenFeature; // pointer to the open feature
  271. BOOL bJclFeature; // whether we're inside JCLOpenUI/JCLCloseUI
  272. BOOL bInstallableGroup; // whether we're inside InstallableOptions group
  273. PLISTOBJ pPpdFileNames; // list of source PPD filenames
  274. INVOCOBJ NickName; // printer model name
  275. DWORD dwChecksum32; // 32-bit CRC checksum of ASCII text PPD file
  276. DWORD dwPpdFilever; // PPD file version
  277. DWORD dwSpecVersion; // PPD spec version number
  278. DWORD dwPSVersion; // PostScript interpreter version number
  279. INVOCOBJ PSVersion; // PSVersion string
  280. INVOCOBJ Product; // Product string
  281. PFEATUREOBJ pFeatures; // List of printer features
  282. PLISTOBJ pUIConstraints; // List of UIConstraints
  283. PLISTOBJ pOrderDep; // List of OrderDependency
  284. PLISTOBJ pQueryOrderDep; // List of QueryOrderPendency
  285. PFONTREC pFonts; // List of device fonts
  286. PJOBPATCHFILEOBJ pJobPatchFiles; // List of JobPatchFile invocation strings
  287. PSYMBOLOBJ pSymbols; // List of symbol definitions
  288. PTTFONTSUB pTTFontSubs; // List of TT font substitution entries
  289. INVOCOBJ Password; // password invocation string
  290. INVOCOBJ ExitServer; // exitserver invocation string
  291. INVOCOBJ PatchFile; // PatchFile invocation string
  292. INVOCOBJ JclBegin; // PJL job start invocation string
  293. INVOCOBJ JclEnterPS; // PJL enter PS invocation string
  294. INVOCOBJ JclEnd; // PJL job end invocation string
  295. INVOCOBJ ManualFeedFalse; // ManualFeed False invocation string
  296. DWORD dwLangEncoding; // language encoding
  297. UINT uCodePage; // code page corresponding to language encoding
  298. DWORD dwLangLevel; // PostScript language level
  299. DWORD dwFreeMem; // default amount of free VM
  300. DWORD dwThroughput; // throughput
  301. DWORD dwJobTimeout; // suggested job timeout value
  302. DWORD dwWaitTimeout; // suggested wait timeout value
  303. DWORD dwColorDevice; // whether the device supports color
  304. DWORD dwProtocols; // protocols supported by the device
  305. DWORD dwTTRasterizer; // TrueType rasterizer option
  306. DWORD dwLSOrientation; // default landscape orientation
  307. FIX_24_8 fxScreenFreq; // default halftone screen frequency
  308. FIX_24_8 fxScreenAngle; // default halftone screen angle
  309. BOOL bDefReversePrint; // DefaultOutputOrder
  310. BOOL bDefOutputOrderSet; // TRUE if bDefReversePrint is set through PPD
  311. DWORD dwExtensions; // language extensions
  312. DWORD dwSetResType; // how to set resolution
  313. DWORD dwReqPageRgn; // RequiresPageRegion All: information
  314. DWORD dwPpdFlags; // misc. PPD flags
  315. PSTR pstrDefaultFont; // DefaultFont: information
  316. DWORD dwCustomSizeFlags; // custom page size flags and parameters
  317. CUSTOMSIZEPARAM CustomSizeParams[CUSTOMPARAM_MAX];
  318. BOOL bEuroInformationSet;// the Euro keyword was found in the PPD
  319. BOOL bHasEuro; // printer device fonts have the Euro
  320. BOOL bTrueGray; // TrueGray shall be detected by default
  321. //
  322. // Use for mapping NT4 feature indices to NT5 feature indices
  323. //
  324. WORD wNt4Checksum;
  325. INT iManualFeedIndex;
  326. INT iDefInstallMemIndex;
  327. INT iReqPageRgnIndex;
  328. BYTE aubOpenUIFeature[MAX_GID];
  329. //
  330. // Buffers used to hold the content of various fields in the current entry
  331. //
  332. BUFOBJ Keyword;
  333. BUFOBJ Option;
  334. BUFOBJ Xlation;
  335. BUFOBJ Value;
  336. DWORD dwValueType;
  337. CHAR achKeyword[MAX_KEYWORD_LEN];
  338. CHAR achOption[MAX_OPTION_LEN];
  339. CHAR achXlation[MAX_XLATION_LEN];
  340. PSTR pstrValue;
  341. //
  342. // These are used for compacting parsed PPD information into
  343. // binary printer description data.
  344. //
  345. PBYTE pubBufStart;
  346. DWORD dwPageSize;
  347. DWORD dwCommitSize;
  348. DWORD dwBufSize;
  349. PINFOHEADER pInfoHdr;
  350. PUIINFO pUIInfo;
  351. PPPDDATA pPpdData;
  352. PVOID pvEndSig; // signature used for debugging
  353. } PARSERDATA, *PPARSERDATA;
  354. //
  355. // Simple integrity check on the parser data structure
  356. //
  357. #define VALIDATE_PARSER_DATA(pParserData) \
  358. ASSERT((pParserData) != NULL && \
  359. (pParserData)->pvStartSig == pParserData && \
  360. (pParserData)->pvEndSig == pParserData)
  361. //
  362. // Parse a PPD file
  363. //
  364. PPDERROR
  365. IParseFile(
  366. PPARSERDATA pParserData,
  367. PTSTR ptstrFilename
  368. );
  369. //
  370. // Grow a buffer object when it becomes full
  371. //
  372. PPDERROR
  373. IGrowValueBuffer(
  374. PBUFOBJ pBufObj
  375. );
  376. //
  377. // Parse one entry from a PPD file
  378. //
  379. PPDERROR
  380. IParseEntry(
  381. PPARSERDATA pParserData
  382. );
  383. //
  384. // Interpret an entry parsed from a PPD file
  385. //
  386. PPDERROR
  387. IInterpretEntry(
  388. PPARSERDATA pParserData
  389. );
  390. //
  391. // Build up data structures to speed up keyword lookup
  392. //
  393. BOOL
  394. BInitKeywordLookup(
  395. PPARSERDATA pParserData
  396. );
  397. //
  398. // Find a named item from a linked-list
  399. //
  400. PVOID
  401. PvFindListItem(
  402. PVOID pvList,
  403. PCSTR pstrName,
  404. PDWORD pdwIndex
  405. );
  406. //
  407. // Convert embedded hexdecimal strings into binary data
  408. //
  409. BOOL
  410. BConvertHexString(
  411. PBUFOBJ pBufObj
  412. );
  413. //
  414. // Search for a keyword from a string table
  415. //
  416. typedef struct _STRTABLE {
  417. PCSTR pstrKeyword; // keyword name
  418. DWORD dwValue; // corresponding value
  419. } STRTABLE;
  420. typedef const STRTABLE *PCSTRTABLE;
  421. BOOL
  422. BSearchStrTable(
  423. PCSTRTABLE pTable,
  424. PSTR pstrKeyword,
  425. DWORD *pdwValue
  426. );
  427. //
  428. // Parse an unsigned floating-point number from a character string
  429. //
  430. BOOL
  431. BGetFloatFromString(
  432. PSTR *ppstr,
  433. PLONG plValue,
  434. INT iType
  435. );
  436. #define FLTYPE_ERROR (-1)
  437. #define FLTYPE_POINT 0
  438. #define FLTYPE_INT 1
  439. #define FLTYPE_FIX 2
  440. #define FLTYPE_POINT_ROUNDUP 3
  441. #define FLTYPE_POINT_ROUNDDOWN 4
  442. //
  443. // Parse an unsigned decimal integer value from a character string
  444. //
  445. BOOL
  446. BGetIntegerFromString(
  447. PSTR *ppstr,
  448. LONG *plValue
  449. );
  450. //
  451. // Strip off the keyword prefix character from the input string
  452. //
  453. PCSTR
  454. PstrStripKeywordChar(
  455. PCSTR pstrKeyword
  456. );
  457. //
  458. // Find the next word in a character string (Words are separated by spaces)
  459. //
  460. BOOL
  461. BFindNextWord(
  462. PSTR *ppstr,
  463. PSTR pstrWord
  464. );
  465. #define MAX_WORD_LEN MAX_KEYWORD_LEN
  466. //
  467. // Create an input file object
  468. //
  469. PFILEOBJ
  470. PCreateFileObj(
  471. PTSTR ptstrFilename
  472. );
  473. //
  474. // Delete an input file object
  475. //
  476. VOID
  477. VDeleteFileObj(
  478. PFILEOBJ pFile
  479. );
  480. //
  481. // Read the next character from the input file
  482. // Special character to indicate end-of-file condition
  483. //
  484. INT
  485. IGetNextChar(
  486. PFILEOBJ pFile
  487. );
  488. #define EOF_CHAR (-1)
  489. //
  490. // Return the last character read to the input file
  491. //
  492. VOID
  493. VUngetChar(
  494. PFILEOBJ pFile
  495. );
  496. //
  497. // Skip all characters until the next non-space character
  498. //
  499. VOID
  500. VSkipSpace(
  501. PFILEOBJ pFile
  502. );
  503. //
  504. // Skip the remaining characters on the current input line
  505. //
  506. VOID
  507. VSkipLine(
  508. PFILEOBJ pFile
  509. );
  510. //
  511. // Check if a character string only consists of printable 7-bit ASCII characters
  512. //
  513. BOOL
  514. BIs7BitAscii(
  515. PSTR pstr
  516. );
  517. //
  518. // Display a syntax error message
  519. //
  520. PPDERROR
  521. ISyntaxErrorMessage(
  522. PFILEOBJ pFile,
  523. PSTR pstrMsg
  524. );
  525. #if DBG
  526. #define ISyntaxError(pFile, errmsg) ISyntaxErrorMessage(pFile, errmsg)
  527. #else
  528. #define ISyntaxError(pFile, errmsg) ISyntaxErrorMessage(pFile, NULL)
  529. #endif
  530. //
  531. // Keyword string for various predefined features
  532. //
  533. extern const CHAR gstrDefault[];
  534. extern const CHAR gstrPageSizeKwd[];
  535. extern const CHAR gstrInputSlotKwd[];
  536. extern const CHAR gstrManualFeedKwd[];
  537. extern const CHAR gstrCustomSizeKwd[];
  538. extern const CHAR gstrLetterSizeKwd[];
  539. extern const CHAR gstrA4SizeKwd[];
  540. extern const CHAR gstrLongKwd[];
  541. extern const CHAR gstrShortKwd[];
  542. extern const CHAR gstrTrueKwd[];
  543. extern const CHAR gstrFalseKwd[];
  544. extern const CHAR gstrOnKwd[];
  545. extern const CHAR gstrOffKwd[];
  546. extern const CHAR gstrNoneKwd[];
  547. extern const CHAR gstrVMOptionKwd[];
  548. extern const CHAR gstrInstallMemKwd[];
  549. extern const CHAR gstrDuplexTumble[];
  550. extern const CHAR gstrDuplexNoTumble[];
  551. #endif // !_PPDPARSE_H_