Initial commit

This commit is contained in:
olemorud
2023-04-24 17:13:47 +02:00
commit 4ce1c34838
12 changed files with 653 additions and 0 deletions

22
include/json_obj.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef _obj_H
#define _obj_H
#include <stdbool.h>
#include <stddef.h>
#define OBJ_SIZE 1024
typedef struct obj_entry {
char const* key;
struct json_value* val;
struct obj_entry* next;
} * __p_obj_entry;
typedef __p_obj_entry obj_t[OBJ_SIZE];
void* obj_at(obj_t m, char* const key);
bool obj_insert(obj_t m, char* const key, struct json_value* value);
void obj_delete(obj_t m);
#endif

32
include/parse.h Normal file
View File

@@ -0,0 +1,32 @@
#ifndef _PARSE_H
#define _PARSE_H
#include "json_obj.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
enum json_type { object,
array,
string,
number,
boolean,
null };
struct json_value {
enum json_type type;
union {
obj_t* object;
struct json_value** array;
char* string;
bool boolean;
int64_t number;
};
};
struct json_value parse_json_value(FILE* fp);
void print_json(struct json_value val, int indent);
#endif

12
include/util.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef _UTIL_H
#define _UTIL_H
#include <stddef.h>
void* malloc_or_die(size_t size);
void* realloc_or_die(void* ptr, size_t size);
void* calloc_or_die(size_t nmemb, size_t size);
void print_trace();
#endif