mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
It is silly for cmd_list_parse to return an integer error when it could
just return NULL.
This commit is contained in:
parent
dad89b6e2c
commit
4caf08d850
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: cfg.c,v 1.52 2017/01/09 21:28:56 nicm Exp $ */
|
||||
/* $OpenBSD: cfg.c,v 1.53 2017/01/15 22:00:56 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
@ -141,7 +141,8 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
||||
if (condition == -1)
|
||||
continue;
|
||||
|
||||
if (cmd_string_parse(p, &cmdlist, path, line, &cause1) != 0) {
|
||||
cmdlist = cmd_string_parse(p, path, line, &cause1);
|
||||
if (cmdlist == NULL) {
|
||||
free(buf);
|
||||
if (cause1 == NULL)
|
||||
continue;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: cmd-command-prompt.c,v 1.40 2017/01/06 13:26:09 nicm Exp $ */
|
||||
/* $OpenBSD: cmd-command-prompt.c,v 1.41 2017/01/15 22:00:56 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
@ -175,7 +175,8 @@ cmd_command_prompt_callback(void *data, const char *s, int done)
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (cmd_string_parse(new_template, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
cmdlist = cmd_string_parse(new_template, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
new_item = cmdq_get_callback(cmd_command_prompt_error,
|
||||
cause);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: cmd-confirm-before.c,v 1.32 2017/01/06 11:57:03 nicm Exp $ */
|
||||
/* $OpenBSD: cmd-confirm-before.c,v 1.33 2017/01/15 22:00:56 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||
@ -112,7 +112,8 @@ cmd_confirm_before_callback(void *data, const char *s, __unused int done)
|
||||
if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')
|
||||
return (0);
|
||||
|
||||
if (cmd_string_parse(cdata->cmd, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
cmdlist = cmd_string_parse(cdata->cmd, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
new_item = cmdq_get_callback(cmd_confirm_before_error,
|
||||
cause);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: cmd-display-panes.c,v 1.16 2016/10/16 19:04:05 nicm Exp $ */
|
||||
/* $OpenBSD: cmd-display-panes.c,v 1.17 2017/01/15 22:00:56 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
@ -90,7 +90,8 @@ cmd_display_panes_callback(struct client *c, struct window_pane *wp)
|
||||
xasprintf(&expanded, "%%%u", wp->id);
|
||||
cmd = cmd_template_replace(template, expanded, 1);
|
||||
|
||||
if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
new_item = cmdq_get_callback(cmd_display_panes_error,
|
||||
cause);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: cmd-if-shell.c,v 1.48 2016/10/16 19:04:05 nicm Exp $ */
|
||||
/* $OpenBSD: cmd-if-shell.c,v 1.49 2017/01/15 22:00:56 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||
@ -96,7 +96,8 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
free(shellcmd);
|
||||
if (cmd == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
@ -167,7 +168,8 @@ cmd_if_shell_callback(struct job *job)
|
||||
if (cmd == NULL)
|
||||
goto out;
|
||||
|
||||
if (cmd_string_parse(cmd, &cmdlist, file, line, &cause) != 0) {
|
||||
cmdlist = cmd_string_parse(cmd, file, line, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL)
|
||||
new_item = cmdq_get_callback(cmd_if_shell_error, cause);
|
||||
else
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: cmd-set-hook.c,v 1.9 2016/10/16 19:04:05 nicm Exp $ */
|
||||
/* $OpenBSD: cmd-set-hook.c,v 1.10 2017/01/15 22:00:56 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012 Thomas Adam <thomas@xteddy.org>
|
||||
@ -115,7 +115,8 @@ cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "no command to set hook: %s", name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: cmd-string.c,v 1.24 2016/10/14 22:14:22 nicm Exp $ */
|
||||
/* $OpenBSD: cmd-string.c,v 1.25 2017/01/15 22:00:56 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
@ -54,32 +54,17 @@ cmd_string_ungetc(size_t *p)
|
||||
(*p)--;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse command string. Returns -1 on error. If returning -1, cause is error
|
||||
* string, or NULL for empty command.
|
||||
*/
|
||||
int
|
||||
cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file,
|
||||
u_int line, char **cause)
|
||||
struct cmd_list *
|
||||
cmd_string_parse(const char *s, const char *file, u_int line, char **cause)
|
||||
{
|
||||
size_t p;
|
||||
int ch, i, argc, rval;
|
||||
char **argv, *buf, *t;
|
||||
const char *whitespace, *equals;
|
||||
size_t len;
|
||||
|
||||
argv = NULL;
|
||||
argc = 0;
|
||||
|
||||
buf = NULL;
|
||||
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;
|
||||
|
||||
*cmdlist = NULL;
|
||||
rval = -1;
|
||||
|
||||
p = 0;
|
||||
for (;;) {
|
||||
ch = cmd_string_getc(s, &p);
|
||||
switch (ch) {
|
||||
@ -133,12 +118,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file,
|
||||
if (argc == 0)
|
||||
goto out;
|
||||
|
||||
*cmdlist = cmd_list_parse(argc, argv, file, line,
|
||||
cause);
|
||||
if (*cmdlist == NULL)
|
||||
goto out;
|
||||
|
||||
rval = 0;
|
||||
cmdlist = cmd_list_parse(argc, argv, file, line, cause);
|
||||
goto out;
|
||||
case '~':
|
||||
if (buf == NULL) {
|
||||
@ -171,7 +151,7 @@ out:
|
||||
free(argv);
|
||||
}
|
||||
|
||||
return (rval);
|
||||
return (cmdlist);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: control.c,v 1.19 2016/10/16 19:04:05 nicm Exp $ */
|
||||
/* $OpenBSD: control.c,v 1.20 2017/01/15 22:00:56 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
@ -85,7 +85,8 @@ control_callback(struct client *c, int closed, __unused void *data)
|
||||
break;
|
||||
}
|
||||
|
||||
if (cmd_string_parse(line, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
cmdlist = cmd_string_parse(line, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
item = cmdq_get_callback(control_error, cause);
|
||||
cmdq_append(c, item);
|
||||
} else {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: key-bindings.c,v 1.68 2017/01/06 11:57:03 nicm Exp $ */
|
||||
/* $OpenBSD: key-bindings.c,v 1.69 2017/01/15 22:00:56 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
@ -379,12 +379,10 @@ key_bindings_init(void)
|
||||
u_int i;
|
||||
struct cmd_list *cmdlist;
|
||||
char *cause;
|
||||
int error;
|
||||
|
||||
for (i = 0; i < nitems(defaults); i++) {
|
||||
error = cmd_string_parse(defaults[i], &cmdlist,
|
||||
"<default-keys>", i, &cause);
|
||||
if (error != 0)
|
||||
cmdlist = cmd_string_parse(defaults[i], "<default>", i, &cause);
|
||||
if (cmdlist == NULL)
|
||||
fatalx("bad default key");
|
||||
cmdq_append(NULL, cmdq_get_command(cmdlist, NULL, NULL, 0));
|
||||
cmd_list_free(cmdlist);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: tmux.h,v 1.697 2017/01/15 20:48:41 nicm Exp $ */
|
||||
/* $OpenBSD: tmux.h,v 1.698 2017/01/15 22:00:56 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
@ -1823,8 +1823,7 @@ 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_parse(const char *, struct cmd_list **, const char *,
|
||||
u_int, char **);
|
||||
struct cmd_list *cmd_string_parse(const char *, const char *, u_int, char **);
|
||||
|
||||
/* cmd-wait-for.c */
|
||||
void cmd_wait_for_flush(void);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: window-choose.c,v 1.83 2017/01/07 15:28:13 nicm Exp $ */
|
||||
/* $OpenBSD: window-choose.c,v 1.84 2017/01/15 22:00:56 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
@ -255,7 +255,8 @@ window_choose_data_run(struct window_choose_data *cdata)
|
||||
if (cdata->command == NULL)
|
||||
return;
|
||||
|
||||
if (cmd_string_parse(cdata->command, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
cmdlist = cmd_string_parse(cdata->command, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
*cause = toupper((u_char) *cause);
|
||||
status_message_set(cdata->start_client, "%s", cause);
|
||||
|
Loading…
Reference in New Issue
Block a user