mirror of
https://github.com/tmux/tmux.git
synced 2025-03-28 09:38:50 +00:00
Merge branch 'obsd-master'
This commit is contained in:
commit
044999ce6d
30
arguments.c
30
arguments.c
@ -21,6 +21,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <vis.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@ -129,9 +130,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);
|
||||
@ -155,20 +157,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;
|
||||
utf8_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;
|
||||
utf8_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);
|
||||
|
@ -104,7 +104,7 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
|
||||
if (args_has(self->args, 'v'))
|
||||
cmdq_print(item, "%s", value);
|
||||
else if (options_isstring(o)) {
|
||||
stravis(&escaped, value, VIS_OCTAL|VIS_TAB|VIS_NL|VIS_DQ);
|
||||
utf8_stravis(&escaped, value, VIS_OCTAL|VIS_TAB|VIS_NL|VIS_DQ);
|
||||
cmdq_print(item, "%s \"%s\"", name, escaped);
|
||||
free(escaped);
|
||||
} else
|
||||
|
1
tmux.h
1
tmux.h
@ -2297,6 +2297,7 @@ enum utf8_state utf8_append(struct utf8_data *, u_char);
|
||||
enum utf8_state utf8_combine(const struct utf8_data *, wchar_t *);
|
||||
enum utf8_state utf8_split(wchar_t, struct utf8_data *);
|
||||
int utf8_strvis(char *, const char *, size_t, int);
|
||||
int utf8_stravis(char **, const char *, int);
|
||||
char *utf8_sanitize(const char *);
|
||||
size_t utf8_strlen(const struct utf8_data *);
|
||||
u_int utf8_strwidth(const struct utf8_data *, ssize_t);
|
||||
|
14
utf8.c
14
utf8.c
@ -218,6 +218,20 @@ utf8_strvis(char *dst, const char *src, size_t len, int flag)
|
||||
return (dst - start);
|
||||
}
|
||||
|
||||
/* Same as utf8_strvis but allocate the buffer. */
|
||||
int
|
||||
utf8_stravis(char **dst, const char *src, int flag)
|
||||
{
|
||||
char *buf;
|
||||
int len;
|
||||
|
||||
buf = xreallocarray(NULL, 4, strlen(src) + 1);
|
||||
len = utf8_strvis(buf, src, strlen(src), flag);
|
||||
|
||||
*dst = xrealloc(buf, len + 1);
|
||||
return (len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Sanitize a string, changing any UTF-8 characters to '_'. Caller should free
|
||||
* the returned string. Anything not valid printable ASCII or UTF-8 is
|
||||
|
Loading…
Reference in New Issue
Block a user