about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2000-12-03 20:53:07 +0000
committerClint Adams <clint@users.sourceforge.net>2000-12-03 20:53:07 +0000
commit13b93a5faacf78e6bbc560837dd4c6cddf4acea9 (patch)
treeab3c28d436fe8ecfff6091e803825b5fc3f47d20 /Src
parenta59b51006b307a1a3cbd79e6b85e6b80400cc8ab (diff)
downloadzsh-13b93a5faacf78e6bbc560837dd4c6cddf4acea9.tar.gz
zsh-13b93a5faacf78e6bbc560837dd4c6cddf4acea9.tar.xz
zsh-13b93a5faacf78e6bbc560837dd4c6cddf4acea9.zip
13215: echotc, echoti, terminfo
Diffstat (limited to 'Src')
-rw-r--r--Src/Modules/termcap.c134
-rw-r--r--Src/Modules/termcap.mdd7
-rw-r--r--Src/Modules/terminfo.c226
-rw-r--r--Src/Modules/terminfo.mdd8
-rw-r--r--Src/builtin.c71
5 files changed, 375 insertions, 71 deletions
diff --git a/Src/Modules/termcap.c b/Src/Modules/termcap.c
new file mode 100644
index 000000000..8f5f650f9
--- /dev/null
+++ b/Src/Modules/termcap.c
@@ -0,0 +1,134 @@
+/*
+ * termcap.c - termcap manipulation through curses
+ *
+ * This file is part of zsh, the Z shell.
+ *
+ * Copyright (c) 1992-1997 Paul Falstad
+ * All rights reserved.
+ *
+ * Permission is hereby granted, without written agreement and without
+ * license or royalty fees, to use, copy, modify, and distribute this
+ * software and to distribute modified versions of this software for any
+ * purpose, provided that the above copyright notice and the following
+ * two paragraphs appear in all copies of this software.
+ *
+ * In no event shall Paul Falstad or the Zsh Development Group be liable
+ * to any party for direct, indirect, special, incidental, or consequential
+ * damages arising out of the use of this software and its documentation,
+ * even if Paul Falstad and the Zsh Development Group have been advised of
+ * the possibility of such damage.
+ *
+ * Paul Falstad and the Zsh Development Group specifically disclaim any
+ * warranties, including, but not limited to, the implied warranties of
+ * merchantability and fitness for a particular purpose.  The software
+ * provided hereunder is on an "as is" basis, and Paul Falstad and the
+ * Zsh Development Group have no obligation to provide maintenance,
+ * support, updates, enhancements, or modifications.
+ *
+ */
+
+#include "termcap.mdh"
+#include "termcap.pro"
+
+/* echotc: output a termcap */
+
+/**/
+int
+bin_echotc(char *name, char **argv, char *ops, int func)
+{
+    char *s, buf[2048], *t, *u;
+    int num, argct;
+
+    s = *argv++;
+    if (termflags & TERM_BAD)
+	return 1;
+    if ((termflags & TERM_UNKNOWN) && (isset(INTERACTIVE) || !init_term()))
+	return 1;
+    /* if the specified termcap has a numeric value, display it */
+    if ((num = tgetnum(s)) != -1) {
+	printf("%d\n", num);
+	return 0;
+    }
+    /* if the specified termcap is boolean, and set, say so  *
+     * ncurses can tell if an existing boolean capability is *
+     * off so in this case we print "no".                    */
+#if !defined(NCURSES_VERSION) || !defined(COLOR_PAIR)
+    if (tgetflag(s) > 0) {
+	puts("yes");
+	return (0);
+    }
+#else /* NCURSES_VERSION && COLOR_PAIR */
+    switch (tgetflag(s)) {
+    case -1:
+	break;
+    case 0:
+	puts("no");
+	return 0;
+    default:
+	puts("yes");
+	return 0;
+    }
+#endif /* NCURSES_VERSION && COLOR_PAIR */
+    /* get a string-type capability */
+    u = buf;
+    t = tgetstr(s, &u);
+    if (!t || !*t) {
+	/* capability doesn't exist, or (if boolean) is off */
+	zwarnnam(name, "no such capability: %s", s, 0);
+	return 1;
+    }
+    /* 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(tgoto(t, atoi(*argv), num), num, putraw);
+    }
+    return 0;
+}
+
+static struct builtin bintab[] = {
+    BUILTIN("echotc", 0, bin_echotc, 1, -1, 0, NULL, NULL),
+};
+
+/**/
+int
+setup_(Module m)
+{
+    return 0;
+}
+
+/**/
+int
+boot_(Module m)
+{
+    return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
+}
+
+/**/
+int
+cleanup_(Module m)
+{
+    deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
+    return 0;
+}
+
+/**/
+int
+finish_(Module m)
+{
+    return 0;
+}
diff --git a/Src/Modules/termcap.mdd b/Src/Modules/termcap.mdd
new file mode 100644
index 000000000..5f88a9662
--- /dev/null
+++ b/Src/Modules/termcap.mdd
@@ -0,0 +1,7 @@
+name=zsh/termcap
+link=either
+load=yes
+
+autobins="echotc"
+
+objects="termcap.o"
diff --git a/Src/Modules/terminfo.c b/Src/Modules/terminfo.c
new file mode 100644
index 000000000..3ad8a8a27
--- /dev/null
+++ b/Src/Modules/terminfo.c
@@ -0,0 +1,226 @@
+/*
+ * terminfo.c - parameter interface to terminfo via curses
+ *
+ * This file is part of zsh, the Z shell.
+ *
+ * Copyright (c) 2000 Sven Wishnowsky, Clint Adams
+ * All rights reserved.
+ *
+ * Permission is hereby granted, without written agreement and without
+ * license or royalty fees, to use, copy, modify, and distribute this
+ * software and to distribute modified versions of this software for any
+ * purpose, provided that the above copyright notice and the following
+ * two paragraphs appear in all copies of this software.
+ *
+ * In no event shall Sven Wishnowsky, Clint Adams or the Zsh Development Group
+ * be liable to any party for direct, indirect, special, incidental, or
+ * consequential damages arising out of the use of this software and its
+ * documentation, even if Sven Wishnowsky, Clint Adams and the Zsh
+ * Development Group have been advised of the possibility of such damage.
+ *
+ * Sven Wishnowsky, Clint Adams and the Zsh Development Group specifically
+ * disclaim any warranties, including, but not limited to, the implied
+ * warranties of merchantability and fitness for a particular purpose.
+ * The software provided hereunder is on an "as is" basis, and Sven
+ * Wishnowsky, Clint Adams and the Zsh Development Group have no obligation
+ * to provide maintenance, support, updates, enhancements, or modifications.
+ *
+ */
+
+#include "terminfo.mdh"
+#include "terminfo.pro"
+
+static char terminfo_nam[] = "terminfo";
+static Param terminfo_pm;
+
+/* echoti: output a terminfo capability */
+
+/**/
+int
+bin_echoti(char *name, char **argv, char *ops, int func)
+{
+    char *s, buf[2048], *t, *u;
+    int num, argct;
+    
+    s = *argv++;
+    if (termflags & TERM_BAD)
+	return 1;
+    if ((termflags & TERM_UNKNOWN) && (isset(INTERACTIVE) || !init_term()))
+	return 1;
+    /* if the specified capability has a numeric value, display it */
+    if (((num = tigetnum(s)) != -1) && (num != -2)) {
+    printf("%d\n", num);
+    return 0;
+}
+
+switch (tigetflag(s)) {
+ case -1:
+     break;
+ case 0:
+     puts("no");
+     return 0;
+ default:
+     puts("yes");
+     return 0;
+}
+
+/* get a string-type capability */
+t = tigetstr(s);
+if (!t || !*t) {
+    /* capability doesn't exist, or (if boolean) is off */
+    zwarnnam(name, "no such terminfo capability: %s", s, 0);
+    return 1;
+}
+
+printf("%s", t);
+return 0;
+}
+
+static struct builtin bintab[] = {
+BUILTIN("echoti", 0, bin_echoti, 1, -1, 0, NULL, NULL),
+    };
+
+/* This says if we are cleaning up when the module is unloaded. */
+
+static int incleanup;
+
+/* Empty dummy function for special hash parameters. */
+
+/**/
+static void
+shempty(void)
+{
+}
+
+/* Create a simple special hash parameter. */
+
+/**/
+static Param
+createtihash()
+{
+    Param pm;
+    HashTable ht;
+
+    unsetparam(terminfo_nam);
+    
+    if (!(pm = createparam(terminfo_nam, PM_SPECIAL|PM_HIDE|PM_HIDEVAL|
+			   PM_REMOVABLE|PM_HASHED)))
+	return NULL;
+    
+    pm->level = pm->old ? locallevel : 0;
+    pm->gets.hfn = hashgetfn;
+    pm->sets.hfn = hashsetfn;
+    pm->unsetfn = stdunsetfn;
+    pm->u.hash = ht = newhashtable(7, terminfo_nam, NULL);
+    
+    ht->hash        = hasher;
+    ht->emptytable  = (TableFunc) shempty;
+    ht->filltable   = NULL;
+    ht->addnode     = (AddNodeFunc) shempty;
+    ht->getnode     = ht->getnode2 = getterminfo;
+    ht->removenode  = (RemoveNodeFunc) shempty;
+    ht->disablenode = NULL;
+    ht->enablenode  = NULL;
+    ht->freenode    = (FreeNodeFunc) shempty;
+    ht->printnode   = printparamnode;
+    ht->scantab     = scanterminfo;
+
+    return (terminfo_pm = pm);
+}
+
+/**/
+static HashNode
+getterminfo(HashTable ht, char *name)
+{
+    int len, num;
+    char *tistr;
+    Param pm = NULL;
+
+    if (termflags & TERM_BAD)
+	return 1;
+    if ((termflags & TERM_UNKNOWN) && (isset(INTERACTIVE) || !init_term()))
+	return 1;
+
+    unmetafy(name, &len);
+
+    pm = (Param) zhalloc(sizeof(struct param));
+    pm->nam = dupstring(name);
+    pm->flags = PM_READONLY;
+    pm->sets.cfn = NULL;
+    pm->gets.cfn = strgetfn;
+    pm->unsetfn = NULL;
+    pm->ct = 0;
+    pm->env = NULL;
+    pm->ename = NULL;
+    pm->old = NULL;
+    pm->level = 0;
+
+    if (((num = tigetnum(name)) != -1) && (num != -2)) {
+	pm->u.val = num;
+	pm->flags |= PM_INTEGER;
+    }
+    else if ((num = tigetflag(name)) != -1) {
+	pm->u.str = num ? dupstring("yes") : dupstring("no");
+	pm->flags |= PM_SCALAR;
+    }
+    else if ((tistr = tigetstr(name)) != NULL)
+    {
+	pm->u.str = dupstring(tistr);
+	pm->flags |= PM_SCALAR;
+    }
+    else
+    {
+    zwarn("no such capability: %s", name, 0);
+    pm->u.str = dupstring("");
+    pm->flags |= PM_UNSET;
+    }
+    return (HashNode) pm;
+
+}
+
+/**/
+static void
+scanterminfo(HashTable ht, ScanFunc func, int flags)
+{
+return 0;	    
+}
+
+/**/
+int
+setup_(Module m)
+{
+    incleanup = 0;
+
+    return 0;
+}
+
+/**/
+int
+boot_(Module m)
+{
+    return !createtihash() || !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
+}
+
+/**/
+int
+cleanup_(Module m)
+{
+    Param pm;
+
+    incleanup = 1;
+
+	if ((pm = (Param) paramtab->getnode(paramtab, terminfo_nam)) &&
+	    pm == terminfo_pm) {
+	    pm->flags &= ~PM_READONLY;
+	    unsetparam_pm(pm, 0, 1);
+	}
+    deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
+    return 0;
+}
+
+/**/
+int
+finish_(Module m)
+{
+    return 0;
+}
diff --git a/Src/Modules/terminfo.mdd b/Src/Modules/terminfo.mdd
new file mode 100644
index 000000000..cb628dd30
--- /dev/null
+++ b/Src/Modules/terminfo.mdd
@@ -0,0 +1,8 @@
+name=zsh/terminfo
+link=either
+load=yes
+
+autobins="echoti"
+autoparams="terminfo"
+
+objects="terminfo.o"
diff --git a/Src/builtin.c b/Src/builtin.c
index d1cea8393..16e5caca7 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -55,7 +55,6 @@ static struct builtin builtins[] =
     BUILTIN("disable", 0, bin_enable, 0, -1, BIN_DISABLE, "afmr", NULL),
     BUILTIN("disown", 0, bin_fg, 0, -1, BIN_DISOWN, NULL, NULL),
     BUILTIN("echo", BINF_PRINTOPTS | BINF_ECHOPTS, bin_print, 0, -1, BIN_ECHO, "neE", "-"),
-    BUILTIN("echotc", 0, bin_echotc, 1, -1, 0, NULL, NULL),
     BUILTIN("emulate", 0, bin_emulate, 1, 1, 0, "LR", NULL),
     BUILTIN("enable", 0, bin_enable, 0, -1, BIN_ENABLE, "afmr", NULL),
     BUILTIN("eval", BINF_PSPECIAL, bin_eval, 0, -1, BIN_EVAL, NULL, NULL),
@@ -2899,76 +2898,6 @@ bin_print(char *name, char **args, char *ops, int func)
     return 0;
 }
 
-/* echotc: output a termcap */
-
-/**/
-int
-bin_echotc(char *name, char **argv, char *ops, int func)
-{
-    char *s, buf[2048], *t, *u;
-    int num, argct;
-
-    s = *argv++;
-    if (termflags & TERM_BAD)
-	return 1;
-    if ((termflags & TERM_UNKNOWN) && (isset(INTERACTIVE) || !init_term()))
-	return 1;
-    /* if the specified termcap has a numeric value, display it */
-    if ((num = tgetnum(s)) != -1) {
-	printf("%d\n", num);
-	return 0;
-    }
-    /* if the specified termcap is boolean, and set, say so  *
-     * ncurses can tell if an existing boolean capability is *
-     * off so in this case we print "no".                    */
-#if !defined(NCURSES_VERSION) || !defined(COLOR_PAIR)
-    if (tgetflag(s) > 0) {
-	puts("yes");
-	return (0);
-    }
-#else /* NCURSES_VERSION && COLOR_PAIR */
-    switch (tgetflag(s)) {
-    case -1:
-	break;
-    case 0:
-	puts("no");
-	return 0;
-    default:
-	puts("yes");
-	return 0;
-    }
-#endif /* NCURSES_VERSION && COLOR_PAIR */
-    /* get a string-type capability */
-    u = buf;
-    t = tgetstr(s, &u);
-    if (!t || !*t) {
-	/* capability doesn't exist, or (if boolean) is off */
-	zwarnnam(name, "no such capability: %s", s, 0);
-	return 1;
-    }
-    /* 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(tgoto(t, atoi(*argv), num), num, putraw);
-    }
-    return 0;
-}
-
 /* shift builtin */
 
 /**/