Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Re: zsh/termcap and zsh/terminfo modules
- X-seq: zsh-workers 13922
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: PATCH: Re: zsh/termcap and zsh/terminfo modules
- Date: Mon, 9 Apr 2001 15:45:50 +0000
- In-reply-to: <20010409091249.A1844@xxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <1010405001506.ZM644@xxxxxxxxxxxxxxxxxxxxxxx> <001801c0bd94$16f37f80$21c9ca95@xxxxxxxxxxxxxx> <20010405095812.A18353@xxxxxxxx> <1010406183939.ZM14729@xxxxxxxxxxxxxxxxxxxxxxx> <20010409091249.A1844@xxxxxxxx>
On Apr 9, 9:12am, Clint Adams wrote:
}
} > The other thought I had was to make both modules loadable, but simply
} > not do anything useful if the corresponding library wasn't available
} > (e.g. on my system "echoti ..." would always return nonzero, and the
} > $terminfo hash would be empty). That makes (( $+terminfo )) useless.
}
} Perhaps the libraries to link to for each module should be dictated
} by the .mdd files.
Possibly, but I don't see how that solves the problem.
Here's the sort of thing I mean:
schaefer[501] zmodload -i zsh/cap
schaefer[502] cap
cap: not available on this system
schaefer[503] zmodload -i zsh/terminfo
zsh: failed to load module: zsh/terminfo
Note that the "cap" module loads without complaint even though I have none
of the POSIX capability set libraries; it's the "cap" command that results
in a failure.
That convinces me that the following patch is appropriate; it makes the
`terminfo' variable disappear if zsh/terminfo can't support it, and the
`echoti' command reports "not available" in that case; but the module
will still load. Similarly for zsh/termcap if tgetent() is not there.
I don't think it hurts anything to declare an autoparam that's never
defined?
Index: Src/Modules/termcap.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/termcap.c,v
retrieving revision 1.2
diff -u -r1.2 termcap.c
--- Src/Modules/termcap.c 2001/02/13 14:35:08 1.2
+++ Src/Modules/termcap.c 2001/04/09 15:40:58
@@ -32,6 +32,8 @@
/* echotc: output a termcap */
+#ifdef HAVE_TGETENT
+
/**/
static int
bin_echotc(char *name, char **argv, char *ops, int func)
@@ -99,6 +101,12 @@
}
return 0;
}
+
+#else /* ! HAVE_TGETENT */
+
+#define bin_echotc bin_notavail
+
+#endif /* HAVE_TGETENT */
static struct builtin bintab[] = {
BUILTIN("echotc", 0, bin_echotc, 1, -1, 0, NULL, NULL),
Index: Src/Modules/termcap.mdd
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/termcap.mdd,v
retrieving revision 1.2
diff -u -r1.2 termcap.mdd
--- Src/Modules/termcap.mdd 2001/02/13 14:35:08 1.2
+++ Src/Modules/termcap.mdd 2001/04/09 15:40:58
@@ -7,10 +7,15 @@
echo static
fi
else
+ echo either;
+ fi
+'
+load='if test "x$ac_cv_func_tgetent" = xyes; then
+ echo yes;
+ else
echo no;
fi
'
-load=yes
autobins="echotc"
Index: Src/Modules/terminfo.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/terminfo.c,v
retrieving revision 1.5
diff -u -r1.5 terminfo.c
--- Src/Modules/terminfo.c 2001/02/13 14:35:08 1.5
+++ Src/Modules/terminfo.c 2001/04/09 15:40:59
@@ -35,13 +35,15 @@
/* echoti: output a terminfo capability */
+#ifdef HAVE_TIGETSTR
+
/**/
static int
bin_echoti(char *name, char **argv, char *ops, int func)
{
char *s, *t;
int num;
-
+
s = *argv++;
/* This depends on the termcap stuff in init.c */
if (termflags & TERM_BAD)
@@ -53,7 +55,7 @@
printf("%d\n", num);
return 0;
}
-
+
switch (tigetflag(s)) {
case -1:
break;
@@ -64,7 +66,7 @@
puts("yes");
return 0;
}
-
+
/* get a string-type capability */
t = (char *)tigetstr(s);
if (!t || t == (char *)-1 || !*t) {
@@ -72,11 +74,17 @@
zwarnnam(name, "no such terminfo capability: %s", s, 0);
return 1;
}
-
+
tputs(t, 1, putchar);
return 0;
}
+#else
+
+#define bin_echoti bin_notavail
+
+#endif
+
static struct builtin bintab[] = {
BUILTIN("echoti", 0, bin_echoti, 1, -1, 0, NULL, NULL),
};
@@ -85,6 +93,8 @@
static int incleanup;
+#ifdef HAVE_TIGETSTR
+
/* Empty dummy function for special hash parameters. */
/**/
@@ -101,19 +111,19 @@
{
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;
@@ -142,9 +152,9 @@
return NULL;
if ((termflags & TERM_UNKNOWN) && (isset(INTERACTIVE) || !init_term()))
return NULL;
-
+
unmetafy(name, &len);
-
+
pm = (Param) zhalloc(sizeof(struct param));
pm->nam = dupstring(name);
pm->flags = PM_READONLY;
@@ -156,7 +166,7 @@
pm->ename = NULL;
pm->old = NULL;
pm->level = 0;
-
+
if (((num = tigetnum(name)) != -1) && (num != -2)) {
pm->u.val = num;
pm->flags |= PM_INTEGER;
@@ -172,12 +182,11 @@
}
else
{
- zwarn("no such capability: %s", name, 0);
+ /* zwarn("no such capability: %s", name, 0); */
pm->u.str = dupstring("");
pm->flags |= PM_UNSET;
}
return (HashNode) pm;
-
}
/**/
@@ -186,12 +195,14 @@
{
}
+#endif /* HAVE_TIGETSTR */
+
/**/
int
setup_(Module m)
{
incleanup = 0;
-
+
return 0;
}
@@ -199,9 +210,13 @@
int
boot_(Module m)
{
+#ifdef HAVE_TIGETSTR
setupterm((char *)0, 1, (int *)0);
- return !createtihash() || !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
+ if (!createtihash())
+ return 1;
+#endif
+ return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
}
/**/
@@ -209,14 +224,16 @@
cleanup_(Module m)
{
Param pm;
-
+
incleanup = 1;
-
+
+#ifdef HAVE_TIGETSTR
if ((pm = (Param) paramtab->getnode(paramtab, terminfo_nam)) &&
pm == terminfo_pm) {
pm->flags &= ~PM_READONLY;
unsetparam_pm(pm, 0, 1);
}
+#endif
deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
return 0;
}
@@ -227,7 +244,3 @@
{
return 0;
}
-
-
-
-
Index: Src/Modules/terminfo.mdd
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/terminfo.mdd,v
retrieving revision 1.4
diff -u -r1.4 terminfo.mdd
--- Src/Modules/terminfo.mdd 2001/02/13 14:35:08 1.4
+++ Src/Modules/terminfo.mdd 2001/04/09 15:40:59
@@ -7,10 +7,15 @@
echo static
fi
else
+ echo either;
+ fi
+'
+load='if test "x$ac_cv_func_tigetstr" = xyes; then
+ echo yes;
+ else
echo no;
fi
'
-load=yes
autobins="echoti"
autoparams="terminfo"
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
Messages sorted by:
Reverse Date,
Date,
Thread,
Author