source: bootcd/isolinux/syslinux-6.03/com32/gplinclude/zzjson/zzjson.h

Last change on this file was e16e8f2, checked in by Edwin Eefting <edwin@datux.nl>, 3 years ago

bootstuff

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[e16e8f2]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 */
31typedef 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
47typedef 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
60typedef 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
85ZZJSON *zzjson_parse(ZZJSON_CONFIG *config);
86void zzjson_free(ZZJSON_CONFIG *config, ZZJSON *zzjson);
87int zzjson_print(ZZJSON_CONFIG *config, ZZJSON *zzjson);
88
89ZZJSON *zzjson_object_find_label(ZZJSON *zzjson, char *label);
90ZZJSON *zzjson_object_find_labels(ZZJSON *zzjson, ...); // end with , NULL
91unsigned int zzjson_object_count(ZZJSON *zzjson);
92unsigned int zzjson_array_count(ZZJSON *zzjson);
93
94ZZJSON *zzjson_create_true(ZZJSON_CONFIG *config);
95ZZJSON *zzjson_create_false(ZZJSON_CONFIG *config);
96ZZJSON *zzjson_create_null(ZZJSON_CONFIG *config);
97ZZJSON *zzjson_create_number_d(ZZJSON_CONFIG *config, double d);
98ZZJSON *zzjson_create_number_i(ZZJSON_CONFIG *config, long long i);
99ZZJSON *zzjson_create_string(ZZJSON_CONFIG *config, char *s);
100
101/* list of ZZJSON *'s and end with , NULL */
102ZZJSON *zzjson_create_array(ZZJSON_CONFIG *config, ...);
103
104/* list of char*,ZZJSON* pairs, end with , NULL */
105ZZJSON *zzjson_create_object(ZZJSON_CONFIG *config, ...);
106
107ZZJSON *zzjson_array_prepend(ZZJSON_CONFIG *config, ZZJSON *array,
108                                                    ZZJSON *val);
109ZZJSON *zzjson_array_append (ZZJSON_CONFIG *config, ZZJSON *array,
110                                                    ZZJSON *val);
111
112ZZJSON *zzjson_object_prepend(ZZJSON_CONFIG *config, ZZJSON *object,
113                                        char *label, ZZJSON *val);
114ZZJSON *zzjson_object_append (ZZJSON_CONFIG *config, ZZJSON *object,
115                                        char *label, ZZJSON *val);
116#endif
Note: See TracBrowser for help on using the repository browser.