nutcracker 0.4.0.16 → 0.4.1.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -3
  3. data/ext/nutcracker/ChangeLog +33 -8
  4. data/ext/nutcracker/Makefile.in +34 -21
  5. data/ext/nutcracker/README.md +61 -26
  6. data/ext/nutcracker/aclocal.m4 +34 -31
  7. data/ext/nutcracker/autom4te.cache/output.0 +1875 -1330
  8. data/ext/nutcracker/autom4te.cache/output.1 +1875 -1330
  9. data/ext/nutcracker/autom4te.cache/requests +232 -451
  10. data/ext/nutcracker/autom4te.cache/traces.0 +2256 -2129
  11. data/ext/nutcracker/autom4te.cache/traces.1 +73 -59
  12. data/ext/nutcracker/config.h.in +1 -2
  13. data/ext/nutcracker/config.h.in~ +333 -0
  14. data/ext/nutcracker/config/compile +1 -1
  15. data/ext/nutcracker/config/config.guess +13 -160
  16. data/ext/nutcracker/config/config.sub +25 -11
  17. data/ext/nutcracker/config/depcomp +1 -1
  18. data/ext/nutcracker/config/install-sh +170 -196
  19. data/ext/nutcracker/config/ltmain.sh +3509 -2018
  20. data/ext/nutcracker/config/missing +1 -1
  21. data/ext/nutcracker/configure +1874 -1329
  22. data/ext/nutcracker/configure.ac +3 -2
  23. data/ext/nutcracker/contrib/Makefile.in +18 -5
  24. data/ext/nutcracker/contrib/yaml-0.1.4/LICENSE +19 -0
  25. data/ext/nutcracker/contrib/yaml-0.1.4/Makefile.am +20 -0
  26. data/ext/nutcracker/contrib/yaml-0.1.4/Makefile.in +832 -0
  27. data/ext/nutcracker/contrib/yaml-0.1.4/README +27 -0
  28. data/ext/nutcracker/contrib/yaml-0.1.4/aclocal.m4 +1157 -0
  29. data/ext/nutcracker/contrib/yaml-0.1.4/autom4te.cache/output.0 +13342 -0
  30. data/ext/nutcracker/contrib/yaml-0.1.4/autom4te.cache/output.1 +14611 -0
  31. data/ext/nutcracker/{autom4te.cache → contrib/yaml-0.1.4/autom4te.cache}/output.2 +3465 -8761
  32. data/ext/nutcracker/contrib/yaml-0.1.4/autom4te.cache/requests +516 -0
  33. data/ext/nutcracker/{autom4te.cache/traces.2 → contrib/yaml-0.1.4/autom4te.cache/traces.0} +662 -698
  34. data/ext/nutcracker/contrib/yaml-0.1.4/autom4te.cache/traces.1 +577 -0
  35. data/ext/nutcracker/contrib/yaml-0.1.4/autom4te.cache/traces.2 +2721 -0
  36. data/ext/nutcracker/contrib/yaml-0.1.4/config.h.in +79 -0
  37. data/ext/nutcracker/contrib/yaml-0.1.4/config.h.in~ +80 -0
  38. data/ext/nutcracker/contrib/yaml-0.1.4/config/compile +347 -0
  39. data/ext/nutcracker/contrib/yaml-0.1.4/config/config.guess +1421 -0
  40. data/ext/nutcracker/contrib/yaml-0.1.4/config/config.sub +1807 -0
  41. data/ext/nutcracker/contrib/yaml-0.1.4/config/depcomp +791 -0
  42. data/ext/nutcracker/contrib/yaml-0.1.4/config/install-sh +501 -0
  43. data/ext/nutcracker/contrib/yaml-0.1.4/config/ltmain.sh +11147 -0
  44. data/ext/nutcracker/contrib/yaml-0.1.4/config/missing +215 -0
  45. data/ext/nutcracker/contrib/yaml-0.1.4/config/test-driver +148 -0
  46. data/ext/nutcracker/contrib/yaml-0.1.4/configure +14611 -0
  47. data/ext/nutcracker/contrib/yaml-0.1.4/configure.ac +75 -0
  48. data/ext/nutcracker/contrib/yaml-0.1.4/doc/doxygen.cfg +222 -0
  49. data/ext/nutcracker/contrib/yaml-0.1.4/include/yaml.h +1971 -0
  50. data/ext/nutcracker/contrib/yaml-0.1.4/m4/libtool.m4 +8369 -0
  51. data/ext/nutcracker/contrib/yaml-0.1.4/m4/ltoptions.m4 +437 -0
  52. data/ext/nutcracker/contrib/yaml-0.1.4/m4/ltsugar.m4 +124 -0
  53. data/ext/nutcracker/contrib/yaml-0.1.4/m4/ltversion.m4 +23 -0
  54. data/ext/nutcracker/contrib/yaml-0.1.4/m4/lt~obsolete.m4 +99 -0
  55. data/ext/nutcracker/contrib/yaml-0.1.4/src/Makefile.am +4 -0
  56. data/ext/nutcracker/contrib/yaml-0.1.4/src/Makefile.in +600 -0
  57. data/ext/nutcracker/contrib/yaml-0.1.4/src/api.c +1392 -0
  58. data/ext/nutcracker/contrib/yaml-0.1.4/src/dumper.c +394 -0
  59. data/ext/nutcracker/contrib/yaml-0.1.4/src/emitter.c +2329 -0
  60. data/ext/nutcracker/contrib/yaml-0.1.4/src/loader.c +432 -0
  61. data/ext/nutcracker/contrib/yaml-0.1.4/src/parser.c +1374 -0
  62. data/ext/nutcracker/contrib/yaml-0.1.4/src/reader.c +465 -0
  63. data/ext/nutcracker/contrib/yaml-0.1.4/src/scanner.c +3570 -0
  64. data/ext/nutcracker/contrib/yaml-0.1.4/src/writer.c +141 -0
  65. data/ext/nutcracker/contrib/yaml-0.1.4/src/yaml_private.h +640 -0
  66. data/ext/nutcracker/contrib/yaml-0.1.4/tests/Makefile.am +8 -0
  67. data/ext/nutcracker/contrib/yaml-0.1.4/tests/Makefile.in +1083 -0
  68. data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-deconstructor-alt.c +800 -0
  69. data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-deconstructor.c +1130 -0
  70. data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-reformatter-alt.c +217 -0
  71. data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-reformatter.c +202 -0
  72. data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-dumper.c +311 -0
  73. data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-emitter.c +327 -0
  74. data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-loader.c +63 -0
  75. data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-parser.c +63 -0
  76. data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-scanner.c +63 -0
  77. data/ext/nutcracker/contrib/yaml-0.1.4/tests/test-reader.c +354 -0
  78. data/ext/nutcracker/contrib/yaml-0.1.4/tests/test-version.c +29 -0
  79. data/ext/nutcracker/m4/libtool.m4 +1474 -1087
  80. data/ext/nutcracker/m4/ltoptions.m4 +90 -37
  81. data/ext/nutcracker/m4/ltsugar.m4 +4 -3
  82. data/ext/nutcracker/m4/ltversion.m4 +6 -6
  83. data/ext/nutcracker/m4/lt~obsolete.m4 +4 -3
  84. data/ext/nutcracker/man/nutcracker.8 +1 -1
  85. data/ext/nutcracker/notes/memcache.md +162 -0
  86. data/ext/nutcracker/notes/recommendation.md +10 -5
  87. data/ext/nutcracker/notes/redis.md +23 -9
  88. data/ext/nutcracker/scripts/nutcracker.init +10 -0
  89. data/ext/nutcracker/scripts/nutcracker.init.debian +83 -0
  90. data/ext/nutcracker/scripts/nutcracker.spec +36 -2
  91. data/ext/nutcracker/scripts/redis-check.sh +4 -0
  92. data/ext/nutcracker/src/Makefile.am +6 -1
  93. data/ext/nutcracker/src/Makefile.in +26 -12
  94. data/ext/nutcracker/src/event/Makefile.in +19 -6
  95. data/ext/nutcracker/src/hashkit/Makefile.in +19 -6
  96. data/ext/nutcracker/src/hashkit/nc_jenkins.c +1 -1
  97. data/ext/nutcracker/src/hashkit/nc_ketama.c +3 -3
  98. data/ext/nutcracker/src/nc.c +1 -1
  99. data/ext/nutcracker/src/nc_conf.c +67 -19
  100. data/ext/nutcracker/src/nc_conf.h +9 -4
  101. data/ext/nutcracker/src/nc_connection.c +35 -2
  102. data/ext/nutcracker/src/nc_connection.h +53 -47
  103. data/ext/nutcracker/src/nc_core.c +8 -1
  104. data/ext/nutcracker/src/nc_message.c +23 -7
  105. data/ext/nutcracker/src/nc_message.h +24 -1
  106. data/ext/nutcracker/src/nc_proxy.c +14 -3
  107. data/ext/nutcracker/src/nc_rbtree.c +1 -5
  108. data/ext/nutcracker/src/nc_request.c +58 -10
  109. data/ext/nutcracker/src/nc_response.c +27 -4
  110. data/ext/nutcracker/src/nc_server.c +33 -5
  111. data/ext/nutcracker/src/nc_server.h +10 -9
  112. data/ext/nutcracker/src/nc_string.h +17 -0
  113. data/ext/nutcracker/src/nc_util.c +5 -1
  114. data/ext/nutcracker/src/proto/Makefile.in +19 -6
  115. data/ext/nutcracker/src/proto/nc_memcache.c +76 -12
  116. data/ext/nutcracker/src/proto/nc_proto.h +9 -0
  117. data/ext/nutcracker/src/proto/nc_redis.c +400 -18
  118. data/lib/nutcracker.rb +1 -1
  119. data/lib/nutcracker/version.rb +1 -1
  120. metadata +61 -6
  121. data/ext/nutcracker/notes/memcache.txt +0 -123
@@ -0,0 +1,800 @@
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 input_event;
19
+ yaml_document_t output_document;
20
+
21
+ int root;
22
+
23
+ /* Clear the objects. */
24
+
25
+ memset(&parser, 0, sizeof(parser));
26
+ memset(&emitter, 0, sizeof(emitter));
27
+ memset(&input_event, 0, sizeof(input_event));
28
+ memset(&output_document, 0, sizeof(output_document));
29
+
30
+ /* Analyze command line options. */
31
+
32
+ for (k = 1; k < argc; k ++)
33
+ {
34
+ if (strcmp(argv[k], "-h") == 0
35
+ || strcmp(argv[k], "--help") == 0) {
36
+ help = 1;
37
+ }
38
+
39
+ else if (strcmp(argv[k], "-c") == 0
40
+ || strcmp(argv[k], "--canonical") == 0) {
41
+ canonical = 1;
42
+ }
43
+
44
+ else if (strcmp(argv[k], "-u") == 0
45
+ || strcmp(argv[k], "--unicode") == 0) {
46
+ unicode = 1;
47
+ }
48
+
49
+ else {
50
+ fprintf(stderr, "Unrecognized option: %s\n"
51
+ "Try `%s --help` for more information.\n",
52
+ argv[k], argv[0]);
53
+ return 1;
54
+ }
55
+ }
56
+
57
+ /* Display the help string. */
58
+
59
+ if (help)
60
+ {
61
+ printf("%s <input\n"
62
+ "or\n%s -h | --help\nDeconstruct a YAML stream\n\nOptions:\n"
63
+ "-h, --help\t\tdisplay this help and exit\n"
64
+ "-c, --canonical\t\toutput in the canonical YAML format\n"
65
+ "-u, --unicode\t\toutput unescaped non-ASCII characters\n",
66
+ argv[0], argv[0]);
67
+ return 0;
68
+ }
69
+
70
+ /* Initialize the parser and emitter objects. */
71
+
72
+ if (!yaml_parser_initialize(&parser)) {
73
+ fprintf(stderr, "Could not initialize the parser object\n");
74
+ return 1;
75
+ }
76
+
77
+ if (!yaml_emitter_initialize(&emitter)) {
78
+ yaml_parser_delete(&parser);
79
+ fprintf(stderr, "Could not inialize the emitter object\n");
80
+ return 1;
81
+ }
82
+
83
+ /* Set the parser parameters. */
84
+
85
+ yaml_parser_set_input_file(&parser, stdin);
86
+
87
+ /* Set the emitter parameters. */
88
+
89
+ yaml_emitter_set_output_file(&emitter, stdout);
90
+
91
+ yaml_emitter_set_canonical(&emitter, canonical);
92
+ yaml_emitter_set_unicode(&emitter, unicode);
93
+
94
+ /* Create and emit the STREAM-START event. */
95
+
96
+ if (!yaml_emitter_open(&emitter))
97
+ goto emitter_error;
98
+
99
+ /* Create a output_document object. */
100
+
101
+ if (!yaml_document_initialize(&output_document, NULL, NULL, NULL, 0, 0))
102
+ goto document_error;
103
+
104
+ /* Create the root sequence. */
105
+
106
+ root = yaml_document_add_sequence(&output_document, NULL,
107
+ YAML_BLOCK_SEQUENCE_STYLE);
108
+ if (!root) goto document_error;
109
+
110
+ /* Loop through the input events. */
111
+
112
+ while (!done)
113
+ {
114
+ int properties, key, value, map, seq;
115
+
116
+ /* Get the next event. */
117
+
118
+ if (!yaml_parser_parse(&parser, &input_event))
119
+ goto parser_error;
120
+
121
+ /* Check if this is the stream end. */
122
+
123
+ if (input_event.type == YAML_STREAM_END_EVENT) {
124
+ done = 1;
125
+ }
126
+
127
+ /* Create a mapping node and attach it to the root sequence. */
128
+
129
+ properties = yaml_document_add_mapping(&output_document, NULL,
130
+ YAML_BLOCK_MAPPING_STYLE);
131
+ if (!properties) goto document_error;
132
+ if (!yaml_document_append_sequence_item(&output_document,
133
+ root, properties)) goto document_error;
134
+
135
+ /* Analyze the event. */
136
+
137
+ switch (input_event.type)
138
+ {
139
+ case YAML_STREAM_START_EVENT:
140
+
141
+ /* Add 'type': 'STREAM-START'. */
142
+
143
+ key = yaml_document_add_scalar(&output_document, NULL,
144
+ "type", -1, YAML_PLAIN_SCALAR_STYLE);
145
+ if (!key) goto document_error;
146
+ value = yaml_document_add_scalar(&output_document, NULL,
147
+ "STREAM-START", -1, YAML_PLAIN_SCALAR_STYLE);
148
+ if (!value) goto document_error;
149
+ if (!yaml_document_append_mapping_pair(&output_document,
150
+ properties, key, value)) goto document_error;
151
+
152
+ /* Add 'encoding': <encoding>. */
153
+
154
+ if (input_event.data.stream_start.encoding)
155
+ {
156
+ yaml_encoding_t encoding
157
+ = input_event.data.stream_start.encoding;
158
+
159
+ key = yaml_document_add_scalar(&output_document, NULL,
160
+ "encoding", -1, YAML_PLAIN_SCALAR_STYLE);
161
+ if (!key) goto document_error;
162
+ value = yaml_document_add_scalar(&output_document, NULL,
163
+ (encoding == YAML_UTF8_ENCODING ? "utf-8" :
164
+ encoding == YAML_UTF16LE_ENCODING ? "utf-16-le" :
165
+ encoding == YAML_UTF16BE_ENCODING ? "utf-16-be" :
166
+ "unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
167
+ if (!value) goto document_error;
168
+ if (!yaml_document_append_mapping_pair(&output_document,
169
+ properties, key, value)) goto document_error;
170
+ }
171
+
172
+ break;
173
+
174
+ case YAML_STREAM_END_EVENT:
175
+
176
+ /* Add 'type': 'STREAM-END'. */
177
+
178
+ key = yaml_document_add_scalar(&output_document, NULL,
179
+ "type", -1, YAML_PLAIN_SCALAR_STYLE);
180
+ if (!key) goto document_error;
181
+ value = yaml_document_add_scalar(&output_document, NULL,
182
+ "STREAM-END", -1, YAML_PLAIN_SCALAR_STYLE);
183
+ if (!value) goto document_error;
184
+ if (!yaml_document_append_mapping_pair(&output_document,
185
+ properties, key, value)) goto document_error;
186
+
187
+ break;
188
+
189
+ case YAML_DOCUMENT_START_EVENT:
190
+
191
+ /* Add 'type': 'DOCUMENT-START'. */
192
+
193
+ key = yaml_document_add_scalar(&output_document, NULL,
194
+ "type", -1, YAML_PLAIN_SCALAR_STYLE);
195
+ if (!key) goto document_error;
196
+ value = yaml_document_add_scalar(&output_document, NULL,
197
+ "DOCUMENT-START", -1, YAML_PLAIN_SCALAR_STYLE);
198
+ if (!value) goto document_error;
199
+ if (!yaml_document_append_mapping_pair(&output_document,
200
+ properties, key, value)) goto document_error;
201
+
202
+ /* Display the output_document version numbers. */
203
+
204
+ if (input_event.data.document_start.version_directive)
205
+ {
206
+ yaml_version_directive_t *version
207
+ = input_event.data.document_start.version_directive;
208
+ char number[64];
209
+
210
+ /* Add 'version': {}. */
211
+
212
+ key = yaml_document_add_scalar(&output_document, NULL,
213
+ "version", -1, YAML_PLAIN_SCALAR_STYLE);
214
+ if (!key) goto document_error;
215
+ map = yaml_document_add_mapping(&output_document, NULL,
216
+ YAML_FLOW_MAPPING_STYLE);
217
+ if (!map) goto document_error;
218
+ if (!yaml_document_append_mapping_pair(&output_document,
219
+ properties, key, map)) goto document_error;
220
+
221
+ /* Add 'major': <number>. */
222
+
223
+ key = yaml_document_add_scalar(&output_document, NULL,
224
+ "major", -1, YAML_PLAIN_SCALAR_STYLE);
225
+ if (!key) goto document_error;
226
+ sprintf(number, "%d", version->major);
227
+ value = yaml_document_add_scalar(&output_document, YAML_INT_TAG,
228
+ number, -1, YAML_PLAIN_SCALAR_STYLE);
229
+ if (!value) goto document_error;
230
+ if (!yaml_document_append_mapping_pair(&output_document,
231
+ map, key, value)) goto document_error;
232
+
233
+ /* Add 'minor': <number>. */
234
+
235
+ key = yaml_document_add_scalar(&output_document, NULL,
236
+ "minor", -1, YAML_PLAIN_SCALAR_STYLE);
237
+ if (!key) goto document_error;
238
+ sprintf(number, "%d", version->minor);
239
+ value = yaml_document_add_scalar(&output_document, YAML_INT_TAG,
240
+ number, -1, YAML_PLAIN_SCALAR_STYLE);
241
+ if (!value) goto document_error;
242
+ if (!yaml_document_append_mapping_pair(&output_document,
243
+ map, key, value)) goto document_error;
244
+ }
245
+
246
+ /* Display the output_document tag directives. */
247
+
248
+ if (input_event.data.document_start.tag_directives.start
249
+ != input_event.data.document_start.tag_directives.end)
250
+ {
251
+ yaml_tag_directive_t *tag;
252
+
253
+ /* Add 'tags': []. */
254
+
255
+ key = yaml_document_add_scalar(&output_document, NULL,
256
+ "tags", -1, YAML_PLAIN_SCALAR_STYLE);
257
+ if (!key) goto document_error;
258
+ seq = yaml_document_add_sequence(&output_document, NULL,
259
+ YAML_BLOCK_SEQUENCE_STYLE);
260
+ if (!seq) goto document_error;
261
+ if (!yaml_document_append_mapping_pair(&output_document,
262
+ properties, key, seq)) goto document_error;
263
+
264
+ for (tag = input_event.data.document_start.tag_directives.start;
265
+ tag != input_event.data.document_start.tag_directives.end;
266
+ tag ++)
267
+ {
268
+ /* Add {}. */
269
+
270
+ map = yaml_document_add_mapping(&output_document, NULL,
271
+ YAML_FLOW_MAPPING_STYLE);
272
+ if (!map) goto document_error;
273
+ if (!yaml_document_append_sequence_item(&output_document,
274
+ seq, map)) goto document_error;
275
+
276
+ /* Add 'handle': <handle>. */
277
+
278
+ key = yaml_document_add_scalar(&output_document, NULL,
279
+ "handle", -1, YAML_PLAIN_SCALAR_STYLE);
280
+ if (!key) goto document_error;
281
+ value = yaml_document_add_scalar(&output_document, NULL,
282
+ tag->handle, -1, YAML_DOUBLE_QUOTED_SCALAR_STYLE);
283
+ if (!value) goto document_error;
284
+ if (!yaml_document_append_mapping_pair(&output_document,
285
+ map, key, value)) goto document_error;
286
+
287
+ /* Add 'prefix': <prefix>. */
288
+
289
+ key = yaml_document_add_scalar(&output_document, NULL,
290
+ "prefix", -1, YAML_PLAIN_SCALAR_STYLE);
291
+ if (!key) goto document_error;
292
+ value = yaml_document_add_scalar(&output_document, NULL,
293
+ tag->prefix, -1, YAML_DOUBLE_QUOTED_SCALAR_STYLE);
294
+ if (!value) goto document_error;
295
+ if (!yaml_document_append_mapping_pair(&output_document,
296
+ map, key, value)) goto document_error;
297
+ }
298
+ }
299
+
300
+ /* Add 'implicit': <flag>. */
301
+
302
+ key = yaml_document_add_scalar(&output_document, NULL,
303
+ "implicit", -1, YAML_PLAIN_SCALAR_STYLE);
304
+ if (!key) goto document_error;
305
+ value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG,
306
+ (input_event.data.document_start.implicit ?
307
+ "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
308
+ if (!value) goto document_error;
309
+ if (!yaml_document_append_mapping_pair(&output_document,
310
+ properties, key, value)) goto document_error;
311
+
312
+ break;
313
+
314
+ case YAML_DOCUMENT_END_EVENT:
315
+
316
+ /* Add 'type': 'DOCUMENT-END'. */
317
+
318
+ key = yaml_document_add_scalar(&output_document, NULL,
319
+ "type", -1, YAML_PLAIN_SCALAR_STYLE);
320
+ if (!key) goto document_error;
321
+ value = yaml_document_add_scalar(&output_document, NULL,
322
+ "DOCUMENT-END", -1, YAML_PLAIN_SCALAR_STYLE);
323
+ if (!value) goto document_error;
324
+ if (!yaml_document_append_mapping_pair(&output_document,
325
+ properties, key, value)) goto document_error;
326
+
327
+ /* Add 'implicit': <flag>. */
328
+
329
+ key = yaml_document_add_scalar(&output_document, NULL,
330
+ "implicit", -1, YAML_PLAIN_SCALAR_STYLE);
331
+ if (!key) goto document_error;
332
+ value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG,
333
+ (input_event.data.document_end.implicit ?
334
+ "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
335
+ if (!value) goto document_error;
336
+ if (!yaml_document_append_mapping_pair(&output_document,
337
+ properties, key, value)) goto document_error;
338
+
339
+ break;
340
+
341
+ case YAML_ALIAS_EVENT:
342
+
343
+ /* Add 'type': 'ALIAS'. */
344
+
345
+ key = yaml_document_add_scalar(&output_document, NULL,
346
+ "type", -1, YAML_PLAIN_SCALAR_STYLE);
347
+ if (!key) goto document_error;
348
+ value = yaml_document_add_scalar(&output_document, NULL,
349
+ "ALIAS", -1, YAML_PLAIN_SCALAR_STYLE);
350
+ if (!value) goto document_error;
351
+ if (!yaml_document_append_mapping_pair(&output_document,
352
+ properties, key, value)) goto document_error;
353
+
354
+ /* Add 'anchor': <anchor>. */
355
+
356
+ key = yaml_document_add_scalar(&output_document, NULL,
357
+ "anchor", -1, YAML_PLAIN_SCALAR_STYLE);
358
+ if (!key) goto document_error;
359
+ value = yaml_document_add_scalar(&output_document, NULL,
360
+ input_event.data.alias.anchor, -1,
361
+ YAML_DOUBLE_QUOTED_SCALAR_STYLE);
362
+ if (!value) goto document_error;
363
+ if (!yaml_document_append_mapping_pair(&output_document,
364
+ properties, key, value)) goto document_error;
365
+
366
+ break;
367
+
368
+ case YAML_SCALAR_EVENT:
369
+
370
+ /* Add 'type': 'SCALAR'. */
371
+
372
+ key = yaml_document_add_scalar(&output_document, NULL,
373
+ "type", -1, YAML_PLAIN_SCALAR_STYLE);
374
+ if (!key) goto document_error;
375
+ value = yaml_document_add_scalar(&output_document, NULL,
376
+ "SCALAR", -1, YAML_PLAIN_SCALAR_STYLE);
377
+ if (!value) goto document_error;
378
+ if (!yaml_document_append_mapping_pair(&output_document,
379
+ properties, key, value)) goto document_error;
380
+
381
+ /* Add 'anchor': <anchor>. */
382
+
383
+ if (input_event.data.scalar.anchor)
384
+ {
385
+ key = yaml_document_add_scalar(&output_document, NULL,
386
+ "anchor", -1, YAML_PLAIN_SCALAR_STYLE);
387
+ if (!key) goto document_error;
388
+ value = yaml_document_add_scalar(&output_document, NULL,
389
+ input_event.data.scalar.anchor, -1,
390
+ YAML_DOUBLE_QUOTED_SCALAR_STYLE);
391
+ if (!value) goto document_error;
392
+ if (!yaml_document_append_mapping_pair(&output_document,
393
+ properties, key, value)) goto document_error;
394
+ }
395
+
396
+ /* Add 'tag': <tag>. */
397
+
398
+ if (input_event.data.scalar.tag)
399
+ {
400
+ key = yaml_document_add_scalar(&output_document, NULL,
401
+ "tag", -1, YAML_PLAIN_SCALAR_STYLE);
402
+ if (!key) goto document_error;
403
+ value = yaml_document_add_scalar(&output_document, NULL,
404
+ input_event.data.scalar.tag, -1,
405
+ YAML_DOUBLE_QUOTED_SCALAR_STYLE);
406
+ if (!value) goto document_error;
407
+ if (!yaml_document_append_mapping_pair(&output_document,
408
+ properties, key, value)) goto document_error;
409
+ }
410
+
411
+ /* Add 'value': <value>. */
412
+
413
+ key = yaml_document_add_scalar(&output_document, NULL,
414
+ "value", -1, YAML_PLAIN_SCALAR_STYLE);
415
+ if (!key) goto document_error;
416
+ value = yaml_document_add_scalar(&output_document, NULL,
417
+ input_event.data.scalar.value,
418
+ input_event.data.scalar.length,
419
+ YAML_DOUBLE_QUOTED_SCALAR_STYLE);
420
+ if (!value) goto document_error;
421
+ if (!yaml_document_append_mapping_pair(&output_document,
422
+ properties, key, value)) goto document_error;
423
+
424
+ /* Display if the scalar tag is implicit. */
425
+
426
+ /* Add 'implicit': {} */
427
+
428
+ key = yaml_document_add_scalar(&output_document, NULL,
429
+ "version", -1, YAML_PLAIN_SCALAR_STYLE);
430
+ if (!key) goto document_error;
431
+ map = yaml_document_add_mapping(&output_document, NULL,
432
+ YAML_FLOW_MAPPING_STYLE);
433
+ if (!map) goto document_error;
434
+ if (!yaml_document_append_mapping_pair(&output_document,
435
+ properties, key, map)) goto document_error;
436
+
437
+ /* Add 'plain': <flag>. */
438
+
439
+ key = yaml_document_add_scalar(&output_document, NULL,
440
+ "plain", -1, YAML_PLAIN_SCALAR_STYLE);
441
+ if (!key) goto document_error;
442
+ value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG,
443
+ (input_event.data.scalar.plain_implicit ?
444
+ "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
445
+ if (!value) goto document_error;
446
+ if (!yaml_document_append_mapping_pair(&output_document,
447
+ map, key, value)) goto document_error;
448
+
449
+ /* Add 'quoted': <flag>. */
450
+
451
+ key = yaml_document_add_scalar(&output_document, NULL,
452
+ "quoted", -1, YAML_PLAIN_SCALAR_STYLE);
453
+ if (!key) goto document_error;
454
+ value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG,
455
+ (input_event.data.scalar.quoted_implicit ?
456
+ "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
457
+ if (!value) goto document_error;
458
+ if (!yaml_document_append_mapping_pair(&output_document,
459
+ map, key, value)) goto document_error;
460
+
461
+ /* Display the style information. */
462
+
463
+ if (input_event.data.scalar.style)
464
+ {
465
+ yaml_scalar_style_t style = input_event.data.scalar.style;
466
+
467
+ /* Add 'style': <style>. */
468
+
469
+ key = yaml_document_add_scalar(&output_document, NULL,
470
+ "style", -1, YAML_PLAIN_SCALAR_STYLE);
471
+ if (!key) goto document_error;
472
+ value = yaml_document_add_scalar(&output_document, NULL,
473
+ (style == YAML_PLAIN_SCALAR_STYLE ? "plain" :
474
+ style == YAML_SINGLE_QUOTED_SCALAR_STYLE ?
475
+ "single-quoted" :
476
+ style == YAML_DOUBLE_QUOTED_SCALAR_STYLE ?
477
+ "double-quoted" :
478
+ style == YAML_LITERAL_SCALAR_STYLE ? "literal" :
479
+ style == YAML_FOLDED_SCALAR_STYLE ? "folded" :
480
+ "unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
481
+ if (!value) goto document_error;
482
+ if (!yaml_document_append_mapping_pair(&output_document,
483
+ properties, key, value)) goto document_error;
484
+ }
485
+
486
+ break;
487
+
488
+ case YAML_SEQUENCE_START_EVENT:
489
+
490
+ /* Add 'type': 'SEQUENCE-START'. */
491
+
492
+ key = yaml_document_add_scalar(&output_document, NULL,
493
+ "type", -1, YAML_PLAIN_SCALAR_STYLE);
494
+ if (!key) goto document_error;
495
+ value = yaml_document_add_scalar(&output_document, NULL,
496
+ "SEQUENCE-START", -1, YAML_PLAIN_SCALAR_STYLE);
497
+ if (!value) goto document_error;
498
+ if (!yaml_document_append_mapping_pair(&output_document,
499
+ properties, key, value)) goto document_error;
500
+
501
+ /* Add 'anchor': <anchor>. */
502
+
503
+ if (input_event.data.sequence_start.anchor)
504
+ {
505
+ key = yaml_document_add_scalar(&output_document, NULL,
506
+ "anchor", -1, YAML_PLAIN_SCALAR_STYLE);
507
+ if (!key) goto document_error;
508
+ value = yaml_document_add_scalar(&output_document, NULL,
509
+ input_event.data.sequence_start.anchor, -1,
510
+ YAML_DOUBLE_QUOTED_SCALAR_STYLE);
511
+ if (!value) goto document_error;
512
+ if (!yaml_document_append_mapping_pair(&output_document,
513
+ properties, key, value)) goto document_error;
514
+ }
515
+
516
+ /* Add 'tag': <tag>. */
517
+
518
+ if (input_event.data.sequence_start.tag)
519
+ {
520
+ key = yaml_document_add_scalar(&output_document, NULL,
521
+ "tag", -1, YAML_PLAIN_SCALAR_STYLE);
522
+ if (!key) goto document_error;
523
+ value = yaml_document_add_scalar(&output_document, NULL,
524
+ input_event.data.sequence_start.tag, -1,
525
+ YAML_DOUBLE_QUOTED_SCALAR_STYLE);
526
+ if (!value) goto document_error;
527
+ if (!yaml_document_append_mapping_pair(&output_document,
528
+ properties, key, value)) goto document_error;
529
+ }
530
+
531
+ /* Add 'implicit': <flag>. */
532
+
533
+ key = yaml_document_add_scalar(&output_document, NULL,
534
+ "implicit", -1, YAML_PLAIN_SCALAR_STYLE);
535
+ if (!key) goto document_error;
536
+ value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG,
537
+ (input_event.data.sequence_start.implicit ?
538
+ "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
539
+ if (!value) goto document_error;
540
+ if (!yaml_document_append_mapping_pair(&output_document,
541
+ properties, key, value)) goto document_error;
542
+
543
+ /* Display the style information. */
544
+
545
+ if (input_event.data.sequence_start.style)
546
+ {
547
+ yaml_sequence_style_t style
548
+ = input_event.data.sequence_start.style;
549
+
550
+ /* Add 'style': <style>. */
551
+
552
+ key = yaml_document_add_scalar(&output_document, NULL,
553
+ "style", -1, YAML_PLAIN_SCALAR_STYLE);
554
+ if (!key) goto document_error;
555
+ value = yaml_document_add_scalar(&output_document, NULL,
556
+ (style == YAML_BLOCK_SEQUENCE_STYLE ? "block" :
557
+ style == YAML_FLOW_SEQUENCE_STYLE ? "flow" :
558
+ "unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
559
+ if (!value) goto document_error;
560
+ if (!yaml_document_append_mapping_pair(&output_document,
561
+ properties, key, value)) goto document_error;
562
+ }
563
+
564
+ break;
565
+
566
+ case YAML_SEQUENCE_END_EVENT:
567
+
568
+ /* Add 'type': 'SEQUENCE-END'. */
569
+
570
+ key = yaml_document_add_scalar(&output_document, NULL,
571
+ "type", -1, YAML_PLAIN_SCALAR_STYLE);
572
+ if (!key) goto document_error;
573
+ value = yaml_document_add_scalar(&output_document, NULL,
574
+ "SEQUENCE-END", -1, YAML_PLAIN_SCALAR_STYLE);
575
+ if (!value) goto document_error;
576
+ if (!yaml_document_append_mapping_pair(&output_document,
577
+ properties, key, value)) goto document_error;
578
+
579
+ break;
580
+
581
+ case YAML_MAPPING_START_EVENT:
582
+
583
+ /* Add 'type': 'MAPPING-START'. */
584
+
585
+ key = yaml_document_add_scalar(&output_document, NULL,
586
+ "type", -1, YAML_PLAIN_SCALAR_STYLE);
587
+ if (!key) goto document_error;
588
+ value = yaml_document_add_scalar(&output_document, NULL,
589
+ "MAPPING-START", -1, YAML_PLAIN_SCALAR_STYLE);
590
+ if (!value) goto document_error;
591
+ if (!yaml_document_append_mapping_pair(&output_document,
592
+ properties, key, value)) goto document_error;
593
+
594
+ /* Add 'anchor': <anchor>. */
595
+
596
+ if (input_event.data.mapping_start.anchor)
597
+ {
598
+ key = yaml_document_add_scalar(&output_document, NULL,
599
+ "anchor", -1, YAML_PLAIN_SCALAR_STYLE);
600
+ if (!key) goto document_error;
601
+ value = yaml_document_add_scalar(&output_document, NULL,
602
+ input_event.data.mapping_start.anchor, -1,
603
+ YAML_DOUBLE_QUOTED_SCALAR_STYLE);
604
+ if (!value) goto document_error;
605
+ if (!yaml_document_append_mapping_pair(&output_document,
606
+ properties, key, value)) goto document_error;
607
+ }
608
+
609
+ /* Add 'tag': <tag>. */
610
+
611
+ if (input_event.data.mapping_start.tag)
612
+ {
613
+ key = yaml_document_add_scalar(&output_document, NULL,
614
+ "tag", -1, YAML_PLAIN_SCALAR_STYLE);
615
+ if (!key) goto document_error;
616
+ value = yaml_document_add_scalar(&output_document, NULL,
617
+ input_event.data.mapping_start.tag, -1,
618
+ YAML_DOUBLE_QUOTED_SCALAR_STYLE);
619
+ if (!value) goto document_error;
620
+ if (!yaml_document_append_mapping_pair(&output_document,
621
+ properties, key, value)) goto document_error;
622
+ }
623
+
624
+ /* Add 'implicit': <flag>. */
625
+
626
+ key = yaml_document_add_scalar(&output_document, NULL,
627
+ "implicit", -1, YAML_PLAIN_SCALAR_STYLE);
628
+ if (!key) goto document_error;
629
+ value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG,
630
+ (input_event.data.mapping_start.implicit ?
631
+ "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
632
+ if (!value) goto document_error;
633
+ if (!yaml_document_append_mapping_pair(&output_document,
634
+ properties, key, value)) goto document_error;
635
+
636
+ /* Display the style information. */
637
+
638
+ if (input_event.data.sequence_start.style)
639
+ {
640
+ yaml_sequence_style_t style
641
+ = input_event.data.mapping_start.style;
642
+
643
+ /* Add 'style': <style>. */
644
+
645
+ key = yaml_document_add_scalar(&output_document, NULL,
646
+ "style", -1, YAML_PLAIN_SCALAR_STYLE);
647
+ if (!key) goto document_error;
648
+ value = yaml_document_add_scalar(&output_document, NULL,
649
+ (style == YAML_BLOCK_MAPPING_STYLE ? "block" :
650
+ style == YAML_FLOW_MAPPING_STYLE ? "flow" :
651
+ "unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
652
+ if (!value) goto document_error;
653
+ if (!yaml_document_append_mapping_pair(&output_document,
654
+ properties, key, value)) goto document_error;
655
+ }
656
+
657
+ break;
658
+
659
+ case YAML_MAPPING_END_EVENT:
660
+
661
+ /* Add 'type': 'MAPPING-END'. */
662
+
663
+ key = yaml_document_add_scalar(&output_document, NULL,
664
+ "type", -1, YAML_PLAIN_SCALAR_STYLE);
665
+ if (!key) goto document_error;
666
+ value = yaml_document_add_scalar(&output_document, NULL,
667
+ "MAPPING-END", -1, YAML_PLAIN_SCALAR_STYLE);
668
+ if (!value) goto document_error;
669
+ if (!yaml_document_append_mapping_pair(&output_document,
670
+ properties, key, value)) goto document_error;
671
+
672
+ break;
673
+
674
+ default:
675
+ /* It couldn't really happen. */
676
+ break;
677
+ }
678
+
679
+ /* Delete the event object. */
680
+
681
+ yaml_event_delete(&input_event);
682
+ }
683
+
684
+ if (!yaml_emitter_dump(&emitter, &output_document))
685
+ goto emitter_error;
686
+ if (!yaml_emitter_close(&emitter))
687
+ goto emitter_error;
688
+
689
+ yaml_parser_delete(&parser);
690
+ yaml_emitter_delete(&emitter);
691
+
692
+ return 0;
693
+
694
+ parser_error:
695
+
696
+ /* Display a parser error message. */
697
+
698
+ switch (parser.error)
699
+ {
700
+ case YAML_MEMORY_ERROR:
701
+ fprintf(stderr, "Memory error: Not enough memory for parsing\n");
702
+ break;
703
+
704
+ case YAML_READER_ERROR:
705
+ if (parser.problem_value != -1) {
706
+ fprintf(stderr, "Reader error: %s: #%X at %d\n", parser.problem,
707
+ parser.problem_value, parser.problem_offset);
708
+ }
709
+ else {
710
+ fprintf(stderr, "Reader error: %s at %d\n", parser.problem,
711
+ parser.problem_offset);
712
+ }
713
+ break;
714
+
715
+ case YAML_SCANNER_ERROR:
716
+ if (parser.context) {
717
+ fprintf(stderr, "Scanner error: %s at line %d, column %d\n"
718
+ "%s at line %d, column %d\n", parser.context,
719
+ parser.context_mark.line+1, parser.context_mark.column+1,
720
+ parser.problem, parser.problem_mark.line+1,
721
+ parser.problem_mark.column+1);
722
+ }
723
+ else {
724
+ fprintf(stderr, "Scanner error: %s at line %d, column %d\n",
725
+ parser.problem, parser.problem_mark.line+1,
726
+ parser.problem_mark.column+1);
727
+ }
728
+ break;
729
+
730
+ case YAML_PARSER_ERROR:
731
+ if (parser.context) {
732
+ fprintf(stderr, "Parser error: %s at line %d, column %d\n"
733
+ "%s at line %d, column %d\n", parser.context,
734
+ parser.context_mark.line+1, parser.context_mark.column+1,
735
+ parser.problem, parser.problem_mark.line+1,
736
+ parser.problem_mark.column+1);
737
+ }
738
+ else {
739
+ fprintf(stderr, "Parser error: %s at line %d, column %d\n",
740
+ parser.problem, parser.problem_mark.line+1,
741
+ parser.problem_mark.column+1);
742
+ }
743
+ break;
744
+
745
+ default:
746
+ /* Couldn't happen. */
747
+ fprintf(stderr, "Internal error\n");
748
+ break;
749
+ }
750
+
751
+ yaml_event_delete(&input_event);
752
+ yaml_document_delete(&output_document);
753
+ yaml_parser_delete(&parser);
754
+ yaml_emitter_delete(&emitter);
755
+
756
+ return 1;
757
+
758
+ emitter_error:
759
+
760
+ /* Display an emitter error message. */
761
+
762
+ switch (emitter.error)
763
+ {
764
+ case YAML_MEMORY_ERROR:
765
+ fprintf(stderr, "Memory error: Not enough memory for emitting\n");
766
+ break;
767
+
768
+ case YAML_WRITER_ERROR:
769
+ fprintf(stderr, "Writer error: %s\n", emitter.problem);
770
+ break;
771
+
772
+ case YAML_EMITTER_ERROR:
773
+ fprintf(stderr, "Emitter error: %s\n", emitter.problem);
774
+ break;
775
+
776
+ default:
777
+ /* Couldn't happen. */
778
+ fprintf(stderr, "Internal error\n");
779
+ break;
780
+ }
781
+
782
+ yaml_event_delete(&input_event);
783
+ yaml_document_delete(&output_document);
784
+ yaml_parser_delete(&parser);
785
+ yaml_emitter_delete(&emitter);
786
+
787
+ return 1;
788
+
789
+ document_error:
790
+
791
+ fprintf(stderr, "Memory error: Not enough memory for creating a document\n");
792
+
793
+ yaml_event_delete(&input_event);
794
+ yaml_document_delete(&output_document);
795
+ yaml_parser_delete(&parser);
796
+ yaml_emitter_delete(&emitter);
797
+
798
+ return 1;
799
+ }
800
+