about summary refs log tree commit diff
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2003-03-25 05:33:18 +0000
committerClint Adams <clint@users.sourceforge.net>2003-03-25 05:33:18 +0000
commit1761a3b14674350f51a074f104a4b141b6c0caa8 (patch)
tree20332d8587959a9460c8f09405872a9e0ba8c6e7
parent63de268fee7f7850d3c234d9c6aa9d3a99f1e871 (diff)
downloadzsh-1761a3b14674350f51a074f104a4b141b6c0caa8.tar.gz
zsh-1761a3b14674350f51a074f104a4b141b6c0caa8.tar.xz
zsh-1761a3b14674350f51a074f104a4b141b6c0caa8.zip
users/5986, 18380: arg support for echoti builtin.
-rw-r--r--ChangeLog5
-rw-r--r--Doc/Zsh/mod_terminfo.yo4
-rw-r--r--Src/Modules/terminfo.c27
3 files changed, 30 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index d4a63dd95..401e302df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-03-25  Clint Adams  <clint@zsh.org>
+
+	* users/5986, 18380: Src/Modules/terminfo.c,
+	Doc/Zsh/mod_terminfo.yo: arg support for echoti builtin.
+
 2003-03-24  Peter Stephenson  <pws@csr.com>
 
 	* 18378: Src/Zle/params.c: memory management for $killring
diff --git a/Doc/Zsh/mod_terminfo.yo b/Doc/Zsh/mod_terminfo.yo
index 7132b44d1..82c93a452 100644
--- a/Doc/Zsh/mod_terminfo.yo
+++ b/Doc/Zsh/mod_terminfo.yo
@@ -6,9 +6,9 @@ The tt(zsh/terminfo) module makes available one builtin command:
 startitem()
 findex(echoti)
 cindex(terminfo value, printing)
-item(tt(echoti) var(cap))(
+item(tt(echoti) var(cap) [ var(arg) ])(
 Output the terminfo value corresponding to the capability
-var(cap).
+var(cap), instantiated with var(arg) if applicable.
 )
 enditem()
 
diff --git a/Src/Modules/terminfo.c b/Src/Modules/terminfo.c
index 744defc8c..c8e5c23fb 100644
--- a/Src/Modules/terminfo.c
+++ b/Src/Modules/terminfo.c
@@ -59,8 +59,8 @@ static Param terminfo_pm;
 static int
 bin_echoti(char *name, char **argv, Options ops, int func)
 {
-    char *s, *t;
-    int num;
+    char *s, *t, *u;
+    int num, argct;
 
     s = *argv++;
     /* This depends on the termcap stuff in init.c */
@@ -92,9 +92,28 @@ bin_echoti(char *name, char **argv, Options ops, int func)
 	zwarnnam(name, "no such terminfo capability: %s", s, 0);
 	return 1;
     }
-
-    tputs(t, 1, putchar);
+    /* count the number of arguments required */
+    for (argct = 0, u = t; *u; u++)
+        if (*u == '%') {
+            if (u++, (*u == 'd' || *u == '2' || *u == '3' || *u == '.' ||
+                      *u == '+'))
+                argct++;
+        }
+    /* check that the number of arguments provided is correct */
+    if (arrlen(argv) != argct) {
+        zwarnnam(name, (arrlen(argv) < argct) ? "not enough arguments" :
+                 "too many arguments", NULL, 0);
+        return 1;
+    }
+    /* output string, through the proper termcap functions */
+    if (!argct)
+        tputs(t, 1, putraw);
+    else {
+        num = (argv[1]) ? atoi(argv[1]) : atoi(*argv);
+        tputs(tparm(t, atoi(*argv)), num, putraw);
+    }
     return 0;
+
 }
 
 /**/