diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2008-06-02 18:08:17 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2008-06-02 18:08:17 +0000 |
commit | c7243b73cb3baaf6993d8a9dfb16c054c3978040 (patch) | |
tree | 1d67ee4c5cf764dc83245c79d27da52857b4a89d /tmux.c | |
parent | 11ee55e755af67dc9155e956b4569c8fdeb11848 (diff) | |
download | rtmux-c7243b73cb3baaf6993d8a9dfb16c054c3978040.tar.gz rtmux-c7243b73cb3baaf6993d8a9dfb16c054c3978040.tar.bz2 rtmux-c7243b73cb3baaf6993d8a9dfb16c054c3978040.zip |
Move -s and -c down a level so handling them is the responsibility of the command (with some helper functions), rather than the top-level. This changes the action command syntax so that -s and -c must be after the command rather than before.
Diffstat (limited to 'tmux.c')
-rw-r--r-- | tmux.c | 46 |
1 files changed, 28 insertions, 18 deletions
@@ -1,4 +1,4 @@ -/* $Id: tmux.c,v 1.46 2007-12-06 18:28:55 nicm Exp $ */ +/* $Id: tmux.c,v 1.47 2008-06-02 18:08:17 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -42,6 +42,7 @@ const char *_malloc_options = "AJX"; volatile sig_atomic_t sigwinch; volatile sig_atomic_t sigterm; +char *cfg_file; char *default_command; char *paste_buffer; int bell_action; @@ -59,8 +60,7 @@ usage(char **ptr, const char *fmt, ...) char *msg; va_list ap; -#define USAGE \ - "usage: %s [-v] [-S socket-path] [-s session-name] [-c client-tty]" +#define USAGE "usage: %s [-v] [-f file] [-S socket-path]" if (fmt == NULL) { xasprintf(ptr, USAGE " command [flags]", __progname); } else { @@ -182,22 +182,19 @@ main(int argc, char **argv) struct hdr hdr; const char *shell; struct passwd *pw; - char *client, *path, *name, *cause; + char *client, *path, *name, *cause, *home; char rpath[MAXPATHLEN]; int n, opt; client = path = name = NULL; - while ((opt = getopt(argc, argv, "c:S:s:vV")) != EOF) { + while ((opt = getopt(argc, argv, "c:f:S:s:vV")) != EOF) { switch (opt) { - case 'c': - client = xstrdup(optarg); + case 'f': + cfg_file = xstrdup(optarg); break; case 'S': path = xstrdup(optarg); break; - case 's': - name = xstrdup(optarg); - break; case 'v': debug_level++; break; @@ -225,6 +222,26 @@ main(int argc, char **argv) paste_buffer = NULL; + if (cfg_file == NULL) { + home = getenv("HOME"); + if (home == NULL || *home == '\0') { + pw = getpwuid(getuid()); + if (pw != NULL) + home = pw->pw_dir; + endpwent(); + } + xasprintf(&cfg_file, "%s/%s", home, DEFAULT_CFG); + if (access(cfg_file, R_OK) != 0) { + xfree(cfg_file); + cfg_file = NULL; + } + } else { + if (access(cfg_file, R_OK) != 0) { + log_warn("%s", cfg_file); + exit(1); + } + } + if (path == NULL) { xasprintf(&path, "%s/%s-%lu", _PATH_TMP, __progname, (u_long) getuid()); @@ -265,14 +282,10 @@ main(int argc, char **argv) } memset(&cctx, 0, sizeof cctx); - if (!(cmd->entry->flags & CMD_NOSESSION) || - (cmd->entry->flags & CMD_CANTNEST)) - client_fill_session(&data); + client_fill_session(&data); if (client_init(rpath, &cctx, cmd->entry->flags & CMD_STARTSERVER) != 0) exit(1); b = buffer_create(BUFSIZ); - cmd_send_string(b, name); - cmd_send_string(b, client); cmd_send(cmd, b); cmd_free(cmd); @@ -280,9 +293,6 @@ main(int argc, char **argv) MSG_COMMAND, &data, sizeof data, BUFFER_OUT(b), BUFFER_USED(b)); buffer_destroy(b); - if (name != NULL) - xfree(name); - for (;;) { pfd.fd = cctx.srv_fd; pfd.events = POLLIN; |