Add headers

This commit is contained in:
Gregory Lirent 2022-08-26 10:07:43 +03:00
parent 6292a9c866
commit eebedd557f
3 changed files with 86 additions and 0 deletions

35
include/bits/__generics.h Normal file
View File

@ -0,0 +1,35 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "../../modules/libcdsb/include/bits/__generics.h"
#ifndef LIBCJSONP_BITS_GENERICS_H
#define LIBCJSONP_BITS_GENERICS_H
#define _LIBCJSONP_vtypeof_hack(x) (vtype)(_Generic((x),\
default: VTYPE_POINTER,\
const void*: VTYPE_POINTER, void*: VTYPE_POINTER,\
const char**: VTYPE_STRING, char**: VTYPE_STRING,\
const vtype_string*: VTYPE_STRING, vtype_string*: VTYPE_STRING,\
const vtype_array*: VTYPE_ARRAY, vtype_array*: VTYPE_ARRAY,\
const vtype_list*: VTYPE_LIST, vtype_list*: VTYPE_LIST,\
const vtype_map*: VTYPE_MAP, vtype_map*: VTYPE_MAP,\
const vtype_set*: VTYPE_SET, vtype_set*: VTYPE_SET,\
const vtype_dict*: VTYPE_DICT, vtype_dict*: VTYPE_DICT,\
vtype_bool: VTYPE_BOOLEAN,\
vtype_uint8: VTYPE_UINT8,\
vtype_uint16: VTYPE_UINT16,\
vtype_uint32: VTYPE_UINT32,\
vtype_uint64: VTYPE_UINT64,\
vtype_int8: VTYPE_INT8,\
vtype_int16: VTYPE_INT16,\
vtype_int32: VTYPE_INT32,\
vtype_int64: VTYPE_INT64,\
vtype_float: VTYPE_FLOAT,\
vtype_double: VTYPE_DOUBLE,\
vtype_ldouble: VTYPE_LDOUBLE))
#define _LIBCJSONP_vtypeof(x) _Generic((x), default: _LIBCJSONP_vtypeof_hack(_Generic((x), default: (x),const char*: &(x),char*:&(x))), const json_t*:json_type(x),json_t*:json_type(x))
#define _LIBCJSONP_value_pointer(x) _Generic((x), default: _LIBCDSB_value_pointer(x), const json_t*: json_value(x), json_t*: json_value(x))
#endif /* LIBCJSONP_BITS_GENERICS_H */

13
include/bits/string.h Normal file
View File

@ -0,0 +1,13 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <string.h>
#include "../../modules/libcdsb/include/vtype.h"
#ifndef LIBCJSONP_BITS_STRING_H
#define LIBCJSONP_BITS_STRING_H
extern void libcjsonp_string_unescape(vtype_string* x);
extern void libcjsonp_string_escape (vtype_string* s);
#endif /* LIBCJSONP_BITS_STRING_H */

38
include/jsonp.h Normal file
View File

@ -0,0 +1,38 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <stdio.h>
#include "bits/__generics.h"
#include "../modules/libcdsb/include/vtype.h"
#ifndef LIBCJSONP_JSONP_H
#define LIBCJSONP_JSONP_H
typedef struct { void* data; vtype type; } json_t;
extern void json_free (json_t* x);
inline vtype json_type (json_t* x) Always_inline__ Nonnull__(1);
inline void* json_value(json_t* x) Always_inline__ Nonnull__(1);
extern bool json_load (json_t* x, FILE* s) Nonnull__(1, 2);
inline vtype json_type (json_t* x) { return x->type; }
inline void* json_value(json_t* x) { return x->data; }
/*#####################################################################################################################*/
#define json_parse(x, src) libcjsonp_json_parse (x, _LIBCDSB_to_cstring(src), 0)
#define json_init(x, value) libcjsonp_json_init (x, _LIBCJSONP_value_pointer(value), _LIBCJSONP_vtypeof(value), 0)
#define json_stringify(value) libcjsonp_json_stringify (_LIBCJSONP_value_pointer(value), _LIBCJSONP_vtypeof(value), 0, 0)
#define json_stringify_pretty(value) libcjsonp_json_stringify (_LIBCJSONP_value_pointer(value), _LIBCJSONP_vtypeof(value), 4, 0)
#define json_dump(dest, value) libcjsonp_json_dump(dest, _LIBCJSONP_value_pointer(value), _LIBCJSONP_vtypeof(value), 0, 0)
#define json_dump_pretty(dest, value) libcjsonp_json_dump(dest, _LIBCJSONP_value_pointer(value), _LIBCJSONP_vtypeof(value), 4, 0)
/*#####################################################################################################################*/
extern void libcjsonp_json_init (json_t* x, void* value, vtype type, bool attach) Nonnull__(1);
extern bool libcjsonp_json_parse(json_t* x, const char* value, size_t nmemb) Nonnull__(1);
extern vtype_string libcjsonp_json_stringify (const void* value, vtype type, size_t padsize, int padchr) Pure__;
extern bool libcjsonp_json_dump(FILE* dest, const void* value, vtype type, size_t padsize, int padchr) Nonnull__(1);
#endif /* LIBCJSONP_JSONP_H */