about summary refs log tree commit diff
path: root/Src/Zle/zle_thingy.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2012-01-05 20:01:24 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2012-01-05 20:01:24 +0000
commit9b923cccea05b93eeade4a69694985880d5affa2 (patch)
tree5c84bd3790c4b8e36e44fc96c5b2efc007410b40 /Src/Zle/zle_thingy.c
parent432112c4256bf7e33776fa1ad57e148b5864e303 (diff)
downloadzsh-9b923cccea05b93eeade4a69694985880d5affa2.tar.gz
zsh-9b923cccea05b93eeade4a69694985880d5affa2.tar.xz
zsh-9b923cccea05b93eeade4a69694985880d5affa2.zip
30084: `zle -T tc func' for zle testing of termcap output
Diffstat (limited to 'Src/Zle/zle_thingy.c')
-rw-r--r--Src/Zle/zle_thingy.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c
index 03e73b4ca..49d715e06 100644
--- a/Src/Zle/zle_thingy.c
+++ b/Src/Zle/zle_thingy.c
@@ -353,6 +353,7 @@ bin_zle(char *name, char **args, Options ops, UNUSED(int func))
 	{ 'K', bin_zle_keymap, 1, 1 },
 	{ 'I', bin_zle_invalidate, 0, 0 },
 	{ 'F', bin_zle_fd, 0, 2 },
+	{ 'T', bin_zle_transform, 0, 2},
 	{ 0,   bin_zle_call, 0, -1 },
     };
     struct opn const *op, *opp;
@@ -856,6 +857,69 @@ bin_zle_fd(char *name, char **args, Options ops, UNUSED(char func))
     return 0;
 }
 
+/**/
+static int
+bin_zle_transform(char *name, char **args, Options ops, UNUSED(char func))
+{
+    /*
+     * -1: too few arguments
+     * 0: just right
+     * 1: too many arguments
+     * 2: first argument not recognised
+     */
+    int badargs = 0;
+
+    if (OPT_ISSET(ops,'L')) {
+	if (args[0]) {
+	    if (args[1]) {
+		badargs = 1;
+	    } else if (strcmp(args[0], "tc")) {
+		badargs = 2;
+	    }
+	}
+	if (!badargs && tcout_func_name) {
+	    fputs("zle -T tc ", stdout);
+	    quotedzputs(tcout_func_name, stdout);
+	    putchar('\n');
+	}
+    } else if (OPT_ISSET(ops,'r')) {
+	if (!args[0]) {
+	    badargs = -1;
+	} else if (args[1]) {
+	    badargs = 1;
+	} else if (tcout_func_name) {
+	    zsfree(tcout_func_name);
+	    tcout_func_name = NULL;
+	}
+    } else {
+	if (!args[0] || !args[1]) {
+	    badargs = -1;
+	    /* we've already checked args <= 2 */
+	} else {
+	    if (!strcmp(args[0], "tc")) {
+		if (tcout_func_name) {
+		    zsfree(tcout_func_name);
+		}
+		tcout_func_name = ztrdup(args[1]);
+	    } else {
+		badargs = 2;
+	    }
+	}
+    }
+
+    if (badargs) {
+	if (badargs == 2) {
+	    zwarnnam(name, "-T: no such transformation '%s'", args[0]);
+	} else {
+	    char *way = (badargs > 0) ? "many" : "few";
+	    zwarnnam(name, "too %s arguments for option -T", way);
+	}
+	return 1;
+    }
+
+    return 0;
+}
+
 /*******************/
 /* initialiasation */
 /*******************/