reorganized files and added usage paragraph to readme
This commit is contained in:
@@ -1,11 +1,16 @@
|
|||||||
# xJSON
|
# xJSON
|
||||||
xJSON is a lightweight library that implements a JSON encoder, decoder and other utility functions.
|
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
|
## Overview
|
||||||
The main functions implemented by xJSON are
|
The main functions implemented by xJSON are
|
||||||
```c
|
```c
|
||||||
xj_value *xj_decode(const char *str, int len, xj_alloc *alloc, xj_error *error);
|
xj_value *xj_decode(const char *str, int len,
|
||||||
char *xj_encode(xj_value *value, 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.
|
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
|
```c
|
||||||
xj_value *xj_value_null(xj_alloc *alloc, xj_error *error);
|
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_bool (xj_bool 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_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_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_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
|
### Error handling
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
CC=gcc
|
CC=gcc
|
||||||
FLAGS="-Wall -Wextra"
|
FLAGS="-Wall -Wextra -Isrc/"
|
||||||
|
|
||||||
for arg in "$@"
|
for arg in "$@"
|
||||||
do
|
do
|
||||||
case $arg in
|
case $arg in
|
||||||
--debug) FLAGS="$FLAGS -DDEBUG -g"
|
--debug) FLAGS="$FLAGS -DDEBUG -g" ;;
|
||||||
;;
|
--release) FLAGS="$FLAGS -DNDEBUG -O3" ;;
|
||||||
--release) FLAGS="$FLAGS -DNDEBUG -O3"
|
--coverage) FLAGS="$FLAGS -fprofile-arcs -ftest-coverage" ;;
|
||||||
;;
|
|
||||||
--coverage) FLAGS="$FLAGS -fprofile-arcs -ftest-coverage"
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
$CC test.c xjson.c -o test $FLAGS
|
$CC tests/test.c src/xjson.c -o test $FLAGS
|
||||||
$CC parse-file.c xjson.c -o parse-file $FLAGS
|
$CC examples/parse-file.c src/xjson.c -o parse-file $FLAGS
|
||||||
@@ -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_I_DONT_CARE_ABOUT_MISSING_CRASHES=1
|
||||||
export AFL_SKIP_CPUFREQ=1
|
export AFL_SKIP_CPUFREQ=1
|
||||||
afl-fuzz -i samples/ -o out -m none -d -- ./fuzzer
|
afl-fuzz -i samples/ -o out -m none -d -- ./fuzzer
|
||||||
Reference in New Issue
Block a user