From: Wayne Davison Date: Sun, 11 Sep 2022 04:05:07 +0000 (-0700) Subject: Improve output of "N-bit" items in json data. X-Git-Tag: v3.2.7pre1~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2dcabdbb9a50074655bd731425c13cea5874c76;p=thirdparty%2Frsync.git Improve output of "N-bit" items in json data. --- diff --git a/support/json-rsync-version b/support/json-rsync-version index afaf7382..a51c3a88 100755 --- a/support/json-rsync-version +++ b/support/json-rsync-version @@ -35,13 +35,18 @@ def main(): for x in line.strip(' ,').split(', '): if ' ' in x: val, var = x.split(' ', 1) + if val == 'no': + val = False + elif val.endswith('-bit'): + var = var[:-1] + '_bits' + val = int(val.split('-')[0]) if var == 'protect-args': var = 'secluded-args' - var = var.replace(' ', '_').replace('-', '_') - info[sect_name][var] = False if val == 'no' else val else: - x = x.replace('-', '_') - info[sect_name][x] = True + var = x + val = True + var = var.replace(' ', '_').replace('-', '_') + info[sect_name][var] = val else: info[sect_name] += [ x for x in line.split() if not x.startswith('(') ] elif line == '': diff --git a/usage.c b/usage.c index a2c2a3f0..7f215a02 100644 --- a/usage.c +++ b/usage.c @@ -172,13 +172,18 @@ static void print_info_flags(enum logcode f) else if (as_json) { char *space = strchr(str, ' '); int is_no = space && strncmp(str, "no ", 3) == 0; - char *quot = space && !is_no ? "\"" : ""; + int is_bits = space && isDigit(str); + char *quot = space && !is_no && !is_bits ? "\"" : ""; char *item = space ? space + 1 : str; char *val = !space ? "true" : is_no ? "false" : str; int val_len = !space ? 4 : is_no ? 5 : space - str; + if (is_bits && (space = strchr(val, '-')) != NULL) + val_len = space - str; item_len = snprintf(item_buf, sizeof item_buf, - " \"%s\": %s%.*s%s%s", item, quot, val_len, val, quot, - need_comma ? "," : ""); + " \"%s%s\": %s%.*s%s%s", item, is_bits ? "bits" : "", + quot, val_len, val, quot, need_comma ? "," : ""); + if (is_bits) + item_buf[strlen(item)+2-1] = '_'; /* Turn the 's' into a '_' */ for (space = item; (space = strpbrk(space, " -")) != NULL; space++) item_buf[space - item + 2] = '_'; } else