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.

119 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. test1.cxx
  5. Abstract:
  6. Main program to test the lexer
  7. Author:
  8. Shankara Shastry [ShankSh] 08-Jul-1996
  9. ++*/
  10. #include <stdio.h>
  11. #include "lexer.hxx"
  12. #include "sconv.hxx"
  13. #include "sqltree.hxx"
  14. #include "sqlparse.hxx"
  15. static WCHAR *DisplayName[] = {
  16. L"TOKEN_ERROR ",
  17. L"TOKEN_EQ ",
  18. L"TOKEN_STAR ",
  19. L"TOKEN_LPARAN ",
  20. L"TOKEN_RPARAN ",
  21. L"TOKEN_INTEGER_LITERAL ",
  22. L"TOKEN_REAL_LITERAL ",
  23. L"TOKEN_STRING_LITERAL ",
  24. L"TOKEN_USER_DEFINED_NAME",
  25. L"TOKEN_COMMA ",
  26. L"TOKEN_LT ",
  27. L"TOKEN_GT ",
  28. L"TOKEN_LE ",
  29. L"TOKEN_GE ",
  30. L"TOKEN_NE ",
  31. L"TOKEN_SELECT ",
  32. L"TOKEN_ALL ",
  33. L"TOKEN_FROM ",
  34. L"TOKEN_WHERE ",
  35. L"TOKEN_BOOLEAN_LITERAL ",
  36. L"TOKEN_AND ",
  37. L"TOKEN_OR ",
  38. L"TOKEN_NOT ",
  39. L"TOKEN_END ",
  40. };
  41. DECLARE_INFOLEVEL(ADs)
  42. int
  43. _cdecl main(
  44. int argc,
  45. char **argv
  46. )
  47. {
  48. HRESULT status = NO_ERROR;
  49. LPWSTR pszPattern;
  50. // Check the arguments.
  51. //
  52. if ( argc != 3 )
  53. {
  54. wprintf( L"\nUsage: lt <pattern> \n" );
  55. wprintf( L"\n where: pattern is the string where the tokens have to be recognised\n" );
  56. return -1;
  57. }
  58. if(!(pszPattern = AllocateUnicodeString(argv[2]))) {
  59. fprintf (stderr, "Not enough memory\n");
  60. return (-1);
  61. }
  62. if (strcmp((LPSTR)argv[1],(LPSTR)"1") == 0) {
  63. CLexer samplePattern(pszPattern);
  64. LPWSTR lexeme;
  65. DWORD token;
  66. wprintf(L"Token\t\tLexeme\n\n");
  67. samplePattern.GetNextToken(&lexeme, &token);
  68. while (token != TOKEN_END && token != TOKEN_ERROR) {
  69. wprintf(L"%s\t%s\n", DisplayName[token - TOKEN_START], lexeme);
  70. samplePattern.GetNextToken(&lexeme, &token);
  71. }
  72. if(token == TOKEN_ERROR)
  73. wprintf(L"%s\n", DisplayName[token - TOKEN_START]);
  74. }
  75. else {
  76. LPWSTR szLocation;
  77. LPWSTR szLDAPQuery;
  78. LPWSTR szSelect;
  79. LPWSTR szOrder;
  80. status = SQLParse(
  81. pszPattern,
  82. &szLocation,
  83. &szLDAPQuery,
  84. &szSelect,
  85. &szOrder);
  86. if (status != S_OK) {
  87. wprintf (L"Error in Parsing: %x\n", status);
  88. exit(-1);
  89. }
  90. wprintf(L"%s;%s;%s\n",szLocation, szLDAPQuery, szSelect);
  91. }
  92. return (0);
  93. }