Rename some example/json* flags

This commit is contained in:
Nigel Tao committed 2020-07-13 08:25:59 +10:00
1 parent 56d9096f81
commit ecadf72e6b
2 files changed
+33 -34

No files matched your search

+9 -10
View File
@@ -107,8 +107,8 @@ static const char* g_usage =
"\n" "\n"
"Flags:\n" "Flags:\n"
" -d=NUM -max-output-depth=NUM\n" " -d=NUM -max-output-depth=NUM\n"
" -s -strict-json-pointer-syntax\n"
" -input-json-extra-comma\n" " -input-json-extra-comma\n"
" -strict-json-pointer-syntax\n"
"\n" "\n"
"The input.json filename is optional. If absent, it reads from stdin.\n" "The input.json filename is optional. If absent, it reads from stdin.\n"
"\n" "\n"
@@ -157,14 +157,13 @@ static const char* g_usage =
"\n" "\n"
"----\n" "----\n"
"\n" "\n"
"The -s or -strict-json-pointer-syntax flag restricts the output lines\n" "The -strict-json-pointer-syntax flag restricts the output lines to\n"
"to exactly RFC 6901, with only two escape sequences: \"~0\" and \"~1\"\n" "exactly RFC 6901, with only two escape sequences: \"~0\" and \"~1\" for\n"
"for \"~\" and \"/\". Without this flag, this program also lets \"~n\"\n" "\"~\" and \"/\". Without this flag, this program also lets \"~n\" and\n"
"and \"~r\" escape the New Line and Carriage Return ASCII control\n" "\"~r\" escape the New Line and Carriage Return ASCII control characters,\n"
"characters, which can work better with line oriented Unix tools that\n" "which can work better with line oriented Unix tools that assume exactly\n"
"assume exactly one value (i.e. one JSON Pointer string) per line. With\n" "one value (i.e. one JSON Pointer string) per line. With this flag, it\n"
"this flag, the program will fail if the input JSON's object keys contain\n" "fails if the input JSON's keys contain \"\\u000A\" or \"\\u000D\".\n"
"\"\\u000A\" or \"\\u000D\".\n"
"\n" "\n"
"----\n" "----\n"
"\n" "\n"
@@ -233,7 +232,7 @@ parse_flags(int argc, char** argv) {
g_flags.input_json_extra_comma = true; g_flags.input_json_extra_comma = true;
continue; continue;
} }
if (!strcmp(arg, "s") || !strcmp(arg, "strict-json-pointer-syntax")) { if (!strcmp(arg, "strict-json-pointer-syntax")) {
g_flags.strict_json_pointer_syntax = true; g_flags.strict_json_pointer_syntax = true;
continue; continue;
} }
+24 -24
View File
@@ -152,13 +152,13 @@ static const char* g_usage =
"Flags:\n" "Flags:\n"
" -c -compact-output\n" " -c -compact-output\n"
" -d=NUM -max-output-depth=NUM\n" " -d=NUM -max-output-depth=NUM\n"
" -i=NUM -indent=NUM\n"
" -q=STR -query=STR\n" " -q=STR -query=STR\n"
" -s -strict-json-pointer-syntax\n" " -s=NUM -spaces=NUM\n"
" -t -tabs\n" " -t -tabs\n"
" -fail-if-unsandboxed\n" " -fail-if-unsandboxed\n"
" -input-json-extra-comma\n" " -input-json-extra-comma\n"
" -output-json-extra-comma\n" " -output-json-extra-comma\n"
" -strict-json-pointer-syntax\n"
"\n" "\n"
"The input.json filename is optional. If absent, it reads from stdin.\n" "The input.json filename is optional. If absent, it reads from stdin.\n"
"\n" "\n"
@@ -173,8 +173,8 @@ static const char* g_usage =
"duplicate keys. Canonicalization does not imply Unicode normalization.\n" "duplicate keys. Canonicalization does not imply Unicode normalization.\n"
"\n" "\n"
"Formatted means that arrays' and objects' elements are indented, each\n" "Formatted means that arrays' and objects' elements are indented, each\n"
"on its own line. Configure this with the -c / -compact-output, -i=NUM /\n" "on its own line. Configure this with the -c / -compact-output, -s=NUM /\n"
"-indent=NUM (for NUM ranging from 0 to 8) and -t / -tabs flags.\n" "-spaces=NUM (for NUM ranging from 0 to 8) and -t / -tabs flags.\n"
"\n" "\n"
"The -input-json-extra-comma flag allows input like \"[1,2,]\", with a\n" "The -input-json-extra-comma flag allows input like \"[1,2,]\", with a\n"
"comma after the final element of a JSON list or dictionary.\n" "comma after the final element of a JSON list or dictionary.\n"
@@ -211,12 +211,12 @@ static const char* g_usage =
"object has multiple \"foo\" children but the first one doesn't have a\n" "object has multiple \"foo\" children but the first one doesn't have a\n"
"\"bar\" child, even if later ones do.\n" "\"bar\" child, even if later ones do.\n"
"\n" "\n"
"The -s or -strict-json-pointer-syntax flag restricts the -query=STR\n" "The -strict-json-pointer-syntax flag restricts the -query=STR string to\n"
"string to exactly RFC 6901, with only two escape sequences: \"~0\" and\n" "exactly RFC 6901, with only two escape sequences: \"~0\" and \"~1\" for\n"
"\"~1\" for \"~\" and \"/\". Without this flag, this program also lets\n" "\"~\" and \"/\". Without this flag, this program also lets \"~n\" and\n"
"\"~n\" and \"~r\" escape the New Line and Carriage Return ASCII control\n" "\"~r\" escape the New Line and Carriage Return ASCII control characters,\n"
"characters, which can work better with line oriented Unix tools that\n" "which can work better with line oriented Unix tools that assume exactly\n"
"assume exactly one value (i.e. one JSON Pointer string) per line.\n" "one value (i.e. one JSON Pointer string) per line.\n"
"\n" "\n"
"----\n" "----\n"
"\n" "\n"
@@ -568,18 +568,18 @@ struct {
bool compact_output; bool compact_output;
bool fail_if_unsandboxed; bool fail_if_unsandboxed;
size_t indent;
bool input_json_extra_comma; bool input_json_extra_comma;
uint32_t max_output_depth; uint32_t max_output_depth;
bool output_json_extra_comma; bool output_json_extra_comma;
char* query_c_string; char* query_c_string;
size_t spaces;
bool strict_json_pointer_syntax; bool strict_json_pointer_syntax;
bool tabs; bool tabs;
} g_flags = {0}; } g_flags = {0};
const char* // const char* //
parse_flags(int argc, char** argv) { parse_flags(int argc, char** argv) {
g_flags.indent = 4; g_flags.spaces = 4;
g_flags.max_output_depth = 0xFFFFFFFF; g_flags.max_output_depth = 0xFFFFFFFF;
int c = (argc > 0) ? 1 : 0; // Skip argv[0], the program name. int c = (argc > 0) ? 1 : 0; // Skip argv[0], the program name.
@@ -626,15 +626,6 @@ parse_flags(int argc, char** argv) {
g_flags.fail_if_unsandboxed = true; g_flags.fail_if_unsandboxed = true;
continue; continue;
} }
if (!strncmp(arg, "i=", 2) || !strncmp(arg, "indent=", 7)) {
while (*arg++ != '=') {
}
if (('0' <= arg[0]) && (arg[0] <= '8') && (arg[1] == '\x00')) {
g_flags.indent = arg[0] - '0';
continue;
}
return g_usage;
}
if (!strcmp(arg, "input-json-extra-comma")) { if (!strcmp(arg, "input-json-extra-comma")) {
g_flags.input_json_extra_comma = true; g_flags.input_json_extra_comma = true;
continue; continue;
@@ -649,7 +640,16 @@ parse_flags(int argc, char** argv) {
g_flags.query_c_string = arg; g_flags.query_c_string = arg;
continue; continue;
} }
if (!strcmp(arg, "s") || !strcmp(arg, "strict-json-pointer-syntax")) { if (!strncmp(arg, "s=", 2) || !strncmp(arg, "spaces=", 7)) {
while (*arg++ != '=') {
}
if (('0' <= arg[0]) && (arg[0] <= '8') && (arg[1] == '\x00')) {
g_flags.spaces = arg[0] - '0';
continue;
}
return g_usage;
}
if (!strcmp(arg, "strict-json-pointer-syntax")) {
g_flags.strict_json_pointer_syntax = true; g_flags.strict_json_pointer_syntax = true;
continue; continue;
} }
@@ -901,7 +901,7 @@ handle_token(wuffs_base__token t, bool start_of_token_chain) {
for (uint32_t i = 0; i < g_depth; i++) { for (uint32_t i = 0; i < g_depth; i++) {
TRY(write_dst( TRY(write_dst(
g_flags.tabs ? INDENT_TAB_STRING : INDENT_SPACES_STRING, g_flags.tabs ? INDENT_TAB_STRING : INDENT_SPACES_STRING,
g_flags.tabs ? 1 : g_flags.indent)); g_flags.tabs ? 1 : g_flags.spaces));
} }
} }
@@ -931,7 +931,7 @@ handle_token(wuffs_base__token t, bool start_of_token_chain) {
for (size_t i = 0; i < g_depth; i++) { for (size_t i = 0; i < g_depth; i++) {
TRY(write_dst( TRY(write_dst(
g_flags.tabs ? INDENT_TAB_STRING : INDENT_SPACES_STRING, g_flags.tabs ? INDENT_TAB_STRING : INDENT_SPACES_STRING,
g_flags.tabs ? 1 : g_flags.indent)); g_flags.tabs ? 1 : g_flags.spaces));
} }
} }
} }