From 304f86cdbb5bf87f7a266e84c0f4fbd7bf25bb5e Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 25 Sep 2014 12:45:35 +0000 Subject: Support ! for last pane. --- cmd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'cmd.c') diff --git a/cmd.c b/cmd.c index 185d39b7..ff362757 100644 --- a/cmd.c +++ b/cmd.c @@ -1192,7 +1192,13 @@ cmd_find_pane(struct cmd_q *cmdq, *wpp = wl->window->active; else if (paneptr[0] == '+' || paneptr[0] == '-') *wpp = cmd_find_pane_offset(paneptr, wl); - else { + else if (paneptr[0] == '!' && paneptr[1] == '\0') { + if (wl->window->last == NULL) { + cmdq_error(cmdq, "no last pane"); + goto error; + } + *wpp = wl->window->last; + } else { idx = strtonum(paneptr, 0, INT_MAX, &errstr); if (errstr != NULL) goto lookup_string; -- cgit v1.2.3 From a54b0055f66bc2d27bd57fc3f818dc185118470f Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 25 Sep 2014 12:51:40 +0000 Subject: Support using pane id as part of session or window specifier (so %1 means session-of-%1 or window-of-%1) and window id as part of session (so @1 means session-of-@1). --- cmd.c | 85 ++++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 46 insertions(+), 39 deletions(-) (limited to 'cmd.c') diff --git a/cmd.c b/cmd.c index ff362757..82410323 100644 --- a/cmd.c +++ b/cmd.c @@ -121,7 +121,7 @@ struct session *cmd_choose_session_list(struct sessionslist *); struct session *cmd_choose_session(int); struct client *cmd_choose_client(struct clients *); struct client *cmd_lookup_client(const char *); -struct session *cmd_lookup_session(const char *, int *); +struct session *cmd_lookup_session(struct cmd_q *, const char *, int *); struct session *cmd_lookup_session_id(const char *); struct winlink *cmd_lookup_window(struct session *, const char *, int *); int cmd_lookup_index(struct session *, const char *, int *); @@ -585,9 +585,11 @@ cmd_lookup_session_id(const char *arg) /* Lookup a session by name. If no session is found, NULL is returned. */ struct session * -cmd_lookup_session(const char *name, int *ambiguous) +cmd_lookup_session(struct cmd_q *cmdq, const char *name, int *ambiguous) { - struct session *s, *sfound; + struct session *s, *sfound; + struct window *w; + struct window_pane *wp; *ambiguous = 0; @@ -595,6 +597,12 @@ cmd_lookup_session(const char *name, int *ambiguous) if ((s = cmd_lookup_session_id(name)) != NULL) return (s); + /* Try as pane or window id. */ + if ((wp = cmd_lookup_paneid(name)) != NULL) + return (cmd_window_session(cmdq, wp->window, NULL)); + if ((w = cmd_lookup_windowid(name)) != NULL) + return (cmd_window_session(cmdq, w, NULL)); + /* * Look for matches. First look for exact matches - session names must * be unique so an exact match can't be ambigious and can just be @@ -630,16 +638,30 @@ cmd_lookup_session(const char *name, int *ambiguous) struct winlink * cmd_lookup_window(struct session *s, const char *name, int *ambiguous) { - struct winlink *wl, *wlfound; - const char *errstr; - u_int idx; + struct winlink *wl, *wlfound; + struct window *w; + struct window_pane *wp; + const char *errstr; + u_int idx; *ambiguous = 0; - /* Try as a window id. */ + /* Try as pane or window id. */ if ((wl = cmd_lookup_winlink_windowid(s, name)) != NULL) return (wl); + /* Lookup as pane or window id. */ + if ((wp = cmd_lookup_paneid(name)) != NULL) { + wl = winlink_find_by_window(&s->windows, wp->window); + if (wl != NULL) + return (wl); + } + if ((w = cmd_lookup_windowid(name)) != NULL) { + wl = winlink_find_by_window(&s->windows, w); + if (wl != NULL) + return (wl); + } + /* First see if this is a valid window index in this session. */ idx = strtonum(name, 0, INT_MAX, &errstr); if (errstr == NULL) { @@ -786,13 +808,11 @@ cmd_window_session(struct cmd_q *cmdq, struct window *w, struct winlink **wlp) struct session * cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached) { - struct session *s; - struct window_pane *wp; - struct window *w; - struct client *c; - char *tmparg; - size_t arglen; - int ambiguous; + struct session *s; + struct client *c; + char *tmparg; + size_t arglen; + int ambiguous; /* A NULL argument means the current session. */ if (arg == NULL) { @@ -801,12 +821,6 @@ cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached) return (s); } - /* Lookup as pane id or window id. */ - if ((wp = cmd_lookup_paneid(arg)) != NULL) - return (cmd_window_session(cmdq, wp->window, NULL)); - if ((w = cmd_lookup_windowid(arg)) != NULL) - return (cmd_window_session(cmdq, w, NULL)); - /* Trim a single trailing colon if any. */ tmparg = xstrdup(arg); arglen = strlen(tmparg); @@ -822,7 +836,7 @@ cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached) } /* Find the session, if any. */ - s = cmd_lookup_session(tmparg, &ambiguous); + s = cmd_lookup_session(cmdq, tmparg, &ambiguous); /* If it doesn't, try to match it as a client. */ if (s == NULL && (c = cmd_lookup_client(tmparg)) != NULL) @@ -844,12 +858,11 @@ cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached) struct winlink * cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp) { - struct session *s; - struct winlink *wl; - struct window_pane *wp; - const char *winptr; - char *sessptr = NULL; - int ambiguous = 0; + struct session *s; + struct winlink *wl; + const char *winptr; + char *sessptr = NULL; + int ambiguous = 0; /* * Find the current session. There must always be a current session, if @@ -867,14 +880,6 @@ cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp) return (s->curw); } - /* Lookup as pane id. */ - if ((wp = cmd_lookup_paneid(arg)) != NULL) { - s = cmd_window_session(cmdq, wp->window, &wl); - if (sp != NULL) - *sp = s; - return (wl); - } - /* Time to look at the argument. If it is empty, that is an error. */ if (*arg == '\0') goto not_found; @@ -889,7 +894,7 @@ cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp) /* Try to lookup the session if present. */ if (*sessptr != '\0') { - if ((s = cmd_lookup_session(sessptr, &ambiguous)) == NULL) + if ((s = cmd_lookup_session(cmdq, sessptr, &ambiguous)) == NULL) goto no_session; } if (sp != NULL) @@ -940,7 +945,8 @@ no_colon: lookup_session: if (ambiguous) goto not_found; - if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL) + if (*arg != '\0' && + (s = cmd_lookup_session(cmdq, arg, &ambiguous)) == NULL) goto no_session; if (sp != NULL) @@ -1030,7 +1036,7 @@ cmd_find_index(struct cmd_q *cmdq, const char *arg, struct session **sp) /* Try to lookup the session if present. */ if (sessptr != NULL && *sessptr != '\0') { - if ((s = cmd_lookup_session(sessptr, &ambiguous)) == NULL) + if ((s = cmd_lookup_session(cmdq, sessptr, &ambiguous)) == NULL) goto no_session; } if (sp != NULL) @@ -1078,7 +1084,8 @@ no_colon: lookup_session: if (ambiguous) goto not_found; - if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL) + if (*arg != '\0' && + (s = cmd_lookup_session(cmdq, arg, &ambiguous)) == NULL) goto no_session; if (sp != NULL) -- cgit v1.2.3 From a27ba6e38006c12c48de88600b8cff9f6aabfed7 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 8 Oct 2014 17:35:58 +0000 Subject: Add xreallocarray and remove nmemb argument from xrealloc. --- cmd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cmd.c') diff --git a/cmd.c b/cmd.c index 82410323..66ac58b8 100644 --- a/cmd.c +++ b/cmd.c @@ -222,7 +222,7 @@ cmd_stringify_argv(int argc, char **argv) for (i = 0; i < argc; i++) { len += strlen(argv[i]) + 1; - buf = xrealloc(buf, 1, len); + buf = xrealloc(buf, len); if (i == 0) *buf = '\0'; @@ -1302,11 +1302,11 @@ cmd_template_replace(const char *template, const char *s, int idx) ptr++; len += strlen(s); - buf = xrealloc(buf, 1, len + 1); + buf = xrealloc(buf, len + 1); strlcat(buf, s, len + 1); continue; } - buf = xrealloc(buf, 1, len + 2); + buf = xrealloc(buf, len + 2); buf[len++] = ch; buf[len] = '\0'; } -- cgit v1.2.3