summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-source-file.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2019-05-28 11:46:30 +0000
committernicm <nicm@openbsd.org>2019-05-28 11:46:30 +0000
commite88cca1e03476ba01196c8b28a56572a1b838cdb (patch)
tree6c3f9408f324c5c91f94059651d1081c0c5e28c6 /usr.bin/tmux/cmd-source-file.c
parentInclude pthread.h to make this header standalone (needs pthread_t and others) (diff)
downloadwireguard-openbsd-e88cca1e03476ba01196c8b28a56572a1b838cdb.tar.xz
wireguard-openbsd-e88cca1e03476ba01196c8b28a56572a1b838cdb.zip
Allow source-file to take multiple arguments.
Diffstat (limited to 'usr.bin/tmux/cmd-source-file.c')
-rw-r--r--usr.bin/tmux/cmd-source-file.c65
1 files changed, 35 insertions, 30 deletions
diff --git a/usr.bin/tmux/cmd-source-file.c b/usr.bin/tmux/cmd-source-file.c
index 14039d4dd16..07fcffdee4d 100644
--- a/usr.bin/tmux/cmd-source-file.c
+++ b/usr.bin/tmux/cmd-source-file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-source-file.c,v 1.38 2019/05/23 11:13:30 nicm Exp $ */
+/* $OpenBSD: cmd-source-file.c,v 1.39 2019/05/28 11:46:30 nicm Exp $ */
/*
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
@@ -38,8 +38,8 @@ const struct cmd_entry cmd_source_file_entry = {
.name = "source-file",
.alias = "source",
- .args = { "nq", 1, 1 },
- .usage = "[-nq] path",
+ .args = { "nq", 1, -1 },
+ .usage = "[-nq] path ...",
.flags = 0,
.exec = cmd_source_file_exec
@@ -53,49 +53,54 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
struct client *c = item->client;
struct cmdq_item *new_item, *after;
enum cmd_retval retval;
- char *pattern, *tmp;
- const char *path = args->argv[0];
+ char *pattern, *cwd;
+ const char *path, *error;
glob_t g;
- u_int i;
+ int i;
+ u_int j;
if (args_has(args, 'q'))
flags |= CMD_PARSE_QUIET;
if (args_has(args, 'n'))
flags |= CMD_PARSE_PARSEONLY;
-
- if (*path == '/')
- pattern = xstrdup(path);
- else {
- utf8_stravis(&tmp, server_client_get_cwd(c, NULL), VIS_GLOB);
- xasprintf(&pattern, "%s/%s", tmp, path);
- free(tmp);
- }
- log_debug("%s: %s", __func__, pattern);
+ utf8_stravis(&cwd, server_client_get_cwd(c, NULL), VIS_GLOB);
retval = CMD_RETURN_NORMAL;
- if (glob(pattern, 0, NULL, &g) != 0) {
- if (errno != ENOENT || (~flags & CMD_PARSE_QUIET)) {
- cmdq_error(item, "%s: %s", path, strerror(errno));
- retval = CMD_RETURN_ERROR;
+ for (i = 0; i < args->argc; i++) {
+ path = args->argv[i];
+ if (*path == '/')
+ pattern = xstrdup(path);
+ else
+ xasprintf(&pattern, "%s/%s", cwd, path);
+ log_debug("%s: %s", __func__, pattern);
+
+ if (glob(pattern, 0, NULL, &g) != 0) {
+ error = strerror(errno);
+ if (errno != ENOENT || (~flags & CMD_PARSE_QUIET)) {
+ cmdq_error(item, "%s: %s", path, error);
+ retval = CMD_RETURN_ERROR;
+ }
+ free(pattern);
+ continue;
}
free(pattern);
- return (retval);
- }
- free(pattern);
-
- after = item;
- for (i = 0; i < (u_int)g.gl_pathc; i++) {
- if (load_cfg(g.gl_pathv[i], c, after, flags, &new_item) < 0)
- retval = CMD_RETURN_ERROR;
- else if (new_item != NULL)
- after = new_item;
+
+ after = item;
+ for (j = 0; j < g.gl_pathc; j++) {
+ path = g.gl_pathv[j];
+ if (load_cfg(path, c, after, flags, &new_item) < 0)
+ retval = CMD_RETURN_ERROR;
+ else if (new_item != NULL)
+ after = new_item;
+ }
+ globfree(&g);
}
if (cfg_finished) {
new_item = cmdq_get_callback(cmd_source_file_done, NULL);
cmdq_insert_after(item, new_item);
}
- globfree(&g);
+ free(cwd);
return (retval);
}