First usage instance is the renaming of the mode-mouse option.
---
trunk/cmd-set-option.c | 3 ++-
trunk/options-table.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++
trunk/tmux.h | 1 +
3 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/trunk/cmd-set-option.c b/trunk/cmd-set-option.c
index ca99a97..89fcdad 100644
--- a/trunk/cmd-set-option.c
+++ b/trunk/cmd-set-option.c
@@ -88,7 +88,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
struct client *c;
struct options *oo;
struct window *w;
- const char *optstr, *valstr;
+ char *optstr, *valstr;
u_int i;
/* Get the option name and value. */
@@ -101,6 +101,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
valstr = NULL;
else
valstr = args->argv[1];
+ options_table_handle_renames(&optstr, &valstr);
/* Find the option entry, try each table. */
table = oe = NULL;
diff --git a/trunk/options-table.c b/trunk/options-table.c
index e3e4362..172542b 100644
--- a/trunk/options-table.c
+++ b/trunk/options-table.c
@@ -18,6 +18,7 @@
#include <sys/types.h>
+#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@@ -31,6 +32,8 @@
* the user sets an option or its value needs to be shown.
*/
+int renamed_entry_cmp(const void *, const void *);
+
/* Choice option type lists. */
const char *options_table_mode_keys_list[] = {
"emacs", "vi", NULL
@@ -713,6 +716,58 @@ const struct options_table_entry window_options_table[] = {
{ .name = NULL }
};
+struct renamed_entry {
+ const char *old;
+ const char *new;
+ const u_int count;
+ const struct renamed_entry *values;
+};
+
+/* Translation table for deprecated option strings */
+const struct renamed_entry renamed_options_table[] = {
+ /* short notation: */
+ { "mode-mouse", "mouse-copy-mode", 1, &((const struct renamed_entry[]){
{ "copy-mode", "within", 0, 0 } }) }
+ /* loOng notation:
+ { .old = "mode-mouse",
+ .new = "mouse-copy-mode",
+ .count = 1,
+ .values = &((const struct renamed_entry[]){
+ { .old = "copy-mode",
+ .new = "within",
+ .count = 0,
+ .values = 0
+ }
+ })
+ } */
+};
+
+int
+renamed_entry_cmp(const void *key, const void *value)
+{
+ const struct renamed_entry *entry = value;
+ return (strcmp(key, entry->old));
+}
+
+/* Rewrite renamed option/value strings for backwards compatibility. */
+void
+options_table_handle_renames(char **optstr, char **valstr)
+{
+ struct renamed_entry *option, *value;
+
+ option = bsearch(*optstr, renamed_options_table,
+ nitems(renamed_options_table),
+ sizeof renamed_options_table[0], renamed_entry_cmp);
+ if (option == NULL)
+ return;
+ *optstr = xstrdup(option->new);
+ value = bsearch(*valstr, option->values, option->count,
+ sizeof option->values[0], renamed_entry_cmp);
+ if (value == NULL)
+ return;
+ *valstr = xstrdup(value->new);
+
+}
+
/* Populate an options tree from a table. */
void
options_table_populate_tree(
diff --git a/trunk/tmux.h b/trunk/tmux.h
index ce44011..f593ade 100644
--- a/trunk/tmux.h
+++ b/trunk/tmux.h
@@ -1554,6 +1554,7 @@ long long options_get_number(struct options *, const char
*);
extern const struct options_table_entry server_options_table[];
extern const struct options_table_entry session_options_table[];
extern const struct options_table_entry window_options_table[];
+void options_table_handle_renames(char **, char **);
void options_table_populate_tree(
const struct options_table_entry *, struct options *);
const char *options_table_print_entry(
--
1.7.10.4
------------------------------------------------------------------------------
How fast is your code?
3 out of 4 devs don\\\'t know how their code performs in production.
Find out how slow your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219672;13503038;z?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
tmux-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-users