summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/client.c17
-rw-r--r--usr.bin/tmux/cmd-string.c84
-rw-r--r--usr.bin/tmux/cmd.c70
-rw-r--r--usr.bin/tmux/key-bindings.c4
-rw-r--r--usr.bin/tmux/options-table.c9
-rw-r--r--usr.bin/tmux/tmux.h3
6 files changed, 49 insertions, 138 deletions
diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c
index df6b5fa8b8d..1e34b94b5e1 100644
--- a/usr.bin/tmux/client.c
+++ b/usr.bin/tmux/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.116 2017/01/16 14:49:14 nicm Exp $ */
+/* $OpenBSD: client.c,v 1.117 2017/01/16 14:52:25 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -252,13 +252,16 @@ client_main(struct event_base *base, int argc, char **argv, int flags,
* flag.
*/
cmdlist = cmd_list_parse(argc, argv, NULL, 0, &cause);
- if (cmdlist != NULL) {
- TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
- if (cmd->entry->flags & CMD_STARTSERVER)
- cmdflags |= CMD_STARTSERVER;
- }
- cmd_list_free(cmdlist);
+ if (cmdlist == NULL) {
+ fprintf(stderr, "%s\n", cause);
+ return (1);
+ }
+ cmdflags &= ~CMD_STARTSERVER;
+ TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
+ if (cmd->entry->flags & CMD_STARTSERVER)
+ cmdflags |= CMD_STARTSERVER;
}
+ cmd_list_free(cmdlist);
}
/* Create client process structure (starts logging). */
diff --git a/usr.bin/tmux/cmd-string.c b/usr.bin/tmux/cmd-string.c
index 363a8bfe597..b0565e62235 100644
--- a/usr.bin/tmux/cmd-string.c
+++ b/usr.bin/tmux/cmd-string.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-string.c,v 1.26 2017/01/16 14:49:14 nicm Exp $ */
+/* $OpenBSD: cmd-string.c,v 1.27 2017/01/16 14:52:25 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -54,15 +54,17 @@ cmd_string_ungetc(size_t *p)
(*p)--;
}
-int
-cmd_string_split(const char *s, int *rargc, char ***rargv)
+struct cmd_list *
+cmd_string_parse(const char *s, const char *file, u_int line, char **cause)
{
- size_t p = 0;
- int ch, argc = 0, append = 0;
- char **argv = NULL, *buf = NULL, *t;
- const char *whitespace, *equals;
- size_t len = 0;
+ size_t p = 0;
+ int ch, i, argc = 0;
+ char **argv = NULL, *buf = NULL, *t;
+ const char *whitespace, *equals;
+ size_t len = 0;
+ struct cmd_list *cmdlist = NULL;
+ *cause = NULL;
for (;;) {
ch = cmd_string_getc(s, &p);
switch (ch) {
@@ -113,67 +115,43 @@ cmd_string_split(const char *s, int *rargc, char ***rargv)
argc--;
memmove(argv, argv + 1, argc * (sizeof *argv));
}
- goto done;
+ if (argc == 0)
+ goto out;
+
+ cmdlist = cmd_list_parse(argc, argv, file, line, cause);
+ goto out;
case '~':
- if (buf != NULL) {
- append = 1;
+ if (buf == NULL) {
+ t = cmd_string_expand_tilde(s, &p);
+ if (t == NULL)
+ goto error;
+ cmd_string_copy(&buf, t, &len);
break;
}
- t = cmd_string_expand_tilde(s, &p);
- if (t == NULL)
- goto error;
- cmd_string_copy(&buf, t, &len);
- break;
+ /* FALLTHROUGH */
default:
- append = 1;
- break;
- }
- if (append) {
if (len >= SIZE_MAX - 2)
goto error;
+
buf = xrealloc(buf, len + 1);
buf[len++] = ch;
+ break;
}
- append = 0;
}
-done:
- *rargc = argc;
- *rargv = argv;
-
- free(buf);
- return (0);
-
error:
- if (argv != NULL)
- cmd_free_argv(argc, argv);
- free(buf);
- return (-1);
-}
+ xasprintf(cause, "invalid or unknown command: %s", s);
-struct cmd_list *
-cmd_string_parse(const char *s, const char *file, u_int line, char **cause)
-{
- struct cmd_list *cmdlist = NULL;
- int argc;
- char **argv;
+out:
+ free(buf);
- *cause = NULL;
- if (cmd_string_split(s, &argc, &argv) != 0)
- goto error;
- if (argc != 0) {
- cmdlist = cmd_list_parse(argc, argv, file, line, cause);
- if (cmdlist == NULL) {
- cmd_free_argv(argc, argv);
- goto error;
- }
+ if (argv != NULL) {
+ for (i = 0; i < argc; i++)
+ free(argv[i]);
+ free(argv);
}
- cmd_free_argv(argc, argv);
- return (cmdlist);
-error:
- xasprintf(cause, "invalid or unknown command: %s", s);
- return (NULL);
+ return (cmdlist);
}
static void
diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c
index c46f42825f8..1079167d1ea 100644
--- a/usr.bin/tmux/cmd.c
+++ b/usr.bin/tmux/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.133 2017/01/16 14:49:14 nicm Exp $ */
+/* $OpenBSD: cmd.c,v 1.134 2017/01/16 14:52:25 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -308,74 +308,21 @@ cmd_stringify_argv(int argc, char **argv)
return (buf);
}
-static int
-cmd_try_alias(int *argc, char ***argv)
-{
- struct options_entry *o;
- int old_argc = *argc, new_argc;
- char **old_argv = *argv, **new_argv;
- u_int size, idx;
- int i;
- size_t wanted;
- const char *s, *cp = NULL;
-
- o = options_get_only(global_options, "command-alias");
- if (o == NULL || options_array_size(o, &size) == -1 || size == 0)
- return (-1);
-
- wanted = strlen(old_argv[0]);
- for (idx = 0; idx < size; idx++) {
- s = options_array_get(o, idx);
- if (s == NULL)
- continue;
-
- cp = strchr(s, '=');
- if (cp == NULL || (size_t)(cp - s) != wanted)
- continue;
- if (strncmp(old_argv[0], s, wanted) == 0)
- break;
- }
- if (idx == size)
- return (-1);
-
- if (cmd_string_split(cp + 1, &new_argc, &new_argv) != 0)
- return (-1);
-
- *argc = new_argc + old_argc - 1;
- *argv = xcalloc((*argc) + 1, sizeof **argv);
-
- for (i = 0; i < new_argc; i++)
- (*argv)[i] = xstrdup(new_argv[i]);
- for (i = 1; i < old_argc; i++)
- (*argv)[new_argc + i - 1] = xstrdup(old_argv[i]);
-
- log_debug("alias: %s=%s", old_argv[0], cp + 1);
- for (i = 0; i < *argc; i++)
- log_debug("alias: argv[%d] = %s", i, (*argv)[i]);
-
- cmd_free_argv(new_argc, new_argv);
- return (0);
-}
-
struct cmd *
cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
{
- const char *name;
const struct cmd_entry **entryp, *entry;
struct cmd *cmd;
struct args *args;
char s[BUFSIZ];
- int ambiguous, allocated = 0;
+ int ambiguous = 0;
*cause = NULL;
if (argc == 0) {
xasprintf(cause, "no command");
return (NULL);
}
- name = argv[0];
-retry:
- ambiguous = 0;
entry = NULL;
for (entryp = cmd_table; *entryp != NULL; entryp++) {
if ((*entryp)->alias != NULL &&
@@ -395,17 +342,10 @@ retry:
if (strcmp(entry->name, argv[0]) == 0)
break;
}
- if ((ambiguous || entry == NULL) &&
- server_proc != NULL &&
- !allocated &&
- cmd_try_alias(&argc, &argv) == 0) {
- allocated = 1;
- goto retry;
- }
if (ambiguous)
goto ambiguous;
if (entry == NULL) {
- xasprintf(cause, "unknown command: %s", name);
+ xasprintf(cause, "unknown command: %s", argv[0]);
return (NULL);
}
@@ -425,8 +365,6 @@ retry:
cmd->file = xstrdup(file);
cmd->line = line;
- if (allocated)
- cmd_free_argv(argc, argv);
return (cmd);
ambiguous:
@@ -440,7 +378,7 @@ ambiguous:
break;
}
s[strlen(s) - 2] = '\0';
- xasprintf(cause, "ambiguous command: %s, could be: %s", name, s);
+ xasprintf(cause, "ambiguous command: %s, could be: %s", argv[0], s);
return (NULL);
usage:
diff --git a/usr.bin/tmux/key-bindings.c b/usr.bin/tmux/key-bindings.c
index 0a4a22048d3..af0bf7bb1dc 100644
--- a/usr.bin/tmux/key-bindings.c
+++ b/usr.bin/tmux/key-bindings.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: key-bindings.c,v 1.70 2017/01/16 14:49:14 nicm Exp $ */
+/* $OpenBSD: key-bindings.c,v 1.71 2017/01/16 14:52:25 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -383,7 +383,7 @@ key_bindings_init(void)
for (i = 0; i < nitems(defaults); i++) {
cmdlist = cmd_string_parse(defaults[i], "<default>", i, &cause);
if (cmdlist == NULL)
- fatalx("bad default key: %s", defaults[i]);
+ fatalx("bad default key");
cmdq_append(NULL, cmdq_get_command(cmdlist, NULL, NULL, 0));
cmd_list_free(cmdlist);
}
diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c
index c5b6d6281e8..a6a8eec4222 100644
--- a/usr.bin/tmux/options-table.c
+++ b/usr.bin/tmux/options-table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options-table.c,v 1.81 2017/01/16 14:49:14 nicm Exp $ */
+/* $OpenBSD: options-table.c,v 1.82 2017/01/16 14:52:25 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -65,13 +65,6 @@ const struct options_table_entry options_table[] = {
.default_num = 20
},
- { .name = "command-alias",
- .type = OPTIONS_TABLE_ARRAY,
- .scope = OPTIONS_TABLE_SERVER,
- .default_str = "split-pane=split-window,"
- "splitp=split-window"
- },
-
{ .name = "default-terminal",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SERVER,
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index af051fc9a2e..ea7f0360190 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.699 2017/01/16 14:49:14 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.700 2017/01/16 14:52:25 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1823,7 +1823,6 @@ void printflike(2, 3) cmdq_print(struct cmdq_item *, const char *, ...);
void printflike(2, 3) cmdq_error(struct cmdq_item *, const char *, ...);
/* cmd-string.c */
-int cmd_string_split(const char *, int *, char ***);
struct cmd_list *cmd_string_parse(const char *, const char *, u_int, char **);
/* cmd-wait-for.c */