reorganized files and added usage paragraph to readme

This commit is contained in:
cozis
2022-04-25 14:29:30 +02:00
parent 577af0d33b
commit c380c2fcce
8 changed files with 20 additions and 16 deletions
+13 -6
View File
@@ -1,11 +1,16 @@
# xJSON
xJSON is a lightweight library that implements a JSON encoder, decoder and other utility functions.
## Usage
To use xJSON, just add `xjson.c` and `xjson.h` to your files, then include `xjson.h` where you want to use it and compile `xjson.c` with your other files.
## Overview
The main functions implemented by xJSON are
```c
xj_value *xj_decode(const char *str, int len, xj_alloc *alloc, xj_error *error);
char *xj_encode(xj_value *value, int *len);
xj_value *xj_decode(const char *str, int len,
xj_alloc *alloc, xj_error *error);
char *xj_encode(xj_value *value, int *len);
```
which let you transform a JSON-encoded UTF-8 string to an `xj_value` and transform an `xj_value` to a string.
@@ -39,13 +44,15 @@ Although the user can make as many `xj_value` nodes as he wants, some constructo
```c
xj_value *xj_value_null(xj_alloc *alloc, xj_error *error);
xj_value *xj_value_bool (xj_bool val, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_int (xj_i64 val, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_float (xj_f64 val, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_bool (xj_bool val, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_int (xj_i64 val, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_float(xj_f64 val, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_array (xj_value *head, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_object(xj_value *head, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_string(const char *str, int len, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_string(const char *str, int len, xj_alloc *alloc, xj_error *error);
```
### Error handling
+6 -9
View File
@@ -1,17 +1,14 @@
CC=gcc
FLAGS="-Wall -Wextra"
FLAGS="-Wall -Wextra -Isrc/"
for arg in "$@"
do
case $arg in
--debug) FLAGS="$FLAGS -DDEBUG -g"
;;
--release) FLAGS="$FLAGS -DNDEBUG -O3"
;;
--coverage) FLAGS="$FLAGS -fprofile-arcs -ftest-coverage"
;;
--debug) FLAGS="$FLAGS -DDEBUG -g" ;;
--release) FLAGS="$FLAGS -DNDEBUG -O3" ;;
--coverage) FLAGS="$FLAGS -fprofile-arcs -ftest-coverage" ;;
esac
done
$CC test.c xjson.c -o test $FLAGS
$CC parse-file.c xjson.c -o parse-file $FLAGS
$CC tests/test.c src/xjson.c -o test $FLAGS
$CC examples/parse-file.c src/xjson.c -o parse-file $FLAGS
+1 -1
View File
@@ -1,4 +1,4 @@
afl-clang-fast fuzzer.c xjson.c -o fuzzer
afl-clang-fast tests/fuzzer.c src/xjson.c -o fuzzer -Isrc/
export AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1
export AFL_SKIP_CPUFREQ=1
afl-fuzz -i samples/ -o out -m none -d -- ./fuzzer
View File
View File
View File
View File