nutcracker 0.3.0.12 → 0.4.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +3 -3
- data/Rakefile +12 -10
- data/ext/nutcracker/Makefile.in +215 -162
- data/ext/nutcracker/README.md +16 -4
- data/ext/nutcracker/aclocal.m4 +432 -254
- data/ext/nutcracker/{contrib/yaml-0.1.4/configure → autom4te.cache/output.0} +11367 -4545
- data/ext/nutcracker/autom4te.cache/output.1 +19907 -0
- data/ext/nutcracker/autom4te.cache/output.2 +19907 -0
- data/ext/nutcracker/autom4te.cache/requests +518 -0
- data/ext/nutcracker/autom4te.cache/traces.0 +2715 -0
- data/ext/nutcracker/autom4te.cache/traces.1 +967 -0
- data/ext/nutcracker/autom4te.cache/traces.2 +2715 -0
- data/ext/nutcracker/config/compile +347 -0
- data/ext/nutcracker/config/config.guess +116 -78
- data/ext/nutcracker/config/config.sub +65 -45
- data/ext/nutcracker/config/depcomp +295 -192
- data/ext/nutcracker/config/install-sh +7 -7
- data/ext/nutcracker/config/ltmain.sh +15 -20
- data/ext/nutcracker/config/missing +149 -265
- data/ext/nutcracker/configure +493 -367
- data/ext/nutcracker/contrib/Makefile.in +158 -116
- data/ext/nutcracker/extconf.rb +0 -1
- data/ext/nutcracker/m4/libtool.m4 +4 -23
- data/ext/nutcracker/m4/ltoptions.m4 +0 -0
- data/ext/nutcracker/m4/ltsugar.m4 +0 -0
- data/ext/nutcracker/m4/ltversion.m4 +0 -0
- data/ext/nutcracker/m4/lt~obsolete.m4 +0 -0
- data/ext/nutcracker/notes/recommendation.md +1 -1
- data/ext/nutcracker/notes/redis.md +35 -3
- data/ext/nutcracker/scripts/benchmark-mget.py +43 -0
- data/ext/nutcracker/scripts/nutcracker.spec +61 -3
- data/ext/nutcracker/scripts/redis-check.sh +43 -0
- data/ext/nutcracker/src/Makefile.in +205 -142
- data/ext/nutcracker/src/event/Makefile.in +164 -66
- data/ext/nutcracker/src/hashkit/Makefile.in +164 -66
- data/ext/nutcracker/src/nc_conf.c +2 -0
- data/ext/nutcracker/src/nc_connection.c +31 -0
- data/ext/nutcracker/src/nc_connection.h +3 -0
- data/ext/nutcracker/src/nc_core.c +38 -2
- data/ext/nutcracker/src/nc_core.h +11 -0
- data/ext/nutcracker/src/nc_log.c +90 -12
- data/ext/nutcracker/src/nc_log.h +11 -0
- data/ext/nutcracker/src/nc_mbuf.h +1 -1
- data/ext/nutcracker/src/nc_message.c +162 -116
- data/ext/nutcracker/src/nc_message.h +161 -129
- data/ext/nutcracker/src/nc_proxy.c +34 -4
- data/ext/nutcracker/src/nc_request.c +158 -32
- data/ext/nutcracker/src/nc_server.c +59 -5
- data/ext/nutcracker/src/nc_server.h +1 -0
- data/ext/nutcracker/src/nc_signal.c +2 -2
- data/ext/nutcracker/src/nc_stats.c +21 -0
- data/ext/nutcracker/src/nc_stats.h +28 -26
- data/ext/nutcracker/src/nc_string.c +176 -1
- data/ext/nutcracker/src/nc_string.h +26 -0
- data/ext/nutcracker/src/nc_util.c +12 -0
- data/ext/nutcracker/src/nc_util.h +1 -0
- data/ext/nutcracker/src/proto/Makefile.in +164 -66
- data/ext/nutcracker/src/proto/nc_memcache.c +279 -88
- data/ext/nutcracker/src/proto/nc_proto.h +3 -4
- data/ext/nutcracker/src/proto/nc_redis.c +561 -134
- data/lib/nutcracker/version.rb +1 -1
- metadata +31 -67
- data/ext/nutcracker/contrib/yaml-0.1.4/LICENSE +0 -19
- data/ext/nutcracker/contrib/yaml-0.1.4/Makefile.am +0 -20
- data/ext/nutcracker/contrib/yaml-0.1.4/Makefile.in +0 -736
- data/ext/nutcracker/contrib/yaml-0.1.4/README +0 -27
- data/ext/nutcracker/contrib/yaml-0.1.4/aclocal.m4 +0 -956
- data/ext/nutcracker/contrib/yaml-0.1.4/config.h.in +0 -80
- data/ext/nutcracker/contrib/yaml-0.1.4/config/config.guess +0 -1561
- data/ext/nutcracker/contrib/yaml-0.1.4/config/config.sub +0 -1686
- data/ext/nutcracker/contrib/yaml-0.1.4/config/depcomp +0 -630
- data/ext/nutcracker/contrib/yaml-0.1.4/config/install-sh +0 -520
- data/ext/nutcracker/contrib/yaml-0.1.4/config/ltmain.sh +0 -8406
- data/ext/nutcracker/contrib/yaml-0.1.4/config/missing +0 -376
- data/ext/nutcracker/contrib/yaml-0.1.4/configure.ac +0 -75
- data/ext/nutcracker/contrib/yaml-0.1.4/doc/doxygen.cfg +0 -222
- data/ext/nutcracker/contrib/yaml-0.1.4/include/yaml.h +0 -1971
- data/ext/nutcracker/contrib/yaml-0.1.4/m4/libtool.m4 +0 -7357
- data/ext/nutcracker/contrib/yaml-0.1.4/m4/ltoptions.m4 +0 -368
- data/ext/nutcracker/contrib/yaml-0.1.4/m4/ltsugar.m4 +0 -123
- data/ext/nutcracker/contrib/yaml-0.1.4/m4/ltversion.m4 +0 -23
- data/ext/nutcracker/contrib/yaml-0.1.4/m4/lt~obsolete.m4 +0 -92
- data/ext/nutcracker/contrib/yaml-0.1.4/src/Makefile.am +0 -4
- data/ext/nutcracker/contrib/yaml-0.1.4/src/Makefile.in +0 -484
- data/ext/nutcracker/contrib/yaml-0.1.4/src/api.c +0 -1392
- data/ext/nutcracker/contrib/yaml-0.1.4/src/dumper.c +0 -394
- data/ext/nutcracker/contrib/yaml-0.1.4/src/emitter.c +0 -2329
- data/ext/nutcracker/contrib/yaml-0.1.4/src/loader.c +0 -432
- data/ext/nutcracker/contrib/yaml-0.1.4/src/parser.c +0 -1374
- data/ext/nutcracker/contrib/yaml-0.1.4/src/reader.c +0 -465
- data/ext/nutcracker/contrib/yaml-0.1.4/src/scanner.c +0 -3570
- data/ext/nutcracker/contrib/yaml-0.1.4/src/writer.c +0 -141
- data/ext/nutcracker/contrib/yaml-0.1.4/src/yaml_private.h +0 -640
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/Makefile.am +0 -8
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/Makefile.in +0 -675
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-deconstructor-alt.c +0 -800
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-deconstructor.c +0 -1130
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-reformatter-alt.c +0 -217
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-reformatter.c +0 -202
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-dumper.c +0 -311
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-emitter.c +0 -327
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-loader.c +0 -63
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-parser.c +0 -63
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-scanner.c +0 -63
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/test-reader.c +0 -354
- data/ext/nutcracker/contrib/yaml-0.1.4/tests/test-version.c +0 -29
@@ -1,217 +0,0 @@
|
|
1
|
-
|
2
|
-
#include <yaml.h>
|
3
|
-
|
4
|
-
#include <stdlib.h>
|
5
|
-
#include <stdio.h>
|
6
|
-
|
7
|
-
int
|
8
|
-
main(int argc, char *argv[])
|
9
|
-
{
|
10
|
-
int help = 0;
|
11
|
-
int canonical = 0;
|
12
|
-
int unicode = 0;
|
13
|
-
int k;
|
14
|
-
int done = 0;
|
15
|
-
|
16
|
-
yaml_parser_t parser;
|
17
|
-
yaml_emitter_t emitter;
|
18
|
-
yaml_document_t document;
|
19
|
-
|
20
|
-
/* Clear the objects. */
|
21
|
-
|
22
|
-
memset(&parser, 0, sizeof(parser));
|
23
|
-
memset(&emitter, 0, sizeof(emitter));
|
24
|
-
memset(&document, 0, sizeof(document));
|
25
|
-
|
26
|
-
/* Analyze command line options. */
|
27
|
-
|
28
|
-
for (k = 1; k < argc; k ++)
|
29
|
-
{
|
30
|
-
if (strcmp(argv[k], "-h") == 0
|
31
|
-
|| strcmp(argv[k], "--help") == 0) {
|
32
|
-
help = 1;
|
33
|
-
}
|
34
|
-
|
35
|
-
else if (strcmp(argv[k], "-c") == 0
|
36
|
-
|| strcmp(argv[k], "--canonical") == 0) {
|
37
|
-
canonical = 1;
|
38
|
-
}
|
39
|
-
|
40
|
-
else if (strcmp(argv[k], "-u") == 0
|
41
|
-
|| strcmp(argv[k], "--unicode") == 0) {
|
42
|
-
unicode = 1;
|
43
|
-
}
|
44
|
-
|
45
|
-
else {
|
46
|
-
fprintf(stderr, "Unrecognized option: %s\n"
|
47
|
-
"Try `%s --help` for more information.\n",
|
48
|
-
argv[k], argv[0]);
|
49
|
-
return 1;
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
/* Display the help string. */
|
54
|
-
|
55
|
-
if (help)
|
56
|
-
{
|
57
|
-
printf("%s [--canonical] [--unicode] <input >output\n"
|
58
|
-
"or\n%s -h | --help\nReformat a YAML stream\n\nOptions:\n"
|
59
|
-
"-h, --help\t\tdisplay this help and exit\n"
|
60
|
-
"-c, --canonical\t\toutput in the canonical YAML format\n"
|
61
|
-
"-u, --unicode\t\toutput unescaped non-ASCII characters\n",
|
62
|
-
argv[0], argv[0]);
|
63
|
-
return 0;
|
64
|
-
}
|
65
|
-
|
66
|
-
/* Initialize the parser and emitter objects. */
|
67
|
-
|
68
|
-
if (!yaml_parser_initialize(&parser))
|
69
|
-
goto parser_error;
|
70
|
-
|
71
|
-
if (!yaml_emitter_initialize(&emitter))
|
72
|
-
goto emitter_error;
|
73
|
-
|
74
|
-
/* Set the parser parameters. */
|
75
|
-
|
76
|
-
yaml_parser_set_input_file(&parser, stdin);
|
77
|
-
|
78
|
-
/* Set the emitter parameters. */
|
79
|
-
|
80
|
-
yaml_emitter_set_output_file(&emitter, stdout);
|
81
|
-
|
82
|
-
yaml_emitter_set_canonical(&emitter, canonical);
|
83
|
-
yaml_emitter_set_unicode(&emitter, unicode);
|
84
|
-
|
85
|
-
/* The main loop. */
|
86
|
-
|
87
|
-
while (!done)
|
88
|
-
{
|
89
|
-
/* Get the next event. */
|
90
|
-
|
91
|
-
if (!yaml_parser_load(&parser, &document))
|
92
|
-
goto parser_error;
|
93
|
-
|
94
|
-
/* Check if this is the stream end. */
|
95
|
-
|
96
|
-
if (!yaml_document_get_root_node(&document)) {
|
97
|
-
done = 1;
|
98
|
-
}
|
99
|
-
|
100
|
-
/* Emit the event. */
|
101
|
-
|
102
|
-
if (!yaml_emitter_dump(&emitter, &document))
|
103
|
-
goto emitter_error;
|
104
|
-
}
|
105
|
-
|
106
|
-
yaml_parser_delete(&parser);
|
107
|
-
yaml_emitter_delete(&emitter);
|
108
|
-
|
109
|
-
return 0;
|
110
|
-
|
111
|
-
parser_error:
|
112
|
-
|
113
|
-
/* Display a parser error message. */
|
114
|
-
|
115
|
-
switch (parser.error)
|
116
|
-
{
|
117
|
-
case YAML_MEMORY_ERROR:
|
118
|
-
fprintf(stderr, "Memory error: Not enough memory for parsing\n");
|
119
|
-
break;
|
120
|
-
|
121
|
-
case YAML_READER_ERROR:
|
122
|
-
if (parser.problem_value != -1) {
|
123
|
-
fprintf(stderr, "Reader error: %s: #%X at %d\n", parser.problem,
|
124
|
-
parser.problem_value, parser.problem_offset);
|
125
|
-
}
|
126
|
-
else {
|
127
|
-
fprintf(stderr, "Reader error: %s at %d\n", parser.problem,
|
128
|
-
parser.problem_offset);
|
129
|
-
}
|
130
|
-
break;
|
131
|
-
|
132
|
-
case YAML_SCANNER_ERROR:
|
133
|
-
if (parser.context) {
|
134
|
-
fprintf(stderr, "Scanner error: %s at line %d, column %d\n"
|
135
|
-
"%s at line %d, column %d\n", parser.context,
|
136
|
-
parser.context_mark.line+1, parser.context_mark.column+1,
|
137
|
-
parser.problem, parser.problem_mark.line+1,
|
138
|
-
parser.problem_mark.column+1);
|
139
|
-
}
|
140
|
-
else {
|
141
|
-
fprintf(stderr, "Scanner error: %s at line %d, column %d\n",
|
142
|
-
parser.problem, parser.problem_mark.line+1,
|
143
|
-
parser.problem_mark.column+1);
|
144
|
-
}
|
145
|
-
break;
|
146
|
-
|
147
|
-
case YAML_PARSER_ERROR:
|
148
|
-
if (parser.context) {
|
149
|
-
fprintf(stderr, "Parser error: %s at line %d, column %d\n"
|
150
|
-
"%s at line %d, column %d\n", parser.context,
|
151
|
-
parser.context_mark.line+1, parser.context_mark.column+1,
|
152
|
-
parser.problem, parser.problem_mark.line+1,
|
153
|
-
parser.problem_mark.column+1);
|
154
|
-
}
|
155
|
-
else {
|
156
|
-
fprintf(stderr, "Parser error: %s at line %d, column %d\n",
|
157
|
-
parser.problem, parser.problem_mark.line+1,
|
158
|
-
parser.problem_mark.column+1);
|
159
|
-
}
|
160
|
-
break;
|
161
|
-
|
162
|
-
case YAML_COMPOSER_ERROR:
|
163
|
-
if (parser.context) {
|
164
|
-
fprintf(stderr, "Composer error: %s at line %d, column %d\n"
|
165
|
-
"%s at line %d, column %d\n", parser.context,
|
166
|
-
parser.context_mark.line+1, parser.context_mark.column+1,
|
167
|
-
parser.problem, parser.problem_mark.line+1,
|
168
|
-
parser.problem_mark.column+1);
|
169
|
-
}
|
170
|
-
else {
|
171
|
-
fprintf(stderr, "Composer error: %s at line %d, column %d\n",
|
172
|
-
parser.problem, parser.problem_mark.line+1,
|
173
|
-
parser.problem_mark.column+1);
|
174
|
-
}
|
175
|
-
break;
|
176
|
-
|
177
|
-
default:
|
178
|
-
/* Couldn't happen. */
|
179
|
-
fprintf(stderr, "Internal error\n");
|
180
|
-
break;
|
181
|
-
}
|
182
|
-
|
183
|
-
yaml_parser_delete(&parser);
|
184
|
-
yaml_emitter_delete(&emitter);
|
185
|
-
|
186
|
-
return 1;
|
187
|
-
|
188
|
-
emitter_error:
|
189
|
-
|
190
|
-
/* Display an emitter error message. */
|
191
|
-
|
192
|
-
switch (emitter.error)
|
193
|
-
{
|
194
|
-
case YAML_MEMORY_ERROR:
|
195
|
-
fprintf(stderr, "Memory error: Not enough memory for emitting\n");
|
196
|
-
break;
|
197
|
-
|
198
|
-
case YAML_WRITER_ERROR:
|
199
|
-
fprintf(stderr, "Writer error: %s\n", emitter.problem);
|
200
|
-
break;
|
201
|
-
|
202
|
-
case YAML_EMITTER_ERROR:
|
203
|
-
fprintf(stderr, "Emitter error: %s\n", emitter.problem);
|
204
|
-
break;
|
205
|
-
|
206
|
-
default:
|
207
|
-
/* Couldn't happen. */
|
208
|
-
fprintf(stderr, "Internal error\n");
|
209
|
-
break;
|
210
|
-
}
|
211
|
-
|
212
|
-
yaml_parser_delete(&parser);
|
213
|
-
yaml_emitter_delete(&emitter);
|
214
|
-
|
215
|
-
return 1;
|
216
|
-
}
|
217
|
-
|
@@ -1,202 +0,0 @@
|
|
1
|
-
|
2
|
-
#include <yaml.h>
|
3
|
-
|
4
|
-
#include <stdlib.h>
|
5
|
-
#include <stdio.h>
|
6
|
-
|
7
|
-
int
|
8
|
-
main(int argc, char *argv[])
|
9
|
-
{
|
10
|
-
int help = 0;
|
11
|
-
int canonical = 0;
|
12
|
-
int unicode = 0;
|
13
|
-
int k;
|
14
|
-
int done = 0;
|
15
|
-
|
16
|
-
yaml_parser_t parser;
|
17
|
-
yaml_emitter_t emitter;
|
18
|
-
yaml_event_t event;
|
19
|
-
|
20
|
-
/* Clear the objects. */
|
21
|
-
|
22
|
-
memset(&parser, 0, sizeof(parser));
|
23
|
-
memset(&emitter, 0, sizeof(emitter));
|
24
|
-
memset(&event, 0, sizeof(event));
|
25
|
-
|
26
|
-
/* Analyze command line options. */
|
27
|
-
|
28
|
-
for (k = 1; k < argc; k ++)
|
29
|
-
{
|
30
|
-
if (strcmp(argv[k], "-h") == 0
|
31
|
-
|| strcmp(argv[k], "--help") == 0) {
|
32
|
-
help = 1;
|
33
|
-
}
|
34
|
-
|
35
|
-
else if (strcmp(argv[k], "-c") == 0
|
36
|
-
|| strcmp(argv[k], "--canonical") == 0) {
|
37
|
-
canonical = 1;
|
38
|
-
}
|
39
|
-
|
40
|
-
else if (strcmp(argv[k], "-u") == 0
|
41
|
-
|| strcmp(argv[k], "--unicode") == 0) {
|
42
|
-
unicode = 1;
|
43
|
-
}
|
44
|
-
|
45
|
-
else {
|
46
|
-
fprintf(stderr, "Unrecognized option: %s\n"
|
47
|
-
"Try `%s --help` for more information.\n",
|
48
|
-
argv[k], argv[0]);
|
49
|
-
return 1;
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
/* Display the help string. */
|
54
|
-
|
55
|
-
if (help)
|
56
|
-
{
|
57
|
-
printf("%s [--canonical] [--unicode] <input >output\n"
|
58
|
-
"or\n%s -h | --help\nReformat a YAML stream\n\nOptions:\n"
|
59
|
-
"-h, --help\t\tdisplay this help and exit\n"
|
60
|
-
"-c, --canonical\t\toutput in the canonical YAML format\n"
|
61
|
-
"-u, --unicode\t\toutput unescaped non-ASCII characters\n",
|
62
|
-
argv[0], argv[0]);
|
63
|
-
return 0;
|
64
|
-
}
|
65
|
-
|
66
|
-
/* Initialize the parser and emitter objects. */
|
67
|
-
|
68
|
-
if (!yaml_parser_initialize(&parser))
|
69
|
-
goto parser_error;
|
70
|
-
|
71
|
-
if (!yaml_emitter_initialize(&emitter))
|
72
|
-
goto emitter_error;
|
73
|
-
|
74
|
-
/* Set the parser parameters. */
|
75
|
-
|
76
|
-
yaml_parser_set_input_file(&parser, stdin);
|
77
|
-
|
78
|
-
/* Set the emitter parameters. */
|
79
|
-
|
80
|
-
yaml_emitter_set_output_file(&emitter, stdout);
|
81
|
-
|
82
|
-
yaml_emitter_set_canonical(&emitter, canonical);
|
83
|
-
yaml_emitter_set_unicode(&emitter, unicode);
|
84
|
-
|
85
|
-
/* The main loop. */
|
86
|
-
|
87
|
-
while (!done)
|
88
|
-
{
|
89
|
-
/* Get the next event. */
|
90
|
-
|
91
|
-
if (!yaml_parser_parse(&parser, &event))
|
92
|
-
goto parser_error;
|
93
|
-
|
94
|
-
/* Check if this is the stream end. */
|
95
|
-
|
96
|
-
if (event.type == YAML_STREAM_END_EVENT) {
|
97
|
-
done = 1;
|
98
|
-
}
|
99
|
-
|
100
|
-
/* Emit the event. */
|
101
|
-
|
102
|
-
if (!yaml_emitter_emit(&emitter, &event))
|
103
|
-
goto emitter_error;
|
104
|
-
}
|
105
|
-
|
106
|
-
yaml_parser_delete(&parser);
|
107
|
-
yaml_emitter_delete(&emitter);
|
108
|
-
|
109
|
-
return 0;
|
110
|
-
|
111
|
-
parser_error:
|
112
|
-
|
113
|
-
/* Display a parser error message. */
|
114
|
-
|
115
|
-
switch (parser.error)
|
116
|
-
{
|
117
|
-
case YAML_MEMORY_ERROR:
|
118
|
-
fprintf(stderr, "Memory error: Not enough memory for parsing\n");
|
119
|
-
break;
|
120
|
-
|
121
|
-
case YAML_READER_ERROR:
|
122
|
-
if (parser.problem_value != -1) {
|
123
|
-
fprintf(stderr, "Reader error: %s: #%X at %d\n", parser.problem,
|
124
|
-
parser.problem_value, parser.problem_offset);
|
125
|
-
}
|
126
|
-
else {
|
127
|
-
fprintf(stderr, "Reader error: %s at %d\n", parser.problem,
|
128
|
-
parser.problem_offset);
|
129
|
-
}
|
130
|
-
break;
|
131
|
-
|
132
|
-
case YAML_SCANNER_ERROR:
|
133
|
-
if (parser.context) {
|
134
|
-
fprintf(stderr, "Scanner error: %s at line %d, column %d\n"
|
135
|
-
"%s at line %d, column %d\n", parser.context,
|
136
|
-
parser.context_mark.line+1, parser.context_mark.column+1,
|
137
|
-
parser.problem, parser.problem_mark.line+1,
|
138
|
-
parser.problem_mark.column+1);
|
139
|
-
}
|
140
|
-
else {
|
141
|
-
fprintf(stderr, "Scanner error: %s at line %d, column %d\n",
|
142
|
-
parser.problem, parser.problem_mark.line+1,
|
143
|
-
parser.problem_mark.column+1);
|
144
|
-
}
|
145
|
-
break;
|
146
|
-
|
147
|
-
case YAML_PARSER_ERROR:
|
148
|
-
if (parser.context) {
|
149
|
-
fprintf(stderr, "Parser error: %s at line %d, column %d\n"
|
150
|
-
"%s at line %d, column %d\n", parser.context,
|
151
|
-
parser.context_mark.line+1, parser.context_mark.column+1,
|
152
|
-
parser.problem, parser.problem_mark.line+1,
|
153
|
-
parser.problem_mark.column+1);
|
154
|
-
}
|
155
|
-
else {
|
156
|
-
fprintf(stderr, "Parser error: %s at line %d, column %d\n",
|
157
|
-
parser.problem, parser.problem_mark.line+1,
|
158
|
-
parser.problem_mark.column+1);
|
159
|
-
}
|
160
|
-
break;
|
161
|
-
|
162
|
-
default:
|
163
|
-
/* Couldn't happen. */
|
164
|
-
fprintf(stderr, "Internal error\n");
|
165
|
-
break;
|
166
|
-
}
|
167
|
-
|
168
|
-
yaml_parser_delete(&parser);
|
169
|
-
yaml_emitter_delete(&emitter);
|
170
|
-
|
171
|
-
return 1;
|
172
|
-
|
173
|
-
emitter_error:
|
174
|
-
|
175
|
-
/* Display an emitter error message. */
|
176
|
-
|
177
|
-
switch (emitter.error)
|
178
|
-
{
|
179
|
-
case YAML_MEMORY_ERROR:
|
180
|
-
fprintf(stderr, "Memory error: Not enough memory for emitting\n");
|
181
|
-
break;
|
182
|
-
|
183
|
-
case YAML_WRITER_ERROR:
|
184
|
-
fprintf(stderr, "Writer error: %s\n", emitter.problem);
|
185
|
-
break;
|
186
|
-
|
187
|
-
case YAML_EMITTER_ERROR:
|
188
|
-
fprintf(stderr, "Emitter error: %s\n", emitter.problem);
|
189
|
-
break;
|
190
|
-
|
191
|
-
default:
|
192
|
-
/* Couldn't happen. */
|
193
|
-
fprintf(stderr, "Internal error\n");
|
194
|
-
break;
|
195
|
-
}
|
196
|
-
|
197
|
-
yaml_parser_delete(&parser);
|
198
|
-
yaml_emitter_delete(&emitter);
|
199
|
-
|
200
|
-
return 1;
|
201
|
-
}
|
202
|
-
|
@@ -1,311 +0,0 @@
|
|
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_DOCUMENTS 16
|
14
|
-
|
15
|
-
int copy_document(yaml_document_t *document_to, yaml_document_t *document_from)
|
16
|
-
{
|
17
|
-
yaml_node_t *node;
|
18
|
-
yaml_node_item_t *item;
|
19
|
-
yaml_node_pair_t *pair;
|
20
|
-
|
21
|
-
if (!yaml_document_initialize(document_to, document_from->version_directive,
|
22
|
-
document_from->tag_directives.start,
|
23
|
-
document_from->tag_directives.end,
|
24
|
-
document_from->start_implicit, document_from->end_implicit))
|
25
|
-
return 0;
|
26
|
-
|
27
|
-
for (node = document_from->nodes.start;
|
28
|
-
node < document_from->nodes.top; node ++) {
|
29
|
-
switch (node->type) {
|
30
|
-
case YAML_SCALAR_NODE:
|
31
|
-
if (!yaml_document_add_scalar(document_to, node->tag,
|
32
|
-
node->data.scalar.value, node->data.scalar.length,
|
33
|
-
node->data.scalar.style)) goto error;
|
34
|
-
break;
|
35
|
-
case YAML_SEQUENCE_NODE:
|
36
|
-
if (!yaml_document_add_sequence(document_to, node->tag,
|
37
|
-
node->data.sequence.style)) goto error;
|
38
|
-
break;
|
39
|
-
case YAML_MAPPING_NODE:
|
40
|
-
if (!yaml_document_add_mapping(document_to, node->tag,
|
41
|
-
node->data.mapping.style)) goto error;
|
42
|
-
break;
|
43
|
-
default:
|
44
|
-
assert(0);
|
45
|
-
break;
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
for (node = document_from->nodes.start;
|
50
|
-
node < document_from->nodes.top; node ++) {
|
51
|
-
switch (node->type) {
|
52
|
-
case YAML_SEQUENCE_NODE:
|
53
|
-
for (item = node->data.sequence.items.start;
|
54
|
-
item < node->data.sequence.items.top; item ++) {
|
55
|
-
if (!yaml_document_append_sequence_item(document_to,
|
56
|
-
node - document_from->nodes.start + 1,
|
57
|
-
*item)) goto error;
|
58
|
-
}
|
59
|
-
break;
|
60
|
-
case YAML_MAPPING_NODE:
|
61
|
-
for (pair = node->data.mapping.pairs.start;
|
62
|
-
pair < node->data.mapping.pairs.top; pair ++) {
|
63
|
-
if (!yaml_document_append_mapping_pair(document_to,
|
64
|
-
node - document_from->nodes.start + 1,
|
65
|
-
pair->key, pair->value)) goto error;
|
66
|
-
}
|
67
|
-
break;
|
68
|
-
default:
|
69
|
-
break;
|
70
|
-
}
|
71
|
-
}
|
72
|
-
return 1;
|
73
|
-
|
74
|
-
error:
|
75
|
-
yaml_document_delete(document_to);
|
76
|
-
return 0;
|
77
|
-
}
|
78
|
-
|
79
|
-
int compare_nodes(yaml_document_t *document1, int index1,
|
80
|
-
yaml_document_t *document2, int index2)
|
81
|
-
{
|
82
|
-
yaml_node_t *node1 = yaml_document_get_node(document1, index1);
|
83
|
-
yaml_node_t *node2 = yaml_document_get_node(document2, index2);
|
84
|
-
int k;
|
85
|
-
|
86
|
-
assert(node1);
|
87
|
-
assert(node2);
|
88
|
-
|
89
|
-
if (node1->type != node2->type)
|
90
|
-
return 0;
|
91
|
-
|
92
|
-
if (strcmp((char *)node1->tag, (char *)node2->tag) != 0) return 0;
|
93
|
-
|
94
|
-
switch (node1->type) {
|
95
|
-
case YAML_SCALAR_NODE:
|
96
|
-
if (node1->data.scalar.length != node2->data.scalar.length)
|
97
|
-
return 0;
|
98
|
-
if (strncmp((char *)node1->data.scalar.value, (char *)node2->data.scalar.value,
|
99
|
-
node1->data.scalar.length) != 0) return 0;
|
100
|
-
break;
|
101
|
-
case YAML_SEQUENCE_NODE:
|
102
|
-
if ((node1->data.sequence.items.top - node1->data.sequence.items.start) !=
|
103
|
-
(node2->data.sequence.items.top - node2->data.sequence.items.start))
|
104
|
-
return 0;
|
105
|
-
for (k = 0; k < (node1->data.sequence.items.top - node1->data.sequence.items.start); k ++) {
|
106
|
-
if (!compare_nodes(document1, node1->data.sequence.items.start[k],
|
107
|
-
document2, node2->data.sequence.items.start[k])) return 0;
|
108
|
-
}
|
109
|
-
break;
|
110
|
-
case YAML_MAPPING_NODE:
|
111
|
-
if ((node1->data.mapping.pairs.top - node1->data.mapping.pairs.start) !=
|
112
|
-
(node2->data.mapping.pairs.top - node2->data.mapping.pairs.start))
|
113
|
-
return 0;
|
114
|
-
for (k = 0; k < (node1->data.mapping.pairs.top - node1->data.mapping.pairs.start); k ++) {
|
115
|
-
if (!compare_nodes(document1, node1->data.mapping.pairs.start[k].key,
|
116
|
-
document2, node2->data.mapping.pairs.start[k].key)) return 0;
|
117
|
-
if (!compare_nodes(document1, node1->data.mapping.pairs.start[k].value,
|
118
|
-
document2, node2->data.mapping.pairs.start[k].value)) return 0;
|
119
|
-
}
|
120
|
-
break;
|
121
|
-
default:
|
122
|
-
assert(0);
|
123
|
-
break;
|
124
|
-
}
|
125
|
-
return 1;
|
126
|
-
}
|
127
|
-
|
128
|
-
int compare_documents(yaml_document_t *document1, yaml_document_t *document2)
|
129
|
-
{
|
130
|
-
int k;
|
131
|
-
|
132
|
-
if ((document1->version_directive && !document2->version_directive)
|
133
|
-
|| (!document1->version_directive && document2->version_directive)
|
134
|
-
|| (document1->version_directive && document2->version_directive
|
135
|
-
&& (document1->version_directive->major != document2->version_directive->major
|
136
|
-
|| document1->version_directive->minor != document2->version_directive->minor)))
|
137
|
-
return 0;
|
138
|
-
|
139
|
-
if ((document1->tag_directives.end - document1->tag_directives.start) !=
|
140
|
-
(document2->tag_directives.end - document2->tag_directives.start))
|
141
|
-
return 0;
|
142
|
-
for (k = 0; k < (document1->tag_directives.end - document1->tag_directives.start); k ++) {
|
143
|
-
if ((strcmp((char *)document1->tag_directives.start[k].handle,
|
144
|
-
(char *)document2->tag_directives.start[k].handle) != 0)
|
145
|
-
|| (strcmp((char *)document1->tag_directives.start[k].prefix,
|
146
|
-
(char *)document2->tag_directives.start[k].prefix) != 0))
|
147
|
-
return 0;
|
148
|
-
}
|
149
|
-
|
150
|
-
if ((document1->nodes.top - document1->nodes.start) !=
|
151
|
-
(document2->nodes.top - document2->nodes.start))
|
152
|
-
return 0;
|
153
|
-
|
154
|
-
if (document1->nodes.top != document1->nodes.start) {
|
155
|
-
if (!compare_nodes(document1, 1, document2, 1))
|
156
|
-
return 0;
|
157
|
-
}
|
158
|
-
|
159
|
-
return 1;
|
160
|
-
}
|
161
|
-
|
162
|
-
int print_output(char *name, unsigned char *buffer, size_t size, int count)
|
163
|
-
{
|
164
|
-
FILE *file;
|
165
|
-
char data[BUFFER_SIZE];
|
166
|
-
size_t data_size = 1;
|
167
|
-
size_t total_size = 0;
|
168
|
-
if (count >= 0) {
|
169
|
-
printf("FAILED (at the document #%d)\nSOURCE:\n", count+1);
|
170
|
-
}
|
171
|
-
file = fopen(name, "rb");
|
172
|
-
assert(file);
|
173
|
-
while (data_size > 0) {
|
174
|
-
data_size = fread(data, 1, BUFFER_SIZE, file);
|
175
|
-
assert(!ferror(file));
|
176
|
-
if (!data_size) break;
|
177
|
-
assert(fwrite(data, 1, data_size, stdout) == data_size);
|
178
|
-
total_size += data_size;
|
179
|
-
if (feof(file)) break;
|
180
|
-
}
|
181
|
-
fclose(file);
|
182
|
-
printf("#### (length: %d)\n", total_size);
|
183
|
-
printf("OUTPUT:\n%s#### (length: %d)\n", buffer, size);
|
184
|
-
return 0;
|
185
|
-
}
|
186
|
-
|
187
|
-
int
|
188
|
-
main(int argc, char *argv[])
|
189
|
-
{
|
190
|
-
int number;
|
191
|
-
int canonical = 0;
|
192
|
-
int unicode = 0;
|
193
|
-
|
194
|
-
number = 1;
|
195
|
-
while (number < argc) {
|
196
|
-
if (strcmp(argv[number], "-c") == 0) {
|
197
|
-
canonical = 1;
|
198
|
-
}
|
199
|
-
else if (strcmp(argv[number], "-u") == 0) {
|
200
|
-
unicode = 1;
|
201
|
-
}
|
202
|
-
else if (argv[number][0] == '-') {
|
203
|
-
printf("Unknown option: '%s'\n", argv[number]);
|
204
|
-
return 0;
|
205
|
-
}
|
206
|
-
if (argv[number][0] == '-') {
|
207
|
-
if (number < argc-1) {
|
208
|
-
memmove(argv+number, argv+number+1, (argc-number-1)*sizeof(char *));
|
209
|
-
}
|
210
|
-
argc --;
|
211
|
-
}
|
212
|
-
else {
|
213
|
-
number ++;
|
214
|
-
}
|
215
|
-
}
|
216
|
-
|
217
|
-
if (argc < 2) {
|
218
|
-
printf("Usage: %s [-c] [-u] file1.yaml ...\n", argv[0]);
|
219
|
-
return 0;
|
220
|
-
}
|
221
|
-
|
222
|
-
for (number = 1; number < argc; number ++)
|
223
|
-
{
|
224
|
-
FILE *file;
|
225
|
-
yaml_parser_t parser;
|
226
|
-
yaml_emitter_t emitter;
|
227
|
-
|
228
|
-
yaml_document_t document;
|
229
|
-
unsigned char buffer[BUFFER_SIZE];
|
230
|
-
size_t written = 0;
|
231
|
-
yaml_document_t documents[MAX_DOCUMENTS];
|
232
|
-
size_t document_number = 0;
|
233
|
-
int done = 0;
|
234
|
-
int count = 0;
|
235
|
-
int error = 0;
|
236
|
-
int k;
|
237
|
-
memset(buffer, 0, BUFFER_SIZE);
|
238
|
-
memset(documents, 0, MAX_DOCUMENTS*sizeof(yaml_document_t));
|
239
|
-
|
240
|
-
printf("[%d] Loading, dumping, and loading again '%s': ", number, argv[number]);
|
241
|
-
fflush(stdout);
|
242
|
-
|
243
|
-
file = fopen(argv[number], "rb");
|
244
|
-
assert(file);
|
245
|
-
|
246
|
-
assert(yaml_parser_initialize(&parser));
|
247
|
-
yaml_parser_set_input_file(&parser, file);
|
248
|
-
assert(yaml_emitter_initialize(&emitter));
|
249
|
-
if (canonical) {
|
250
|
-
yaml_emitter_set_canonical(&emitter, 1);
|
251
|
-
}
|
252
|
-
if (unicode) {
|
253
|
-
yaml_emitter_set_unicode(&emitter, 1);
|
254
|
-
}
|
255
|
-
yaml_emitter_set_output_string(&emitter, buffer, BUFFER_SIZE, &written);
|
256
|
-
yaml_emitter_open(&emitter);
|
257
|
-
|
258
|
-
while (!done)
|
259
|
-
{
|
260
|
-
if (!yaml_parser_load(&parser, &document)) {
|
261
|
-
error = 1;
|
262
|
-
break;
|
263
|
-
}
|
264
|
-
|
265
|
-
done = (!yaml_document_get_root_node(&document));
|
266
|
-
if (!done) {
|
267
|
-
assert(document_number < MAX_DOCUMENTS);
|
268
|
-
assert(copy_document(&(documents[document_number++]), &document));
|
269
|
-
assert(yaml_emitter_dump(&emitter, &document) ||
|
270
|
-
(yaml_emitter_flush(&emitter) && print_output(argv[number], buffer, written, count)));
|
271
|
-
count ++;
|
272
|
-
}
|
273
|
-
else {
|
274
|
-
yaml_document_delete(&document);
|
275
|
-
}
|
276
|
-
}
|
277
|
-
|
278
|
-
yaml_parser_delete(&parser);
|
279
|
-
assert(!fclose(file));
|
280
|
-
yaml_emitter_close(&emitter);
|
281
|
-
yaml_emitter_delete(&emitter);
|
282
|
-
|
283
|
-
if (!error)
|
284
|
-
{
|
285
|
-
count = done = 0;
|
286
|
-
assert(yaml_parser_initialize(&parser));
|
287
|
-
yaml_parser_set_input_string(&parser, buffer, written);
|
288
|
-
|
289
|
-
while (!done)
|
290
|
-
{
|
291
|
-
assert(yaml_parser_load(&parser, &document) || print_output(argv[number], buffer, written, count));
|
292
|
-
done = (!yaml_document_get_root_node(&document));
|
293
|
-
if (!done) {
|
294
|
-
assert(compare_documents(documents+count, &document) || print_output(argv[number], buffer, written, count));
|
295
|
-
count ++;
|
296
|
-
}
|
297
|
-
yaml_document_delete(&document);
|
298
|
-
}
|
299
|
-
yaml_parser_delete(&parser);
|
300
|
-
}
|
301
|
-
|
302
|
-
for (k = 0; k < document_number; k ++) {
|
303
|
-
yaml_document_delete(documents+k);
|
304
|
-
}
|
305
|
-
|
306
|
-
printf("PASSED (length: %d)\n", written);
|
307
|
-
print_output(argv[number], buffer, written, -1);
|
308
|
-
}
|
309
|
-
|
310
|
-
return 0;
|
311
|
-
}
|