Improve output of "N-bit" items in json data.
authorWayne Davison <wayne@opencoder.net>
Sun, 11 Sep 2022 04:05:07 +0000 (21:05 -0700)
committerWayne Davison <wayne@opencoder.net>
Sun, 11 Sep 2022 04:10:10 +0000 (21:10 -0700)
support/json-rsync-version
usage.c

index afaf7382d5369491081cf61a27e4f15c4b9d8805..a51c3a88f505a108a95600dd2e3e89a0a53d0105 100755 (executable)
@@ -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 a2c2a3f03e7b4e4954dcb325f48f94694faf6338..7f215a02902d30a4ebff49f07eabe6ae98dd5ac8 100644 (file)
--- 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