summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/arguments.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/tmux/arguments.c')
-rw-r--r--usr.bin/tmux/arguments.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/usr.bin/tmux/arguments.c b/usr.bin/tmux/arguments.c
index 8908224a333..a6a8f5872bb 100644
--- a/usr.bin/tmux/arguments.c
+++ b/usr.bin/tmux/arguments.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arguments.c,v 1.15 2016/10/11 13:21:59 nicm Exp $ */
+/* $OpenBSD: arguments.c,v 1.16 2017/01/18 10:00:50 nicm Exp $ */
/*
* Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <vis.h>
#include "tmux.h"
@@ -130,9 +131,10 @@ char *
args_print(struct args *args)
{
size_t len;
- char *buf;
- int i;
+ char *buf, *escaped;
+ int i, flags;
struct args_entry *entry;
+ static const char quoted[] = " #\"';$";
len = 1;
buf = xcalloc(1, len);
@@ -156,20 +158,32 @@ args_print(struct args *args)
args_print_add(&buf, &len, " -%c ", entry->flag);
else
args_print_add(&buf, &len, "-%c ", entry->flag);
- if (strchr(entry->value, ' ') != NULL)
- args_print_add(&buf, &len, "\"%s\"", entry->value);
+
+ flags = VIS_OCTAL|VIS_TAB|VIS_NL;
+ if (entry->value[strcspn(entry->value, quoted)] != '\0')
+ flags |= VIS_DQ;
+ stravis(&escaped, entry->value, flags);
+ if (flags & VIS_DQ)
+ args_print_add(&buf, &len, "\"%s\"", escaped);
else
- args_print_add(&buf, &len, "%s", entry->value);
+ args_print_add(&buf, &len, "%s", escaped);
+ free(escaped);
}
/* And finally the argument vector. */
for (i = 0; i < args->argc; i++) {
if (*buf != '\0')
args_print_add(&buf, &len, " ");
- if (strchr(args->argv[i], ' ') != NULL)
- args_print_add(&buf, &len, "\"%s\"", args->argv[i]);
+
+ flags = VIS_OCTAL|VIS_TAB|VIS_NL;
+ if (args->argv[i][strcspn(args->argv[i], quoted)] != '\0')
+ flags |= VIS_DQ;
+ stravis(&escaped, args->argv[i], flags);
+ if (flags & VIS_DQ)
+ args_print_add(&buf, &len, "\"%s\"", escaped);
else
- args_print_add(&buf, &len, "%s", args->argv[i]);
+ args_print_add(&buf, &len, "%s", escaped);
+ free(escaped);
}
return (buf);