hdt: Fixing array size
[hdt-cyring.git] / com32 / modules / zzjson.c
blobe2516fa14a6c3e82be3361b6f27bf6c70b2a7ac7
1 /*
2 * Display directory contents
3 */
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <console.h>
7 #include <string.h>
8 #include <com32.h>
9 #include <zzjson/zzjson.h>
10 #include <stdarg.h>
12 static void myerror(void *ehandle, const char *format, ...) {
13 va_list ap;
14 fprintf(ehandle, "error: ");
15 va_start(ap, format);
16 vfprintf(ehandle, format, ap);
17 va_end(ap);
18 fputc('\n', ehandle);
22 int main(int argc, char *argv[])
24 openconsole(&dev_rawcon_r, &dev_stdcon_w);
25 (void) argc;
26 (void) argv;
27 ZZJSON *tmp;
28 ZZJSON_CONFIG config = { ZZJSON_VERY_STRICT, NULL,
29 (int(*)(void*)) fgetc,
30 NULL,
31 malloc, calloc, free, realloc,
32 stderr, myerror, stdout,
33 (int(*)(void*,const char*,...)) fprintf,
34 (int(*)(int,void*)) fputc };
36 do {
37 ZZJSON *tmp2;
39 tmp = zzjson_create_array(&config,
40 zzjson_create_number_d(&config, 3.14),
41 zzjson_create_number_i(&config, 1234LL),
42 zzjson_create_number_i(&config, -4321LL),
43 zzjson_create_true(&config),
44 zzjson_create_false(&config),
45 zzjson_create_null(&config),
46 zzjson_create_string(&config, "hello, world"),
47 zzjson_create_object(&config,
48 "picard", zzjson_create_string(&config, "jean-luc"),
49 "riker", zzjson_create_string(&config, "william t."),
50 NULL),
51 zzjson_create_object(&config, NULL),
52 zzjson_create_array(&config, NULL),
53 NULL );
55 if (!tmp) {
56 fprintf(stderr, "error during creation of json tree\n");
57 break;
60 tmp2 = zzjson_array_prepend(&config, tmp,
61 zzjson_create_string(&config, "prepended string"));
63 if (!tmp2) {
64 fprintf(stderr, "error during prepend\n");
65 break;
67 tmp = tmp2;
69 tmp2 = zzjson_array_append(&config, tmp,
70 zzjson_create_string(&config, "appended string (slow)"));
72 if (!tmp2) {
73 fprintf(stderr, "error during append\n");
74 break;
76 tmp = tmp2;
78 zzjson_print(&config, tmp);
79 } while(0);
80 if (tmp) zzjson_free(&config, tmp);
83 tmp = zzjson_create_array(&config, NULL); /* empty array */
84 tmp = zzjson_array_prepend(&config, tmp, zzjson_create_true(&config));
85 zzjson_print(&config, tmp);
86 zzjson_free(&config, tmp);
90 tmp = zzjson_create_object(&config, NULL); /* empty object */
91 tmp = zzjson_object_prepend(&config, tmp, "hello",
92 zzjson_create_string(&config, "world"));
93 tmp = zzjson_object_append(&config, tmp, "goodbye",
94 zzjson_create_string(&config, "cruel world"));
95 zzjson_print(&config, tmp);
96 zzjson_free(&config, tmp);
99 return 0;