Home | History | Annotate | Download | only in modules
      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>
     11 
     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);
     19 }
     20 
     21 
     22 int main(int argc, char *argv[])
     23 {
     24 #if 0
     25 	/* this hangs! */
     26     openconsole(&dev_rawcon_r, &dev_stdcon_w);
     27 #else
     28 	/* this works */
     29     openconsole(&dev_rawcon_r, &dev_ansiserial_w);
     30 #endif
     31     (void) argc;
     32     (void) argv;
     33     ZZJSON  *tmp;
     34     ZZJSON_CONFIG config = { ZZJSON_VERY_STRICT, NULL,
     35                              (int(*)(void*)) fgetc,
     36                              NULL,
     37                              malloc, calloc, free, realloc,
     38                              stderr, myerror, stdout,
     39                              (int(*)(void*,const char*,...)) fprintf,
     40                              (int(*)(int,void*)) fputc };
     41 
     42     do {
     43         ZZJSON *tmp2;
     44 
     45         tmp = zzjson_create_array(&config,
     46                 zzjson_create_number_d(&config, 3.14),
     47                 zzjson_create_number_i(&config, 1234LL),
     48                 zzjson_create_number_i(&config, -4321LL),
     49                 zzjson_create_true(&config),
     50                 zzjson_create_false(&config),
     51                 zzjson_create_null(&config),
     52                 zzjson_create_string(&config, "hello, world"),
     53                 zzjson_create_object(&config,
     54                     "picard", zzjson_create_string(&config, "jean-luc"),
     55                     "riker",  zzjson_create_string(&config, "william t."),
     56                     NULL),
     57                 zzjson_create_object(&config, NULL),
     58                 zzjson_create_array(&config, NULL),
     59                 NULL );
     60 
     61         if (!tmp) {
     62             fprintf(stderr, "error during creation of json tree\n");
     63             break;
     64         }
     65 
     66         tmp2 = zzjson_array_prepend(&config, tmp,
     67                     zzjson_create_string(&config, "prepended string"));
     68 
     69         if (!tmp2) {
     70             fprintf(stderr, "error during prepend\n");
     71             break;
     72         }
     73         tmp = tmp2;
     74 
     75         tmp2 = zzjson_array_append(&config, tmp,
     76                     zzjson_create_string(&config, "appended string (slow)"));
     77 
     78         if (!tmp2) {
     79             fprintf(stderr, "error during append\n");
     80             break;
     81         }
     82         tmp = tmp2;
     83 
     84         zzjson_print(&config, tmp);
     85     } while(0);
     86     if (tmp) zzjson_free(&config, tmp);
     87 
     88     {
     89         tmp = zzjson_create_array(&config, NULL); /* empty array */
     90         tmp = zzjson_array_prepend(&config, tmp, zzjson_create_true(&config));
     91         zzjson_print(&config, tmp);
     92         zzjson_free(&config, tmp);
     93     }
     94 
     95     {
     96         tmp = zzjson_create_object(&config, NULL); /* empty object */
     97         tmp = zzjson_object_prepend(&config, tmp, "hello",
     98                                 zzjson_create_string(&config, "world"));
     99         tmp = zzjson_object_append(&config, tmp, "goodbye",
    100                                 zzjson_create_string(&config, "cruel world"));
    101         zzjson_print(&config, tmp);
    102         zzjson_free(&config, tmp);
    103     }
    104 
    105     return 0;
    106 }
    107 
    108