nutcracker 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -0
- data/Rakefile +55 -0
- data/bin/nutcracker +2 -0
- data/ext/nutcracker/ChangeLog +66 -0
- data/ext/nutcracker/LICENSE +177 -0
- data/ext/nutcracker/Makefile.am +7 -0
- data/ext/nutcracker/Makefile.in +726 -0
- data/ext/nutcracker/NOTICE +124 -0
- data/ext/nutcracker/README.md +240 -0
- data/ext/nutcracker/aclocal.m4 +956 -0
- data/ext/nutcracker/conf/nutcracker.leaf.yml +10 -0
- data/ext/nutcracker/conf/nutcracker.root.yml +8 -0
- data/ext/nutcracker/conf/nutcracker.yml +67 -0
- data/ext/nutcracker/config.h.in +316 -0
- data/ext/nutcracker/config/config.guess +1561 -0
- data/ext/nutcracker/config/config.sub +1686 -0
- data/ext/nutcracker/config/depcomp +630 -0
- data/ext/nutcracker/config/install-sh +520 -0
- data/ext/nutcracker/config/ltmain.sh +8413 -0
- data/ext/nutcracker/config/missing +376 -0
- data/ext/nutcracker/configure +18862 -0
- data/ext/nutcracker/configure.ac +155 -0
- data/ext/nutcracker/contrib/Makefile.am +3 -0
- data/ext/nutcracker/contrib/Makefile.in +560 -0
- data/ext/nutcracker/contrib/yaml-0.1.4.tar.gz +0 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/LICENSE +19 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/Makefile.am +20 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/Makefile.in +736 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/README +27 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/aclocal.m4 +956 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/config.h.in +80 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/config/config.guess +1561 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/config/config.sub +1686 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/config/depcomp +630 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/config/install-sh +520 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/config/ltmain.sh +8406 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/config/missing +376 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/configure +13085 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/configure.ac +75 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/doc/doxygen.cfg +222 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/include/yaml.h +1971 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/m4/libtool.m4 +7357 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/m4/ltoptions.m4 +368 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/m4/ltsugar.m4 +123 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/m4/ltversion.m4 +23 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/m4/lt~obsolete.m4 +92 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/src/Makefile.am +4 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/src/Makefile.in +484 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/src/api.c +1392 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/src/dumper.c +394 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/src/emitter.c +2329 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/src/loader.c +432 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/src/parser.c +1374 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/src/reader.c +465 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/src/scanner.c +3570 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/src/writer.c +141 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/src/yaml_private.h +640 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/Makefile.am +8 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/Makefile.in +675 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-deconstructor-alt.c +800 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-deconstructor.c +1130 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-reformatter-alt.c +217 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-reformatter.c +202 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-dumper.c +311 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-emitter.c +327 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-loader.c +63 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-parser.c +63 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-scanner.c +63 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/test-reader.c +354 -0
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/test-version.c +29 -0
- data/ext/nutcracker/extconf.rb +5 -0
- data/ext/nutcracker/m4/libtool.m4 +7376 -0
- data/ext/nutcracker/m4/ltoptions.m4 +368 -0
- data/ext/nutcracker/m4/ltsugar.m4 +123 -0
- data/ext/nutcracker/m4/ltversion.m4 +23 -0
- data/ext/nutcracker/m4/lt~obsolete.m4 +92 -0
- data/ext/nutcracker/notes/c-styleguide.txt +425 -0
- data/ext/nutcracker/notes/debug.txt +96 -0
- data/ext/nutcracker/notes/memcache.txt +123 -0
- data/ext/nutcracker/notes/recommendation.md +118 -0
- data/ext/nutcracker/notes/redis.md +415 -0
- data/ext/nutcracker/notes/socket.txt +131 -0
- data/ext/nutcracker/scripts/multi_get.sh +26 -0
- data/ext/nutcracker/scripts/nutcracker.init +73 -0
- data/ext/nutcracker/scripts/nutcracker.spec +52 -0
- data/ext/nutcracker/scripts/pipelined_read.sh +23 -0
- data/ext/nutcracker/scripts/pipelined_write.sh +29 -0
- data/ext/nutcracker/scripts/populate_memcached.sh +24 -0
- data/ext/nutcracker/scripts/redis-check.py +23 -0
- data/ext/nutcracker/scripts/redis-check.sh +564 -0
- data/ext/nutcracker/src/Makefile.am +46 -0
- data/ext/nutcracker/src/Makefile.in +726 -0
- data/ext/nutcracker/src/hashkit/Makefile.am +22 -0
- data/ext/nutcracker/src/hashkit/Makefile.in +501 -0
- data/ext/nutcracker/src/hashkit/nc_crc32.c +105 -0
- data/ext/nutcracker/src/hashkit/nc_fnv.c +82 -0
- data/ext/nutcracker/src/hashkit/nc_hashkit.h +74 -0
- data/ext/nutcracker/src/hashkit/nc_hsieh.c +93 -0
- data/ext/nutcracker/src/hashkit/nc_jenkins.c +230 -0
- data/ext/nutcracker/src/hashkit/nc_ketama.c +240 -0
- data/ext/nutcracker/src/hashkit/nc_md5.c +379 -0
- data/ext/nutcracker/src/hashkit/nc_modula.c +144 -0
- data/ext/nutcracker/src/hashkit/nc_murmur.c +99 -0
- data/ext/nutcracker/src/hashkit/nc_one_at_a_time.c +51 -0
- data/ext/nutcracker/src/hashkit/nc_random.c +146 -0
- data/ext/nutcracker/src/nc.c +573 -0
- data/ext/nutcracker/src/nc_array.c +204 -0
- data/ext/nutcracker/src/nc_array.h +73 -0
- data/ext/nutcracker/src/nc_client.c +189 -0
- data/ext/nutcracker/src/nc_client.h +28 -0
- data/ext/nutcracker/src/nc_conf.c +1766 -0
- data/ext/nutcracker/src/nc_conf.h +134 -0
- data/ext/nutcracker/src/nc_connection.c +392 -0
- data/ext/nutcracker/src/nc_connection.h +99 -0
- data/ext/nutcracker/src/nc_core.c +334 -0
- data/ext/nutcracker/src/nc_core.h +131 -0
- data/ext/nutcracker/src/nc_event.c +214 -0
- data/ext/nutcracker/src/nc_event.h +39 -0
- data/ext/nutcracker/src/nc_log.c +254 -0
- data/ext/nutcracker/src/nc_log.h +120 -0
- data/ext/nutcracker/src/nc_mbuf.c +285 -0
- data/ext/nutcracker/src/nc_mbuf.h +67 -0
- data/ext/nutcracker/src/nc_message.c +828 -0
- data/ext/nutcracker/src/nc_message.h +253 -0
- data/ext/nutcracker/src/nc_proxy.c +359 -0
- data/ext/nutcracker/src/nc_proxy.h +34 -0
- data/ext/nutcracker/src/nc_queue.h +788 -0
- data/ext/nutcracker/src/nc_rbtree.c +348 -0
- data/ext/nutcracker/src/nc_rbtree.h +47 -0
- data/ext/nutcracker/src/nc_request.c +588 -0
- data/ext/nutcracker/src/nc_response.c +332 -0
- data/ext/nutcracker/src/nc_server.c +841 -0
- data/ext/nutcracker/src/nc_server.h +143 -0
- data/ext/nutcracker/src/nc_signal.c +131 -0
- data/ext/nutcracker/src/nc_signal.h +34 -0
- data/ext/nutcracker/src/nc_stats.c +1188 -0
- data/ext/nutcracker/src/nc_stats.h +206 -0
- data/ext/nutcracker/src/nc_string.c +109 -0
- data/ext/nutcracker/src/nc_string.h +112 -0
- data/ext/nutcracker/src/nc_util.c +619 -0
- data/ext/nutcracker/src/nc_util.h +214 -0
- data/ext/nutcracker/src/proto/Makefile.am +14 -0
- data/ext/nutcracker/src/proto/Makefile.in +482 -0
- data/ext/nutcracker/src/proto/nc_memcache.c +1306 -0
- data/ext/nutcracker/src/proto/nc_proto.h +155 -0
- data/ext/nutcracker/src/proto/nc_redis.c +2102 -0
- data/lib/nutcracker.rb +7 -0
- data/lib/nutcracker/version.rb +3 -0
- metadata +194 -0
@@ -0,0 +1,327 @@
|
|
1
|
+
#include <yaml.h>
|
2
|
+
|
3
|
+
#include <stdlib.h>
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <string.h>
|
6
|
+
|
7
|
+
#ifdef NDEBUG
|
8
|
+
#undef NDEBUG
|
9
|
+
#endif
|
10
|
+
#include <assert.h>
|
11
|
+
|
12
|
+
#define BUFFER_SIZE 65536
|
13
|
+
#define MAX_EVENTS 1024
|
14
|
+
|
15
|
+
int copy_event(yaml_event_t *event_to, yaml_event_t *event_from)
|
16
|
+
{
|
17
|
+
switch (event_from->type)
|
18
|
+
{
|
19
|
+
case YAML_STREAM_START_EVENT:
|
20
|
+
return yaml_stream_start_event_initialize(event_to,
|
21
|
+
event_from->data.stream_start.encoding);
|
22
|
+
|
23
|
+
case YAML_STREAM_END_EVENT:
|
24
|
+
return yaml_stream_end_event_initialize(event_to);
|
25
|
+
|
26
|
+
case YAML_DOCUMENT_START_EVENT:
|
27
|
+
return yaml_document_start_event_initialize(event_to,
|
28
|
+
event_from->data.document_start.version_directive,
|
29
|
+
event_from->data.document_start.tag_directives.start,
|
30
|
+
event_from->data.document_start.tag_directives.end,
|
31
|
+
event_from->data.document_start.implicit);
|
32
|
+
|
33
|
+
case YAML_DOCUMENT_END_EVENT:
|
34
|
+
return yaml_document_end_event_initialize(event_to,
|
35
|
+
event_from->data.document_end.implicit);
|
36
|
+
|
37
|
+
case YAML_ALIAS_EVENT:
|
38
|
+
return yaml_alias_event_initialize(event_to,
|
39
|
+
event_from->data.alias.anchor);
|
40
|
+
|
41
|
+
case YAML_SCALAR_EVENT:
|
42
|
+
return yaml_scalar_event_initialize(event_to,
|
43
|
+
event_from->data.scalar.anchor,
|
44
|
+
event_from->data.scalar.tag,
|
45
|
+
event_from->data.scalar.value,
|
46
|
+
event_from->data.scalar.length,
|
47
|
+
event_from->data.scalar.plain_implicit,
|
48
|
+
event_from->data.scalar.quoted_implicit,
|
49
|
+
event_from->data.scalar.style);
|
50
|
+
|
51
|
+
case YAML_SEQUENCE_START_EVENT:
|
52
|
+
return yaml_sequence_start_event_initialize(event_to,
|
53
|
+
event_from->data.sequence_start.anchor,
|
54
|
+
event_from->data.sequence_start.tag,
|
55
|
+
event_from->data.sequence_start.implicit,
|
56
|
+
event_from->data.sequence_start.style);
|
57
|
+
|
58
|
+
case YAML_SEQUENCE_END_EVENT:
|
59
|
+
return yaml_sequence_end_event_initialize(event_to);
|
60
|
+
|
61
|
+
case YAML_MAPPING_START_EVENT:
|
62
|
+
return yaml_mapping_start_event_initialize(event_to,
|
63
|
+
event_from->data.mapping_start.anchor,
|
64
|
+
event_from->data.mapping_start.tag,
|
65
|
+
event_from->data.mapping_start.implicit,
|
66
|
+
event_from->data.mapping_start.style);
|
67
|
+
|
68
|
+
case YAML_MAPPING_END_EVENT:
|
69
|
+
return yaml_mapping_end_event_initialize(event_to);
|
70
|
+
|
71
|
+
default:
|
72
|
+
assert(1);
|
73
|
+
}
|
74
|
+
|
75
|
+
return 0;
|
76
|
+
}
|
77
|
+
|
78
|
+
int compare_events(yaml_event_t *event1, yaml_event_t *event2)
|
79
|
+
{
|
80
|
+
int k;
|
81
|
+
|
82
|
+
if (event1->type != event2->type)
|
83
|
+
return 0;
|
84
|
+
|
85
|
+
switch (event1->type)
|
86
|
+
{
|
87
|
+
case YAML_STREAM_START_EVENT:
|
88
|
+
return 1;
|
89
|
+
/* return (event1->data.stream_start.encoding ==
|
90
|
+
event2->data.stream_start.encoding); */
|
91
|
+
|
92
|
+
case YAML_DOCUMENT_START_EVENT:
|
93
|
+
if ((event1->data.document_start.version_directive && !event2->data.document_start.version_directive)
|
94
|
+
|| (!event1->data.document_start.version_directive && event2->data.document_start.version_directive)
|
95
|
+
|| (event1->data.document_start.version_directive && event2->data.document_start.version_directive
|
96
|
+
&& (event1->data.document_start.version_directive->major != event2->data.document_start.version_directive->major
|
97
|
+
|| event1->data.document_start.version_directive->minor != event2->data.document_start.version_directive->minor)))
|
98
|
+
return 0;
|
99
|
+
if ((event1->data.document_start.tag_directives.end - event1->data.document_start.tag_directives.start) !=
|
100
|
+
(event2->data.document_start.tag_directives.end - event2->data.document_start.tag_directives.start))
|
101
|
+
return 0;
|
102
|
+
for (k = 0; k < (event1->data.document_start.tag_directives.end - event1->data.document_start.tag_directives.start); k ++) {
|
103
|
+
if ((strcmp((char *)event1->data.document_start.tag_directives.start[k].handle,
|
104
|
+
(char *)event2->data.document_start.tag_directives.start[k].handle) != 0)
|
105
|
+
|| (strcmp((char *)event1->data.document_start.tag_directives.start[k].prefix,
|
106
|
+
(char *)event2->data.document_start.tag_directives.start[k].prefix) != 0))
|
107
|
+
return 0;
|
108
|
+
}
|
109
|
+
/* if (event1->data.document_start.implicit != event2->data.document_start.implicit)
|
110
|
+
return 0; */
|
111
|
+
return 1;
|
112
|
+
|
113
|
+
case YAML_DOCUMENT_END_EVENT:
|
114
|
+
return 1;
|
115
|
+
/* return (event1->data.document_end.implicit ==
|
116
|
+
event2->data.document_end.implicit); */
|
117
|
+
|
118
|
+
case YAML_ALIAS_EVENT:
|
119
|
+
return (strcmp((char *)event1->data.alias.anchor,
|
120
|
+
(char *)event2->data.alias.anchor) == 0);
|
121
|
+
|
122
|
+
case YAML_SCALAR_EVENT:
|
123
|
+
if ((event1->data.scalar.anchor && !event2->data.scalar.anchor)
|
124
|
+
|| (!event1->data.scalar.anchor && event2->data.scalar.anchor)
|
125
|
+
|| (event1->data.scalar.anchor && event2->data.scalar.anchor
|
126
|
+
&& strcmp((char *)event1->data.scalar.anchor,
|
127
|
+
(char *)event2->data.scalar.anchor) != 0))
|
128
|
+
return 0;
|
129
|
+
if ((event1->data.scalar.tag && !event2->data.scalar.tag
|
130
|
+
&& strcmp((char *)event1->data.scalar.tag, "!") != 0)
|
131
|
+
|| (!event1->data.scalar.tag && event2->data.scalar.tag
|
132
|
+
&& strcmp((char *)event2->data.scalar.tag, "!") != 0)
|
133
|
+
|| (event1->data.scalar.tag && event2->data.scalar.tag
|
134
|
+
&& strcmp((char *)event1->data.scalar.tag,
|
135
|
+
(char *)event2->data.scalar.tag) != 0))
|
136
|
+
return 0;
|
137
|
+
if ((event1->data.scalar.length != event2->data.scalar.length)
|
138
|
+
|| memcmp(event1->data.scalar.value, event2->data.scalar.value,
|
139
|
+
event1->data.scalar.length) != 0)
|
140
|
+
return 0;
|
141
|
+
if ((event1->data.scalar.plain_implicit != event2->data.scalar.plain_implicit)
|
142
|
+
|| (event2->data.scalar.quoted_implicit != event2->data.scalar.quoted_implicit)
|
143
|
+
/* || (event2->data.scalar.style != event2->data.scalar.style) */)
|
144
|
+
return 0;
|
145
|
+
return 1;
|
146
|
+
|
147
|
+
case YAML_SEQUENCE_START_EVENT:
|
148
|
+
if ((event1->data.sequence_start.anchor && !event2->data.sequence_start.anchor)
|
149
|
+
|| (!event1->data.sequence_start.anchor && event2->data.sequence_start.anchor)
|
150
|
+
|| (event1->data.sequence_start.anchor && event2->data.sequence_start.anchor
|
151
|
+
&& strcmp((char *)event1->data.sequence_start.anchor,
|
152
|
+
(char *)event2->data.sequence_start.anchor) != 0))
|
153
|
+
return 0;
|
154
|
+
if ((event1->data.sequence_start.tag && !event2->data.sequence_start.tag)
|
155
|
+
|| (!event1->data.sequence_start.tag && event2->data.sequence_start.tag)
|
156
|
+
|| (event1->data.sequence_start.tag && event2->data.sequence_start.tag
|
157
|
+
&& strcmp((char *)event1->data.sequence_start.tag,
|
158
|
+
(char *)event2->data.sequence_start.tag) != 0))
|
159
|
+
return 0;
|
160
|
+
if ((event1->data.sequence_start.implicit != event2->data.sequence_start.implicit)
|
161
|
+
/* || (event2->data.sequence_start.style != event2->data.sequence_start.style) */)
|
162
|
+
return 0;
|
163
|
+
return 1;
|
164
|
+
|
165
|
+
case YAML_MAPPING_START_EVENT:
|
166
|
+
if ((event1->data.mapping_start.anchor && !event2->data.mapping_start.anchor)
|
167
|
+
|| (!event1->data.mapping_start.anchor && event2->data.mapping_start.anchor)
|
168
|
+
|| (event1->data.mapping_start.anchor && event2->data.mapping_start.anchor
|
169
|
+
&& strcmp((char *)event1->data.mapping_start.anchor,
|
170
|
+
(char *)event2->data.mapping_start.anchor) != 0))
|
171
|
+
return 0;
|
172
|
+
if ((event1->data.mapping_start.tag && !event2->data.mapping_start.tag)
|
173
|
+
|| (!event1->data.mapping_start.tag && event2->data.mapping_start.tag)
|
174
|
+
|| (event1->data.mapping_start.tag && event2->data.mapping_start.tag
|
175
|
+
&& strcmp((char *)event1->data.mapping_start.tag,
|
176
|
+
(char *)event2->data.mapping_start.tag) != 0))
|
177
|
+
return 0;
|
178
|
+
if ((event1->data.mapping_start.implicit != event2->data.mapping_start.implicit)
|
179
|
+
/* || (event2->data.mapping_start.style != event2->data.mapping_start.style) */)
|
180
|
+
return 0;
|
181
|
+
return 1;
|
182
|
+
|
183
|
+
default:
|
184
|
+
return 1;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
int print_output(char *name, unsigned char *buffer, size_t size, int count)
|
189
|
+
{
|
190
|
+
FILE *file;
|
191
|
+
char data[BUFFER_SIZE];
|
192
|
+
size_t data_size = 1;
|
193
|
+
size_t total_size = 0;
|
194
|
+
if (count >= 0) {
|
195
|
+
printf("FAILED (at the event #%d)\nSOURCE:\n", count+1);
|
196
|
+
}
|
197
|
+
file = fopen(name, "rb");
|
198
|
+
assert(file);
|
199
|
+
while (data_size > 0) {
|
200
|
+
data_size = fread(data, 1, BUFFER_SIZE, file);
|
201
|
+
assert(!ferror(file));
|
202
|
+
if (!data_size) break;
|
203
|
+
assert(fwrite(data, 1, data_size, stdout) == data_size);
|
204
|
+
total_size += data_size;
|
205
|
+
if (feof(file)) break;
|
206
|
+
}
|
207
|
+
fclose(file);
|
208
|
+
printf("#### (length: %d)\n", total_size);
|
209
|
+
printf("OUTPUT:\n%s#### (length: %d)\n", buffer, size);
|
210
|
+
return 0;
|
211
|
+
}
|
212
|
+
|
213
|
+
int
|
214
|
+
main(int argc, char *argv[])
|
215
|
+
{
|
216
|
+
int number;
|
217
|
+
int canonical = 0;
|
218
|
+
int unicode = 0;
|
219
|
+
|
220
|
+
number = 1;
|
221
|
+
while (number < argc) {
|
222
|
+
if (strcmp(argv[number], "-c") == 0) {
|
223
|
+
canonical = 1;
|
224
|
+
}
|
225
|
+
else if (strcmp(argv[number], "-u") == 0) {
|
226
|
+
unicode = 1;
|
227
|
+
}
|
228
|
+
else if (argv[number][0] == '-') {
|
229
|
+
printf("Unknown option: '%s'\n", argv[number]);
|
230
|
+
return 0;
|
231
|
+
}
|
232
|
+
if (argv[number][0] == '-') {
|
233
|
+
if (number < argc-1) {
|
234
|
+
memmove(argv+number, argv+number+1, (argc-number-1)*sizeof(char *));
|
235
|
+
}
|
236
|
+
argc --;
|
237
|
+
}
|
238
|
+
else {
|
239
|
+
number ++;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
if (argc < 2) {
|
244
|
+
printf("Usage: %s [-c] [-u] file1.yaml ...\n", argv[0]);
|
245
|
+
return 0;
|
246
|
+
}
|
247
|
+
|
248
|
+
for (number = 1; number < argc; number ++)
|
249
|
+
{
|
250
|
+
FILE *file;
|
251
|
+
yaml_parser_t parser;
|
252
|
+
yaml_emitter_t emitter;
|
253
|
+
yaml_event_t event;
|
254
|
+
unsigned char buffer[BUFFER_SIZE];
|
255
|
+
size_t written = 0;
|
256
|
+
yaml_event_t events[MAX_EVENTS];
|
257
|
+
size_t event_number = 0;
|
258
|
+
int done = 0;
|
259
|
+
int count = 0;
|
260
|
+
int error = 0;
|
261
|
+
int k;
|
262
|
+
memset(buffer, 0, BUFFER_SIZE);
|
263
|
+
memset(events, 0, MAX_EVENTS*sizeof(yaml_event_t));
|
264
|
+
|
265
|
+
printf("[%d] Parsing, emitting, and parsing again '%s': ", number, argv[number]);
|
266
|
+
fflush(stdout);
|
267
|
+
|
268
|
+
file = fopen(argv[number], "rb");
|
269
|
+
assert(file);
|
270
|
+
|
271
|
+
assert(yaml_parser_initialize(&parser));
|
272
|
+
yaml_parser_set_input_file(&parser, file);
|
273
|
+
assert(yaml_emitter_initialize(&emitter));
|
274
|
+
if (canonical) {
|
275
|
+
yaml_emitter_set_canonical(&emitter, 1);
|
276
|
+
}
|
277
|
+
if (unicode) {
|
278
|
+
yaml_emitter_set_unicode(&emitter, 1);
|
279
|
+
}
|
280
|
+
yaml_emitter_set_output_string(&emitter, buffer, BUFFER_SIZE, &written);
|
281
|
+
|
282
|
+
while (!done)
|
283
|
+
{
|
284
|
+
if (!yaml_parser_parse(&parser, &event)) {
|
285
|
+
error = 1;
|
286
|
+
break;
|
287
|
+
}
|
288
|
+
|
289
|
+
done = (event.type == YAML_STREAM_END_EVENT);
|
290
|
+
assert(event_number < MAX_EVENTS);
|
291
|
+
assert(copy_event(&(events[event_number++]), &event));
|
292
|
+
assert(yaml_emitter_emit(&emitter, &event) ||
|
293
|
+
(yaml_emitter_flush(&emitter) && print_output(argv[number], buffer, written, count)));
|
294
|
+
count ++;
|
295
|
+
}
|
296
|
+
|
297
|
+
yaml_parser_delete(&parser);
|
298
|
+
assert(!fclose(file));
|
299
|
+
yaml_emitter_delete(&emitter);
|
300
|
+
|
301
|
+
if (!error)
|
302
|
+
{
|
303
|
+
count = done = 0;
|
304
|
+
assert(yaml_parser_initialize(&parser));
|
305
|
+
yaml_parser_set_input_string(&parser, buffer, written);
|
306
|
+
|
307
|
+
while (!done)
|
308
|
+
{
|
309
|
+
assert(yaml_parser_parse(&parser, &event) || print_output(argv[number], buffer, written, count));
|
310
|
+
done = (event.type == YAML_STREAM_END_EVENT);
|
311
|
+
assert(compare_events(events+count, &event) || print_output(argv[number], buffer, written, count));
|
312
|
+
yaml_event_delete(&event);
|
313
|
+
count ++;
|
314
|
+
}
|
315
|
+
yaml_parser_delete(&parser);
|
316
|
+
}
|
317
|
+
|
318
|
+
for (k = 0; k < event_number; k ++) {
|
319
|
+
yaml_event_delete(events+k);
|
320
|
+
}
|
321
|
+
|
322
|
+
printf("PASSED (length: %d)\n", written);
|
323
|
+
print_output(argv[number], buffer, written, -1);
|
324
|
+
}
|
325
|
+
|
326
|
+
return 0;
|
327
|
+
}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#include <yaml.h>
|
2
|
+
|
3
|
+
#include <stdlib.h>
|
4
|
+
#include <stdio.h>
|
5
|
+
|
6
|
+
#ifdef NDEBUG
|
7
|
+
#undef NDEBUG
|
8
|
+
#endif
|
9
|
+
#include <assert.h>
|
10
|
+
|
11
|
+
int
|
12
|
+
main(int argc, char *argv[])
|
13
|
+
{
|
14
|
+
int number;
|
15
|
+
|
16
|
+
if (argc < 2) {
|
17
|
+
printf("Usage: %s file1.yaml ...\n", argv[0]);
|
18
|
+
return 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
for (number = 1; number < argc; number ++)
|
22
|
+
{
|
23
|
+
FILE *file;
|
24
|
+
yaml_parser_t parser;
|
25
|
+
yaml_document_t document;
|
26
|
+
int done = 0;
|
27
|
+
int count = 0;
|
28
|
+
int error = 0;
|
29
|
+
|
30
|
+
printf("[%d] Loading '%s': ", number, argv[number]);
|
31
|
+
fflush(stdout);
|
32
|
+
|
33
|
+
file = fopen(argv[number], "rb");
|
34
|
+
assert(file);
|
35
|
+
|
36
|
+
assert(yaml_parser_initialize(&parser));
|
37
|
+
|
38
|
+
yaml_parser_set_input_file(&parser, file);
|
39
|
+
|
40
|
+
while (!done)
|
41
|
+
{
|
42
|
+
if (!yaml_parser_load(&parser, &document)) {
|
43
|
+
error = 1;
|
44
|
+
break;
|
45
|
+
}
|
46
|
+
|
47
|
+
done = (!yaml_document_get_root_node(&document));
|
48
|
+
|
49
|
+
yaml_document_delete(&document);
|
50
|
+
|
51
|
+
if (!done) count ++;
|
52
|
+
}
|
53
|
+
|
54
|
+
yaml_parser_delete(&parser);
|
55
|
+
|
56
|
+
assert(!fclose(file));
|
57
|
+
|
58
|
+
printf("%s (%d documents)\n", (error ? "FAILURE" : "SUCCESS"), count);
|
59
|
+
}
|
60
|
+
|
61
|
+
return 0;
|
62
|
+
}
|
63
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#include <yaml.h>
|
2
|
+
|
3
|
+
#include <stdlib.h>
|
4
|
+
#include <stdio.h>
|
5
|
+
|
6
|
+
#ifdef NDEBUG
|
7
|
+
#undef NDEBUG
|
8
|
+
#endif
|
9
|
+
#include <assert.h>
|
10
|
+
|
11
|
+
int
|
12
|
+
main(int argc, char *argv[])
|
13
|
+
{
|
14
|
+
int number;
|
15
|
+
|
16
|
+
if (argc < 2) {
|
17
|
+
printf("Usage: %s file1.yaml ...\n", argv[0]);
|
18
|
+
return 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
for (number = 1; number < argc; number ++)
|
22
|
+
{
|
23
|
+
FILE *file;
|
24
|
+
yaml_parser_t parser;
|
25
|
+
yaml_event_t event;
|
26
|
+
int done = 0;
|
27
|
+
int count = 0;
|
28
|
+
int error = 0;
|
29
|
+
|
30
|
+
printf("[%d] Parsing '%s': ", number, argv[number]);
|
31
|
+
fflush(stdout);
|
32
|
+
|
33
|
+
file = fopen(argv[number], "rb");
|
34
|
+
assert(file);
|
35
|
+
|
36
|
+
assert(yaml_parser_initialize(&parser));
|
37
|
+
|
38
|
+
yaml_parser_set_input_file(&parser, file);
|
39
|
+
|
40
|
+
while (!done)
|
41
|
+
{
|
42
|
+
if (!yaml_parser_parse(&parser, &event)) {
|
43
|
+
error = 1;
|
44
|
+
break;
|
45
|
+
}
|
46
|
+
|
47
|
+
done = (event.type == YAML_STREAM_END_EVENT);
|
48
|
+
|
49
|
+
yaml_event_delete(&event);
|
50
|
+
|
51
|
+
count ++;
|
52
|
+
}
|
53
|
+
|
54
|
+
yaml_parser_delete(&parser);
|
55
|
+
|
56
|
+
assert(!fclose(file));
|
57
|
+
|
58
|
+
printf("%s (%d events)\n", (error ? "FAILURE" : "SUCCESS"), count);
|
59
|
+
}
|
60
|
+
|
61
|
+
return 0;
|
62
|
+
}
|
63
|
+
|