about summary refs log tree commit diff
diff options
context:
space:
mode:
-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;
+
 }
 
 /**/