Annotation of src/usr.bin/tmux/cmd-source-file.c, Revision 1.33
1.33 ! nicm 1: /* $OpenBSD: cmd-source-file.c,v 1.32 2017/01/09 19:29:12 nicm Exp $ */
1.1 nicm 2:
3: /*
4: * Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15: * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16: * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17: */
18:
19: #include <sys/types.h>
20:
1.31 nicm 21: #include <errno.h>
22: #include <glob.h>
1.12 nicm 23: #include <stdlib.h>
1.31 nicm 24: #include <string.h>
1.12 nicm 25:
1.1 nicm 26: #include "tmux.h"
27:
28: /*
29: * Sources a configuration file.
30: */
31:
1.30 nicm 32: static enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmdq_item *);
1.15 nicm 33:
1.30 nicm 34: static enum cmd_retval cmd_source_file_done(struct cmdq_item *, void *);
1.1 nicm 35:
36: const struct cmd_entry cmd_source_file_entry = {
1.23 nicm 37: .name = "source-file",
38: .alias = "source",
39:
1.25 tim 40: .args = { "q", 1, 1 },
41: .usage = "[-q] path",
1.23 nicm 42:
43: .flags = 0,
44: .exec = cmd_source_file_exec
1.1 nicm 45: };
46:
1.26 nicm 47: static enum cmd_retval
1.30 nicm 48: cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
1.15 nicm 49: {
1.30 nicm 50: struct args *args = self->args;
51: struct client *c = item->client;
52: int quiet;
53: struct cmdq_item *new_item;
1.31 nicm 54: enum cmd_retval retval;
55: glob_t g;
1.33 ! nicm 56: u_int i;
1.15 nicm 57:
1.32 nicm 58: quiet = args_has(args, 'q');
1.31 nicm 59: if (glob(args->argv[0], 0, NULL, &g) != 0) {
1.32 nicm 60: if (quiet && errno == ENOENT)
61: return (CMD_RETURN_NORMAL);
1.31 nicm 62: cmdq_error(item, "%s: %s", args->argv[0], strerror(errno));
63: return (CMD_RETURN_ERROR);
64: }
65:
66: retval = CMD_RETURN_NORMAL;
1.33 ! nicm 67: for (i = 0; i < (u_int)g.gl_pathc; i++) {
1.31 nicm 68: if (load_cfg(g.gl_pathv[i], c, item, quiet) != 0)
69: retval = CMD_RETURN_ERROR;
1.15 nicm 70: }
1.29 nicm 71: if (cfg_finished) {
1.30 nicm 72: new_item = cmdq_get_callback(cmd_source_file_done, NULL);
73: cmdq_insert_after(item, new_item);
1.29 nicm 74: }
1.31 nicm 75:
76: globfree(&g);
77: return (retval);
1.15 nicm 78: }
79:
1.29 nicm 80: static enum cmd_retval
1.30 nicm 81: cmd_source_file_done(struct cmdq_item *item, __unused void *data)
1.15 nicm 82: {
1.30 nicm 83: cfg_print_causes(item);
1.29 nicm 84: return (CMD_RETURN_NORMAL);
1.1 nicm 85: }