diff options
Diffstat (limited to 'usr.bin/tmux/cmd.c')
-rw-r--r-- | usr.bin/tmux/cmd.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c index 7bd5af4de7d..9288bcba82f 100644 --- a/usr.bin/tmux/cmd.c +++ b/usr.bin/tmux/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.14 2009/08/23 16:45:00 nicm Exp $ */ +/* $OpenBSD: cmd.c,v 1.15 2009/08/25 12:18:51 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -31,6 +31,7 @@ const struct cmd_entry *cmd_table[] = { &cmd_attach_session_entry, &cmd_bind_key_entry, &cmd_break_pane_entry, + &cmd_choose_client_entry, &cmd_choose_session_entry, &cmd_choose_window_entry, &cmd_clear_history_entry, @@ -858,3 +859,44 @@ error: xfree(winptr); return (NULL); } + +/* Replace the first %% or %idx in template by s. */ +char * +cmd_template_replace(char *template, const char *s, int idx) +{ + char ch; + char *buf, *ptr; + int replaced; + size_t len; + + if (strstr(template, "%") == NULL) + return (xstrdup(template)); + + buf = xmalloc(1); + *buf = '\0'; + len = 0; + replaced = 0; + + ptr = template; + while (*ptr != '\0') { + switch (ch = *ptr++) { + case '%': + if (*ptr < '1' || *ptr > '9' || *ptr - '0' != idx) { + if (*ptr != '%' || replaced) + break; + replaced = 1; + } + ptr++; + + len += strlen(s); + buf = xrealloc(buf, 1, len + 1); + strlcat(buf, s, len + 1); + continue; + } + buf = xrealloc(buf, 1, len + 2); + buf[len++] = ch; + buf[len] = '\0'; + } + + return (buf); +} |