The branch, hooks has been updated
       via  3115f5dff5ab1620cedcf94cac397d54d635a16b (commit)
      from  0076ed760a51cd2c8e99ef7bbdaf891438f4754a (commit)

- Log -----------------------------------------------------------------
commit 3115f5dff5ab1620cedcf94cac397d54d635a16b
Author: Nicholas Marriott <[email protected]>
Commit: Nicholas Marriott <[email protected]>

    Allow client to be NULL to make it work during config.
---
 cmd.c |   67 ++++++++++++++++++++++++++++++++++------------------------------
 1 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/cmd.c b/cmd.c
index 17c1b4c..1489b79 100644
--- a/cmd.c
+++ b/cmd.c
@@ -118,7 +118,7 @@ const struct cmd_entry *cmd_table[] = {
 };
 
 void            cmd_clear_state(struct cmd_state *);
-struct client  *cmd_get_state_client(struct cmd_q *);
+struct client  *cmd_get_state_client(struct cmd_q *, int);
 int             cmd_set_state_tflag(struct cmd *, struct cmd_q *, int);
 int             cmd_set_state_sflag(struct cmd *, struct cmd_q *, int);
 int             cmd_session_better(struct session *, struct session *, int);
@@ -335,7 +335,7 @@ cmd_clear_state(struct cmd_state *state)
 }
 
 struct client *
-cmd_get_state_client(struct cmd_q *cmdq)
+cmd_get_state_client(struct cmd_q *cmdq, int quiet)
 {
        struct cmd      *cmd = cmdq->cmd;
        struct args     *args = cmd->args;
@@ -344,9 +344,9 @@ cmd_get_state_client(struct cmd_q *cmdq)
        case 0:
                return (cmd_current_client(cmdq));
        case CMD_PREP_CLIENT_C:
-               return (cmd_find_client(cmdq, args_get(args, 'c'), 0));
+               return (cmd_find_client(cmdq, args_get(args, 'c'), quiet));
        case CMD_PREP_CLIENT_T:
-               return (cmd_find_client(cmdq, args_get(args, 't'), 0));
+               return (cmd_find_client(cmdq, args_get(args, 't'), quiet));
        default:
                log_fatalx("both -t and -c for %s", cmd->entry->name);
        }
@@ -390,10 +390,17 @@ cmd_set_state_tflag(struct cmd *cmd, struct cmd_q *cmdq, 
int everything)
        default:
                log_fatalx("too many -t for %s", cmd->entry->name);
        }
-
        if (everything) {
-               if (state->tflag.s == NULL)
-                       state->tflag.s = state->c->session;
+               if (state->tflag.s == NULL) {
+                       if (state->c != NULL)
+                               state->tflag.s = state->c->session;
+                       if (state->tflag.s == NULL)
+                               state->tflag.s = cmd_current_session(cmdq, 0);
+                       if (state->tflag.s == NULL) {
+                               cmdq_error(cmdq, "no current session");
+                               return (-1);
+                       }
+               }
                if (state->tflag.wl == NULL)
                        state->tflag.wl = state->tflag.s->curw;
                if (state->tflag.wp == NULL)
@@ -442,8 +449,16 @@ cmd_set_state_sflag(struct cmd *cmd, struct cmd_q *cmdq, 
int everything)
        }
 
        if (everything) {
-               if (state->sflag.s == NULL)
-                       state->sflag.s = state->c->session;
+               if (state->sflag.s == NULL) {
+                       if (state->c != NULL)
+                               state->sflag.s = state->c->session;
+                       if (state->sflag.s == NULL)
+                               state->sflag.s = cmd_current_session(cmdq, 0);
+                       if (state->sflag.s == NULL) {
+                               cmdq_error(cmdq, "no current session");
+                               return (-1);
+                       }
+               }
                if (state->sflag.wl == NULL)
                        state->sflag.wl = state->sflag.s->curw;
                if (state->sflag.wp == NULL)
@@ -469,29 +484,19 @@ cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq)
        /* Start with an empty state. */
        cmd_clear_state(state);
 
-       /* FIXME:  Handle this!  What should happen during cfg_load? */
-       if (cfg_finished == 0)
-               return (0);
-
        /*
         * If the command wants a client and provides -c or -t, use it. If not,
-        * try the base command instead via cmd_get_state_client.
+        * try the base command instead via cmd_get_state_client. No client is
+        * allowed if no flags, otherwise it must be available.
         */
        switch (cmd->entry->flags & (CMD_PREP_CLIENT_C|CMD_PREP_CLIENT_T)) {
        case 0:
-               state->c = cmd_get_state_client(cmdq);
-               if (state->c == NULL) {
-                       if ((cmd->entry->flags & CMD_PREP_ALL_T) != 0)
-                               return (-1);
-                       if ((cmd->entry->flags & CMD_PREP_ALL_S) != 0)
-                               return (-1);
-                       return (0);
-               }
+               state->c = cmd_get_state_client(cmdq, 1);
                break;
        case CMD_PREP_CLIENT_C:
                cflag = args_get(args, 'c');
                if (cflag == NULL)
-                       state->c = cmd_get_state_client(cmdq);
+                       state->c = cmd_get_state_client(cmdq, 0);
                else
                        state->c = cmd_find_client(cmdq, cflag, 0);
                if (state->c == NULL)
@@ -500,7 +505,7 @@ cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq)
        case CMD_PREP_CLIENT_T:
                tflag = args_get(args, 't');
                if (tflag == NULL)
-                       state->c = cmd_get_state_client(cmdq);
+                       state->c = cmd_get_state_client(cmdq, 0);
                else
                        state->c = cmd_find_client(cmdq, tflag, 0);
                if (state->c == NULL)
@@ -519,13 +524,13 @@ cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq)
                error = cmd_set_state_tflag(cmdq->cmd, cmdq, 1);
        else
                error = cmd_set_state_tflag(cmd, cmdq, 0);
-       if (error != 0)
-               return (error);
-       sflag = args_get(args, 's');
-       if (sflag == NULL && (cmd->entry->flags & CMD_PREP_ALL_S) != 0)
-               error = cmd_set_state_sflag(cmdq->cmd, cmdq, 1);
-       else
-               error = cmd_set_state_sflag(cmd, cmdq, 0);
+       if (error == 0) {
+               sflag = args_get(args, 's');
+               if (sflag == NULL && (cmd->entry->flags & CMD_PREP_ALL_S) != 0)
+                       error = cmd_set_state_sflag(cmdq->cmd, cmdq, 1);
+               else
+                       error = cmd_set_state_sflag(cmd, cmdq, 0);
+       }
        return (error);
 }
 


-----------------------------------------------------------------------

Summary of changes:
 cmd.c |   67 ++++++++++++++++++++++++++++++++++------------------------------
 1 files changed, 36 insertions(+), 31 deletions(-)


hooks/post-receive
-- 
tmux

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
tmux-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to