Skip to content

Commit

Permalink
sync with dbg, dyn_array, jparse repos
Browse files Browse the repository at this point in the history
  • Loading branch information
lcn2 committed Oct 1, 2024
1 parent 3fcf959 commit 72fda28
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 138 deletions.
2 changes: 1 addition & 1 deletion dbg/dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -6348,7 +6348,7 @@ main(int argc, char *argv[])
break;
case 'V': /* -V - write version and exit */
errno = 0; /* pre-clear errno for warnp() */
ret = printf("%s\n", dbg_version);
ret = printf("%s version: %s\n", DBG_BASENAME, dbg_version);
if (ret <= 0) {
warnp(__func__, "printf error writing version string: %s", dbg_version);
}
Expand Down
5 changes: 5 additions & 0 deletions dbg/dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
*/
#define DBG_VERSION "3.0 2023-08-05" /* format: major.minor YYYY-MM-DD */

/*
* dbg basename
*/
#define DBG_BASENAME "dbg"


/*
* standard truth :-)
Expand Down
8 changes: 4 additions & 4 deletions dyn_array/dyn_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ static const char * const usage_msg =
" 3\tcommand line error\n"
" >=10\tinternal error\n"
"\n"
"dyn_array library version: %s\n"
"dyn_test version: %s";
"%s version: %s\n"
"dyn_array library version: %s\n";


/*
Expand Down Expand Up @@ -158,7 +158,7 @@ main(int argc, char *argv[])
}
break;
case 'V': /* -V - print version and exit */
(void) printf("%s\n", DYN_TEST_VERSION);
(void) printf("%s version: %s\n", DYN_TEST_BASENAME, DYN_TEST_VERSION);
exit(2); /*ooo*/
not_reached();
break;
Expand Down Expand Up @@ -302,7 +302,7 @@ usage(int exitcode, char const *prog, char const *str)
fprintf_usage(DO_NOT_EXIT, stderr, "%s\n", str);
}

fprintf_usage(exitcode, stderr, usage_msg, prog, DBG_DEFAULT, dyn_array_version, DYN_TEST_VERSION);
fprintf_usage(exitcode, stderr, usage_msg, prog, DBG_DEFAULT, DYN_TEST_BASENAME, DYN_TEST_VERSION, dyn_array_version);
exit(exitcode); /*ooo*/
not_reached();
}
Expand Down
6 changes: 6 additions & 0 deletions dyn_array/dyn_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
*/
#include "dyn_array.h"

/*
* dyn_test tool basename
*/
#define DYN_TEST_BASENAME "dyn_test"




#endif /* INCLUDE_DYN_TEST_H */
52 changes: 31 additions & 21 deletions jparse/jparse.l
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,26 @@
* -- Sirius Cybernetics Corporation Complaints Division, JSON spec department. :-)
*/

/* Section 1: Declarations and option settings */
/* Section 0: Declarations and option settings */
/*
* noyywrap prevents needing to link in the flex(1) library which means those
* without flex can compile the code. Even if everyone had flex(1) though under
* %option noyywrap prevents needing to link in the flex(1) library (flex(3)) which means those
* without flex can compile the code. Even if everyone had flex(1), though, under
* macOS you have to pass -ll to the compiler to link in the flex library
* whereas in other systems you have to use -lfl which would cause a lot of
* problems. Another way is to provide 'int yywrap() { return 1; }' but this is
* unnecessary.
*/
%option noyywrap
/*
* we also need a few other options set:
*
* %option nodefault nounput noinput
* %option yylineno 8bit
* %option bison-bridge bison-locations reentrant
* %option prefix="jparse_"
* %option header-file="jparse.lex.h"
* %option extra-type="struct json_extra *"
*/
%option nodefault nounput noinput
%option yylineno 8bit
%option bison-bridge bison-locations reentrant
Expand Down Expand Up @@ -98,13 +108,13 @@ static YY_BUFFER_STATE bs;
%}

/*
* Section 2: Patterns (regular expressions) and actions.
* Section 1: Patterns (regular expressions) and actions.
*/

JSON_WS [ \t\r]+
JSON_NL \n+
/*
* NOTE: On the subject of JSON_STRING one might ask the question about the
* NOTE: on the subject of JSON_STRING one might ask the question about the
* tighter restrictions on JSON strings and why we don't even consider them.
* This is a good question but the answer is simple: the JSON string conversion
* routines actually do these checks. This simplifies the lexer regex and so we
Expand Down Expand Up @@ -140,9 +150,9 @@ JSON_COMMA ","
/*
* Whitespace excluding newlines
*
* NOTE: We have to include this action as otherwise
* the action '.' will return an invalid token to
* the parser.
* NOTE: we have to include this action (JSON_WS) as
* otherwise the action '.' will return an invalid
* token to the parser.
*
* We don't need the below message but for debugging
* purposes we print how many whitespaces are
Expand All @@ -153,7 +163,7 @@ JSON_COMMA ","
}
{JSON_NL} {
yycolumn = 1;
yycolumn = 1; /* on newline we need to reset the column for error location tracking */
}
{JSON_STRING} {
Expand Down Expand Up @@ -243,7 +253,7 @@ JSON_COMMA ","
%%
/* Section 3: Code that's copied to the generated scanner */
/* Section 2: Code that's copied to the generated scanner */
/*
Expand Down Expand Up @@ -289,7 +299,7 @@ JSON_COMMA ","
* those characters to used outside elements of JSON syntax:
*
* We scan data for bytes in the class: [\x00-\x08\x0e-\x1f]. When such
* bytes are detected, we increment the external variable, we will indicate to
* bytes are detected, we increment the external variable and we will indicate to
* the caller that the JSON is invalid by returning true.
*
* We also keep track of newlines. Not to exclude them, but to make it easy
Expand All @@ -312,9 +322,9 @@ JSON_COMMA ","
* nul_bytes - pointer to set the number of NUL bytes found in
*
* return:
* true ==> data == NULL OR len <= 0 OR one or more [\x00-\x08\x0e-\x1f]
* true ==> data == NULL OR len <= 0 OR one or more [\x00-\x08\x0e-\x1f]
* bytes are found OR low_bytes == NULL OR nul_bytes == NULL
* false ==> data != NULL AND len > 0 AND no NUL [\x00-\x08\x0e-\x1f] bytes were found
* false ==> data != NULL AND len > 0 AND no NUL [\x00-\x08\x0e-\x1f] bytes were found
*/
static bool
low_byte_scan(char const *data, size_t len, size_t *low_bytes, size_t *nul_bytes)
Expand Down Expand Up @@ -464,23 +474,23 @@ low_byte_scan(char const *data, size_t len, size_t *low_bytes, size_t *nul_bytes
/*
* parse_json - parse a JSON document of a given length
*
* Given a pointer to char and a length, use the parser to determine if the json
* Given a pointer to char and a length, use the parser to determine if the JSON
* is valid or not.
*
* given:
*
* ptr - pointer to start of json blob
* len - length of the json blob
* ptr - pointer to start of JSON blob
* len - length of the JSON blob
* filename - filename or NULL for stdin
* is_valid - non-NULL printer to boolean to set depending on json validity
* is_valid - non-NULL pointer to boolean to set depending on JSON validity
*
* return:
* pointer to a JSON parse tree
*
* NOTE: The reason this is in the scanner and not the parser is because
* NOTE: the reason this is in the scanner and not the parser is because
* YY_BUFFER_STATE is part of the scanner and not the parser.
*
* NOTE: This function only warns on error. This is so that an entire report of
* NOTE: this function only warns on error. This is so that an entire report of
* all the problems can be given at the end if the verbosity level is high
* enough (or otherwise if this information is requested).
*/
Expand Down Expand Up @@ -639,11 +649,11 @@ parse_json(char const *ptr, size_t len, char const *filename, bool *is_valid)
* If stream is NULL or stream is not open, or if read_all() fails,
* then this function warns and sets *is_valid to false.
*
* NOTE: The reason this is in the scanner and not the parser is because
* NOTE: the reason this is in the scanner and not the parser is because
* YY_BUFFER_STATE is part of the scanner and not the parser and that's required
* for the parse_json_block() function.
*
* NOTE: This function only warns on error. It does this via the called function
* NOTE: this function only warns on error. It does this via the called function
* parse_json(). This is done so that an entire report of all the problems can
* be given at the end if the verbosity level is high enough (or otherwise if
* this information is requested).
Expand Down
2 changes: 1 addition & 1 deletion jparse/jparse.lex.ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ extern int yylex \
#undef yyTABLES_NAME
#endif

#line 244 "./jparse.l"
#line 254 "./jparse.l"


#line 732 "jparse.lex.h"
Expand Down
Loading

0 comments on commit 72fda28

Please sign in to comment.