BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file ncd_tokenizer_test.c |
||
3 | * @author Ambroz Bizjak <ambrop7@gmail.com> |
||
4 | * |
||
5 | * @section LICENSE |
||
6 | * |
||
7 | * Redistribution and use in source and binary forms, with or without |
||
8 | * modification, are permitted provided that the following conditions are met: |
||
9 | * 1. Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * 2. Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * 3. Neither the name of the author nor the |
||
15 | * names of its contributors may be used to endorse or promote products |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | */ |
||
29 | |||
30 | #include <stddef.h> |
||
31 | #include <stdio.h> |
||
32 | #include <string.h> |
||
33 | |||
34 | #include <misc/debug.h> |
||
35 | #include <base/BLog.h> |
||
36 | #include <ncd/NCDConfigTokenizer.h> |
||
37 | |||
38 | int error; |
||
39 | |||
40 | static int tokenizer_output (void *user, int token, char *value, size_t value_len, size_t line, size_t line_char) |
||
41 | { |
||
42 | if (token == NCD_ERROR) { |
||
43 | printf("line %zu, character %zu: tokenizer error\n", line, line_char); |
||
44 | error = 1; |
||
45 | return 0; |
||
46 | } |
||
47 | |||
48 | switch (token) { |
||
49 | case NCD_EOF: |
||
50 | printf("eof\n"); |
||
51 | break; |
||
52 | case NCD_TOKEN_CURLY_OPEN: |
||
53 | printf("curly_open\n"); |
||
54 | break; |
||
55 | case NCD_TOKEN_CURLY_CLOSE: |
||
56 | printf("curly_close\n"); |
||
57 | break; |
||
58 | case NCD_TOKEN_ROUND_OPEN: |
||
59 | printf("round_open\n"); |
||
60 | break; |
||
61 | case NCD_TOKEN_ROUND_CLOSE: |
||
62 | printf("round_close\n"); |
||
63 | break; |
||
64 | case NCD_TOKEN_SEMICOLON: |
||
65 | printf("semicolon\n"); |
||
66 | break; |
||
67 | case NCD_TOKEN_DOT: |
||
68 | printf("dot\n"); |
||
69 | break; |
||
70 | case NCD_TOKEN_COMMA: |
||
71 | printf("comma\n"); |
||
72 | break; |
||
73 | case NCD_TOKEN_PROCESS: |
||
74 | printf("process\n"); |
||
75 | break; |
||
76 | case NCD_TOKEN_NAME: |
||
77 | printf("name %s\n", value); |
||
78 | free(value); |
||
79 | break; |
||
80 | case NCD_TOKEN_STRING: |
||
81 | printf("string %s\n", value); |
||
82 | free(value); |
||
83 | break; |
||
84 | case NCD_TOKEN_ARROW: |
||
85 | printf("arrow\n"); |
||
86 | break; |
||
87 | case NCD_TOKEN_TEMPLATE: |
||
88 | printf("template\n"); |
||
89 | break; |
||
90 | case NCD_TOKEN_COLON: |
||
91 | printf("colon\n"); |
||
92 | break; |
||
93 | case NCD_TOKEN_BRACKET_OPEN: |
||
94 | printf("bracket open\n"); |
||
95 | break; |
||
96 | case NCD_TOKEN_BRACKET_CLOSE: |
||
97 | printf("bracket close\n"); |
||
98 | break; |
||
99 | case NCD_TOKEN_IF: |
||
100 | printf("if\n"); |
||
101 | break; |
||
102 | case NCD_TOKEN_ELIF: |
||
103 | printf("elif\n"); |
||
104 | break; |
||
105 | case NCD_TOKEN_ELSE: |
||
106 | printf("else\n"); |
||
107 | break; |
||
108 | case NCD_TOKEN_FOREACH: |
||
109 | printf("foreach\n"); |
||
110 | break; |
||
111 | case NCD_TOKEN_AS: |
||
112 | printf("as\n"); |
||
113 | break; |
||
114 | case NCD_TOKEN_INCLUDE: |
||
115 | printf("include\n"); |
||
116 | break; |
||
117 | case NCD_TOKEN_INCLUDE_GUARD: |
||
118 | printf("include_guard\n"); |
||
119 | break; |
||
120 | case NCD_TOKEN_AT: |
||
121 | printf("at\n"); |
||
122 | break; |
||
123 | case NCD_TOKEN_BLOCK: |
||
124 | printf("block\n"); |
||
125 | break; |
||
126 | case NCD_TOKEN_CARET: |
||
127 | printf("caret\n"); |
||
128 | break; |
||
129 | case NCD_TOKEN_DO: |
||
130 | printf("do\n"); |
||
131 | break; |
||
132 | case NCD_TOKEN_INTERRUPT: |
||
133 | printf("interrupt\n"); |
||
134 | break; |
||
135 | default: |
||
136 | printf("UNKNOWN_TOKEN\n"); |
||
137 | break; |
||
138 | } |
||
139 | |||
140 | return 1; |
||
141 | } |
||
142 | |||
143 | int main (int argc, char **argv) |
||
144 | { |
||
145 | if (argc < 1) { |
||
146 | return 1; |
||
147 | } |
||
148 | |||
149 | if (argc != 2) { |
||
150 | printf("Usage: %s <string>\n", argv[0]); |
||
151 | return 1; |
||
152 | } |
||
153 | |||
154 | BLog_InitStdout(); |
||
155 | |||
156 | error = 0; |
||
157 | |||
158 | NCDConfigTokenizer_Tokenize(MemRef_MakeCstr(argv[1]), tokenizer_output, NULL); |
||
159 | |||
160 | if (error) { |
||
161 | return 1; |
||
162 | } |
||
163 | |||
164 | return 0; |
||
165 | } |