-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream_test.c
More file actions
68 lines (64 loc) · 1.75 KB
/
stream_test.c
File metadata and controls
68 lines (64 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* This tool prints out the token stream for standard input. It's
* intended to test.
*/
#include <stdio.h>
#include "kvp_parser.h"
const char json_typename[][16] = {
[JSON_ERROR] = "ERROR",
[JSON_END] = "JSON_END",
[JSON_STRING] = "STRING",
[JSON_NUMBER] = "NUMBER",
[JSON_TRUE] = "TRUE",
[JSON_FALSE] = "FALSE",
[JSON_NULL] = "NULL",
};
int main()
{
kvp_iterator s[1];
kvp_open_stream(s, stdin);
kvp_set_streaming(s, 1);
puts("struct expect seq[] = {");
for (bool first = true;;) {
enum kvp_json_type type = kvp_next(s);
const char *value = 0;
switch (type) {
case JSON_NULL:
value = "null";
break;
case JSON_TRUE:
value = "true";
break;
case JSON_FALSE:
value = "false";
break;
case JSON_NUMBER:
value = kvp_get_string(s, 0);
break;
case JSON_STRING:
value = kvp_get_string(s, 0);
break;
/*case JSON_ARRAY:
case JSON_OBJECT:
case JSON_OBJECT_END:
case JSON_ARRAY_END:
case JSON_ERROR:*/
case JSON_END:
break;
}
if (value)
printf(" {JSON_%s, \"%s\"},\n", json_typename[type], value);
else
printf(" {JSON_%s},\n", json_typename[type]);
if (type == JSON_ERROR)
break;
if (type == JSON_END) {
if (first)
break;
kvp_reset_iterator(s);
first = true;
} else
first = false;
}
puts("};");
kvp_close(s);
}