From c380c2fcce0bd766540f0eee63ed8a5d204b69fa Mon Sep 17 00:00:00 2001 From: cozis Date: Mon, 25 Apr 2022 14:29:30 +0200 Subject: [PATCH] reorganized files and added usage paragraph to readme --- README.md | 19 +++++++++++++------ build.sh | 15 ++++++--------- parse-file.c => examples/parse-file.c | 0 fuzzer.sh | 2 +- xjson.c => src/xjson.c | 0 xjson.h => src/xjson.h | 0 fuzzer.c => tests/fuzzer.c | 0 test.c => tests/test.c | 0 8 files changed, 20 insertions(+), 16 deletions(-) rename parse-file.c => examples/parse-file.c (100%) rename xjson.c => src/xjson.c (100%) rename xjson.h => src/xjson.h (100%) rename fuzzer.c => tests/fuzzer.c (100%) rename test.c => tests/test.c (100%) diff --git a/README.md b/README.md index 7ed9f01..c2f57b9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/build.sh b/build.sh index a93fa4d..9dd76e7 100755 --- a/build.sh +++ b/build.sh @@ -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 \ No newline at end of file +$CC tests/test.c src/xjson.c -o test $FLAGS +$CC examples/parse-file.c src/xjson.c -o parse-file $FLAGS \ No newline at end of file diff --git a/parse-file.c b/examples/parse-file.c similarity index 100% rename from parse-file.c rename to examples/parse-file.c diff --git a/fuzzer.sh b/fuzzer.sh index d54e9fe..d7ba8db 100755 --- a/fuzzer.sh +++ b/fuzzer.sh @@ -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 \ No newline at end of file diff --git a/xjson.c b/src/xjson.c similarity index 100% rename from xjson.c rename to src/xjson.c diff --git a/xjson.h b/src/xjson.h similarity index 100% rename from xjson.h rename to src/xjson.h diff --git a/fuzzer.c b/tests/fuzzer.c similarity index 100% rename from fuzzer.c rename to tests/fuzzer.c diff --git a/test.c b/tests/test.c similarity index 100% rename from test.c rename to tests/test.c