1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-11 13:01:28 +02:00

13227: terminfo module fixes

This commit is contained in:
Clint Adams 2000-12-05 00:28:40 +00:00
parent cfe1038ff1
commit 5d7a9e949b
4 changed files with 67 additions and 50 deletions

View file

@ -1,3 +1,12 @@
2000-12-04 Clint Adams <schizo@debian.org>
* 13227: configure.in, Src/Modules/terminfo.c,
Src/Modules/terminfo.mdd: do not build terminfo
module if tigetstr() is not found in the same library
as tgetent(), indentation fix, use tputs() in echoti
builtin for outputting string capabilities, use
setupterm() for module boot.
2000-12-04 Peter Stephenson <pws@csr.com> 2000-12-04 Peter Stephenson <pws@csr.com>
* 13226: configure.in, Config/defs.mk, Config/installfns.sh, * 13226: configure.in, Config/defs.mk, Config/installfns.sh,

View file

@ -39,46 +39,47 @@ static Param terminfo_pm;
int int
bin_echoti(char *name, char **argv, char *ops, int func) bin_echoti(char *name, char **argv, char *ops, int func)
{ {
char *s, buf[2048], *t, *u; char *s, *t;
int num, argct; int num;
s = *argv++; s = *argv++;
/* This depends on the termcap stuff in init.c */
if (termflags & TERM_BAD) if (termflags & TERM_BAD)
return 1; return 1;
if ((termflags & TERM_UNKNOWN) && (isset(INTERACTIVE) || !init_term())) if ((termflags & TERM_UNKNOWN) && (isset(INTERACTIVE) || !init_term()))
return 1; return 1;
/* if the specified capability has a numeric value, display it */ /* if the specified capability has a numeric value, display it */
if (((num = tigetnum(s)) != -1) && (num != -2)) { if (((num = tigetnum(s)) != -1) && (num != -2)) {
printf("%d\n", num); 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 = (char *)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;
}
tputs(t, 1, putchar);
return 0; 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[] = { static struct builtin bintab[] = {
BUILTIN("echoti", 0, bin_echoti, 1, -1, 0, NULL, NULL), BUILTIN("echoti", 0, bin_echoti, 1, -1, 0, NULL, NULL),
}; };
/* This says if we are cleaning up when the module is unloaded. */ /* This says if we are cleaning up when the module is unloaded. */
@ -100,7 +101,7 @@ createtihash()
{ {
Param pm; Param pm;
HashTable ht; HashTable ht;
unsetparam(terminfo_nam); unsetparam(terminfo_nam);
if (!(pm = createparam(terminfo_nam, PM_SPECIAL|PM_HIDE|PM_HIDEVAL| if (!(pm = createparam(terminfo_nam, PM_SPECIAL|PM_HIDE|PM_HIDEVAL|
@ -136,13 +137,14 @@ getterminfo(HashTable ht, char *name)
char *tistr; char *tistr;
Param pm = NULL; Param pm = NULL;
/* This depends on the termcap stuff in init.c */
if (termflags & TERM_BAD) if (termflags & TERM_BAD)
return 1; return NULL;
if ((termflags & TERM_UNKNOWN) && (isset(INTERACTIVE) || !init_term())) if ((termflags & TERM_UNKNOWN) && (isset(INTERACTIVE) || !init_term()))
return 1; return NULL;
unmetafy(name, &len); unmetafy(name, &len);
pm = (Param) zhalloc(sizeof(struct param)); pm = (Param) zhalloc(sizeof(struct param));
pm->nam = dupstring(name); pm->nam = dupstring(name);
pm->flags = PM_READONLY; pm->flags = PM_READONLY;
@ -154,7 +156,7 @@ getterminfo(HashTable ht, char *name)
pm->ename = NULL; pm->ename = NULL;
pm->old = NULL; pm->old = NULL;
pm->level = 0; pm->level = 0;
if (((num = tigetnum(name)) != -1) && (num != -2)) { if (((num = tigetnum(name)) != -1) && (num != -2)) {
pm->u.val = num; pm->u.val = num;
pm->flags |= PM_INTEGER; pm->flags |= PM_INTEGER;
@ -163,26 +165,25 @@ getterminfo(HashTable ht, char *name)
pm->u.str = num ? dupstring("yes") : dupstring("no"); pm->u.str = num ? dupstring("yes") : dupstring("no");
pm->flags |= PM_SCALAR; pm->flags |= PM_SCALAR;
} }
else if ((tistr = tigetstr(name)) != NULL) else if ((tistr = (char *)tigetstr(name)) != NULL)
{ {
pm->u.str = dupstring(tistr); pm->u.str = dupstring(tistr);
pm->flags |= PM_SCALAR; pm->flags |= PM_SCALAR;
} }
else else
{ {
zwarn("no such capability: %s", name, 0); zwarn("no such capability: %s", name, 0);
pm->u.str = dupstring(""); pm->u.str = dupstring("");
pm->flags |= PM_UNSET; pm->flags |= PM_UNSET;
} }
return (HashNode) pm; return (HashNode) pm;
} }
/**/ /**/
static void static void
scanterminfo(HashTable ht, ScanFunc func, int flags) scanterminfo(HashTable ht, ScanFunc func, int flags)
{ {
return 0;
} }
/**/ /**/
@ -190,7 +191,7 @@ int
setup_(Module m) setup_(Module m)
{ {
incleanup = 0; incleanup = 0;
return 0; return 0;
} }
@ -198,6 +199,8 @@ setup_(Module m)
int int
boot_(Module m) boot_(Module m)
{ {
setupterm((char *)0, 1, (int *)0);
return !createtihash() || !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); return !createtihash() || !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
} }
@ -206,14 +209,14 @@ int
cleanup_(Module m) cleanup_(Module m)
{ {
Param pm; Param pm;
incleanup = 1; incleanup = 1;
if ((pm = (Param) paramtab->getnode(paramtab, terminfo_nam)) && if ((pm = (Param) paramtab->getnode(paramtab, terminfo_nam)) &&
pm == terminfo_pm) { pm == terminfo_pm) {
pm->flags &= ~PM_READONLY; pm->flags &= ~PM_READONLY;
unsetparam_pm(pm, 0, 1); unsetparam_pm(pm, 0, 1);
} }
deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
return 0; return 0;
} }
@ -224,3 +227,7 @@ finish_(Module m)
{ {
return 0; return 0;
} }

View file

@ -1,5 +1,5 @@
name=zsh/terminfo name=zsh/terminfo
link=either link=`if test "x$ac_cv_have_tigetstr" = xyes; then echo either; else echo no; fi`
load=yes load=yes
autobins="echoti" autobins="echoti"

View file

@ -848,7 +848,8 @@ AC_CHECK_FUNCS(strftime difftime gettimeofday \
signgam \ signgam \
putenv getenv \ putenv getenv \
brk sbrk \ brk sbrk \
pathconf sysconf) pathconf sysconf \
tigetflag tigetnum tigetstr)
AC_FUNC_STRCOLL AC_FUNC_STRCOLL
AC_FUNC_MMAP AC_FUNC_MMAP