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.

137 lines
3.3 KiB

  1. /*++
  2. Copyright (C) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. QL_TEST.CPP
  5. Abstract:
  6. Test driver for Level 1 Syntax QL Parser
  7. Takes the filename of a file containing one or more WQL queries. Writes
  8. the output to the console.
  9. History:
  10. mdavis 23-Apr-99 Created from sql_test.cpp in Stdlibrary
  11. --*/
  12. #include "precomp.h"
  13. #include <stdio.h>
  14. #include <genlex.h>
  15. #include <qllex.h>
  16. #include <ql.h>
  17. void xmain(int argc, char **argv)
  18. {
  19. if (argc < 2 || strchr(argv[1], '?') != NULL)
  20. {
  21. printf("Usage: ql_test WQL-query-file\n");
  22. return;
  23. }
  24. int nLine = 1;
  25. char buf[2048];
  26. FILE *f = fopen(argv[1], "rt");
  27. if (f == NULL)
  28. {
  29. printf("Usage: ql_test WQL-query-file\nError: cannot open file %s!\n", argv[1]);
  30. return;
  31. }
  32. while (fgets(buf, 2048, f) != NULL)
  33. {
  34. // get rid of newline
  35. char* ptr;
  36. if ((ptr = strchr(buf, '\n')) != NULL)
  37. {
  38. *ptr = '\0';
  39. }
  40. // get start of text
  41. ptr = buf;
  42. while (*ptr == ' ')
  43. {
  44. ptr++;
  45. }
  46. // ignore blank lines
  47. if (*ptr != '\0')
  48. {
  49. wchar_t buf2[2048];
  50. MultiByteToWideChar(CP_ACP, 0, ptr, -1, buf2, 2048);
  51. CTextLexSource src(buf2);
  52. QL1_Parser parser(&src);
  53. QL_LEVEL_1_RPN_EXPRESSION *pExp = NULL;
  54. // get the class (parse to WHERE clause)
  55. wchar_t classbuf[128];
  56. *classbuf = 0;
  57. printf("----GetQueryClass----\n");
  58. int nRes = parser.GetQueryClass(classbuf, 128);
  59. if (nRes)
  60. {
  61. printf("ERROR %d: line %d, token %S\n",
  62. nRes,
  63. parser.CurrentLine(),
  64. parser.CurrentToken()
  65. );
  66. goto ContinueRead;
  67. }
  68. printf("Query class is %S\n", classbuf);
  69. // parse the rest of the query
  70. nRes = parser.Parse(&pExp);
  71. if (nRes)
  72. {
  73. printf("ERROR %d: line %d, token %S\n",
  74. nRes,
  75. parser.CurrentLine(),
  76. parser.CurrentToken()
  77. );
  78. //goto ContinueRead;
  79. }
  80. else
  81. {
  82. printf("No errors.\n");
  83. }
  84. // call Dump function to display tokens and GetText function to show
  85. // query passed to providers
  86. if (pExp)
  87. {
  88. pExp->Dump("CON");
  89. LPWSTR wszText = pExp->GetText();
  90. printf("--WQL passed to provider--\n");
  91. printf("%S\n", wszText);
  92. printf("----end of WQL----\n");
  93. delete [] wszText;
  94. }
  95. ContinueRead:
  96. delete pExp;
  97. printf("%S\n", buf2);
  98. printf("=================================================EOL %d=======================================================\n", nLine);
  99. }
  100. nLine++;
  101. }
  102. if (ferror(f) != 0)
  103. {
  104. printf("\nError: line %d", nLine);
  105. }
  106. fclose(f);
  107. }
  108. void main(int argc, char **argv)
  109. {
  110. xmain(argc, argv);
  111. }