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.

173 lines
4.7 KiB

  1. // HTML lexer tables
  2. // Copyright (c)1997-1999 Microsoft Corporation, All Rights Reserved
  3. #ifndef __HLTABLE_H__
  4. #define __HLTABLE_H__
  5. #include "lexhtml.h"
  6. #ifndef PURE
  7. #define PURE =0
  8. #endif
  9. // These values must match the number of built-in tables (CV_FIXED),
  10. // and the capacity of the inVariant bits of the lex state (CV_MAX).
  11. const UINT CV_FIXED = 4; // Count Variants in Fixed tables
  12. const UINT CV_MAX = 16; // Count variants maximum total
  13. // Macro for determining number of elements in an array
  14. #define CELEM_ARRAY(a) (sizeof(a) / sizeof(a[0]))
  15. // length-limited string compare function pointer (e.g. strncmp/strnicmp)
  16. typedef int (_cdecl* PFNNCMP)(LPCTSTR, LPCTSTR, size_t);
  17. #define CASE (TRUE)
  18. #define NOCASE (FALSE)
  19. #define NOT_FOUND (-1)
  20. ////////////////////////////////////////////////////////////////////////////
  21. // return A-Z[a-z] index if alpha, else -1
  22. inline int PeekIndex(TCHAR c, BOOL bCase /*= NOCASE*/)
  23. {
  24. if ((c >= _T('A')) && (c <= _T('Z')))
  25. return c - _T('A');
  26. else if ((c >= _T('a')) && (c <= _T('z')))
  27. return c - _T('a') + (bCase ? 26 : 0);
  28. else
  29. return -1;
  30. }
  31. // static table lookups
  32. int LookupLinearKeyword(ReservedWord *rwTable, int cel, RWATT_T att, LPCTSTR pchLine, int cbLen, BOOL bCase = NOCASE);
  33. int LookupIndexedKeyword(ReservedWord *rwTable, int cel, int * indexTable, RWATT_T att, LPCTSTR pchLine, int cbLen, BOOL bCase = NOCASE);
  34. // content model
  35. // Map between element / lex state
  36. //
  37. struct ELLEX {
  38. LPCTSTR sz;
  39. int cb;
  40. DWORD lxs;
  41. };
  42. DWORD TextStateFromElement(LPCTSTR szEl, int cb);
  43. ELLEX * pellexFromTextState(DWORD state);
  44. inline LPCTSTR ElementFromTextState(DWORD state)
  45. {
  46. ELLEX *pellex = pellexFromTextState(state);
  47. return pellex ? pellex->sz : 0;
  48. }
  49. #ifdef _DEBUG
  50. int CheckWordTable(ReservedWord *arw, int cel, LPCTSTR szName = NULL);
  51. int CheckWordTableIndex(ReservedWord *arw, int cel, int *ai, BOOL bCase = FALSE, LPCTSTR szName = NULL);
  52. int MakeIndexHere(ReservedWord *arw, int cel, int *ab, BOOL bCase = FALSE, LPCTSTR szName = NULL);
  53. #endif
  54. int MakeIndex(ReservedWord *arw, int cel, int **pab, BOOL bCase = FALSE, LPCTSTR szName = NULL);
  55. ////////////////////////////////////////////////////////////////////////////
  56. // test for SGML identifier character:
  57. // alphanumeric or '-' or '.'
  58. inline BOOL IsIdChar(TCHAR ch)
  59. {
  60. return IsCharAlphaNumeric(ch) || ch == _T('-') || ch == _T('.') || ch == _T(':');
  61. }
  62. ////////////////////////////////////////////////////////////////////////////
  63. // Abstract Base Classes
  64. //
  65. class CTable
  66. {
  67. public:
  68. virtual ~CTable() {}
  69. virtual int Find(LPCTSTR pch, int cb) PURE;
  70. };
  71. class CTableSet
  72. {
  73. public:
  74. virtual ~CTableSet() {}
  75. virtual int FindElement(LPCTSTR pch, int cb) PURE;
  76. virtual int FindAttribute(LPCTSTR pch, int cb) PURE;
  77. virtual int FindEntity(LPCTSTR pch, int cb) PURE;
  78. const TCHAR* Name() const { return m_strName; }
  79. protected:
  80. TCHAR m_strName[1024];
  81. };
  82. typedef CTable *PTABLE;
  83. typedef CTableSet * PTABLESET;
  84. typedef const CTableSet * PCTABLESET;
  85. // static, built-in table
  86. class CStaticTable : public CTable
  87. {
  88. public:
  89. CStaticTable(
  90. RWATT_T att,
  91. ReservedWord *prgrw, UINT cel,
  92. int *prgi = NULL,
  93. BOOL bCase = FALSE,
  94. LPCTSTR szName = NULL);
  95. virtual ~CStaticTable() {} // nothing to delete
  96. BOOL Find(LPCTSTR pch, int cb);
  97. private:
  98. ReservedWord *m_prgrw; // reserved word table
  99. UINT m_cel; // element count (size)
  100. int *m_prgi; // index table
  101. BOOL m_bCase; // case sensitive?
  102. RWATT_T m_att; // attribute mask for table lookup
  103. };
  104. class CStaticTableSet : public CTableSet
  105. {
  106. public:
  107. CStaticTableSet(RWATT_T att, UINT nIdName);
  108. virtual ~CStaticTableSet() {}
  109. int FindElement(LPCTSTR pch, int cb);
  110. int FindAttribute(LPCTSTR pch, int cb);
  111. int FindEntity(LPCTSTR pch, int cb);
  112. private:
  113. CStaticTable m_Elements;
  114. CStaticTable m_Attributes;
  115. CStaticTable m_Entities;
  116. };
  117. ////////////////////////////////////////////////////////////////////////////
  118. // CLStr
  119. // A very simple length-and-buffer string representation
  120. // with just enough functionality for our purpose.
  121. class CLStr
  122. {
  123. public:
  124. CLStr() : m_cb(0), m_rgb(0) {}
  125. CLStr(const BYTE * rgb, DWORD cb) : m_rgb(rgb), m_cb(cb) {}
  126. BOOL Compare(const BYTE * rgb, DWORD cb, BOOL bCase)
  127. {
  128. int r;
  129. if (bCase)
  130. r = memcmp(rgb, m_rgb, __min(m_cb, cb));
  131. else
  132. r = _memicmp(rgb, m_rgb, __min(m_cb, cb));
  133. return (0 == r) ? (cb - m_cb) : r;
  134. }
  135. // data
  136. DWORD m_cb;
  137. const BYTE * m_rgb;
  138. };
  139. typedef CLStr * PLSTR;
  140. typedef const CLStr * PCLSTR;
  141. typedef const CLStr & RCLSTR;
  142. extern CStaticTableSet * g_pTabDefault;
  143. extern PTABLESET g_pTable;
  144. extern HINT g_hintTable[];
  145. #endif // __HLTABLE_H__