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.

131 lines
3.6 KiB

  1. /* Copyright (C) Microsoft Corporation, 1998. All rights reserved. */
  2. #ifndef _GETSYM_H_
  3. #define _GETSYM_H_
  4. #define INPUT_BUFFER_SIZE 4096
  5. #define OUTPUT_BUFFER_SIZE 4096
  6. #define INVALID_CHAR ((char) 0)
  7. class CInput
  8. {
  9. public:
  10. CInput ( BOOL *pfRetCode, LPSTR pszPathName, UINT cbBufSize = INPUT_BUFFER_SIZE );
  11. ~CInput ( void );
  12. void NextChar ( void );
  13. void PeekChars ( UINT cChars, LPSTR pszChars );
  14. void SkipChars ( UINT cChars );
  15. char GetChar ( void ) { return (char)m_chCurr; }
  16. BOOL IsEOF ( void )
  17. {
  18. return (m_fEndOfFile && (m_nCurrOffset >= m_cbValidData));
  19. }
  20. UINT GetFileSize ( void ) { return m_cbFileSize; }
  21. BOOL Rewind ( void );
  22. private:
  23. BOOL CheckBuffer ( UINT cChars );
  24. LPSTR m_pszPathName;
  25. UINT m_chCurr;
  26. UINT m_nCurrOffset;
  27. BOOL m_fEndOfFile;
  28. UINT m_cbBufSize;
  29. LPBYTE m_pbDataBuf;
  30. UINT m_cbValidData;
  31. HANDLE m_hFile;
  32. UINT m_cbFileSize;
  33. };
  34. typedef enum
  35. {
  36. SYMBOL_UNKNOWN, // initial value
  37. SYMBOL_EOF,
  38. SYMBOL_IDENTIFIER,
  39. SYMBOL_KEYWORD,
  40. SYMBOL_SPECIAL,
  41. SYMBOL_NUMBER,
  42. SYMBOL_DEFINITION, // "::="
  43. SYMBOL_COMMENT, // "--"
  44. SYMBOL_DOTDOTDOT, // "..."
  45. SYMBOL_SPACE,
  46. SYMBOL_SPACE_EOL,
  47. SYMBOL_FIELD, // "&Type"
  48. }
  49. SYMBOL_ID;
  50. class CSymbol
  51. {
  52. public:
  53. CSymbol ( CInput *pInput );
  54. ~CSymbol ( void ) { }
  55. BOOL NextSymbol ( void );
  56. BOOL NextUsefulSymbol ( void );
  57. SYMBOL_ID GetID ( void ) { return m_eSymbolID; }
  58. UINT GetStrLen ( void ) { return m_cchSymbolStr; }
  59. LPSTR GetStr ( void ) { return &m_szSymbolStr[0]; }
  60. BOOL IsSpecial ( void ) { return (SYMBOL_SPECIAL == m_eSymbolID); }
  61. BOOL IsSpecialChar ( char ch ) { return (IsSpecial() && ch == m_szSymbolStr[0]); }
  62. BOOL IsLeftBigBracket ( void ) { return IsSpecialChar('{'); }
  63. BOOL IsRightBigBracket ( void ) { return IsSpecialChar('}'); }
  64. BOOL IsComma ( void ) { return IsSpecialChar(','); }
  65. BOOL IsDot ( void ) { return IsSpecialChar('.'); }
  66. BOOL IsLeftParenth ( void ) { return IsSpecialChar('('); }
  67. BOOL IsRightParenth ( void ) { return IsSpecialChar(')'); }
  68. BOOL IsSemicolon ( void ) { return IsSpecialChar(';'); }
  69. BOOL IsComment ( void ) { return (SYMBOL_COMMENT == m_eSymbolID); }
  70. private:
  71. CInput *m_pInput;
  72. SYMBOL_ID m_eSymbolID;
  73. UINT m_cchSymbolStr;
  74. char m_szSymbolStr[MAX_PATH];
  75. };
  76. class COutput
  77. {
  78. public:
  79. COutput ( BOOL *pfRetCode, LPSTR pszPathName, UINT cbBufSize = OUTPUT_BUFFER_SIZE );
  80. ~COutput ( void );
  81. void Flush ( void ) { ::FlushFileBuffers(m_hFile); }
  82. BOOL Write ( LPBYTE pbDataBuf, UINT cbData );
  83. BOOL Write ( LPSTR pszDataBuf, UINT cbData ) { return Write((LPBYTE) pszDataBuf, cbData); }
  84. BOOL Write ( LPCSTR pszDataBuf, UINT cbData ) { return Write((LPBYTE) pszDataBuf, cbData); }
  85. BOOL Write ( CSymbol *pSym ) { return Write(pSym->GetStr(), pSym->GetStrLen()); }
  86. BOOL Writeln ( LPBYTE pbDataBuf, UINT cbData );
  87. BOOL Writeln ( LPSTR pszDataBuf, UINT cbData ) { return Writeln((LPBYTE) pszDataBuf, cbData); }
  88. BOOL Writeln ( LPCSTR pszDataBuf, UINT cbData ) { return Writeln((LPBYTE) pszDataBuf, cbData); }
  89. private:
  90. LPSTR m_pszPathName;
  91. UINT m_cbBufSize;
  92. LPBYTE m_pbDataBuf;
  93. UINT m_cbValidData;
  94. HANDLE m_hFile;
  95. };
  96. #endif // _GETSYM_H_