diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2019-07-29 10:51:30 +0100 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2019-07-29 10:51:30 +0100 |
commit | da552eb73b80bab3c0a28dfb9ae2c75fa6d4bdaf (patch) | |
tree | cf9c86c3218659faf46e606a1e38bc6ebb570dcd /arguments.c | |
parent | 5a501a8ae27c2d0128870caa48c5708e97528567 (diff) | |
parent | b90a9fcd13f4434aed0fe1785d619aa668bbc77d (diff) | |
download | rtmux-da552eb73b80bab3c0a28dfb9ae2c75fa6d4bdaf.tar.gz rtmux-da552eb73b80bab3c0a28dfb9ae2c75fa6d4bdaf.tar.bz2 rtmux-da552eb73b80bab3c0a28dfb9ae2c75fa6d4bdaf.zip |
Merge branch 'master' into 3.0-rc
Diffstat (limited to 'arguments.c')
-rw-r--r-- | arguments.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/arguments.c b/arguments.c index 38e50829..026272af 100644 --- a/arguments.c +++ b/arguments.c @@ -37,6 +37,7 @@ TAILQ_HEAD(args_values, args_value); struct args_entry { u_char flag; struct args_values values; + u_int count; RB_ENTRY(args_entry) entry; }; @@ -173,6 +174,7 @@ args_print(struct args *args) size_t len; char *buf; int i; + u_int j; struct args_entry *entry; struct args_value *value; @@ -186,7 +188,8 @@ args_print(struct args *args) if (*buf == '\0') args_print_add(&buf, &len, "-"); - args_print_add(&buf, &len, "%c", entry->flag); + for (j = 0; j < entry->count; j++) + args_print_add(&buf, &len, "%c", entry->flag); } /* Then the flags with arguments. */ @@ -212,12 +215,14 @@ args_escape(const char *s) if (*s == '\0') return (xstrdup(s)); - if ((strchr(quoted, s[0]) != NULL || s[0] == '~') && s[1] == '\0') { + if (s[0] != ' ' && + (strchr(quoted, s[0]) != NULL || s[0] == '~') && + s[1] == '\0') { xasprintf(&escaped, "\\%c", s[0]); return (escaped); } - flags = VIS_OCTAL|VIS_TAB|VIS_NL; + flags = VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL; if (s[strcspn(s, quoted)] != '\0') flags |= VIS_DQ; utf8_stravis(&escaped, s, flags); @@ -241,7 +246,12 @@ args_escape(const char *s) int args_has(struct args *args, u_char ch) { - return (args_find(args, ch) != NULL); + struct args_entry *entry; + + entry = args_find(args, ch); + if (entry == NULL) + return (0); + return (entry->count); } /* Set argument value in the arguments tree. */ @@ -255,9 +265,11 @@ args_set(struct args *args, u_char ch, const char *s) if (entry == NULL) { entry = xcalloc(1, sizeof *entry); entry->flag = ch; + entry->count = 1; TAILQ_INIT(&entry->values); RB_INSERT(args_tree, &args->tree, entry); - } + } else + entry->count++; if (s != NULL) { value = xcalloc(1, sizeof *value); |