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.

134 lines
3.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1992-1998, Microsoft Corporation.
  4. //
  5. // File: SCANNER.HXX
  6. //
  7. // Contents: Query scanner
  8. //
  9. // Classes: CQueryScanner
  10. //
  11. // History: 29-Apr-92 AmyA Created.
  12. // 23-Jun-92 MikeHew Added weight tokens.
  13. // 15-Jun-94 t-jeffc Added regex support & error info
  14. //
  15. //----------------------------------------------------------------------------
  16. #pragma once
  17. #include <ci64.hxx>
  18. enum Token {
  19. EQUAL_TOKEN = 0, // the order of these operators is important -
  20. NOT_EQUAL_TOKEN, // they are used to index an array
  21. GREATER_TOKEN,
  22. GREATER_EQUAL_TOKEN,
  23. LESS_TOKEN,
  24. LESS_EQUAL_TOKEN,
  25. ALLOF_TOKEN,
  26. SOMEOF_TOKEN,
  27. AND_TOKEN, // order doesn't matter from here on...
  28. OR_TOKEN,
  29. PROX_TOKEN,
  30. NOT_TOKEN,
  31. FUZZY_TOKEN,
  32. FUZ2_TOKEN,
  33. PROP_TOKEN,
  34. PROP_REGEX_TOKEN,
  35. PROP_NATLANG_TOKEN,
  36. OPEN_TOKEN,
  37. CLOSE_TOKEN,
  38. W_OPEN_TOKEN,
  39. W_CLOSE_TOKEN,
  40. COMMA_TOKEN,
  41. EOS_TOKEN,
  42. TEXT_TOKEN,
  43. QUOTES_TOKEN,
  44. C_OPEN_TOKEN,
  45. C_CLOSE_TOKEN,
  46. PLUS_TOKEN,
  47. CONTAINS_TOKEN,
  48. ISEMPTY_TOKEN,
  49. ISTYPEEQUAL_TOKEN
  50. };
  51. // chars that cannot appear in a phrase
  52. #define PHRASE_STR L"{}!&|~*@#$()[],=<>\n\"^"
  53. // chars that cannot appear in a command or path
  54. #define CMND_STR L"{}!&|~*@#()[],=<> \t\n\""
  55. // chars that cannot appear outside of the <> braces in a regex
  56. #define REGEX_STR L"&|~()[], \n"
  57. // chars that cannot appear in an unquoted column name
  58. #define COLUMN_STR L"{}!&|~*@#()[],=<>+%$^{}:;'./?\\` \t\n\""
  59. //+---------------------------------------------------------------------------
  60. //
  61. // Class: CQueryScanner
  62. //
  63. // Purpose: Scans the input from the property list file, the startup
  64. // file and the console.
  65. //
  66. // History: 29-Apr-92 AmyA Created.
  67. //
  68. //----------------------------------------------------------------------------
  69. class CQueryScanner
  70. {
  71. public:
  72. CQueryScanner( WCHAR const * buffer,
  73. BOOL fLookForTextualKeywords,
  74. LCID lcid = GetUserDefaultLCID(),
  75. BOOL fTreatPlusAsToken = FALSE );
  76. Token LookAhead() { return _token; }
  77. void Accept();
  78. void AcceptWord();
  79. void AcceptColumn();
  80. void AcceptQuote() { Win4Assert( L'"' == *_text ); _text++; }
  81. void AcceptCommand();
  82. BOOL IsEmpty() { return ( _token == EOS_TOKEN ); }
  83. WCHAR* AcqPath();
  84. WCHAR* AcqWord();
  85. WCHAR* AcqColumn();
  86. WCHAR* AcqPhrase();
  87. WCHAR* AcqLine( BOOL fParseQuotes = TRUE );
  88. WCHAR* AcqRegEx();
  89. WCHAR* AcqPhraseInQuotes();
  90. BOOL GetNumber( ULONG & number, BOOL & fAtEndOfString );
  91. BOOL GetNumber( LONG & number, BOOL & fAtEndOfString );
  92. BOOL GetNumber( unsigned _int64 & number, BOOL & fAtEndOfString );
  93. BOOL GetNumber( _int64 & number, BOOL & fAtEndOfString );
  94. BOOL GetNumber( double & number );
  95. WCHAR GetCommandChar();
  96. void ResetBuffer( WCHAR const * buffer );
  97. ULONG CurrentOffset()
  98. {
  99. return CiPtrToUlong( _text - _pBuf );
  100. }
  101. private:
  102. WCHAR * AllocReturnString( int cch );
  103. void EatWhiteSpace();
  104. WCHAR * FindStringToken( WCHAR * pwcIn, Token & token, unsigned & cwc );
  105. BOOL IsEndOfTextToken();
  106. WCHAR const * _pBuf;
  107. WCHAR const * _pLookAhead;
  108. WCHAR const * _text;
  109. Token _token;
  110. BOOL _fLookForTextualKeywords;
  111. BOOL _fTreatPlusAsToken;
  112. LCID _lcid;
  113. };