about summary refs log tree commit diff
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2003-11-19 17:06:48 +0000
committerClint Adams <clint@users.sourceforge.net>2003-11-19 17:06:48 +0000
commit184fd22fd4b127ed2636cd871a0f71466f322bc8 (patch)
treef52b0e216ea4aeaad9111d87749b322c7d357712
parenta9cb4b0fa70d20a10de484599698b06d31b9eb2e (diff)
downloadzsh-184fd22fd4b127ed2636cd871a0f71466f322bc8.tar.gz
zsh-184fd22fd4b127ed2636cd871a0f71466f322bc8.tar.xz
zsh-184fd22fd4b127ed2636cd871a0f71466f322bc8.zip
19258: arg support for echoti.
-rw-r--r--ChangeLog5
-rw-r--r--Doc/Zsh/mod_terminfo.yo23
-rw-r--r--Src/Modules/terminfo.c38
3 files changed, 61 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 454d3de6c..7e249de46 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-11-19  Clint Adams  <clint@zsh.org>
+
+	* 19258: Doc/Zsh/mod_terminfo.yo, Src/Modules/terminfo.c:
+	arg support for echoti.
+
 2003-11-14  Clint Adams  <clint@zsh.org>
 
 	* unposted: config.guess, config.sub:
diff --git a/Doc/Zsh/mod_terminfo.yo b/Doc/Zsh/mod_terminfo.yo
new file mode 100644
index 000000000..82c93a452
--- /dev/null
+++ b/Doc/Zsh/mod_terminfo.yo
@@ -0,0 +1,23 @@
+COMMENT(!MOD!zsh/terminfo
+Interface to the terminfo database.
+!MOD!)
+The tt(zsh/terminfo) module makes available one builtin command:
+
+startitem()
+findex(echoti)
+cindex(terminfo value, printing)
+item(tt(echoti) var(cap) [ var(arg) ])(
+Output the terminfo value corresponding to the capability
+var(cap), instantiated with var(arg) if applicable.
+)
+enditem()
+
+The tt(zsh/terminfo) module makes available one parameter:
+
+startitem()
+vindex(terminfo)
+item(tt(terminfo))(
+An associative array that maps terminfo capability names to
+their values.
+)
+enditem()
diff --git a/Src/Modules/terminfo.c b/Src/Modules/terminfo.c
index ca54a333e..b3fb83e2a 100644
--- a/Src/Modules/terminfo.c
+++ b/Src/Modules/terminfo.c
@@ -51,6 +51,12 @@ static char terminfo_nam[] = "terminfo";
 #  include <term.h>
 # endif
 
+/* If ERR isn't defined, we probably have bigger problems,
+ * but try this anyway. */
+# ifndef ERR
+#  define ERR (-1)
+# endif
+
 static Param terminfo_pm;
 
 /* echoti: output a terminfo capability */
@@ -59,8 +65,8 @@ static Param terminfo_pm;
 static int
 bin_echoti(char *name, char **argv, char *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 +98,28 @@ bin_echoti(char *name, char **argv, char *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;
+
 }
 
 /**/
@@ -351,7 +376,10 @@ boot_(Module m)
 {
 #ifdef HAVE_TIGETSTR
 # ifdef HAVE_SETUPTERM
-    setupterm((char *)0, 1, (int *)0);
+    int errret;
+
+    if (setupterm((char *)0, 1, &errret) == ERR)
+	return 1;
 # endif
 
     if (!createtihash())