diff --git a/.gitignore b/.gitignore index fa8ec6b25..b22c21504 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ jparse.xml jparse/jfmt jparse/jnamval jparse/jparse +*jprint* jparse/jval jparse/lex.yy.c jparse/test_jparse/print_test diff --git a/CHANGES.md b/CHANGES.md index a8d1f83fc..136280344 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,33 @@ # Major changes to the IOCCC entry toolkit +## Release 1.0.49 2023-08-05 + +New version of `jnamval`: `"0.0.11 2023-08-05"`. Add `-I` option with same +semantics as `jfmt`. Updated `jnamval.1` to add this option and fix typos. + +Change available options for `jnamval -t` to be that of `jval -t`. Updated man +page. + +Typo fixes in `jfmt.1` and `jval.1`. Removed `-I` from `jval.1` as it's not a +valid option. + +Fix typo in usage string in `jnamval` which referred to non-existent option (it +is actually an option arg, not an option, that is correct and that is now what +it says). + +Add option `-P` to `jnamval`. This is just like what `-t` for `jnamval` used to +be but it will indicate what to print rather than what to match. Man page +updated for this option. As the code is common to both `jval` and `jnamval` the +`jval` utility could be updated easily to support this option is desired but +this is TBD later. + +Add some bad test JSON files in the `jparse/test_jparse/test_JSON/bad_loc` +directory, updated Makefile rule Added appropriate `err` files. +Updated Makefile rule `rebuild_jparse_err_files` to not show the command being +run for each file to make the output clean (and to show what it looks like in +the README.md file - which has been updated due to slight changes). + + ## Release 1.0.48 2023-08-04 Bug fixes in `location` tool wrt the `-a` and `-s` options. New version `"1.0.2 diff --git a/jparse/jnamval.c b/jparse/jnamval.c index 3e440c934..9569ba411 100644 --- a/jparse/jnamval.c +++ b/jparse/jnamval.c @@ -40,9 +40,9 @@ static bool quiet = false; /* true ==> quiet mode */ * Use the usage() function to print the usage_msg([0-9]?)+ strings. */ static const char * const usage_msg0 = - "usage:\t%s [-h] [-V] [-v level] [-J level] [-q] [-L {[t|s]}] [-t type] [-l lvl]\n" - "\t[-Q] [-D] [-d] [-i] [-s] [-f] [-c] [-C] [-g] [-e] [-n op=num] [-S op=str] [-o ofile]\n" - "\t[-p parts] [-N] [-H] [-m max_depth] [-K] [-F fmt] file.json [arg ...]\n" + "usage:\t%s [-h] [-V] [-v level] [-J level] [-q] [-L {[t|s]}] [-I {[t|s]}]\n" + "\t[-t types] [-P types] [-l lvl] [-Q] [-D] [-d] [-i] [-s] [-f] [-c] [-C] [-g] [-e] [-n op=num]\n" + "\t[-S op=str] [-o ofile] [-p parts] [-N] [-H] [-m max_depth] [-K] [-F fmt] file.json [arg ...]\n" "\n" "\t-h\t\tPrint help and exit\n" "\t-V\t\tPrint version and exit\n" @@ -53,10 +53,27 @@ static const char * const usage_msg0 = "\t-L [{t|s}]\tPrint JSON level (root is 0) followed by a number of tabs or spaces (def: don't print levels)\n" "\t-L tab\t\tAlias for: '-L 1t'\n" "\n" + "\t\t\tTrailing 't' implies indent with number of tabs whereas trailing 's' implies spaces.\n" + "\t\t\tNot specifying 's' or 't' implies spaces.\n" + "\n" + "\t-I {[t|s]}\tWhen printing JSON syntax, indent levels (def: indent with 4 spaces)\n" + "\t-I tab\t\tAlias for '-I 1t'\n" + "\n" "\t\t\tTrailing 't' implies tabs whereas trailing 's' implies spaces.\n" "\t\t\tNot specifying 's' or 't' implies spaces.\n" "\n" - "\t-t type\t\tMatch only the comma-separated types (def: simple):\n" + "\t-t types\t\tMatch only the comma-separated types (def: simple):\n" + "\n" + "\t\t\t\tint\t\tinteger values\n" + "\t\t\t\tfloat\t\tfloating point values\n" + "\t\t\t\texp\t\texponential notation values\n" + "\t\t\t\tnum\t\talias for 'int,float,exp'\n" + "\t\t\t\tbool\t\tboolean values\n" + "\t\t\t\tstr\t\tstring values\n" + "\t\t\t\tnull\t\tnull values\n" + "\t\t\t\tsimple\t\talias for 'int,float,exp,bool,str,null' (the default)\n" + "\n" + "\t-P types\t\tPrint only the comma-separated types (def: any):\n" "\n" "\t\t\t\tint\t\tinteger values\n" "\t\t\t\tfloat\t\tfloating point values\n" @@ -68,8 +85,9 @@ static const char * const usage_msg0 = "\t\t\t\tmember\t\tmembers\n" "\t\t\t\tobject\t\tobjects\n" "\t\t\t\tarray\t\tarrays\n" - "\t\t\t\tcompound\tcompound values\n" - "\t\t\t\tsimple\t\talias for 'int,float,exp,bool,str,null' (the default)\n" + "\t\t\t\tcompound\talias for 'member,object,array'\n" + "\t\t\t\tsimple\t\talias for 'int,float,exp,bool,str,null'\n" + "\t\t\t\tany\t\talias for 'int,float,exp,bool,str,null,member,object,array' (default)\n" "\n" "\t-p {n,v,b,j}\tPrint JSON key, value, both or JSON members (def: print JSON values)\n" "\t-p name\t\tAlias for '-p n'\n" @@ -77,7 +95,7 @@ static const char * const usage_msg0 = "\t-p both\t\tAlias for '-p n,v'\n" "\t-p json\t\tAlias for '-p j'\n" "\n" - "\t\t\tIt is an error to use -p n or -p v with -j.\n" + "\t\t\tIt is an error to use -p n or -p v with -p j.\n" "\n" "\n" "\t-l lvl\t\tPrint values at specific JSON levels (def: print any level)\n" @@ -188,7 +206,7 @@ main(int argc, char **argv) * parse args */ program = argv[0]; - while ((i = getopt(argc, argv, ":hVv:J:qL:t:l:QDdisfcCgen:S:o:m:Kp:NHF:")) != -1) { + while ((i = getopt(argc, argv, ":hVv:J:qL:I:t:P:l:QDdisfcCgen:S:o:m:Kp:NHF:")) != -1) { switch (i) { case 'h': /* -h - print help to stderr and exit 0 */ free_jnamval(&jnamval); @@ -221,9 +239,17 @@ main(int argc, char **argv) jnamval->common.print_json_levels = true; /* print JSON levels */ json_util_parse_st_level_option(optarg, &jnamval->common.num_level_spaces, &jnamval->common.print_level_tab); break; + case 'I': + jnamval->common.indent_levels = true; + json_util_parse_st_indent_option(optarg, &jnamval->common.indent_spaces, &jnamval->common.indent_tab); + break; case 't': - jnamval->json_name_val.json_types_specified = true; - jnamval->json_name_val.json_types = jnamval_parse_types_option(optarg); + jnamval->json_name_val.match_json_types_specified = true; + jnamval->json_name_val.match_json_types = json_util_parse_match_types(optarg); + break; + case 'P': + jnamval->json_name_val.print_json_types_specified = true; + jnamval->json_name_val.print_json_types = jnamval_parse_print_types(optarg); break; case 'l': jnamval->common.levels_constrained = true; @@ -305,8 +331,8 @@ main(int argc, char **argv) } break; case 'p': - jnamval->print_json_types_option = true; - jnamval->print_json_types = jnamval_parse_print_option(optarg); + jnamval->match_json_types_option = true; + jnamval->match_json_types = jnamval_parse_print_option(optarg); break; case 'N': jnamval->match_json_member_names = true; diff --git a/jparse/jnamval.h b/jparse/jnamval.h index cc605b013..969f8282c 100644 --- a/jparse/jnamval.h +++ b/jparse/jnamval.h @@ -63,7 +63,7 @@ #include "jparse.h" /* jnamval version string */ -#define JNAMVAL_VERSION "0.0.10 2023-08-01" /* format: major.minor YYYY-MM-DD */ +#define JNAMVAL_VERSION "0.0.11 2023-08-05" /* format: major.minor YYYY-MM-DD */ /* jnamval functions - see jnamval_util.h for most */ diff --git a/jparse/jnamval_test.c b/jparse/jnamval_test.c index fd3ce79bf..c81aca8d5 100644 --- a/jparse/jnamval_test.c +++ b/jparse/jnamval_test.c @@ -201,125 +201,222 @@ jnamval_run_tests(void) /* test -t option bits */ /* first int,float,exp */ - bits = jnamval_parse_types_option("int,float,exp"); + bits = json_util_parse_match_types("int,float,exp"); /* check that any number will match */ - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_int, "JNAMVAL_TYPE_INT") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_float, "JNAMVAL_TYPE_FLOAT") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_exp, "JNAMVAL_TYPE_EXP"); + test = jnamval_test_bits(true, bits, __LINE__, json_util_match_int, "JSON_UTIL_MATCH_TYPE_INT") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_float, "JSON_UTIL_MATCH_TYPE_FLOAT") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_exp, "JSON_UTIL_MATCH_TYPE_EXP"); if (!test) { okay = false; } /* just exponents */ - bits = jnamval_parse_types_option("exp"); + bits = json_util_parse_match_types("exp"); /* check that int and float will fail but exp will succeed */ - test = jnamval_test_bits(false, bits, __LINE__, jnamval_match_int, "JNAMVAL_TYPE_INT") && - jnamval_test_bits(false, bits, __LINE__, jnamval_match_float, "JNAMVAL_TYPE_FLOAT") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_exp, "JNAMVAL_TYPE_EXP"); + test = jnamval_test_bits(false, bits, __LINE__, json_util_match_int, "JSON_UTIL_MATCH_TYPE_INT") && + jnamval_test_bits(false, bits, __LINE__, json_util_match_float, "JSON_UTIL_MATCH_TYPE_FLOAT") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_exp, "JSON_UTIL_MATCH_TYPE_EXP"); if (!test) { okay = false; } - /* test all types */ - bits = jnamval_parse_types_option("any"); - /* verify that it is the any bit */ - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_any, "JNAMVAL_TYPE_ANY"); + /* test simple */ + bits = json_util_parse_match_types("simple"); + /* verify that the simple type is set by simple match function */ + test = jnamval_test_bits(true, bits, __LINE__, json_util_match_simple, "JSON_UTIL_MATCH_TYPE_SIMPLE"); + if (!test) { + okay = false; + } + /* verify that the simple type is set by matching each type */ + test = jnamval_test_bits(true, bits, __LINE__, json_util_match_num, "JSON_UTIL_MATCH_TYPE_NUM") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_bool, "JSON_UTIL_MATCH_TYPE_BOOL") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_string, "JSON_UTIL_MATCH_TYPE_STR") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_null, "JSON_UTIL_MATCH_TYPE_NULL"); if (!test) { okay = false; } - /* test compound */ - bits = jnamval_parse_types_option("compound"); - /* verify that the compound type is set by compound match function */ - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_compound, "JNAMVAL_TYPE_COMPOUND"); + /* test int */ + bits = json_util_parse_match_types("int"); + /* verify that the int type is set by int match function */ + test = jnamval_test_bits(true, bits, __LINE__, json_util_match_int, "JSON_UTIL_MATCH_TYPE_INT"); if (!test) { okay = false; } - /* verify that the compound type is set by matching all types */ - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_object, "JNAMVAL_TYPE_OBJECT") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_array, "JNAMVAL_TYPE_ARRAY"); + + /* test float */ + bits = json_util_parse_match_types("float"); + /* verify that the float type is set by float match function */ + test = jnamval_test_bits(true, bits, __LINE__, json_util_match_float, "JSON_UTIL_MATCH_TYPE_FLOAT"); if (!test) { okay = false; } - /* test member */ - bits = jnamval_parse_types_option("member"); - /* verify that the member type is set by member match function */ - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_member, "JNAMVAL_TYPE_MEMBER"); + /* test exp */ + bits = json_util_parse_match_types("exp"); + /* verify that the exp type is set by exp match function */ + test = jnamval_test_bits(true, bits, __LINE__, json_util_match_exp, "JSON_UTIL_MATCH_TYPE_EXP"); if (!test) { okay = false; } - /* test simple */ - bits = jnamval_parse_types_option("simple"); + /* test bool */ + bits = json_util_parse_match_types("bool"); + /* verify that the bool type is set by bool match function */ + test = jnamval_test_bits(true, bits, __LINE__, json_util_match_bool, "JSON_UTIL_MATCH_TYPE_BOOL"); + if (!test) { + okay = false; + } + + /* test string */ + bits = json_util_parse_match_types("str"); + /* verify that the string type is set by string match function */ + test = jnamval_test_bits(true, bits, __LINE__, json_util_match_string, "JSON_UTIL_MATCH_TYPE_STR"); + if (!test) { + okay = false; + } + + /* test null */ + bits = json_util_parse_match_types("null"); + /* verify that the null type is set by null match function */ + test = jnamval_test_bits(true, bits, __LINE__, json_util_match_null, "JSON_UTIL_MATCH_TYPE_NULL"); + if (!test) { + okay = false; + } + + /* test int,str,null */ + bits = json_util_parse_match_types("int,str,null"); + /* verify that the int,str,null types are set by match functions */ + test = jnamval_test_bits(true, bits, __LINE__, json_util_match_int, "JSON_UTIL_MATCH_TYPE_INT") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_string, "JSON_UTIL_MATCH_TYPE_STR") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_null, "JSON_UTIL_MATCH_TYPE_NULL"); + if (!test) { + okay = false; + } + + /* + * test that none of the bits are set not via the match none function but by + * each match function + */ + bits = JSON_UTIL_MATCH_TYPE_NONE; + test = jnamval_test_bits(false, bits, __LINE__, json_util_match_int, "JSON_UTIL_MATCH_TYPE_INT") && + jnamval_test_bits(false, bits, __LINE__, json_util_match_float, "JSON_UTIL_MATCH_TYPE_FLOAT") && + jnamval_test_bits(false, bits, __LINE__, json_util_match_exp, "JSON_UTIL_MATCH_TYPE_EXP") && + jnamval_test_bits(false, bits, __LINE__, json_util_match_num, "JSON_UTIL_MATCH_TYPE_NUM") && + jnamval_test_bits(false, bits, __LINE__, json_util_match_bool, "JSON_UTIL_MATCH_TYPE_BOOL") && + jnamval_test_bits(false, bits, __LINE__, json_util_match_string, "JSON_UTIL_MATCH_TYPE_STR") && + jnamval_test_bits(false, bits, __LINE__, json_util_match_null, "JSON_UTIL_MATCH_TYPE_NULL") && + jnamval_test_bits(false, bits, __LINE__, json_util_match_simple, "JSON_UTIL_MATCH_TYPE_SIMPLE"); + if (!test) { + okay = false; + } + + /* check all types */ + bits = json_util_parse_match_types("int,float,exp,num,bool,str,null,simple"); + test = jnamval_test_bits(true, bits, __LINE__, json_util_match_int, "JSON_UTIL_MATCH_TYPE_INT") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_float, "JSON_UTIL_MATCH_TYPE_FLOAT") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_exp, "JSON_UTIL_MATCH_TYPE_EXP") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_num, "JSON_UTIL_MATCH_TYPE_NUM") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_bool, "JSON_UTIL_MATCH_TYPE_BOOL") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_string, "JSON_UTIL_MATCH_TYPE_STR") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_null, "JSON_UTIL_MATCH_TYPE_NULL") && + jnamval_test_bits(true, bits, __LINE__, json_util_match_simple, "JSON_UTIL_MATCH_TYPE_SIMPLE"); + if (!test) { + okay = false; + } + + + /* test -P option bits */ + + /* first int,float,exp */ + bits = json_util_parse_match_types("int,float,exp"); + /* check that any number will match */ + test = jnamval_test_bits(true, bits, __LINE__, jnamval_print_int, "JNAMVAL_TYPE_INT") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_float, "JNAMVAL_TYPE_FLOAT") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_exp, "JNAMVAL_TYPE_EXP"); + if (!test) { + okay = false; + } + + /* just exponents */ + bits = json_util_parse_match_types("exp"); + /* check that int and float will fail but exp will succeed */ + test = jnamval_test_bits(false, bits, __LINE__, jnamval_print_int, "JNAMVAL_TYPE_INT") && + jnamval_test_bits(false, bits, __LINE__, jnamval_print_float, "JNAMVAL_TYPE_FLOAT") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_exp, "JNAMVAL_TYPE_EXP"); + if (!test) { + okay = false; + } + + bits = json_util_parse_match_types("simple"); /* verify that the simple type is set by simple match function */ - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_simple, "JNAMVAL_TYPE_SIMPLE"); + test = jnamval_test_bits(true, bits, __LINE__, jnamval_print_simple, "JNAMVAL_TYPE_SIMPLE"); if (!test) { okay = false; } /* verify that the simple type is set by matching each type */ - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_num, "JNAMVAL_TYPE_NUM") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_bool, "JNAMVAL_TYPE_BOOL") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_string, "JNAMVAL_TYPE_STR") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_null, "JNAMVAL_TYPE_NULL"); + test = jnamval_test_bits(true, bits, __LINE__, jnamval_print_num, "JNAMVAL_TYPE_NUM") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_bool, "JNAMVAL_TYPE_BOOL") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_string, "JNAMVAL_TYPE_STR") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_null, "JNAMVAL_TYPE_NULL"); if (!test) { okay = false; } /* test int */ - bits = jnamval_parse_types_option("int"); + bits = json_util_parse_match_types("int"); /* verify that the int type is set by int match function */ - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_int, "JNAMVAL_TYPE_INT"); + test = jnamval_test_bits(true, bits, __LINE__, jnamval_print_int, "JNAMVAL_TYPE_INT"); if (!test) { okay = false; } /* test float */ - bits = jnamval_parse_types_option("float"); + bits = json_util_parse_match_types("float"); /* verify that the float type is set by float match function */ - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_float, "JNAMVAL_TYPE_FLOAT"); + test = jnamval_test_bits(true, bits, __LINE__, jnamval_print_float, "JNAMVAL_TYPE_FLOAT"); if (!test) { okay = false; } /* test exp */ - bits = jnamval_parse_types_option("exp"); + bits = json_util_parse_match_types("exp"); /* verify that the exp type is set by exp match function */ - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_exp, "JNAMVAL_TYPE_EXP"); + test = jnamval_test_bits(true, bits, __LINE__, jnamval_print_exp, "JNAMVAL_TYPE_EXP"); if (!test) { okay = false; } /* test bool */ - bits = jnamval_parse_types_option("bool"); + bits = json_util_parse_match_types("bool"); /* verify that the bool type is set by bool match function */ - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_bool, "JNAMVAL_TYPE_BOOL"); + test = jnamval_test_bits(true, bits, __LINE__, jnamval_print_bool, "JNAMVAL_TYPE_BOOL"); if (!test) { okay = false; } /* test string */ - bits = jnamval_parse_types_option("str"); + bits = json_util_parse_match_types("str"); /* verify that the string type is set by string match function */ - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_string, "JNAMVAL_TYPE_STR"); + test = jnamval_test_bits(true, bits, __LINE__, jnamval_print_string, "JNAMVAL_TYPE_STR"); if (!test) { okay = false; } /* test null */ - bits = jnamval_parse_types_option("null"); + bits = json_util_parse_match_types("null"); /* verify that the null type is set by null match function */ - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_null, "JNAMVAL_TYPE_NULL"); + test = jnamval_test_bits(true, bits, __LINE__, jnamval_print_null, "JNAMVAL_TYPE_NULL"); if (!test) { okay = false; } /* test int,str,null */ - bits = jnamval_parse_types_option("int,str,null"); + bits = json_util_parse_match_types("int,str,null"); /* verify that the int,str,null types are set by match functions */ - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_int, "JNAMVAL_TYPE_INT") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_string, "JNAMVAL_TYPE_STR") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_null, "JNAMVAL_TYPE_NULL"); + test = jnamval_test_bits(true, bits, __LINE__, jnamval_print_int, "JNAMVAL_TYPE_INT") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_string, "JNAMVAL_TYPE_STR") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_null, "JNAMVAL_TYPE_NULL"); if (!test) { okay = false; } @@ -328,37 +425,33 @@ jnamval_run_tests(void) * test that none of the bits are set not via the match none function but by * each match function */ - bits = JNAMVAL_TYPE_NONE; - test = jnamval_test_bits(false, bits, __LINE__, jnamval_match_int, "JNAMVAL_TYPE_INT") && - jnamval_test_bits(false, bits, __LINE__, jnamval_match_float, "JNAMVAL_TYPE_FLOAT") && - jnamval_test_bits(false, bits, __LINE__, jnamval_match_exp, "JNAMVAL_TYPE_EXP") && - jnamval_test_bits(false, bits, __LINE__, jnamval_match_num, "JNAMVAL_TYPE_NUM") && - jnamval_test_bits(false, bits, __LINE__, jnamval_match_bool, "JNAMVAL_TYPE_BOOL") && - jnamval_test_bits(false, bits, __LINE__, jnamval_match_string, "JNAMVAL_TYPE_STR") && - jnamval_test_bits(false, bits, __LINE__, jnamval_match_null, "JNAMVAL_TYPE_NULL") && - jnamval_test_bits(false, bits, __LINE__, jnamval_match_object, "JNAMVAL_TYPE_OBJECT") && - jnamval_test_bits(false, bits, __LINE__, jnamval_match_array, "JNAMVAL_TYPE_ARRAY") && - jnamval_test_bits(false, bits, __LINE__, jnamval_match_any, "JNAMVAL_TYPE_ANY") && - jnamval_test_bits(false, bits, __LINE__, jnamval_match_simple, "JNAMVAL_TYPE_SIMPLE") && - jnamval_test_bits(false, bits, __LINE__, jnamval_match_compound, "JNAMVAL_TYPE_COMPOUND"); + bits = JNAMVAL_PRINT_TYPE_NONE; + test = jnamval_test_bits(false, bits, __LINE__, jnamval_print_int, "JNAMVAL_PRINT_TYPE_INT") && + jnamval_test_bits(false, bits, __LINE__, jnamval_print_float, "JNAMVAL_PRINT_TYPE_FLOAT") && + jnamval_test_bits(false, bits, __LINE__, jnamval_print_exp, "JNAMVAL_PRINT_TYPE_EXP") && + jnamval_test_bits(false, bits, __LINE__, jnamval_print_num, "JNAMVAL_PRINT_TYPE_NUM") && + jnamval_test_bits(false, bits, __LINE__, jnamval_print_bool, "JNAMVAL_PRINT_TYPE_BOOL") && + jnamval_test_bits(false, bits, __LINE__, jnamval_print_string, "JNAMVAL_PRINT_TYPE_STR") && + jnamval_test_bits(false, bits, __LINE__, jnamval_print_null, "JNAMVAL_PRINT_TYPE_NULL") && + jnamval_test_bits(false, bits, __LINE__, jnamval_print_object, "JNAMVAL_PRINT_TYPE_OBJECT") && + jnamval_test_bits(false, bits, __LINE__, jnamval_print_array, "JNAMVAL_PRINT_TYPE_ARRAY") && + jnamval_test_bits(false, bits, __LINE__, jnamval_print_any, "JNAMVAL_PRINT_TYPE_ANY") && + jnamval_test_bits(false, bits, __LINE__, jnamval_print_simple, "JNAMVAL_PRINT_TYPE_SIMPLE") && + jnamval_test_bits(false, bits, __LINE__, jnamval_print_compound, "JNAMVAL_PRINT_TYPE_COMPOUND"); if (!test) { okay = false; } /* check all types */ - bits = jnamval_parse_types_option("int,float,exp,num,bool,str,null,object,array,any,simple,compound"); - test = jnamval_test_bits(true, bits, __LINE__, jnamval_match_int, "JNAMVAL_TYPE_INT") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_float, "JNAMVAL_TYPE_FLOAT") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_exp, "JNAMVAL_TYPE_EXP") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_num, "JNAMVAL_TYPE_NUM") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_bool, "JNAMVAL_TYPE_BOOL") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_string, "JNAMVAL_TYPE_STR") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_null, "JNAMVAL_TYPE_NULL") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_object, "JNAMVAL_TYPE_OBJECT") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_array, "JNAMVAL_TYPE_ARRAY") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_any, "JNAMVAL_TYPE_ANY") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_simple, "JNAMVAL_TYPE_SIMPLE") && - jnamval_test_bits(true, bits, __LINE__, jnamval_match_compound, "JNAMVAL_TYPE_COMPOUND"); + bits = json_util_parse_match_types("int,float,exp,num,bool,str,null,simple"); + test = jnamval_test_bits(true, bits, __LINE__, jnamval_print_int, "JNAMVAL_PRINT_TYPE_INT") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_float, "JNAMVAL_PRINT_TYPE_FLOAT") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_exp, "JNAMVAL_PRINT_TYPE_EXP") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_num, "JNAMVAL_PRINT_TYPE_NUM") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_bool, "JNAMVAL_PRINT_TYPE_BOOL") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_string, "JNAMVAL_PRINT_TYPE_STR") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_null, "JNAMVAL_PRINT_TYPE_NULL") && + jnamval_test_bits(true, bits, __LINE__, jnamval_print_simple, "JNAMVAL_PRINT_TYPE_SIMPLE"); if (!test) { okay = false; } diff --git a/jparse/jnamval_util.c b/jparse/jnamval_util.c index 5a5c8b8f9..97770183a 100644 --- a/jparse/jnamval_util.c +++ b/jparse/jnamval_util.c @@ -78,8 +78,8 @@ alloc_jnamval(void) jnamval->common.indent_levels = false; /* -I used */ jnamval->common.indent_spaces = 4; /* -I number of tabs or spaces */ jnamval->common.indent_tab = false; /* -I [{t|s}] specified */ - jnamval->print_json_types_option = false; /* -p explicitly used */ - jnamval->print_json_types = JNAMVAL_PRINT_VALUE; /* -p type specified */ + jnamval->match_json_types_option = false; /* -t explicitly used */ + jnamval->match_json_types = JNAMVAL_PRINT_VALUE; /* -t type specified */ jnamval->json_name_val.print_decoded = false; /* -D not used if false */ jnamval->json_name_val.invert_matches = false; /* -i used */ @@ -88,8 +88,10 @@ alloc_jnamval(void) /* search / matching related */ /* json types to look for */ - jnamval->json_name_val.json_types_specified = false; /* -t used */ - jnamval->json_name_val.json_types = JNAMVAL_TYPE_SIMPLE; /* -t type specified, default simple */ + jnamval->json_name_val.match_json_types_specified = false; /* -t used */ + jnamval->json_name_val.match_json_types = JNAMVAL_PRINT_TYPE_SIMPLE; /* -t type specified, default simple */ + jnamval->json_name_val.print_json_types_specified = false; /* -P used */ + jnamval->json_name_val.print_json_types = JNAMVAL_PRINT_TYPE_ANY; /* -P types, default any */ jnamval->json_name_val.ignore_case = false; /* true if -f, case-insensitive */ jnamval->json_name_val.match_decoded = false; /* if -d used match decoded */ jnamval->json_name_val.arg_specified = false; /* true if an arg was specified */ @@ -123,9 +125,8 @@ alloc_jnamval(void) return jnamval; } - /* - * jnamval_match_none - if no types should match + * jnamval_print_none - if no types should print * * given: * @@ -134,19 +135,19 @@ alloc_jnamval(void) * Returns true if types == 0. */ bool -jnamval_match_none(uintmax_t types) +jnamval_print_none(uintmax_t types) { - return types == JNAMVAL_TYPE_NONE; + return types == JNAMVAL_PRINT_TYPE_NONE; } /* - * jnamval_match_int - if ints should match + * jnamval_print_int - if ints should print * * given: * * types - types set * - * Returns true if types has JNAMVAL_TYPE_INT set. + * Returns true if types has JNAMVAL_PRINT_TYPE_INT set. * * NOTE: why do we return that the bitwise AND is not != 0 rather than just the * bitwise AND? Because in some cases (like the test routines) we compare the @@ -160,18 +161,18 @@ jnamval_match_none(uintmax_t types) * but this seems like needless complications. */ bool -jnamval_match_int(uintmax_t types) +jnamval_print_int(uintmax_t types) { - return (types & JNAMVAL_TYPE_INT) != 0; + return (types & JNAMVAL_PRINT_TYPE_INT) != 0; } /* - * jnamval_match_float - if floats should match + * jnamval_print_float - if floats should print * * given: * * types - types set * - * Returns true if types has JNAMVAL_TYPE_FLOAT set. + * Returns true if types has JNAMVAL_PRINT_TYPE_FLOAT set. * * NOTE: why do we return that the bitwise AND is not != 0 rather than just the * bitwise AND? Because in some cases (like the test routines) we compare the @@ -185,18 +186,18 @@ jnamval_match_int(uintmax_t types) * but this seems like needless complications. */ bool -jnamval_match_float(uintmax_t types) +jnamval_print_float(uintmax_t types) { - return (types & JNAMVAL_TYPE_FLOAT) != 0; + return (types & JNAMVAL_PRINT_TYPE_FLOAT) != 0; } /* - * jnamval_match_exp - if exponents should match + * jnamval_print_exp - if exponents should print * * given: * * types - types set * - * Returns true if types has JNAMVAL_TYPE_EXP set. + * Returns true if types has JNAMVAL_PRINT_TYPE_EXP set. * * NOTE: why do we return that the bitwise AND is not != 0 rather than just the * bitwise AND? Because in some cases (like the test routines) we compare the @@ -210,18 +211,18 @@ jnamval_match_float(uintmax_t types) * but this seems like needless complications. */ bool -jnamval_match_exp(uintmax_t types) +jnamval_print_exp(uintmax_t types) { - return (types & JNAMVAL_TYPE_EXP) != 0; + return (types & JNAMVAL_PRINT_TYPE_EXP) != 0; } /* - * jnamval_match_num - if numbers of any type should match + * jnamval_print_num - if numbers of any type should print * * given: * * types - types set * - * Returns true if types has JNAMVAL_TYPE_NUM (or any of the number types) set. + * Returns true if types has JNAMVAL_PRINT_TYPE_NUM (or any of the number types) set. * * NOTE: why do we return that the bitwise AND is not != 0 rather than just the * bitwise AND? Because in some cases (like the test routines) we compare the @@ -235,19 +236,19 @@ jnamval_match_exp(uintmax_t types) * but this seems like needless complications. */ bool -jnamval_match_num(uintmax_t types) +jnamval_print_num(uintmax_t types) { - return ((types & JNAMVAL_TYPE_NUM)||(types & JNAMVAL_TYPE_INT) || (types & JNAMVAL_TYPE_FLOAT) || - (types & JNAMVAL_TYPE_EXP))!= 0; + return ((types & JNAMVAL_PRINT_TYPE_NUM)||(types & JNAMVAL_PRINT_TYPE_INT) || (types & JNAMVAL_PRINT_TYPE_FLOAT) || + (types & JNAMVAL_PRINT_TYPE_EXP))!= 0; } /* - * jnamval_match_bool - if booleans should match + * jnamval_print_bool - if booleans should print * * given: * * types - types set * - * Returns true if types has JNAMVAL_TYPE_BOOL set. + * Returns true if types has JNAMVAL_PRINT_TYPE_BOOL set. * * NOTE: why do we return that the bitwise AND is not != 0 rather than just the * bitwise AND? Because in some cases (like the test routines) we compare the @@ -261,18 +262,18 @@ jnamval_match_num(uintmax_t types) * but this seems like needless complications. */ bool -jnamval_match_bool(uintmax_t types) +jnamval_print_bool(uintmax_t types) { - return (types & JNAMVAL_TYPE_BOOL) != 0; + return (types & JNAMVAL_PRINT_TYPE_BOOL) != 0; } /* - * jnamval_match_string - if strings should match + * jnamval_print_string - if strings should print * * given: * * types - types set * - * Returns true if types has JNAMVAL_TYPE_STR set. + * Returns true if types has JNAMVAL_PRINT_TYPE_STR set. * * NOTE: why do we return that the bitwise AND is not != 0 rather than just the * bitwise AND? Because in some cases (like the test routines) we compare the @@ -286,18 +287,18 @@ jnamval_match_bool(uintmax_t types) * but this seems like needless complications. */ bool -jnamval_match_string(uintmax_t types) +jnamval_print_string(uintmax_t types) { - return (types & JNAMVAL_TYPE_STR) != 0; + return (types & JNAMVAL_PRINT_TYPE_STR) != 0; } /* - * jnamval_match_null - if null should match + * jnamval_print_null - if null should print * * given: * * types - types set * - * Returns true if types has JNAMVAL_TYPE_NULL set. + * Returns true if types has JNAMVAL_PRINT_TYPE_NULL set. * * NOTE: why do we return that the bitwise AND is not != 0 rather than just the * bitwise AND? Because in some cases (like the test routines) we compare the @@ -311,19 +312,19 @@ jnamval_match_string(uintmax_t types) * but this seems like needless complications. */ bool -jnamval_match_null(uintmax_t types) +jnamval_print_null(uintmax_t types) { - return (types & JNAMVAL_TYPE_NULL) != 0; + return (types & JNAMVAL_PRINT_TYPE_NULL) != 0; } /* - * jnamval_match_object - if objects should match + * jnamval_print_object - if objects should print * * given: * * types - types set * - * Returns true if types has JNAMVAL_TYPE_OBJECT set. + * Returns true if types has JNAMVAL_PRINT_TYPE_OBJECT set. * * NOTE: why do we return that the bitwise AND is not != 0 rather than just the * bitwise AND? Because in some cases (like the test routines) we compare the @@ -337,19 +338,19 @@ jnamval_match_null(uintmax_t types) * but this seems like needless complications. */ bool -jnamval_match_object(uintmax_t types) +jnamval_print_object(uintmax_t types) { - return (types & JNAMVAL_TYPE_OBJECT) != 0; + return (types & JNAMVAL_PRINT_TYPE_OBJECT) != 0; } /* - * jnamval_match_array - if arrays should match + * jnamval_print_array - if arrays should print * * given: * * types - types set * - * Returns true if types has JNAMVAL_TYPE_ARRAY set. + * Returns true if types has JNAMVAL_PRINT_TYPE_ARRAY set. * * NOTE: why do we return that the bitwise AND is not != 0 rather than just the * bitwise AND? Because in some cases (like the test routines) we compare the @@ -363,14 +364,14 @@ jnamval_match_object(uintmax_t types) * but this seems like needless complications. */ bool -jnamval_match_array(uintmax_t types) +jnamval_print_array(uintmax_t types) { - return (types & JNAMVAL_TYPE_ARRAY) != 0; + return (types & JNAMVAL_PRINT_TYPE_ARRAY) != 0; } /* - * jnamval_match_simple - if simple types should match + * jnamval_print_simple - if simple types should print * * given: * @@ -378,7 +379,7 @@ jnamval_match_array(uintmax_t types) * * Simple is defined as a number, a bool, a string or a null. * - * Returns true if types has JNAMVAL_TYPE_SIMPLE set. + * Returns true if types has JNAMVAL_PRINT_TYPE_SIMPLE set. * * NOTE: why do we return that the bitwise AND is not != 0 rather than just the * bitwise AND? Because in some cases (like the test routines) we compare the @@ -392,12 +393,12 @@ jnamval_match_array(uintmax_t types) * but this seems like needless complications. */ bool -jnamval_match_simple(uintmax_t types) +jnamval_print_simple(uintmax_t types) { - return (types & JNAMVAL_TYPE_SIMPLE) != 0; + return (types & JNAMVAL_PRINT_TYPE_SIMPLE) != 0; } /* - * jnamval_match_member - if members should match + * jnamval_print_member - if members should print * * given: * @@ -405,7 +406,7 @@ jnamval_match_simple(uintmax_t types) * * A member is defined as an object or array. * - * Returns true if types has JNAMVAL_TYPE_MEMBER set. + * Returns true if types has JNAMVAL_PRINT_TYPE_MEMBER set. * * NOTE: why do we return that the bitwise AND is not != 0 rather than just the * bitwise AND? Because in some cases (like the test routines) we compare the @@ -419,14 +420,14 @@ jnamval_match_simple(uintmax_t types) * but this seems like needless complications. */ bool -jnamval_match_member(uintmax_t types) +jnamval_print_member(uintmax_t types) { - return (types & JNAMVAL_TYPE_MEMBER) != 0; + return (types & JNAMVAL_PRINT_TYPE_MEMBER) != 0; } /* - * jnamval_match_compound - if compounds should match + * jnamval_print_compound - if compounds should print * * given: * @@ -434,7 +435,7 @@ jnamval_match_member(uintmax_t types) * * A compound is defined as an object or array. * - * Returns true if types has JNAMVAL_TYPE_COMPOUND set. + * Returns true if types has JNAMVAL_PRINT_TYPE_COMPOUND set. * * NOTE: why do we return that the bitwise AND is not != 0 rather than just the * bitwise AND? Because in some cases (like the test routines) we compare the @@ -448,58 +449,59 @@ jnamval_match_member(uintmax_t types) * but this seems like needless complications. */ bool -jnamval_match_compound(uintmax_t types) +jnamval_print_compound(uintmax_t types) { - return (types & JNAMVAL_TYPE_COMPOUND) != 0; + return (types & JNAMVAL_PRINT_TYPE_COMPOUND) != 0; } /* - * jnamval_match_any - if any type should match + * jnamval_print_any - if any type should print * * given: * * types - types set * - * Returns true if types is equal to JNAMVAL_TYPE_ANY. + * Returns true if types is equal to JNAMVAL_PRINT_TYPE_ANY. * - * Why does it have to equal JNAMVAL_TYPE_ANY if it checks for any type? Because - * the point is that if JNAMVAL_TYPE_ANY is set it can be any type but not + * Why does it have to equal JNAMVAL_PRINT_TYPE_ANY if it checks for any type? Because + * the point is that if JNAMVAL_PRINT_TYPE_ANY is set it can be any type but not * specific types. For the specific types those bits have to be set instead. If - * JNAMVAL_TYPE_ANY is set then any type can be set but if types is say - * JNAMVAL_TYPE_INT then checking for JNAMVAL_TYPE_INT & JNAMVAL_TYPE_ANY would be + * JNAMVAL_PRINT_TYPE_ANY is set then any type can be set but if types is say + * JNAMVAL_PRINT_TYPE_INT then checking for JNAMVAL_PRINT_TYPE_INT & JNAMVAL_PRINT_TYPE_ANY would be * != 0 (as it's a bitwise OR of all the types) which would suggest that any - * type is okay even if JNAMVAL_TYPE_INT was the only type. + * type is okay even if JNAMVAL_PRINT_TYPE_INT was the only type. */ bool -jnamval_match_any(uintmax_t types) +jnamval_print_any(uintmax_t types) { - return types == JNAMVAL_TYPE_ANY; + return types == JNAMVAL_PRINT_TYPE_ANY; } /* - * jnamval_parse_types_option - parse -t types list + * jnamval_parse_types_option - parse -t types or -P types list * * given: * - * optarg - option argument to -t option + * optarg - option argument to -P or -t option * * Returns: bitvector of types requested. * * NOTE: if optarg is NULL (which should never happen) or empty it returns the - * default, JNAMVAL_TYPE_SIMPLE (as if '-t simple'). + * default, JNAMVAL_PRINT_TYPE_SIMPLE (as if '-t simple' or '-P simple'). */ uintmax_t -jnamval_parse_types_option(char *optarg) +jnamval_parse_print_types(char *optarg) { char *p = NULL; /* for strtok_r() */ char *saveptr = NULL; /* for strtok_r() */ char *dup = NULL; /* strdup()d copy of optarg */ - uintmax_t type = JNAMVAL_TYPE_SIMPLE; /* default is simple: num, bool, str and null */ + uintmax_t type = JNAMVAL_PRINT_TYPE_ANY; /* default depends on option used */ + /* firewall */ if (optarg == NULL || !*optarg) { - /* NULL or empty optarg, assume simple */ + /* NULL or empty optarg, assume simple or any depending on option used */ return type; } else { /* pre-clear errno for errp() */ @@ -511,6 +513,12 @@ jnamval_parse_types_option(char *optarg) } } + /* + * set type to none before we parse the types as not doing so can mess up + * the bits as we have to do bitwise OR for each type found. + */ + type = JNAMVAL_PRINT_TYPE_NONE; + /* * Go through comma-separated list of types, setting each as a bitvector * @@ -519,31 +527,31 @@ jnamval_parse_types_option(char *optarg) */ for (p = strtok_r(dup, ",", &saveptr); p; p = strtok_r(NULL, ",", &saveptr)) { if (!strcmp(p, "int")) { - type |= JNAMVAL_TYPE_INT; + type |= JNAMVAL_PRINT_TYPE_INT; } else if (!strcmp(p, "float")) { - type |= JNAMVAL_TYPE_FLOAT; + type |= JNAMVAL_PRINT_TYPE_FLOAT; } else if (!strcmp(p, "exp")) { - type |= JNAMVAL_TYPE_EXP; + type |= JNAMVAL_PRINT_TYPE_EXP; } else if (!strcmp(p, "num")) { - type |= JNAMVAL_TYPE_NUM; + type |= JNAMVAL_PRINT_TYPE_NUM; } else if (!strcmp(p, "bool")) { - type |= JNAMVAL_TYPE_BOOL; + type |= JNAMVAL_PRINT_TYPE_BOOL; } else if (!strcmp(p, "str")) { - type |= JNAMVAL_TYPE_STR; + type |= JNAMVAL_PRINT_TYPE_STR; } else if (!strcmp(p, "null")) { - type |= JNAMVAL_TYPE_NULL; + type |= JNAMVAL_PRINT_TYPE_NULL; } else if (!strcmp(p, "object")) { - type |= JNAMVAL_TYPE_OBJECT; + type |= JNAMVAL_PRINT_TYPE_OBJECT; } else if (!strcmp(p, "array")) { - type |= JNAMVAL_TYPE_ARRAY; + type |= JNAMVAL_PRINT_TYPE_ARRAY; } else if (!strcmp(p, "simple")) { - type |= JNAMVAL_TYPE_SIMPLE; + type |= JNAMVAL_PRINT_TYPE_SIMPLE; } else if (!strcmp(p, "compound")) { - type |= JNAMVAL_TYPE_COMPOUND; + type |= JNAMVAL_PRINT_TYPE_COMPOUND; } else if (!strcmp(p, "member")) { - type |= JNAMVAL_TYPE_MEMBER; + type |= JNAMVAL_PRINT_TYPE_MEMBER; } else if (!strcmp(p, "any")) { - type |= JNAMVAL_TYPE_ANY; + type |= JNAMVAL_PRINT_TYPE_ANY; } else { /* unknown type */ err(3, __func__, "unknown type '%s'", p); /*ooo*/ @@ -737,12 +745,12 @@ jnamval_parse_print_option(char *optarg) * Returns: bitvector of types requested. * * NOTE: if optarg is NULL (which should never happen) or empty it returns the - * default, JNAMVAL_TYPE_SIMPLE (as if '-t simple'). + * default, JNAMVAL_PRINT_TYPE_SIMPLE (as if '-t simple'). */ uintmax_t jnamval_parse_value_type_option(char *optarg) { - uintmax_t type = JNAMVAL_TYPE_SIMPLE; /* default is simple: num, bool, str and null */ + uintmax_t type = JNAMVAL_PRINT_TYPE_SIMPLE; /* default is simple: num, bool, str and null */ char *p = NULL; if (optarg == NULL || !*optarg) { @@ -753,21 +761,21 @@ jnamval_parse_value_type_option(char *optarg) /* Determine if the arg is a valid type. */ if (!strcmp(p, "int")) { - type = JNAMVAL_TYPE_INT; + type = JNAMVAL_PRINT_TYPE_INT; } else if (!strcmp(p, "float")) { - type = JNAMVAL_TYPE_FLOAT; + type = JNAMVAL_PRINT_TYPE_FLOAT; } else if (!strcmp(p, "exp")) { - type = JNAMVAL_TYPE_EXP; + type = JNAMVAL_PRINT_TYPE_EXP; } else if (!strcmp(p, "num")) { - type = JNAMVAL_TYPE_NUM; + type = JNAMVAL_PRINT_TYPE_NUM; } else if (!strcmp(p, "bool")) { - type = JNAMVAL_TYPE_BOOL; + type = JNAMVAL_PRINT_TYPE_BOOL; } else if (!strcmp(p, "str")) { - type = JNAMVAL_TYPE_STR; + type = JNAMVAL_PRINT_TYPE_STR; } else if (!strcmp(p, "null")) { - type = JNAMVAL_TYPE_NULL; + type = JNAMVAL_PRINT_TYPE_NULL; } else if (!strcmp(p, "simple")) { - type = JNAMVAL_TYPE_SIMPLE; + type = JNAMVAL_PRINT_TYPE_SIMPLE; } else { /* unknown or unsupported type */ err(3, __func__, "unknown or unsupported type '%s'", p); /*ooo*/ diff --git a/jparse/jnamval_util.h b/jparse/jnamval_util.h index a572879f2..33d6bc8ad 100644 --- a/jparse/jnamval_util.h +++ b/jparse/jnamval_util.h @@ -58,23 +58,23 @@ /* defines */ -/* -t types */ -#define JNAMVAL_TYPE_NONE (0) -#define JNAMVAL_TYPE_INT (1) -#define JNAMVAL_TYPE_FLOAT (2) -#define JNAMVAL_TYPE_EXP (4) -#define JNAMVAL_TYPE_NUM (8) -#define JNAMVAL_TYPE_BOOL (16) -#define JNAMVAL_TYPE_STR (32) -#define JNAMVAL_TYPE_NULL (64) -#define JNAMVAL_TYPE_MEMBER (128) -#define JNAMVAL_TYPE_OBJECT (256) -#define JNAMVAL_TYPE_ARRAY (512) -#define JNAMVAL_TYPE_ANY (1023) /* bitwise OR of the above values */ -/* JNAMVAL_TYPE_SIMPLE is bitwise OR of num, bool, str and null */ -#define JNAMVAL_TYPE_SIMPLE (JNAMVAL_TYPE_NUM|JNAMVAL_TYPE_BOOL|JNAMVAL_TYPE_STR|JNAMVAL_TYPE_NULL) -/* JNAMVAL_TYPE_COMPOUND is bitwise OR of object and array */ -#define JNAMVAL_TYPE_COMPOUND (JNAMVAL_TYPE_MEMBER|JNAMVAL_TYPE_OBJECT|JNAMVAL_TYPE_ARRAY) +/* -P types */ +#define JNAMVAL_PRINT_TYPE_NONE (0) +#define JNAMVAL_PRINT_TYPE_INT (1) +#define JNAMVAL_PRINT_TYPE_FLOAT (2) +#define JNAMVAL_PRINT_TYPE_EXP (4) +#define JNAMVAL_PRINT_TYPE_NUM (8) +#define JNAMVAL_PRINT_TYPE_BOOL (16) +#define JNAMVAL_PRINT_TYPE_STR (32) +#define JNAMVAL_PRINT_TYPE_NULL (64) +#define JNAMVAL_PRINT_TYPE_MEMBER (128) +#define JNAMVAL_PRINT_TYPE_OBJECT (256) +#define JNAMVAL_PRINT_TYPE_ARRAY (512) +#define JNAMVAL_PRINT_TYPE_ANY (1023) /* bitwise OR of the above values */ +/* JNAMVAL_PRINT_TYPE_SIMPLE is bitwise OR of num, bool, str and null */ +#define JNAMVAL_PRINT_TYPE_SIMPLE (JNAMVAL_PRINT_TYPE_NUM|JNAMVAL_PRINT_TYPE_BOOL|JNAMVAL_PRINT_TYPE_STR|JNAMVAL_PRINT_TYPE_NULL) +/* JNAMVAL_PRINT_TYPE_COMPOUND is bitwise OR of member, object and array */ +#define JNAMVAL_PRINT_TYPE_COMPOUND (JNAMVAL_PRINT_TYPE_MEMBER|JNAMVAL_PRINT_TYPE_OBJECT|JNAMVAL_PRINT_TYPE_ARRAY) /* print types for -p option */ #define JNAMVAL_PRINT_NAME (1) @@ -103,9 +103,9 @@ struct jnamval /* below are those not common to any other tools */ - /* printing related options */ - bool print_json_types_option; /* -p explicitly used */ - uintmax_t print_json_types; /* -p type specified */ + /* matching and printing related options */ + bool match_json_types_option; /* -p explicitly used */ + uintmax_t match_json_types; /* -p type specified */ /* search / matching related */ bool match_json_member_names; /* -N used, match based on member names */ @@ -116,22 +116,23 @@ struct jnamval /* function prototypes */ struct jnamval *alloc_jnamval(void); -/* JSON types - -t option*/ -uintmax_t jnamval_parse_types_option(char *optarg); -bool jnamval_match_none(uintmax_t types); -bool jnamval_match_any(uintmax_t types); -bool jnamval_match_int(uintmax_t types); -bool jnamval_match_float(uintmax_t types); -bool jnamval_match_exp(uintmax_t types); -bool jnamval_match_bool(uintmax_t types); -bool jnamval_match_num(uintmax_t types); -bool jnamval_match_string(uintmax_t types); -bool jnamval_match_null(uintmax_t types); -bool jnamval_match_simple(uintmax_t types); -bool jnamval_match_object(uintmax_t types); -bool jnamval_match_array(uintmax_t types); -bool jnamval_match_compound(uintmax_t types); -bool jnamval_match_member(uintmax_t types); +/* JSON types - -P option */ +uintmax_t jnamval_parse_print_types(char *optarg); +/* JSON types to match for -P option */ +bool jnamval_print_none(uintmax_t types); +bool jnamval_print_any(uintmax_t types); +bool jnamval_print_int(uintmax_t types); +bool jnamval_print_float(uintmax_t types); +bool jnamval_print_exp(uintmax_t types); +bool jnamval_print_bool(uintmax_t types); +bool jnamval_print_num(uintmax_t types); +bool jnamval_print_string(uintmax_t types); +bool jnamval_print_null(uintmax_t types); +bool jnamval_print_simple(uintmax_t types); +bool jnamval_print_object(uintmax_t types); +bool jnamval_print_array(uintmax_t types); +bool jnamval_print_compound(uintmax_t types); +bool jnamval_print_member(uintmax_t types); /* what to print - -p option */ uintmax_t jnamval_parse_print_option(char *optarg); @@ -139,6 +140,24 @@ bool jnamval_print_name(uintmax_t types); bool jnamval_print_value(uintmax_t types); bool jnamval_print_both(uintmax_t types); bool jnamval_print_json(uintmax_t types); +/* JSON types to match for -P option + * NOTE: the types bitvector is NOT the same as for -p! + */ +bool jnamval_print_none(uintmax_t types); +bool jnamval_print_any(uintmax_t types); +bool jnamval_print_int(uintmax_t types); +bool jnamval_print_float(uintmax_t types); +bool jnamval_print_exp(uintmax_t types); +bool jnamval_print_bool(uintmax_t types); +bool jnamval_print_num(uintmax_t types); +bool jnamval_print_string(uintmax_t types); +bool jnamval_print_null(uintmax_t types); +bool jnamval_print_simple(uintmax_t types); +bool jnamval_print_object(uintmax_t types); +bool jnamval_print_array(uintmax_t types); +bool jnamval_print_compound(uintmax_t types); +bool jnamval_print_member(uintmax_t types); + /* functions to print matches */ diff --git a/jparse/json_util.c b/jparse/json_util.c index f0eb32952..235e3bca3 100644 --- a/jparse/json_util.c +++ b/jparse/json_util.c @@ -2904,3 +2904,286 @@ parse_json_util_format(struct json_util *json_util, char const *name, char const return format; } +/* + * json_util_parse_match_types - parse -t types list + * + * given: + * + * optarg - option argument to -t option + * + * Returns: bitvector of types requested. + * + * NOTE: if optarg is NULL (which should never happen) or empty it returns the + * default, JSON_UTIL_MATCH_TYPE_SIMPLE (as if '-t simple'). + */ +uintmax_t +json_util_parse_match_types(char *optarg) +{ + uintmax_t type = JSON_UTIL_MATCH_TYPE_SIMPLE; /* default is simple: num, bool, str and null */ + char *saveptr = NULL; /* for strtok_r() */ + char *dup = NULL; /* strdup()d copy of optarg */ + char *p = NULL; + + if (optarg == NULL || !*optarg) { + /* NULL or empty optarg, assume simple */ + return type; + } + p = optarg; + + errno = 0; /* pre-clear errno for errp() */ + dup = strdup(optarg); + if (dup == NULL) { + errp(24, __func__, "strdup(%s) failed", optarg); + not_reached(); + } + + /* + * Go through comma-separated list of what to match, setting each as a bitvector + */ + for (p = strtok_r(dup, ",", &saveptr); p; p = strtok_r(NULL, ",", &saveptr)) { + if (!strcmp(p, "int")) { + type |= JSON_UTIL_MATCH_TYPE_INT; + } else if (!strcmp(p, "float")) { + type |= JSON_UTIL_MATCH_TYPE_FLOAT; + } else if (!strcmp(p, "exp")) { + type |= JSON_UTIL_MATCH_TYPE_EXP; + } else if (!strcmp(p, "num")) { + type |= JSON_UTIL_MATCH_TYPE_NUM; + } else if (!strcmp(p, "bool")) { + type |= JSON_UTIL_MATCH_TYPE_BOOL; + } else if (!strcmp(p, "str")) { + type |= JSON_UTIL_MATCH_TYPE_STR; + } else if (!strcmp(p, "null")) { + type |= JSON_UTIL_MATCH_TYPE_NULL; + } else if (!strcmp(p, "simple")) { + type |= JSON_UTIL_MATCH_TYPE_SIMPLE; + } else { + /* unknown or unsupported type */ + err(3, __func__, "unknown or unsupported type '%s'", p); /*ooo*/ + not_reached(); + } + } + + return type; +} + +/* + * json_util_match_none - if no types should match + * + * given: + * + * types - types set + * + * Returns true if types == 0. + */ +bool +json_util_match_none(uintmax_t types) +{ + return types == JSON_UTIL_MATCH_TYPE_NONE; +} + +/* + * json_util_match_int - if ints should match + * + * given: + * + * types - types set + * + * Returns true if types has JSON_UTIL_MATCH_TYPE_INT set. + * + * NOTE: why do we return that the bitwise AND is not != 0 rather than just the + * bitwise AND? Because in some cases (like the test routines) we compare the + * expected true value to the result of the function. But depending on the bits + * set it might not end up being 1 so it ends up not comparing true to true but + * another value to true which it might not be. This could be done a different + * way where the test would be something like: + * + * if ((test && !expected) || (expected && !test)) + * + * but this seems like needless complications. + */ +bool +json_util_match_int(uintmax_t types) +{ + return (types & JSON_UTIL_MATCH_TYPE_INT) != 0; +} +/* + * json_util_match_float - if floats should match + * + * given: + * + * types - types set + * + * Returns true if types has JSON_UTIL_MATCH_TYPE_FLOAT set. + * + * NOTE: why do we return that the bitwise AND is not != 0 rather than just the + * bitwise AND? Because in some cases (like the test routines) we compare the + * expected true value to the result of the function. But depending on the bits + * set it might not end up being 1 so it ends up not comparing true to true but + * another value to true which it might not be. This could be done a different + * way where the test would be something like: + * + * if ((test && !expected) || (expected && !test)) + * + * but this seems like needless complications. + */ +bool +json_util_match_float(uintmax_t types) +{ + return (types & JSON_UTIL_MATCH_TYPE_FLOAT) != 0; +} +/* + * json_util_match_exp - if exponents should match + * + * given: + * + * types - types set + * + * Returns true if types has JSON_UTIL_MATCH_TYPE_EXP set. + * + * NOTE: why do we return that the bitwise AND is not != 0 rather than just the + * bitwise AND? Because in some cases (like the test routines) we compare the + * expected true value to the result of the function. But depending on the bits + * set it might not end up being 1 so it ends up not comparing true to true but + * another value to true which it might not be. This could be done a different + * way where the test would be something like: + * + * if ((test && !expected) || (expected && !test)) + * + * but this seems like needless complications. + */ +bool +json_util_match_exp(uintmax_t types) +{ + return (types & JSON_UTIL_MATCH_TYPE_EXP) != 0; +} +/* + * json_util_match_num - if numbers of any type should match + * + * given: + * + * types - types set + * + * Returns true if types has JSON_UTIL_MATCH_TYPE_NUM (or any of the number types) set. + * + * NOTE: why do we return that the bitwise AND is not != 0 rather than just the + * bitwise AND? Because in some cases (like the test routines) we compare the + * expected true value to the result of the function. But depending on the bits + * set it might not end up being 1 so it ends up not comparing true to true but + * another value to true which it might not be. This could be done a different + * way where the test would be something like: + * + * if ((test && !expected) || (expected && !test)) + * + * but this seems like needless complications. + */ +bool +json_util_match_num(uintmax_t types) +{ + return ((types & JSON_UTIL_MATCH_TYPE_NUM)||(types & JSON_UTIL_MATCH_TYPE_INT) || (types & JSON_UTIL_MATCH_TYPE_FLOAT) || + (types & JSON_UTIL_MATCH_TYPE_EXP))!= 0; +} +/* + * json_util_match_bool - if booleans should match + * + * given: + * + * types - types set + * + * Returns true if types has JSON_UTIL_MATCH_TYPE_BOOL set. + * + * NOTE: why do we return that the bitwise AND is not != 0 rather than just the + * bitwise AND? Because in some cases (like the test routines) we compare the + * expected true value to the result of the function. But depending on the bits + * set it might not end up being 1 so it ends up not comparing true to true but + * another value to true which it might not be. This could be done a different + * way where the test would be something like: + * + * if ((test && !expected) || (expected && !test)) + * + * but this seems like needless complications. + */ +bool +json_util_match_bool(uintmax_t types) +{ + return (types & JSON_UTIL_MATCH_TYPE_BOOL) != 0; +} +/* + * json_util_match_string - if strings should match + * + * given: + * + * types - types set + * + * Returns true if types has JSON_UTIL_MATCH_TYPE_STR set. + * + * NOTE: why do we return that the bitwise AND is not != 0 rather than just the + * bitwise AND? Because in some cases (like the test routines) we compare the + * expected true value to the result of the function. But depending on the bits + * set it might not end up being 1 so it ends up not comparing true to true but + * another value to true which it might not be. This could be done a different + * way where the test would be something like: + * + * if ((test && !expected) || (expected && !test)) + * + * but this seems like needless complications. + */ +bool +json_util_match_string(uintmax_t types) +{ + return (types & JSON_UTIL_MATCH_TYPE_STR) != 0; +} +/* + * json_util_match_null - if null should match + * + * given: + * + * types - types set + * + * Returns true if types has JSON_UTIL_MATCH_TYPE_NULL set. + * + * NOTE: why do we return that the bitwise AND is not != 0 rather than just the + * bitwise AND? Because in some cases (like the test routines) we compare the + * expected true value to the result of the function. But depending on the bits + * set it might not end up being 1 so it ends up not comparing true to true but + * another value to true which it might not be. This could be done a different + * way where the test would be something like: + * + * if ((test && !expected) || (expected && !test)) + * + * but this seems like needless complications. + */ +bool +json_util_match_null(uintmax_t types) +{ + return (types & JSON_UTIL_MATCH_TYPE_NULL) != 0; +} +/* + * json_util_match_simple - if simple types should match + * + * given: + * + * types - types set + * + * Simple is defined as a number, a bool, a string or a null. + * + * Returns true if types has JSON_UTIL_MATCH_TYPE_SIMPLE set. + * + * NOTE: why do we return that the bitwise AND is not != 0 rather than just the + * bitwise AND? Because in some cases (like the test routines) we compare the + * expected true value to the result of the function. But depending on the bits + * set it might not end up being 1 so it ends up not comparing true to true but + * another value to true which it might not be. This could be done a different + * way where the test would be something like: + * + * if ((test && !expected) || (expected && !test)) + * + * but this seems like needless complications. + */ +bool +json_util_match_simple(uintmax_t types) +{ + return (types & JSON_UTIL_MATCH_TYPE_SIMPLE) != 0; +} + + diff --git a/jparse/json_util.h b/jparse/json_util.h index 1388efc68..8f1840c84 100644 --- a/jparse/json_util.h +++ b/jparse/json_util.h @@ -85,6 +85,20 @@ enum output_format { #define JSON_UTIL_FMT_PEDANTIC (1) #define JSON_UTIL_FMT_COLOUR (2) +/* jval and jnamval -t types */ +#define JSON_UTIL_MATCH_TYPE_NONE (0) +#define JSON_UTIL_MATCH_TYPE_INT (1) +#define JSON_UTIL_MATCH_TYPE_FLOAT (2) +#define JSON_UTIL_MATCH_TYPE_EXP (4) +#define JSON_UTIL_MATCH_TYPE_NUM (8) +#define JSON_UTIL_MATCH_TYPE_BOOL (16) +#define JSON_UTIL_MATCH_TYPE_STR (32) +#define JSON_UTIL_MATCH_TYPE_NULL (64) +/* JSON_UTIL_MATCH_TYPE_SIMPLE is bitwise OR of num, bool, str and null */ +#define JSON_UTIL_MATCH_TYPE_SIMPLE \ + (JSON_UTIL_MATCH_TYPE_NUM|JSON_UTIL_MATCH_TYPE_BOOL|JSON_UTIL_MATCH_TYPE_STR|JSON_UTIL_MATCH_TYPE_NULL) + + /* structures */ /* structures for jval and jnamval */ @@ -123,8 +137,10 @@ struct json_util_name_val /* search / matching related */ bool invert_matches; /* -i used */ - bool json_types_specified; /* -t used */ - uintmax_t json_types; /* -t type */ + bool match_json_types_specified; /* -t used */ + uintmax_t match_json_types; /* -t types */ + bool print_json_types_specified; /* -P used */ + uintmax_t print_json_types; /* -P types */ bool match_substrings; /* -s used, match substrings */ bool use_regexps; /* -g used, allow grep-like regexps */ @@ -242,5 +258,18 @@ void json_util_parse_st_indent_option(char *optarg, uintmax_t *indent_level, boo struct json_util_cmp_op *json_util_parse_cmp_op(struct json_util_name_val *json_util_name_val, const char *option, char *optarg); /* for -F option */ enum output_format parse_json_util_format(struct json_util *json_util, char const *name, char const *optarg); +/* JSON types - -t option*/ +uintmax_t json_util_parse_match_types(char *optarg); +bool json_util_match_none(uintmax_t types); +bool json_util_match_int(uintmax_t types); +bool json_util_match_float(uintmax_t types); +bool json_util_match_exp(uintmax_t types); +bool json_util_match_exp(uintmax_t types); +bool json_util_match_bool(uintmax_t types); +bool json_util_match_num(uintmax_t types); +bool json_util_match_string(uintmax_t types); +bool json_util_match_null(uintmax_t types); +bool json_util_match_simple(uintmax_t types); + #endif /* INCLUDE_JSON_UTIL_H */ diff --git a/jparse/jval.c b/jparse/jval.c index 431f88307..d2d60e071 100644 --- a/jparse/jval.c +++ b/jparse/jval.c @@ -202,8 +202,8 @@ main(int argc, char **argv) json_util_parse_st_level_option(optarg, &jval->common.num_level_spaces, &jval->common.print_level_tab); break; case 't': - jval->json_name_val.json_types_specified = true; - jval->json_name_val.json_types = jval_parse_types_option(optarg); + jval->json_name_val.match_json_types_specified = true; + jval->json_name_val.match_json_types = json_util_parse_match_types(optarg); break; case 'l': jval->common.levels_constrained = true; diff --git a/jparse/jval_test.c b/jparse/jval_test.c index a97c60c56..72e226688 100644 --- a/jparse/jval_test.c +++ b/jparse/jval_test.c @@ -145,95 +145,95 @@ jval_run_tests(void) /* test -t option bits */ /* first int,float,exp */ - bits = jval_parse_types_option("int,float,exp"); + bits = json_util_parse_match_types("int,float,exp"); /* check that any number will match */ - test = jval_test_bits(true, bits, __LINE__, jval_match_int, "JVAL_TYPE_INT") && - jval_test_bits(true, bits, __LINE__, jval_match_float, "JVAL_TYPE_FLOAT") && - jval_test_bits(true, bits, __LINE__, jval_match_exp, "JVAL_TYPE_EXP"); + test = jval_test_bits(true, bits, __LINE__, json_util_match_int, "JSON_UTIL_MATCH_TYPE_INT") && + jval_test_bits(true, bits, __LINE__, json_util_match_float, "JSON_UTIL_MATCH_TYPE_FLOAT") && + jval_test_bits(true, bits, __LINE__, json_util_match_exp, "JSON_UTIL_MATCH_TYPE_EXP"); if (!test) { okay = false; } /* just exponents */ - bits = jval_parse_types_option("exp"); + bits = json_util_parse_match_types("exp"); /* check that int and float will fail but exp will succeed */ - test = jval_test_bits(false, bits, __LINE__, jval_match_int, "JVAL_TYPE_INT") && - jval_test_bits(false, bits, __LINE__, jval_match_float, "JVAL_TYPE_FLOAT") && - jval_test_bits(true, bits, __LINE__, jval_match_exp, "JVAL_TYPE_EXP"); + test = jval_test_bits(false, bits, __LINE__, json_util_match_int, "JSON_UTIL_MATCH_TYPE_INT") && + jval_test_bits(false, bits, __LINE__, json_util_match_float, "JSON_UTIL_MATCH_TYPE_FLOAT") && + jval_test_bits(true, bits, __LINE__, json_util_match_exp, "JSON_UTIL_MATCH_TYPE_EXP"); if (!test) { okay = false; } /* test simple */ - bits = jval_parse_types_option("simple"); + bits = json_util_parse_match_types("simple"); /* verify that the simple type is set by simple match function */ - test = jval_test_bits(true, bits, __LINE__, jval_match_simple, "JVAL_TYPE_SIMPLE"); + test = jval_test_bits(true, bits, __LINE__, json_util_match_simple, "JSON_UTIL_MATCH_TYPE_SIMPLE"); if (!test) { okay = false; } /* verify that the simple type is set by matching each type */ - test = jval_test_bits(true, bits, __LINE__, jval_match_num, "JVAL_TYPE_NUM") && - jval_test_bits(true, bits, __LINE__, jval_match_bool, "JVAL_TYPE_BOOL") && - jval_test_bits(true, bits, __LINE__, jval_match_string, "JVAL_TYPE_STR") && - jval_test_bits(true, bits, __LINE__, jval_match_null, "JVAL_TYPE_NULL"); + test = jval_test_bits(true, bits, __LINE__, json_util_match_num, "JSON_UTIL_MATCH_TYPE_NUM") && + jval_test_bits(true, bits, __LINE__, json_util_match_bool, "JSON_UTIL_MATCH_TYPE_BOOL") && + jval_test_bits(true, bits, __LINE__, json_util_match_string, "JSON_UTIL_MATCH_TYPE_STR") && + jval_test_bits(true, bits, __LINE__, json_util_match_null, "JSON_UTIL_MATCH_TYPE_NULL"); if (!test) { okay = false; } /* test int */ - bits = jval_parse_types_option("int"); + bits = json_util_parse_match_types("int"); /* verify that the int type is set by int match function */ - test = jval_test_bits(true, bits, __LINE__, jval_match_int, "JVAL_TYPE_INT"); + test = jval_test_bits(true, bits, __LINE__, json_util_match_int, "JSON_UTIL_MATCH_TYPE_INT"); if (!test) { okay = false; } /* test float */ - bits = jval_parse_types_option("float"); + bits = json_util_parse_match_types("float"); /* verify that the float type is set by float match function */ - test = jval_test_bits(true, bits, __LINE__, jval_match_float, "JVAL_TYPE_FLOAT"); + test = jval_test_bits(true, bits, __LINE__, json_util_match_float, "JSON_UTIL_MATCH_TYPE_FLOAT"); if (!test) { okay = false; } /* test exp */ - bits = jval_parse_types_option("exp"); + bits = json_util_parse_match_types("exp"); /* verify that the exp type is set by exp match function */ - test = jval_test_bits(true, bits, __LINE__, jval_match_exp, "JVAL_TYPE_EXP"); + test = jval_test_bits(true, bits, __LINE__, json_util_match_exp, "JSON_UTIL_MATCH_TYPE_EXP"); if (!test) { okay = false; } /* test bool */ - bits = jval_parse_types_option("bool"); + bits = json_util_parse_match_types("bool"); /* verify that the bool type is set by bool match function */ - test = jval_test_bits(true, bits, __LINE__, jval_match_bool, "JVAL_TYPE_BOOL"); + test = jval_test_bits(true, bits, __LINE__, json_util_match_bool, "JSON_UTIL_MATCH_TYPE_BOOL"); if (!test) { okay = false; } /* test string */ - bits = jval_parse_types_option("str"); + bits = json_util_parse_match_types("str"); /* verify that the string type is set by string match function */ - test = jval_test_bits(true, bits, __LINE__, jval_match_string, "JVAL_TYPE_STR"); + test = jval_test_bits(true, bits, __LINE__, json_util_match_string, "JSON_UTIL_MATCH_TYPE_STR"); if (!test) { okay = false; } /* test null */ - bits = jval_parse_types_option("null"); + bits = json_util_parse_match_types("null"); /* verify that the null type is set by null match function */ - test = jval_test_bits(true, bits, __LINE__, jval_match_null, "JVAL_TYPE_NULL"); + test = jval_test_bits(true, bits, __LINE__, json_util_match_null, "JSON_UTIL_MATCH_TYPE_NULL"); if (!test) { okay = false; } /* test int,str,null */ - bits = jval_parse_types_option("int,str,null"); + bits = json_util_parse_match_types("int,str,null"); /* verify that the int,str,null types are set by match functions */ - test = jval_test_bits(true, bits, __LINE__, jval_match_int, "JVAL_TYPE_INT") && - jval_test_bits(true, bits, __LINE__, jval_match_string, "JVAL_TYPE_STR") && - jval_test_bits(true, bits, __LINE__, jval_match_null, "JVAL_TYPE_NULL"); + test = jval_test_bits(true, bits, __LINE__, json_util_match_int, "JSON_UTIL_MATCH_TYPE_INT") && + jval_test_bits(true, bits, __LINE__, json_util_match_string, "JSON_UTIL_MATCH_TYPE_STR") && + jval_test_bits(true, bits, __LINE__, json_util_match_null, "JSON_UTIL_MATCH_TYPE_NULL"); if (!test) { okay = false; } @@ -242,29 +242,29 @@ jval_run_tests(void) * test that none of the bits are set not via the match none function but by * each match function */ - bits = JVAL_TYPE_NONE; - test = jval_test_bits(false, bits, __LINE__, jval_match_int, "JVAL_TYPE_INT") && - jval_test_bits(false, bits, __LINE__, jval_match_float, "JVAL_TYPE_FLOAT") && - jval_test_bits(false, bits, __LINE__, jval_match_exp, "JVAL_TYPE_EXP") && - jval_test_bits(false, bits, __LINE__, jval_match_num, "JVAL_TYPE_NUM") && - jval_test_bits(false, bits, __LINE__, jval_match_bool, "JVAL_TYPE_BOOL") && - jval_test_bits(false, bits, __LINE__, jval_match_string, "JVAL_TYPE_STR") && - jval_test_bits(false, bits, __LINE__, jval_match_null, "JVAL_TYPE_NULL") && - jval_test_bits(false, bits, __LINE__, jval_match_simple, "JVAL_TYPE_SIMPLE"); + bits = JSON_UTIL_MATCH_TYPE_NONE; + test = jval_test_bits(false, bits, __LINE__, json_util_match_int, "JSON_UTIL_MATCH_TYPE_INT") && + jval_test_bits(false, bits, __LINE__, json_util_match_float, "JSON_UTIL_MATCH_TYPE_FLOAT") && + jval_test_bits(false, bits, __LINE__, json_util_match_exp, "JSON_UTIL_MATCH_TYPE_EXP") && + jval_test_bits(false, bits, __LINE__, json_util_match_num, "JSON_UTIL_MATCH_TYPE_NUM") && + jval_test_bits(false, bits, __LINE__, json_util_match_bool, "JSON_UTIL_MATCH_TYPE_BOOL") && + jval_test_bits(false, bits, __LINE__, json_util_match_string, "JSON_UTIL_MATCH_TYPE_STR") && + jval_test_bits(false, bits, __LINE__, json_util_match_null, "JSON_UTIL_MATCH_TYPE_NULL") && + jval_test_bits(false, bits, __LINE__, json_util_match_simple, "JSON_UTIL_MATCH_TYPE_SIMPLE"); if (!test) { okay = false; } /* check all types */ - bits = jval_parse_types_option("int,float,exp,num,bool,str,null"); - test = jval_test_bits(true, bits, __LINE__, jval_match_int, "JVAL_TYPE_INT") && - jval_test_bits(true, bits, __LINE__, jval_match_float, "JVAL_TYPE_FLOAT") && - jval_test_bits(true, bits, __LINE__, jval_match_exp, "JVAL_TYPE_EXP") && - jval_test_bits(true, bits, __LINE__, jval_match_num, "JVAL_TYPE_NUM") && - jval_test_bits(true, bits, __LINE__, jval_match_bool, "JVAL_TYPE_BOOL") && - jval_test_bits(true, bits, __LINE__, jval_match_string, "JVAL_TYPE_STR") && - jval_test_bits(true, bits, __LINE__, jval_match_null, "JVAL_TYPE_NULL") && - jval_test_bits(true, bits, __LINE__, jval_match_simple, "JVAL_TYPE_SIMPLE"); + bits = json_util_parse_match_types("int,float,exp,num,bool,str,null"); + test = jval_test_bits(true, bits, __LINE__, json_util_match_int, "JSON_UTIL_MATCH_TYPE_INT") && + jval_test_bits(true, bits, __LINE__, json_util_match_float, "JSON_UTIL_MATCH_TYPE_FLOAT") && + jval_test_bits(true, bits, __LINE__, json_util_match_exp, "JSON_UTIL_MATCH_TYPE_EXP") && + jval_test_bits(true, bits, __LINE__, json_util_match_num, "JSON_UTIL_MATCH_TYPE_NUM") && + jval_test_bits(true, bits, __LINE__, json_util_match_bool, "JSON_UTIL_MATCH_TYPE_BOOL") && + jval_test_bits(true, bits, __LINE__, json_util_match_string, "JSON_UTIL_MATCH_TYPE_STR") && + jval_test_bits(true, bits, __LINE__, json_util_match_null, "JSON_UTIL_MATCH_TYPE_NULL") && + jval_test_bits(true, bits, __LINE__, json_util_match_simple, "JSON_UTIL_MATCH_TYPE_SIMPLE"); if (!test) { okay = false; } diff --git a/jparse/jval_util.c b/jparse/jval_util.c index 5c56e2058..0b650f641 100644 --- a/jparse/jval_util.c +++ b/jparse/jval_util.c @@ -87,8 +87,8 @@ alloc_jval(void) /* search / matching related */ /* json types to look for */ - jval->json_name_val.json_types_specified = false; /* -t used */ - jval->json_name_val.json_types = JVAL_TYPE_SIMPLE; /* -t type specified, default simple */ + jval->json_name_val.match_json_types_specified = false; /* -t used */ + jval->json_name_val.match_json_types = JSON_UTIL_MATCH_TYPE_SIMPLE; /* -t type specified, default simple */ jval->json_name_val.ignore_case = false; /* true if -f, case-insensitive */ jval->json_name_val.match_decoded = false; /* if -d used match decoded */ @@ -116,346 +116,6 @@ alloc_jval(void) } -/* - * jval_match_none - if no types should match - * - * given: - * - * types - types set - * - * Returns true if types == 0. - */ -bool -jval_match_none(uintmax_t types) -{ - return types == JVAL_TYPE_NONE; -} - -/* - * jval_match_int - if ints should match - * - * given: - * - * types - types set - * - * Returns true if types has JVAL_TYPE_INT set. - * - * NOTE: why do we return that the bitwise AND is not != 0 rather than just the - * bitwise AND? Because in some cases (like the test routines) we compare the - * expected true value to the result of the function. But depending on the bits - * set it might not end up being 1 so it ends up not comparing true to true but - * another value to true which it might not be. This could be done a different - * way where the test would be something like: - * - * if ((test && !expected) || (expected && !test)) - * - * but this seems like needless complications. - */ -bool -jval_match_int(uintmax_t types) -{ - return (types & JVAL_TYPE_INT) != 0; -} -/* - * jval_match_float - if floats should match - * - * given: - * - * types - types set - * - * Returns true if types has JVAL_TYPE_FLOAT set. - * - * NOTE: why do we return that the bitwise AND is not != 0 rather than just the - * bitwise AND? Because in some cases (like the test routines) we compare the - * expected true value to the result of the function. But depending on the bits - * set it might not end up being 1 so it ends up not comparing true to true but - * another value to true which it might not be. This could be done a different - * way where the test would be something like: - * - * if ((test && !expected) || (expected && !test)) - * - * but this seems like needless complications. - */ -bool -jval_match_float(uintmax_t types) -{ - return (types & JVAL_TYPE_FLOAT) != 0; -} -/* - * jval_match_exp - if exponents should match - * - * given: - * - * types - types set - * - * Returns true if types has JVAL_TYPE_EXP set. - * - * NOTE: why do we return that the bitwise AND is not != 0 rather than just the - * bitwise AND? Because in some cases (like the test routines) we compare the - * expected true value to the result of the function. But depending on the bits - * set it might not end up being 1 so it ends up not comparing true to true but - * another value to true which it might not be. This could be done a different - * way where the test would be something like: - * - * if ((test && !expected) || (expected && !test)) - * - * but this seems like needless complications. - */ -bool -jval_match_exp(uintmax_t types) -{ - return (types & JVAL_TYPE_EXP) != 0; -} -/* - * jval_match_num - if numbers of any type should match - * - * given: - * - * types - types set - * - * Returns true if types has JVAL_TYPE_NUM (or any of the number types) set. - * - * NOTE: why do we return that the bitwise AND is not != 0 rather than just the - * bitwise AND? Because in some cases (like the test routines) we compare the - * expected true value to the result of the function. But depending on the bits - * set it might not end up being 1 so it ends up not comparing true to true but - * another value to true which it might not be. This could be done a different - * way where the test would be something like: - * - * if ((test && !expected) || (expected && !test)) - * - * but this seems like needless complications. - */ -bool -jval_match_num(uintmax_t types) -{ - return ((types & JVAL_TYPE_NUM)||(types & JVAL_TYPE_INT) || (types & JVAL_TYPE_FLOAT) || - (types & JVAL_TYPE_EXP))!= 0; -} -/* - * jval_match_bool - if booleans should match - * - * given: - * - * types - types set - * - * Returns true if types has JVAL_TYPE_BOOL set. - * - * NOTE: why do we return that the bitwise AND is not != 0 rather than just the - * bitwise AND? Because in some cases (like the test routines) we compare the - * expected true value to the result of the function. But depending on the bits - * set it might not end up being 1 so it ends up not comparing true to true but - * another value to true which it might not be. This could be done a different - * way where the test would be something like: - * - * if ((test && !expected) || (expected && !test)) - * - * but this seems like needless complications. - */ -bool -jval_match_bool(uintmax_t types) -{ - return (types & JVAL_TYPE_BOOL) != 0; -} -/* - * jval_match_string - if strings should match - * - * given: - * - * types - types set - * - * Returns true if types has JVAL_TYPE_STR set. - * - * NOTE: why do we return that the bitwise AND is not != 0 rather than just the - * bitwise AND? Because in some cases (like the test routines) we compare the - * expected true value to the result of the function. But depending on the bits - * set it might not end up being 1 so it ends up not comparing true to true but - * another value to true which it might not be. This could be done a different - * way where the test would be something like: - * - * if ((test && !expected) || (expected && !test)) - * - * but this seems like needless complications. - */ -bool -jval_match_string(uintmax_t types) -{ - return (types & JVAL_TYPE_STR) != 0; -} -/* - * jval_match_null - if null should match - * - * given: - * - * types - types set - * - * Returns true if types has JVAL_TYPE_NULL set. - * - * NOTE: why do we return that the bitwise AND is not != 0 rather than just the - * bitwise AND? Because in some cases (like the test routines) we compare the - * expected true value to the result of the function. But depending on the bits - * set it might not end up being 1 so it ends up not comparing true to true but - * another value to true which it might not be. This could be done a different - * way where the test would be something like: - * - * if ((test && !expected) || (expected && !test)) - * - * but this seems like needless complications. - */ -bool -jval_match_null(uintmax_t types) -{ - return (types & JVAL_TYPE_NULL) != 0; -} -/* - * jval_match_simple - if simple types should match - * - * given: - * - * types - types set - * - * Simple is defined as a number, a bool, a string or a null. - * - * Returns true if types has JVAL_TYPE_SIMPLE set. - * - * NOTE: why do we return that the bitwise AND is not != 0 rather than just the - * bitwise AND? Because in some cases (like the test routines) we compare the - * expected true value to the result of the function. But depending on the bits - * set it might not end up being 1 so it ends up not comparing true to true but - * another value to true which it might not be. This could be done a different - * way where the test would be something like: - * - * if ((test && !expected) || (expected && !test)) - * - * but this seems like needless complications. - */ -bool -jval_match_simple(uintmax_t types) -{ - return (types & JVAL_TYPE_SIMPLE) != 0; -} - -/* - * jval_parse_types_option - parse -t types list - * - * given: - * - * optarg - option argument to -t option - * - * Returns: bitvector of types requested. - * - * NOTE: if optarg is NULL (which should never happen) or empty it returns the - * default, JVAL_TYPE_SIMPLE (as if '-t simple'). - */ -uintmax_t -jval_parse_types_option(char *optarg) -{ - char *p = NULL; /* for strtok_r() */ - char *saveptr = NULL; /* for strtok_r() */ - char *dup = NULL; /* strdup()d copy of optarg */ - - uintmax_t type = JVAL_TYPE_SIMPLE; /* default is simple: num, bool, str and null */ - - if (optarg == NULL || !*optarg) { - /* NULL or empty optarg, assume simple */ - return type; - } else { - /* pre-clear errno for errp() */ - errno = 0; - dup = strdup(optarg); - if (dup == NULL) { - errp(23, __func__, "strdup(%s) failed", optarg); - not_reached(); - } - } - - /* - * Go through comma-separated list of types, setting each as a bitvector - * - * NOTE: the way this is done might change if it proves there is a better - * way (and there might be - I've thought of a number of ways already). - */ - for (p = strtok_r(dup, ",", &saveptr); p; p = strtok_r(NULL, ",", &saveptr)) { - if (!strcmp(p, "int")) { - type |= JVAL_TYPE_INT; - } else if (!strcmp(p, "float")) { - type |= JVAL_TYPE_FLOAT; - } else if (!strcmp(p, "exp")) { - type |= JVAL_TYPE_EXP; - } else if (!strcmp(p, "num")) { - type |= JVAL_TYPE_NUM; - } else if (!strcmp(p, "bool")) { - type |= JVAL_TYPE_BOOL; - } else if (!strcmp(p, "str")) { - type |= JVAL_TYPE_STR; - } else if (!strcmp(p, "null")) { - type |= JVAL_TYPE_NULL; - } else if (!strcmp(p, "simple")) { - type |= JVAL_TYPE_SIMPLE; - } else { - /* unknown type */ - err(3, __func__, "unknown type '%s'", p); /*ooo*/ - not_reached(); - } - } - - if (dup != NULL) { - free(dup); - dup = NULL; - } - return type; -} - - -/* - * jval_parse_value_option - parse -t types list - * - * given: - * - * optarg - option argument to -t option - * - * Returns: bitvector of types requested. - * - * NOTE: if optarg is NULL (which should never happen) or empty it returns the - * default, JVAL_TYPE_SIMPLE (as if '-t simple'). - */ -uintmax_t -jval_parse_value_type_option(char *optarg) -{ - uintmax_t type = JVAL_TYPE_SIMPLE; /* default is simple: num, bool, str and null */ - char *p = NULL; - - if (optarg == NULL || !*optarg) { - /* NULL or empty optarg, assume simple */ - return type; - } - p = optarg; - - /* Determine if the arg is a valid type. */ - if (!strcmp(p, "int")) { - type = JVAL_TYPE_INT; - } else if (!strcmp(p, "float")) { - type = JVAL_TYPE_FLOAT; - } else if (!strcmp(p, "exp")) { - type = JVAL_TYPE_EXP; - } else if (!strcmp(p, "num")) { - type = JVAL_TYPE_NUM; - } else if (!strcmp(p, "bool")) { - type = JVAL_TYPE_BOOL; - } else if (!strcmp(p, "str")) { - type = JVAL_TYPE_STR; - } else if (!strcmp(p, "null")) { - type = JVAL_TYPE_NULL; - } else if (!strcmp(p, "simple")) { - type = JVAL_TYPE_SIMPLE; - } else { - /* unknown or unsupported type */ - err(3, __func__, "unknown or unsupported type '%s'", p); /*ooo*/ - not_reached(); - } - - return type; -} /* * free_jval - free jval struct diff --git a/jparse/jval_util.h b/jparse/jval_util.h index 0e3f8aebd..4ac4210da 100644 --- a/jparse/jval_util.h +++ b/jparse/jval_util.h @@ -58,18 +58,6 @@ /* defines */ -/* -t types */ -#define JVAL_TYPE_NONE (0) -#define JVAL_TYPE_INT (1) -#define JVAL_TYPE_FLOAT (2) -#define JVAL_TYPE_EXP (4) -#define JVAL_TYPE_NUM (8) -#define JVAL_TYPE_BOOL (16) -#define JVAL_TYPE_STR (32) -#define JVAL_TYPE_NULL (64) -/* JVAL_TYPE_SIMPLE is bitwise OR of num, bool, str and null */ -#define JVAL_TYPE_SIMPLE (JVAL_TYPE_NUM|JVAL_TYPE_BOOL|JVAL_TYPE_STR|JVAL_TYPE_NULL) - #define JVAL_CMP_OP_NONE JSON_UTIL_CMP_OP_NONE #define JVAL_CMP_EQ JSON_UTIL_CMP_OP_EQ #define JVAL_CMP_LT JSON_UTIL_CMP_OP_LT @@ -95,19 +83,6 @@ struct jval /* function prototypes */ struct jval *alloc_jval(void); -/* JSON types - -t option*/ -uintmax_t jval_parse_types_option(char *optarg); -bool jval_match_none(uintmax_t types); -bool jval_match_int(uintmax_t types); -bool jval_match_float(uintmax_t types); -bool jval_match_exp(uintmax_t types); -bool jval_match_exp(uintmax_t types); -bool jval_match_bool(uintmax_t types); -bool jval_match_num(uintmax_t types); -bool jval_match_string(uintmax_t types); -bool jval_match_null(uintmax_t types); -bool jval_match_simple(uintmax_t types); - /* functions to print matches */ bool jval_print_count(struct jval *jval); diff --git a/jparse/man/man1/jfmt.1 b/jparse/man/man1/jfmt.1 index 47ac296ea..74380f413 100644 --- a/jparse/man/man1/jfmt.1 +++ b/jparse/man/man1/jfmt.1 @@ -9,7 +9,7 @@ .\" "Share and Enjoy!" .\" -- Sirius Cybernetics Corporation Complaints Division, JSON spec department. :-) .\" -.TH jfmt 1 "02 August 2023" "jfmt" "IOCCC tools" +.TH jfmt 1 "05 August 2023" "jfmt" "IOCCC tools" .SH NAME .B jfmt \- IOCCC JSON printer @@ -86,9 +86,9 @@ Suppress some of the output (def: show more information). .TP .BI \-L\ [{t|s} Print the JSON levels followed by the number of spaces or tabs, depending on the letter specified, -.BR T +.BR t for tabs and -.BR S +.BR s for spaces. Not specifying either defaults to spaces. As a convenience, specifying @@ -99,9 +99,9 @@ is an alias for .TP .BI \-I\ [{t|s} Indent the JSON levels by the number of spaces or tabs, depending on the letter specified, -.BR T +.BR t for tabs and -.BR S +.BR s for spaces. Not specifying either defaults to spaces. As a convenience, specifying diff --git a/jparse/man/man1/jnamval.1 b/jparse/man/man1/jnamval.1 index e42b20e5b..4a13b6fee 100644 --- a/jparse/man/man1/jnamval.1 +++ b/jparse/man/man1/jnamval.1 @@ -9,7 +9,7 @@ .\" "Share and Enjoy!" .\" -- Sirius Cybernetics Corporation Complaints Division, JSON spec department. :-) .\" -.TH jnamval 1 "02 August 2023" "jnamval" "IOCCC tools" +.TH jnamval 1 "05 August 2023" "jnamval" "IOCCC tools" .SH NAME .B jnamval \- IOCCC JSON printer @@ -24,8 +24,12 @@ .RB [\| \-q \|] .RB [\| \-L .IR {[t|s]} \|] +.RB [\| \-I +.IR {[t|s]} \|] .RB [\| \-t .IR type \|] +.RB [\| \-P +.IR type \|] .RB [\| \-l .IR lvl \|] .RB [\| \-Q \|] @@ -93,7 +97,9 @@ option allows you to change the default depth to traverse when parsing the JSON .PP The option .B \-t -controls what types to search for, excluding matches if they are not any of the types in the comma-separated list. +controls what types to search for, excluding matches if they are not any of the types in the comma-separated list whereas the option +.B \-P +controls what types to print. The option .B \-l allows you to restrict the output based on the JSON level. @@ -136,9 +142,9 @@ Suppress some of the output (def: show more information). .TP .BI \-L\ [{t|s} Print the JSON levels followed by the number of spaces or tabs, depending on the letter specified, -.BR T +.BR t for tabs and -.BR S +.BR s for spaces. Not specifying either defaults to spaces. As a convenience, specifying @@ -147,6 +153,19 @@ is an alias for .BI \-L\ 1t\c \&. .TP +.BI \-I\ [{t|s} +Indent the JSON levels by the number of spaces or tabs, depending on the letter specified, +.BR t +for tabs and +.BR s +for spaces. +Not specifying either defaults to spaces. +As a convenience, specifying +.BI \-I\ tab +is an alias for +.BI \-I\ 1t\c +\&. +.TP .BI \-t\ type Match only the comma separated types (def: simple). .RS @@ -182,6 +201,43 @@ null values .RS alias for num,bool,str,null (the default) .RE +.RE +.TP +.BI \-P\ type +Print only the comma separated types (def: any). +.RS +.B int +.RS +integer values +.RE +.B float +.RS +floating point values +.RE +.B exp +.RS +exponential notation values +.RE +.B num +.RS +alias for int,float,exp +.RE +.B bool +.RS +boolean values +.RE +.B str +.RS +string values +.RE +.B null +.RS +null values +.RE +.B simple +.RS +alias for num,bool,str,null +.RE .B member .RS JSON members @@ -200,9 +256,10 @@ alias for 'member,object,array' .RE .B any .RS -alias for 'simple,compound' (everything) +alias for 'simple,compound' (everything, default) .RE .RE + .TP .BI \-l\ lvl Only show JSON members in the given level range (def: show all levels). diff --git a/jparse/man/man1/jval.1 b/jparse/man/man1/jval.1 index 5b61c6215..e24131c7d 100644 --- a/jparse/man/man1/jval.1 +++ b/jparse/man/man1/jval.1 @@ -9,7 +9,7 @@ .\" "Share and Enjoy!" .\" -- Sirius Cybernetics Corporation Complaints Division, JSON spec department. :-) .\" -.TH jval 1 "02 August 2023" "jval" "IOCCC tools" +.TH jval 1 "05 August 2023" "jval" "IOCCC tools" .SH NAME .B jval \- IOCCC JSON printer @@ -85,8 +85,6 @@ allows you to restrict the output based on the JSON level. The option .B \-L tells the program to print the JSON level followed by a given number of spaces or tabs where the default is 4 spaces. -.B \-I -allow for indenting the levels with a default value of 4 spaces. The option .B \-n allows for finding values based on different comparison modes like equality, less than, less than or equal to and so on. @@ -121,9 +119,9 @@ Suppress some of the output (def: show more information). .TP .BI \-L\ [{t|s} Print the JSON levels followed by the number of spaces or tabs, depending on the letter specified, -.BR T +.BR t for tabs and -.BR S +.BR s for spaces. Not specifying either defaults to spaces. As a convenience, specifying diff --git a/jparse/test_jparse/Makefile b/jparse/test_jparse/Makefile index eb0c39cb9..4c1321912 100644 --- a/jparse/test_jparse/Makefile +++ b/jparse/test_jparse/Makefile @@ -377,7 +377,6 @@ rebuild_jparse_err_files: ../jparse ${S} echo ${RM} -f test_JSON/bad_loc/*.err -@for i in test_JSON/./bad_loc/*.json; do \ - echo "../jparse -- $$i 2> $$i.err" ; \ ../jparse -- "$$i" 2> "$$i.err" ; \ done ${S} echo diff --git a/jparse/test_jparse/README.md b/jparse/test_jparse/README.md index f9750101a..24e2d26b5 100644 --- a/jparse/test_jparse/README.md +++ b/jparse/test_jparse/README.md @@ -14,11 +14,17 @@ make rebuild_jparse_err_files You should see something like: ```sh -$ rm -f test_JSON/bad_loc/*.err; make rebuild_jparse_err_files -make: [rebuild_jparse_err_files] Error 1 (ignored) +$ make rebuild_jparse_err_files + +test_jparse: make rebuild_jparse_err_files starting + +rm -f test_JSON/bad_loc/*.err +make: [Makefile:379: rebuild_jparse_err_files] Error 1 (ignored) Make sure to run make test from the top level directory befor doing a git add on all the *.json and *.json.err files in test_json/bad_loc! + +test_jparse: make rebuild_jparse_err_files ending ``` Assuming you see the above you **MUST** then run `make test` from the top level diff --git a/jparse/test_jparse/test_JSON/bad_loc/syntax.error.line-2.column-1 b/jparse/test_jparse/test_JSON/bad_loc/syntax.error.line-2.column-1 new file mode 100644 index 000000000..c3a4cd6ed --- /dev/null +++ b/jparse/test_jparse/test_JSON/bad_loc/syntax.error.line-2.column-1 @@ -0,0 +1,2 @@ +{"hi": [ ] +]} diff --git a/jparse/test_jparse/test_JSON/bad_loc/vtab_comma.json b/jparse/test_jparse/test_JSON/bad_loc/vtab_comma.json new file mode 100644 index 000000000..b4d1d1d5f --- /dev/null +++ b/jparse/test_jparse/test_JSON/bad_loc/vtab_comma.json @@ -0,0 +1,3 @@ +{ +"test":false, + ,} \ No newline at end of file diff --git a/jparse/test_jparse/test_JSON/bad_loc/vtab_comma.json.err b/jparse/test_jparse/test_JSON/bad_loc/vtab_comma.json.err new file mode 100644 index 000000000..e4f0cfc51 --- /dev/null +++ b/jparse/test_jparse/test_JSON/bad_loc/vtab_comma.json.err @@ -0,0 +1,4 @@ +Warning: jparse_lex: at line 3 column 1: invalid token: 0x0b = < > +syntax error in file test_JSON/./bad_loc/vtab_comma.json at line 3 column 1: < > +Warning: ../jparse: JSON parse tree is NULL +ERROR[1]: ../jparse: invalid JSON diff --git a/jparse/test_jparse/test_JSON/good/JSON_duplicity_misfeature.json b/jparse/test_jparse/test_JSON/good/JSON_duplicity_misfeature.json new file mode 100644 index 000000000..708ba82d0 --- /dev/null +++ b/jparse/test_jparse/test_JSON/good/JSON_duplicity_misfeature.json @@ -0,0 +1,4 @@ +{ + "value":"value", + "value" : [ "value", "value", "value" ] +}