1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef __JSON_H__
#define __JSON_H__
#include <stdbool.h>

typedef struct {
    enum  { ELEMENT_INT, ELEMENT_STRING, ELEMENT_LIST } type;
    union {
        int    as_int;          // 4 bytes
        char*  as_string;       // 8 bytes
        struct _Node* as_list;  // 8 bytes
    }; // ANONYMOUS union (C11).
} Element;


typedef struct _Node {
    struct _Node* next;
    Element element;
} Node;


bool parse_int(int* a_value, char const** a_pos);
bool parse_string(char** a_s, char const** a_pos);
bool parse_element(Element* a_element, char const** a_pos);
bool parse_list(Node** a_head, char const** a_pos);
void print_element(Element element);
void free_element(Element element);

#endif

#define JSON_H_VERSION_2
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

© Copyright 2022 Alexander J. Quinn         This content is protected and may not be shared, uploaded, or distributed.