1 mike 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 mike 1.1 **==============================================================================
23 */
24
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <wql/wql.h>
28 #include <base/getopt.h>
29
30 static const char* opt_test;
31
32 static void GetCommandLineOptions(
33 int* argc_,
34 const char* argv[])
35 {
36 int argc = *argc_;
37 GetOptState state = GETOPTSTATE_INITIALIZER;
38 static const char* opts[] =
39 {
40 "-t:",
41 NULL,
42 };
43 mike 1.1
44 for (;;)
45 {
46 int r = GetOpt(&argc, argv, opts, &state);
47
48 if (r == 1)
49 break;
50
51 if (r == -1)
52 {
53 fprintf(stderr, "error: %s\n", state.err);
54 exit(1);
55 }
56
57 if (strcmp(state.opt, "-t") == 0)
58 {
59 opt_test = state.arg;
60 }
61 }
62
63 *argc_ = argc;
64 mike 1.1 }
65
66 static void GenTest(WQL* wql, const char* expr, const char* testName)
67 {
68 printf("static void %s()\n", testName);
69 printf("{\n");
70 printf(" WQL* wql;\n");
71 WQL_Dump(wql, 4);
72
73 printf(" wql = WQL_Parse(\"");
74
75 while (*expr)
76 {
77 char c = *expr++;
78
79 switch (c)
80 {
81 case '"':
82 putchar('\\');
83 putchar('"');
84 break;
85 mike 1.1 case '\\':
86 putchar('\\');
87 putchar('\\');
88 break;
89 default:
90 putchar(c);
91 break;
92 }
93 }
94
95 printf("\", NULL);\n");
96
97 printf(" UT_ASSERT(wql != NULL);\n");
98
99 printf(" UT_ASSERT(WQL_Identical(&_wql, wql));\n");
100 printf(" WQL_Delete(wql);\n");
101 printf("}\n");
102 }
103
104 int main(int argc, const char* argv[])
105 {
106 mike 1.1 WQL* wql;
107
108 /* Get options */
109 GetCommandLineOptions(&argc, argv);
110
111 /* Check usage */
112 if (argc != 2)
113 {
114 fprintf(stderr, "%s EXPRESSION\n", argv[0]);
115 exit(1);
116 }
117
118 /* Parse expression */
119 {
120 wql = WQL_Parse(argv[1], NULL);
121
122 if (!wql)
123 {
124 fprintf(stderr, "%s: error: invalid WQL expression: %s\n",
125 argv[0], argv[1]);
126 exit(1);
127 mike 1.1 }
128 }
129
130 /* Dump definition of WQL object */
131 if (opt_test)
132 GenTest(wql, argv[1], opt_test);
133 else
134 WQL_Dump(wql, 0);
135
136 /* Delete WQL object */
137 WQL_Delete(wql);
138
139 return 0;
140 }
|