Update syslinux to 4.05 to support mic-0.15
[external/syslinux.git] / com32 / gplinclude / zzjson / zzjson.h
1 /* ZZJSON - Copyright (C) 2008 by Ivo van Poorten
2  * License: GNU Lesser General Public License version 2.1
3  */
4 #ifndef ZZJSON_H
5 #define ZZJSON_H
6
7 #include <stdlib.h>
8
9 /* Version: */
10
11 #define ZZJSON_VERSION_MAJOR    1
12 #define ZZJSON_VERSION_MINOR    1
13 #define ZZJSON_VERSION_MICRO    0
14 #define ZZJSON_VERSION_INT      ( 1<<16 | 1<<8 | 0 )
15 #define ZZJSON_IDENT            "zzjson 1.1.0"
16
17 /* Defines: */
18
19 #define ZZJSON_ALLOW_EXTRA_COMMA        1
20 #define ZZJSON_ALLOW_ILLEGAL_ESCAPE     2
21 #define ZZJSON_ALLOW_CONTROL_CHARS      4
22 #define ZZJSON_ALLOW_GARBAGE_AT_END     8
23 #define ZZJSON_ALLOW_COMMENTS           16
24
25 #define ZZJSON_VERY_LOOSE               (-1)
26 #define ZZJSON_VERY_STRICT              0
27
28 /* Types: */
29
30 /* needed by: pa = parser, pr = printer, f = free, q = query, c = create */
31 typedef struct ZZJSON_CONFIG {
32     int strictness;                                        // pa
33     void *ihandle;                                         // pa
34     int (*getchar)(void *ihandle);                         // pa
35     int (*ungetchar)(int c, void *ihandle);                // pa
36     void *(*malloc)(size_t size);                          // pa      c
37     void *(*calloc)(size_t nmemb, size_t size);            // pa      c
38     void (*free)(void *ptr);                               // pa    f c
39     void *(*realloc)(void *ptr, size_t size);              // pa
40     void *ehandle;                                         // pa pr   c
41     void (*error)(void *ehandle, const char *format, ...); // pa pr   c
42     void *ohandle;                                         //    pr
43     int (*print)(void *ohandle, const char *format, ...);  //    pr
44     int (*putchar)(int c, void *handle);                   //    pr
45 } ZZJSON_CONFIG;
46
47 typedef enum ZZJSON_TYPE {
48     ZZJSON_NONE = 0,
49     ZZJSON_OBJECT,
50     ZZJSON_ARRAY,
51     ZZJSON_STRING,
52     ZZJSON_NUMBER_NEGINT,
53     ZZJSON_NUMBER_POSINT,
54     ZZJSON_NUMBER_DOUBLE,
55     ZZJSON_NULL,
56     ZZJSON_TRUE,
57     ZZJSON_FALSE
58 } ZZJSON_TYPE;
59
60 typedef struct ZZJSON {
61     ZZJSON_TYPE type;
62     union {
63         struct {
64             char *label;
65             struct ZZJSON *val;
66         } object;
67         struct {
68             struct ZZJSON *val;
69         } array;
70         struct {
71             char *string;
72         } string;
73         struct {
74             union {
75                 unsigned long long ival;
76                 double             dval;
77             } val;
78         } number;
79     } value;
80     struct ZZJSON *next;
81 } ZZJSON;
82
83 /* Functions: */
84
85 ZZJSON *zzjson_parse(ZZJSON_CONFIG *config);
86 void zzjson_free(ZZJSON_CONFIG *config, ZZJSON *zzjson);
87 int zzjson_print(ZZJSON_CONFIG *config, ZZJSON *zzjson);
88
89 ZZJSON *zzjson_object_find_label(ZZJSON *zzjson, char *label);
90 ZZJSON *zzjson_object_find_labels(ZZJSON *zzjson, ...); // end with , NULL
91 unsigned int zzjson_object_count(ZZJSON *zzjson);
92 unsigned int zzjson_array_count(ZZJSON *zzjson);
93
94 ZZJSON *zzjson_create_true(ZZJSON_CONFIG *config);
95 ZZJSON *zzjson_create_false(ZZJSON_CONFIG *config);
96 ZZJSON *zzjson_create_null(ZZJSON_CONFIG *config);
97 ZZJSON *zzjson_create_number_d(ZZJSON_CONFIG *config, double d);
98 ZZJSON *zzjson_create_number_i(ZZJSON_CONFIG *config, long long i);
99 ZZJSON *zzjson_create_string(ZZJSON_CONFIG *config, char *s);
100
101 /* list of ZZJSON *'s and end with , NULL */
102 ZZJSON *zzjson_create_array(ZZJSON_CONFIG *config, ...);
103
104 /* list of char*,ZZJSON* pairs, end with , NULL */
105 ZZJSON *zzjson_create_object(ZZJSON_CONFIG *config, ...);
106
107 ZZJSON *zzjson_array_prepend(ZZJSON_CONFIG *config, ZZJSON *array,
108                                                     ZZJSON *val);
109 ZZJSON *zzjson_array_append (ZZJSON_CONFIG *config, ZZJSON *array,
110                                                     ZZJSON *val);
111
112 ZZJSON *zzjson_object_prepend(ZZJSON_CONFIG *config, ZZJSON *object,
113                                         char *label, ZZJSON *val);
114 ZZJSON *zzjson_object_append (ZZJSON_CONFIG *config, ZZJSON *object,
115                                         char *label, ZZJSON *val);
116 #endif