From 94440cf6ffe84a1a5793f44c336060ddd3efe718 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 2 Apr 2020 22:28:24 +1100 Subject: [PATCH] Rename example/json* -o flag --- example/jsonfindptrs/jsonfindptrs.cc | 10 ++++---- example/jsonptr/jsonptr.cc | 38 ++++++++++++++-------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/example/jsonfindptrs/jsonfindptrs.cc b/example/jsonfindptrs/jsonfindptrs.cc index d5dc0964..ad5cf8df 100644 --- a/example/jsonfindptrs/jsonfindptrs.cc +++ b/example/jsonfindptrs/jsonfindptrs.cc @@ -101,7 +101,7 @@ static const char* g_usage = "Usage: jsonfindptrs -flags input.json\n" "\n" "Flags:\n" - " -o=NUM -max-output-depth=NUM\n" + " -d=NUM -max-output-depth=NUM\n" " -s -strict-json-pointer-syntax\n" "\n" "The input.json filename is optional. If absent, it reads from stdin.\n" @@ -162,9 +162,9 @@ static const char* g_usage = "The JSON specification permits implementations to set their own maximum\n" "input depth. This JSON implementation sets it to 1024.\n" "\n" - "The -o=NUM or -max-output-depth=NUM flag gives the maximum (inclusive)\n" + "The -d=NUM or -max-output-depth=NUM flag gives the maximum (inclusive)\n" "output depth. JSON containers ([] arrays and {} objects) can hold other\n" - "containers. A bare -o or -max-output-depth is equivalent to -o=1,\n" + "containers. A bare -d or -max-output-depth is equivalent to -d=1,\n" "analogous to the Unix ls command. The flag's absence is equivalent to an\n" "unlimited output depth, analogous to the Unix find command (and hence\n" "the name of this program: jsonfindptrs)."; @@ -203,10 +203,10 @@ parse_flags(int argc, char** argv) { } } - if (!strcmp(arg, "o") || !strcmp(arg, "max-output-depth")) { + if (!strcmp(arg, "d") || !strcmp(arg, "max-output-depth")) { g_flags.max_output_depth = 1; continue; - } else if (!strncmp(arg, "o=", 2) || + } else if (!strncmp(arg, "d=", 2) || !strncmp(arg, "max-output-depth=", 16)) { while (*arg++ != '=') { } diff --git a/example/jsonptr/jsonptr.cc b/example/jsonptr/jsonptr.cc index b3270f7f..58d21566 100644 --- a/example/jsonptr/jsonptr.cc +++ b/example/jsonptr/jsonptr.cc @@ -147,8 +147,8 @@ static const char* g_usage = "\n" "Flags:\n" " -c -compact-output\n" + " -d=NUM -max-output-depth=NUM\n" " -i=NUM -indent=NUM\n" - " -o=NUM -max-output-depth=NUM\n" " -q=STR -query=STR\n" " -s -strict-json-pointer-syntax\n" " -t -tabs\n" @@ -206,11 +206,11 @@ static const char* g_usage = "\n" "----\n" "\n" - "The -o=NUM or -max-output-depth=NUM flag gives the maximum (inclusive)\n" + "The -d=NUM or -max-output-depth=NUM flag gives the maximum (inclusive)\n" "output depth. JSON containers ([] arrays and {} objects) can hold other\n" "containers. When this flag is set, containers at depth NUM are replaced\n" - "with \"[…]\" or \"{…}\". A bare -o or -max-output-depth is equivalent to\n" - "-o=1. The flag's absence is equivalent to an unlimited output depth.\n" + "with \"[…]\" or \"{…}\". A bare -d or -max-output-depth is equivalent to\n" + "-d=1. The flag's absence is equivalent to an unlimited output depth.\n" "\n" "The -max-output-depth flag only affects the program's output. It doesn't\n" "affect whether or not the input is considered valid JSON. The JSON\n" @@ -589,6 +589,21 @@ parse_flags(int argc, char** argv) { g_flags.compact_output = true; continue; } + if (!strcmp(arg, "d") || !strcmp(arg, "max-output-depth")) { + g_flags.max_output_depth = 1; + continue; + } else if (!strncmp(arg, "d=", 2) || + !strncmp(arg, "max-output-depth=", 16)) { + while (*arg++ != '=') { + } + wuffs_base__result_u64 u = wuffs_base__parse_number_u64( + wuffs_base__make_slice_u8((uint8_t*)arg, strlen(arg))); + if (wuffs_base__status__is_ok(&u.status) && (u.value <= 0xFFFFFFFF)) { + g_flags.max_output_depth = (uint32_t)(u.value); + continue; + } + return g_usage; + } if (!strcmp(arg, "fail-if-unsandboxed")) { g_flags.fail_if_unsandboxed = true; continue; @@ -602,21 +617,6 @@ parse_flags(int argc, char** argv) { } return g_usage; } - if (!strcmp(arg, "o") || !strcmp(arg, "max-output-depth")) { - g_flags.max_output_depth = 1; - continue; - } else if (!strncmp(arg, "o=", 2) || - !strncmp(arg, "max-output-depth=", 16)) { - while (*arg++ != '=') { - } - wuffs_base__result_u64 u = wuffs_base__parse_number_u64( - wuffs_base__make_slice_u8((uint8_t*)arg, strlen(arg))); - if (wuffs_base__status__is_ok(&u.status) && (u.value <= 0xFFFFFFFF)) { - g_flags.max_output_depth = (uint32_t)(u.value); - continue; - } - return g_usage; - } if (!strncmp(arg, "q=", 2) || !strncmp(arg, "query=", 6)) { while (*arg++ != '=') { }