diff options
author | Tiago Cunha <tcunha@gmx.com> | 2009-09-22 14:22:21 +0000 |
---|---|---|
committer | Tiago Cunha <tcunha@gmx.com> | 2009-09-22 14:22:21 +0000 |
commit | df7b68480cf37f4039a5fd1809fd7c8dbf127277 (patch) | |
tree | 4e764c63c18a86cd683cabe5bdf1817d970dfb03 /options-cmd.c | |
parent | 31ccf2f8134538bd3f4b2bad0d092536b3adb519 (diff) | |
download | rtmux-df7b68480cf37f4039a5fd1809fd7c8dbf127277.tar.gz rtmux-df7b68480cf37f4039a5fd1809fd7c8dbf127277.tar.bz2 rtmux-df7b68480cf37f4039a5fd1809fd7c8dbf127277.zip |
Sync OpenBSD patchset 343:
Permit multiple prefix keys to be defined, separated by commas, for example:
set -g prefix ^a,^b
Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.
Diffstat (limited to 'options-cmd.c')
-rw-r--r-- | options-cmd.c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/options-cmd.c b/options-cmd.c index bc978611..815c2e63 100644 --- a/options-cmd.c +++ b/options-cmd.c @@ -1,4 +1,4 @@ -/* $Id: options-cmd.c,v 1.7 2009-09-22 13:59:46 tcunha Exp $ */ +/* $Id: options-cmd.c,v 1.8 2009-09-22 14:22:20 tcunha Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -28,6 +28,8 @@ set_option_print(const struct set_option_entry *entry, struct options_entry *o) { static char out[BUFSIZ]; const char *s; + struct keylist *keylist; + u_int i; *out = '\0'; switch (entry->type) { @@ -37,9 +39,14 @@ set_option_print(const struct set_option_entry *entry, struct options_entry *o) case SET_OPTION_NUMBER: xsnprintf(out, sizeof out, "%lld", o->num); break; - case SET_OPTION_KEY: - s = key_string_lookup_key(o->num); - xsnprintf(out, sizeof out, "%s", s); + case SET_OPTION_KEYS: + keylist = o->data; + for (i = 0; i < ARRAY_LENGTH(keylist); i++) { + strlcat(out, key_string_lookup_key( + ARRAY_ITEM(keylist, i)), sizeof out); + if (i != ARRAY_LENGTH(keylist) - 1) + strlcat(out, ",", sizeof out); + } break; case SET_OPTION_COLOUR: s = colour_tostring(o->num); @@ -114,23 +121,35 @@ set_option_number(struct cmd_ctx *ctx, struct options *oo, } void -set_option_key(struct cmd_ctx *ctx, struct options *oo, +set_option_keys(struct cmd_ctx *ctx, struct options *oo, const struct set_option_entry *entry, char *value) { struct options_entry *o; - int key; + struct keylist *keylist; + char *copyvalue, *ptr, *str; + int key; if (value == NULL) { ctx->error(ctx, "empty value"); return; } - if ((key = key_string_lookup_string(value)) == KEYC_NONE) { - ctx->error(ctx, "unknown key: %s", value); - return; + keylist = xmalloc(sizeof *keylist); + ARRAY_INIT(keylist); + + ptr = copyvalue = xstrdup(value); + while ((str = strsep(&ptr, ",")) != NULL) { + if ((key = key_string_lookup_string(str)) == KEYC_NONE) { + xfree(keylist); + ctx->error(ctx, "unknown key: %s", str); + xfree(copyvalue); + return; + } + ARRAY_ADD(keylist, key); } + xfree(copyvalue); - o = options_set_number(oo, entry->name, key); + o = options_set_data(oo, entry->name, keylist, xfree); ctx->info( ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); } |