Source code of Windows XP (NT5)
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.

819 lines
32 KiB

  1. /******************************************************************************
  2. MSOLEX.H
  3. Owner: smueller
  4. Copyright (c) 1997 Microsoft Corporation
  5. General Purpose Text Lexer definitions and prototypes
  6. There are currently multiple instances of this component in Office 9.
  7. Keep them in sync:
  8. %mso%\inc\msolex.h
  9. %otools%\src\em\emtest\msolex.h
  10. %ppt%\office\lexpp.h
  11. %word%\src\inc\lex.h
  12. FUTURE: some of these definitions don't need to be exported and could
  13. live in an msolex.i file.
  14. ******************************************************************************/
  15. #ifndef MSOLEX_H
  16. #define MSOLEX_H
  17. /*----------------------------------------------------------------------------
  18. Enabled features
  19. ----------------------------------------------------------------------------*/
  20. #define EM_MULT_DIM_SCAN
  21. /*----------------------------------------------------------------------------
  22. System limits
  23. ----------------------------------------------------------------------------*/
  24. #define ichTkLenMax 256 // Max token str len
  25. #define ichLexsCacheMax (ichTkLenMax - 1) // Mx num chars cached
  26. #define dirultkNotFound 30000 // arbitrarily lg. flag
  27. #define dtkNotFound dirultkNotFound // alias
  28. /*************************************************************************
  29. Types:
  30. tk Token returned by the lexer.
  31. lexs Lexer state structure.
  32. *************************************************************************/
  33. // Define state tables used by lexer (use with plexs->isttbl)
  34. #define isttblDefault 0 // Default MUST be 0
  35. #define isttblNoBlanks 1
  36. /* T K */
  37. /*----------------------------------------------------------------------------
  38. %%Structure: TK
  39. %%Contact: daleg
  40. Lexer token definitions.
  41. ----------------------------------------------------------------------------*/
  42. #ifndef TK_DEFINED
  43. // Definition of token type returned by lexer
  44. typedef int TK;
  45. #define TK_DEFINED
  46. #endif /* !TK_DEFINED */
  47. // Lexer tokens: Plain Text and Delimiters
  48. #define tk_RESCAN_ (-2) // Dummy: force rescan
  49. #define tkERROR (-1) // Lexer error
  50. #define tkNil 0 // No token at all
  51. #define tkEND_OBJ 1 // End of object
  52. #define tkPARA 2 // 0xB6 (Para mark)
  53. #define tkNEWLINE 3 // \n
  54. #define tkWSPC 4 // Blanks, tabs
  55. #define tkWSPCMULT 5 // Multiple Blanks
  56. #define tkTAB 6 // Tab character
  57. #define tkWORD 7 // E.g. abc
  58. #define tkINTEGER 8 // E.g. 123
  59. #define tkCOMMA 9 // ,
  60. #define tkPERIOD 10 // .
  61. #define tkEXCLAIM 11 // !
  62. #define tkPOUND 12 // #
  63. #define tkDOLLAR 13 // $
  64. #define tkPERCENT 14 // %
  65. #define tkAMPER 15 // &
  66. #define tkLPAREN 16 // (
  67. #define tkRPAREN 17 // )
  68. #define tkASTER 18 // *
  69. #define tkPLUS 19 // +
  70. #define tkMINUS 20 // -
  71. #define tkSLASH 21 // /
  72. #define tkCOLON 22 // :
  73. #define tkSEMI 23 // ;
  74. #define tkLESSTHAN 24 // <
  75. #define tkEQUAL 25 // =
  76. #define tkGREATER 26 // >
  77. #define tkQUEST 27 // ?
  78. #define tkATSIGN 28 // @
  79. #define tkLBRACK 29 // [
  80. #define tkRBRACK 30 // ]
  81. #define tkBSLASH 31 // \
  82. #define tkCARET 32 // ^
  83. #define tkUSCORE 33 // _
  84. #define tkBQUOTE 34 // `
  85. #define tkLBRACE 35 // {
  86. #define tkRBRACE 36 // }
  87. #define tkVBAR 37 // |
  88. #define tkTILDA 38 // ~
  89. #define tkDQUOTE 39 // "
  90. #define tkLDQUOTE 40 // " left curly dbl
  91. #define tkRDQUOTE 41 // " right curly dbl
  92. #define tkQUOTE 42 // '
  93. #define tkLQUOTE 43 // ' left curly sgl
  94. #define tkRQUOTE 44 // ' right curly sgl
  95. #define tkLCHEVRON 45 // << French LDQuote
  96. #define tkRCHEVRON 46 // >> French RDQuote
  97. #define tkENDASH 47 // - en-dash
  98. #define tkEMDASH 48 // -- em-dash
  99. // Lexer tokens: Plain-Text Symbol tokens
  100. #define tkSYMBOL 49 // Symbol char
  101. #define tkBULLET 50 // Std bullet char
  102. #define tkFEWORD 51 // FE word
  103. #define tkFESYMBOL 52 // FE symbol char
  104. #define tkFESPACE 53 // FE Space char
  105. // Lexer tokens: Plain-text formatting info
  106. #define tkSTARTCAP 54 // Word is capitalized
  107. #define tkALLCAPS 55 // Word is all caps
  108. #define tkHASCAPS 56 // Word has 1+ CAPs
  109. // Is TK valid (not tkNil and not tkERROR)
  110. #define FValidTk(tk) \
  111. ((tk) > 0)
  112. /* M S O L E X S */
  113. /*----------------------------------------------------------------------------
  114. %%Structure: MSOLEXS
  115. %%Contact: daleg
  116. AutoFormat LEX State
  117. Contains information about the Event Monitor lexer's current position
  118. in the document.
  119. This information is initialized by LexReset(), and advanced by other
  120. lexer APIs.
  121. ----------------------------------------------------------------------------*/
  122. // Callback typedefs
  123. typedef XCHAR (OFC_CALLBACK *PFNLEXBUF)(MSOCP cpLim, struct _MSOLEXS *plexs);
  124. typedef int (OFC_CALLBACK *PFNLEXRUN)(MSOCP cpLim, struct _MSOLEXS *plexs);
  125. typedef int (OFC_CALLBACK *PFNLEXTXT)
  126. (MSORULTK *prultk, const XCHAR **ppxch, int *pcch, struct _MSOLEXS *plexs);
  127. typedef void (OFC_CALLBACK *PFNLEXFMT)
  128. (int *pfForceTkBreak, struct _MSOLEXS *plexs);
  129. typedef int (OFC_CALLBACK *PFNLEXCNT)(struct _MSOLEXS *plexs);
  130. typedef struct _MSOLEXS
  131. {
  132. // --- values requiring initialization ---
  133. // Keyword lookup information
  134. struct _MSOKWTB *pkwtb; // Keyword-lookup tbl
  135. // Token-history cache information
  136. MSORULTKH rultkhToken; // Text Token cache
  137. // Formatting token-history cache information
  138. MSORULTKH rultkhFormat; // Format Token cache
  139. // Init state
  140. MSOBF fInited : 1; // Lexer inited?
  141. int isttbl; // Which STT?
  142. union
  143. {
  144. unsigned short grpfLexFlags;
  145. struct
  146. {
  147. MSOBF fNoReset : 1; // Reset leave alone
  148. MSOBF fLookup : 1; // Lookup name as kwd?
  149. MSOBF fLookupIntsAndSyms : 1; // Lookup ints as kwd?
  150. MSOBF fAllCapsAsFormat : 1; // ALLCAPS as fmt tk?
  151. MSOBF fRefetchOnOverscan : 1; // Force fetch on OS?
  152. MSOBF fSpare2 : 11;
  153. };
  154. };
  155. // Buffer management callback functions
  156. void *hObjectNil; // Nil object
  157. PFNLEXBUF pfnlexbuf; // Fetch next buffer
  158. PFNLEXRUN pfnlexrun; // Fetch next run
  159. PFNLEXTXT pfnlextxt; // Fetch token text
  160. PFNLEXFMT pfnlexfmt; // Gen format tokens
  161. PFNLEXCNT pfnlexrunDiscontig; // Next run contiguous?
  162. PFNLEXRUN pfnlexrunForceComplete; // Force tk to complete
  163. // Run state information
  164. int ichRun; // Index to vfli.rgch
  165. int cchLookahead; // Num chars lookahead
  166. // --- values initially zero ---
  167. // Run state information
  168. int cchRemain; // Num chars unlexed
  169. MSOCP cpRun; // CP of start of run
  170. MSOCP ccpRun; // Num of CPs in run
  171. MSOCP cpObject; // CP of start of obj
  172. int cchRun; // Num chars run
  173. // Token state information
  174. MSOCP cpTokenFirst; // CP of first char
  175. MSOCP dcpToken; // Num CPs in token
  176. MSOCP cpTokenNext; // CP of next token
  177. int tkTokenIndirect; // Indirect token
  178. int ichTokenFirst; // ich of first char
  179. const XCHAR *pxchTkStart; // First char in token
  180. const XCHAR *pxchNext; // Next char to lex
  181. const XCHAR *pxchRun; // First char of run
  182. const XCHAR *pxchBuffer; // Token string buffer
  183. const XCHAR *pxchBufferIp; // Buffer of obj at IP
  184. union
  185. {
  186. unsigned short grfCurTk;
  187. struct
  188. {
  189. MSOBF fMustSyncLexDocBuffer : 1; // Reset lexer?
  190. };
  191. };
  192. // Vanished/Created text handling
  193. #ifdef EM_LEX_VANISHED
  194. MSOCP cpFirstVanished; // CP of vanished
  195. MSOCP dcpVanished; // dcp of vanished txt
  196. #endif /* EM_LEX_VANISHED */
  197. MSOCP cpFirstCreated; // CP of created
  198. MSOCP dcpCreated; // dcp of created txt
  199. union
  200. {
  201. unsigned short grpfLineFlags;
  202. struct
  203. {
  204. MSOBF fAdjustTokenCps : 1; // Created/Vanished txt
  205. };
  206. };
  207. // Lexer state information
  208. int ichCache; // Num chars cached
  209. XCHAR rgxchCache[ichTkLenMax]; // Cache leading chars
  210. XCHAR rgxchHistToken[ichTkLenMax]; // Text of history tk
  211. void *pObject; // Current object(cell)
  212. void *pObjectIp; // Object at IP
  213. #ifdef EM_MULT_DIM_SCAN
  214. long iCol; // Column of cell
  215. long iRow; // Row of cell
  216. long iColIp; // Column of IP
  217. long iRowIp; // Row of IP
  218. int dcellScanToIp; // #rows/cols 2 prescan
  219. int iScanDirection; // 0 == row, 1 == col
  220. #endif /* EM_MULT_DIM_SCAN */
  221. MSOCP cpFirst; // CP start of scan
  222. MSOCP cpLim; // CP limit of scan
  223. MSOCP cpFirstDoc; // CP limit of scan
  224. MSOCP cpMacDoc; // CP limit of scan
  225. long wInterval; // Count of intervals
  226. // Format lexer state information
  227. union
  228. {
  229. unsigned long grpfFormatFlags;
  230. struct
  231. {
  232. MSOBF fBold : 1; // Is text bold?
  233. MSOBF fItalic : 1; // Is text italic?
  234. MSOBF fUnderline : 1; // Is text underlined?
  235. MSOBF fVanish : 1; // Is text hidden?
  236. MSOBF ico : 5; // Is text colored?
  237. MSOBF fSpareFmt : 7;
  238. };
  239. };
  240. union
  241. {
  242. unsigned short grpfEndFlags;
  243. struct
  244. {
  245. MSOBF fCreateEndObjCh : 1; // Create EOO tk?
  246. MSOBF fEOL : 1; // End of line?
  247. MSOBF fEOP : 1; // End of paragraph?
  248. };
  249. };
  250. // Asynchronous lexer support
  251. unsigned short iuState; // Async state
  252. MSOBF fInvalLexer : 1; // Lexer not synched?
  253. MSOBF fBufferAlloced : 1; // Obj buffer alloced?
  254. MSOBF fAsyncSpare4 : 14;
  255. MSOCP cpIp; // CP of IP if forced
  256. // Multiple lexical scan support
  257. MSOBF fDynAlloced : 1; // struct alloced?
  258. MSOBF fTkCacheDynAlloced : 1; // TK Cache alloced?
  259. MSOBF fFmtTkCacheDynAlloced : 1; // Format Che alloced?
  260. struct _MSOLEXS *plexsNext; // Next struct LIFO
  261. // App-specific goo
  262. void *pUserData; // Cast as desired
  263. } MSOLEXS;
  264. // grpfLexFlags
  265. #define MsoGrfLexFNoReset (1 << 0)
  266. #define MsoGrfLexFLookup (1 << 1)
  267. #define MsoGrfLexFLookupIntsAndSyms (1 << 2)
  268. #define MsoGrfLexFAllCapsAsFormat (1 << 3)
  269. #define MsoGrfLexFRefetchOnOverscan (1 << 4)
  270. extern unsigned short const **vppchtblCharTrans; // Ptr to lexer ch tbl
  271. #ifdef EM_MULT_DIM_SCAN
  272. #define iScanVert 0
  273. #define iScanHoriz 1
  274. #endif /* EM_MULT_DIM_SCAN */
  275. // Return the object the lexer is currently scanning
  276. #define PobjectLexToken(plexs) \
  277. ((plexs)->pObject)
  278. // Return the current lexer token starting CP value
  279. #define CpLexTokenFirst(plexs) \
  280. ((plexs)->cpTokenFirst)
  281. // Set the current lexer token starting CP value
  282. #define SetCpLexTokenFirst(plexs, cp) \
  283. ((plexs)->cpTokenFirst = (cp))
  284. // Return the next lexer token starting CP value
  285. #define CpLexTokenNext(plexs) \
  286. ((plexs)->cpTokenNext)
  287. // Set the next lexer token starting CP value
  288. #define SetCpLexTokenNext(plexs, cp) \
  289. ((plexs)->cpTokenNext = (cp))
  290. // Get the current lexer token dCP (length of CPs consumed)
  291. #define DcpLexToken(plexs) \
  292. ((plexs)->dcpToken)
  293. // Set the current lexer token dCP (length of CPs consumed)
  294. #define SetDcpLexToken(plexs, dcp) \
  295. ((plexs)->dcpToken = (dcp))
  296. // Update the current lexer token dCP (length of CPs consumed)
  297. #define UpdateDcpLexToken(plexs, dcp) \
  298. IncrDcpLexToken(plexs, dcp)
  299. // Update the current lexer token dCP (length of CPs consumed)
  300. #define IncrDcpLexToken(plexs, dcp) \
  301. ((plexs)->dcpToken += (dcp))
  302. #ifndef EM_LEX_VANISHED
  303. // Update the current lexer token dCP (length of CPs consumed)
  304. #define ClearDcpLexToken(plexs) \
  305. SetDcpLexToken(plexs, 0L)
  306. #else /* EM_LEX_VANISHED */
  307. // Update the current lexer token dCP (length of CPs consumed)
  308. #define ClearDcpLexToken(plexs) \
  309. (SetDcpLexToken(plexs, 0L), \
  310. plexs->cpFirstVanished = 0L, \
  311. plexs->dcpVanished = 0L)
  312. #endif /* !EM_LEX_VANISHED */
  313. // Return the current lexer token *running* dCP (length of CPs consumed)
  314. #define DcpLexCurr(plexs) \
  315. (DcpLexToken(plexs) + CchTokenLen(plexs))
  316. // Return the current lexer CP value
  317. #define CpLexCurr(plexs) \
  318. (CpLexTokenFirst(plexs) + DcpLexToken(plexs))
  319. // Is this the last run, period?
  320. #define FLexEndOfScan(plexs) \
  321. ((plexs)->cpRun + (plexs)->ccpRun >= (plexs)->cpLim)
  322. #define CchTokenLen(plexs) \
  323. (CchTokenUncachedLen(plexs) + (plexs)->ichCache)
  324. #define CchTokenUncachedLen(plexs) \
  325. ((plexs)->pxchNext - (plexs)->pxchTkStart)
  326. // Return the index of the start of curr tk into line buffer (vfli.lrgxch)
  327. #define IchLexTkFirst(plexs) \
  328. ((plexs)->pxchTkStart - (plexs)->pxchBuffer)
  329. // Encode a relative TK index as an absolute number
  330. #define _IrultkTokenAbsEncoded(plexs, dirultk) \
  331. ((plexs)->rultkhToken.irultkAbsBase \
  332. + (plexs)->irultkLim + (dirultk))
  333. // Mark that the lexer must reset on next char typed
  334. #define InvalLex(plexs) \
  335. ((plexs)->cchLookahead = -1)
  336. // Return whether the lexer must reset on next char typed
  337. #define FInvalLex(plexs) \
  338. ((plexs)->cchLookahead < 0)
  339. // Mark lexer as probably out of synch with app buffer
  340. #define InvalLexFetch(plexs) \
  341. ((plexs)->cchRemain = 0, \
  342. (plexs)->fInvalLexer = fTrue)
  343. // Return whether lexer out of synch with app buffer
  344. #define FInvalLexFetch(plexs) \
  345. ((plexs)->fInvalLexer)
  346. /*************************************************************************
  347. Token History Cache
  348. *************************************************************************/
  349. // Token-history cache access
  350. #define PrultkFromTokenIrultk(plexs, irultk) \
  351. PrultkFromIrultk(irultk, (plexs)->rultkhToken.rgrultkCache)
  352. // Increment pointer to token-history cache access
  353. #define IncrTokenPrultk(plexs, pprultk, pirultkPrev) \
  354. IncrPrultk(pprultk, pirultkPrev, \
  355. (plexs)->rultkhToken.rgrultkCache, \
  356. (plexs)->rultkhToken.irultkMac)
  357. // Decrement pointer to token-history cache access
  358. #define DecrTokenPrultk(plexs, pprultk, pirultkPrev) \
  359. DecrPrultk(pprultk, pirultkPrev, \
  360. (plexs)->rultkhToken.rgrultkCache, \
  361. (plexs)->rultkhToken.irultkMac)
  362. // Increment index to token-history cache access
  363. #define IncrTokenPirultk(plexs, pirultk, dirultk) \
  364. IncrPirultk(pirultk, dirultk, (plexs)->rultkhToken.irultkMac)
  365. // Increment index to token-history cache access
  366. #define DecrTokenPirultk(plexs, pirultk, dirultk) \
  367. DecrPirultk(pirultk, dirultk, (plexs)->rultkhToken.irultkMac)
  368. // Fill in next tk cache record even if incomplete.
  369. #define _CacheTkTextNext(plexs) \
  370. { \
  371. MSORULTK *prultk; \
  372. int cchPartialTk = (plexs)->cchLookahead; \
  373. \
  374. prultk = PrultkFromTokenIrultk((plexs), \
  375. (plexs)->rultkhToken.irultkLim); \
  376. prultk->pObject = plexs->pObject; \
  377. prultk->cpFirst = CpLexTokenFirst(plexs); \
  378. prultk->dcp = DcpLexCurr(plexs) + cchPartialTk; \
  379. prultk->ich = (plexs)->pxchTkStart - (plexs)->pxchBuffer; \
  380. prultk->dich = CchTokenLen(plexs) + cchPartialTk; \
  381. prultk->wInterval = (plexs)->wInterval; \
  382. prultk->tk = tkNil; \
  383. }
  384. /*************************************************************************
  385. Formatting Token History Cache
  386. *************************************************************************/
  387. // Format token-history cache access
  388. #define PrultkFormatFromIrultk(plexs, irultk) \
  389. PrultkFromIrultk(irultk, (plexs)->rultkhFormat.rgrultkCache)
  390. // Increment pointer to Format token-history cache access
  391. #define IncrFormatPrultk(plexs, pprultk, pirultkPrev) \
  392. IncrPrultk(pprultk, pirultkPrev, \
  393. (plexs)->rultkhFormat.rgrultkCache, \
  394. (plexs)->rultkhFormat.irultkMac)
  395. // Increment pointer to Format token-history cache access
  396. #define DecrFormatPrultk(plexs, pprultk, pirultkPrev) \
  397. DecrPrultk(pprultk, pirultkPrev, \
  398. (plexs)->rultkhFormat.rgrultkCache, \
  399. (plexs)->rultkhFormat.irultkMac)
  400. // Increment index to Format token-history cache access
  401. #define IncrFormatPirultk(pirultk, dirultk) \
  402. IncrPirultk(pirultk, dirultk, (plexs)->rultkhFormat.irultkMac)
  403. // Increment index to Format token-history cache access
  404. #define DecrFormatPirultk(pirultk, dirultk) \
  405. DecrPirultk(pirultk, dirultk, (plexs)->rultkhFormat.irultkMac)
  406. /*************************************************************************
  407. Prototypes and macros for lex.c
  408. *************************************************************************/
  409. // Get the next character from the input buffer
  410. #define XchLexGetChar(plexs, cpLim) \
  411. ((plexs)->cchRemain-- > 0\
  412. ? *(plexs)->pxchNext++ \
  413. : XchLexGetNextBuffer(cpLim, plexs))
  414. // Get the next input buffer
  415. #define XchLexGetNextBuffer(cpLim, plexs) \
  416. ((*(plexs)->pfnlexbuf)(cpLim, plexs))
  417. // Return last char to input buffer
  418. #ifndef AS_FUNCTION
  419. #define LexUngetChar(plexs, cch) \
  420. ((plexs)->pxchNext -= cch, (plexs)->cchRemain += cch)
  421. #else
  422. void LexUngetChar(MSOLEXS *plexs, int cch);
  423. #endif /* !AS_FUNCTION */
  424. // Peek at the next character from the input buffer
  425. #define XchLexPeekChar(plexs) \
  426. ((plexs)->cchRemain > 0 \
  427. ? *(plexs)->pxchNext \
  428. : (XchLexGetNextBuffer(msocpMax, plexs), (plexs)->cchRemain++,\
  429. *(--(plexs)->pxchNext)))
  430. // Number of bytes to copy if we are "peeking" at next char via lexer
  431. #define cbLexsPeek (offset(MSOLEXS, ichCache))
  432. // Define (CH)aracter Translation (T)a(BL)e
  433. typedef unsigned short ISTT; // Col index to Lex STT
  434. typedef ISTT const *CHTBL; // Char trans table
  435. #ifndef VIEWER
  436. // Definition of size of State Transition Table
  437. #define WSttblNumRows 5 // Num rows in Sttbl
  438. #define WSttblNumCols 15 // Num cols in Sttbl
  439. typedef unsigned short const STTBL [WSttblNumCols]; // State trans table
  440. extern unsigned short const rgsttblWsIndirect[WSttblNumRows][WSttblNumCols];
  441. extern unsigned short const rgsttblWsDirect[WSttblNumRows][WSttblNumCols];
  442. extern CHTBL _rgchtblNormal[256]; // Normal ch trans tbl
  443. // Based pointer to current Character Transition Table
  444. extern CHTBL const *vpchtblCharTrans; // Curr ch trans table
  445. // Translate a character into a column in the lexer STTBL
  446. #define IsttFromXch(xch) \
  447. vpchtblCharTrans[MsoHighByteXch(xch)][MsoLowByteXch(xch)]
  448. #endif // !VIEWER
  449. // Define Delimiter Lookup table
  450. extern TK const * Win(const) vrgptkCharToken[256];
  451. // Return delimiter token associated with character
  452. #define TkDelimFromXch(xch) \
  453. vrgptkCharToken[MsoHighByteXch(xch)][MsoLowByteXch(xch)]
  454. // Map a STT column index into a Character token value
  455. extern TK vmpistttkCh[];
  456. MSOAPI_(TK) MsoTkLexText(MSOLEXS *plexs); // Get next token
  457. MSOAPI_(TK) MsoTkLexTextCpLim( // Get next tk < CP
  458. MSOLEXS *plexs,
  459. MSOCP cpLim
  460. );
  461. MSOAPI_(int) MsoFLexTokenCh(MSOLEXS *plexs, XCHAR xch); // Token ready?
  462. void SetLexTokenLim(MSOLEXS *plexs); // Set token Lim
  463. MSOCP DcpLexCurrAdjusted(MSOLEXS *plexs); // Return dCP used
  464. MSOAPI_(XCHAR) MsoWchLexGetNextBufferDoc( // Reload char buf
  465. MSOCP cpLim,
  466. MSOLEXS *plexs
  467. );
  468. void ForceLexEOF(void); // FUTURE: Force EOF
  469. MSOAPI_(MSOLEXS *) MsoPlexsLexInitDoc( // Init from doc
  470. MSOLEXS *plexs,
  471. void *hObjectNil,
  472. PFNLEXRUN pfnlexrun,
  473. PFNLEXTXT pfnlextxt,
  474. PFNLEXFMT pfnlexfmt,
  475. PFNLEXCNT pfnlexrunDiscontig,
  476. int irultkTokenMac,
  477. int irultkFormatMac
  478. );
  479. #ifdef DEBUG
  480. MSOAPI_(void) MsoAssertPlexsInitDoc( // Ensure doc init
  481. MSOLEXS *plexs,
  482. void *hObjectNil,
  483. PFNLEXRUN pfnlexrun,
  484. PFNLEXTXT pfnlextxt,
  485. PFNLEXFMT pfnlexfmt,
  486. PFNLEXCNT pfnlexrunDiscontig,
  487. int irultkTokenMac,
  488. int irultkFormatMac
  489. );
  490. #endif // DEBUG
  491. MSOAPI_(void) MsoLexSetPos( // Reposition in file
  492. MSOLEXS *plexs,
  493. MSOCP cpFirst,
  494. MSOCP cpLim
  495. );
  496. MSOAPI_(XCHAR) MsoWchLexGetNextBufferPxch( // Gen EOF for rgch
  497. MSOCP cpLim,
  498. MSOLEXS *plexs
  499. );
  500. MSOAPI_(MSOLEXS *) MsoPlexsLexInitPxch( // Init from rgch
  501. MSOLEXS *plexs,
  502. XCHAR *pxch,
  503. int cch,
  504. PFNLEXBUF pfnlexbuf,
  505. int irultkTokenMac,
  506. int irultkFormatMac
  507. );
  508. #ifdef DEBUG
  509. MSOAPI_(void) MsoAssertPlexsInitPxch( // Ensure rgch init
  510. MSOLEXS *plexs,
  511. XCHAR *pxch,
  512. int cch,
  513. PFNLEXBUF pfnlexbuf,
  514. int irultkTokenMac,
  515. int irultkFormatMac
  516. );
  517. #endif // DEBUG
  518. void LexFinishPch(void); // Complete rgch scan
  519. STTBL *PsttblFromIsttbl(int isttbl); // table ptr from index
  520. MSOLEXS *PlexsNew(void); // Alloc new MSOLEXS
  521. MSOLEXS *PlexsInitLex( // Init lexer memory
  522. MSOLEXS *plexs,
  523. int irultkTokenMac,
  524. int irultkFormatMac
  525. );
  526. #ifdef DEBUG
  527. void AssertPlexsInit( // Ensure lexer memory
  528. MSOLEXS *plexs,
  529. int irultkTokenMac,
  530. int irultkFormatMac
  531. );
  532. #endif
  533. MSOAPI_(void) MsoResetLexState( // Reset lexer state
  534. MSOLEXS *plexs,
  535. int fFullReset
  536. );
  537. MSOAPI_(void) MsoFreeLexMem(MSOLEXS *plexs); // Free lexer memory
  538. #if defined(DEBUG) && !defined(STANDALONE)
  539. MSOAPI_(void) MsoMarkLexMem(MSOLEXS *plexs); // Mark lexer mem used
  540. #endif // DEBUG && !STANDALONE
  541. int FResetLexDocBuffer( // Reset cpObject
  542. void *pObject,
  543. MSOCP cpObject,
  544. MSOCP cpScan,
  545. MSOCP *pcpObject // RETURN
  546. );
  547. // Return token associated with string by looking up in keyword table
  548. #define TkLookupNameLexs(pxchStr, cchLen, plexs) \
  549. MsoTkLookupName((pxchStr), (cchLen), (plexs)->pkwtb)
  550. // Return token associated with string by looking up in keyword table
  551. #define PkwdLookupNameLexs(pxchStr, cchLen, plexs) \
  552. MsoPkwdLookupName((pxchStr), (cchLen), (plexs)->pkwtb)
  553. // Add a keyword to the lexer lookup table
  554. #define PkwdAddTkLookupNameLexs(pxchStr, cchLen, tk, plexs, fCopyStr) \
  555. MsoPkwdAddTkLookupName((pxchStr), (cchLen), (tk), (plexs)->pkwtb,\
  556. (fCopyStr))
  557. // Remove a keyword from the lexer lookup table
  558. #define FRemoveTkLookupNameLexs(pxchStr, cchLen, plexs, ptk) \
  559. MsoFRemoveTkLookupName((pxchStr), (cchLen), (plexs)->pkwtb, (ptk))
  560. void AppendRultkFormat( // Append format token
  561. MSOLEXS *plexs,
  562. TK tk,
  563. int dcp,
  564. long lValue
  565. );
  566. void InsertRultkFormat( // Insert format token
  567. MSOLEXS *plexs,
  568. TK tk,
  569. MSOCP cp,
  570. long lValue
  571. );
  572. MSOAPI_(void) MsoCacheTkText( // Save text tokens
  573. MSOLEXS *plexs,
  574. TK tk,
  575. long lValue
  576. );
  577. MSOAPI_(int) MsoCchTokenText( // Return token text
  578. MSOLEXS *plexs,
  579. int dtk,
  580. const XCHAR **ppxch // RETURN
  581. );
  582. #define TokenLen(plexs, dtk) \
  583. MsoCchTokenText((plexs), (dtk), NULL)
  584. MSOAPI_(MSOCA *) MsoPcaOfDtk( // Get CA of tk range
  585. MSOCA *pca,
  586. int dtkStart,
  587. int dtk,
  588. MSOLEXS *plexs
  589. );
  590. MSOAPI_(MSOCA *) MsoPcaOfDtkExclusive( // Get CA inside tk rg
  591. MSOCA *pca,
  592. int dtkStart,
  593. int dtk,
  594. MSOLEXS *plexs
  595. );
  596. #ifdef NEVER
  597. int CchCopyTextOfDtk( // Return mult tk text
  598. int dtkStart,
  599. int dtk,
  600. XCHAR *rgxch, // IN, RETURN
  601. int cchMax,
  602. int fPartialTkOK
  603. );
  604. #endif // NEVER
  605. MSOAPI_(long) MsoLFromDtk( // Get integer value
  606. MSOLEXS *plexs,
  607. int dtk,
  608. int fCheckForSign
  609. );
  610. long LFromPxch( // Convert str to long
  611. const XCHAR *pxch,
  612. int cch,
  613. int *pfOverflow
  614. );
  615. int FUpperXch(XCHAR xch); // Char uppercase?
  616. int FLowerXch(XCHAR xch); // Char lowercase?
  617. #ifdef NEVER
  618. int OFC_CALLBACK DxaOfDirultk( // Return tk coord,len
  619. int dtk,
  620. int *pdxaLen // RETURN: optional
  621. );
  622. TK TkFromXch(XCHAR xch); // Return tk from a ch
  623. TK TkFromXchNoLookup(XCHAR xch); // Return tk from ch
  624. XCHAR *PxchTkStartFromPxchReverse(XCHAR *, XCHAR *);
  625. int FXchEndsTk(XCHAR); // Does this xch end a tk?
  626. TK TkFromChIsttbl(XCHAR xch, int isttbl); // Return a tk from a char
  627. int OFC_CALLBACK DtkCacheTkTextToCp( // Fill Text TK cache
  628. int dtk,
  629. MSOCP cpLim,
  630. int fForce
  631. );
  632. #endif // NEVER
  633. void CopyTkTextToCache(MSOLEXS *plexs); // Flush pend lex text
  634. #if defined(DEBUG) || defined(STANDALONE)
  635. char *SzFromPch( // Temp make string
  636. const char *pchStr,
  637. int cchLen,
  638. char *rgchStrBuf
  639. );
  640. XCHAR *XszFromPxch( // Temp make string
  641. const XCHAR *pxchStr,
  642. int cchLen,
  643. XCHAR *rgxchStrBuf
  644. );
  645. #ifndef STANDALONE
  646. char *SzFromPxch( // Temp make string
  647. const XCHAR *pxchStr,
  648. int cchLen,
  649. char *rgchStrBuf
  650. );
  651. #else /* STANDALONE */
  652. #define SzFromPxch(p1,p2,p3) SzFromPch(p1, p2, p3)
  653. #endif /* !STANDALONE */
  654. #endif // DEBUG || STANDALONE
  655. /*************************************************************************
  656. Utilities
  657. *************************************************************************/
  658. #ifndef FAREAST
  659. #define FWhitespaceXch(xch) \
  660. ((xch) == ' ' || (xch) == '\t' || (xch) == xchColumnBreak)
  661. #else /* FAREAST */
  662. #define FWhitespaceXch(xch) \
  663. ((xch) == ' ' || (xch) == '\t' || (xch) == xchColumnBreak \
  664. || (xch) == wchSpace)
  665. #endif /* FAREAST */
  666. /*************************************************************************
  667. Prototypes and macros for Debugging and Error Handling
  668. *************************************************************************/
  669. const XCHAR *PxchLexTokenText( // Return tk text, len
  670. MSOLEXS *plexs,
  671. int *pwLen);
  672. #ifdef DEBUG
  673. MSOAPI_(XCHAR *) MsoLxszLexTokenText(MSOLEXS *plexs); // Return token text
  674. MSOAPI_(CHAR *) MsoSzLexTokenText(MSOLEXS *plexs); // Return token sz
  675. #endif // DEBUG
  676. #endif // MSOLEX_H