Module Name: src Committed By: roy Date: Thu Feb 11 00:27:09 UTC 2010
Modified Files: src/lib/libterminfo: Makefile curterm.c setupterm.c term.c term.h term_private.h Log Message: Embed ansi, dumb, vt100, vt220 and wsvt25 compiled terminal descriptions into libterminfo. Constify some foo. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/lib/libterminfo/Makefile \ src/lib/libterminfo/term.c src/lib/libterminfo/term_private.h cvs rdiff -u -r1.1 -r1.2 src/lib/libterminfo/curterm.c \ src/lib/libterminfo/setupterm.c cvs rdiff -u -r1.3 -r1.4 src/lib/libterminfo/term.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libterminfo/Makefile diff -u src/lib/libterminfo/Makefile:1.4 src/lib/libterminfo/Makefile:1.5 --- src/lib/libterminfo/Makefile:1.4 Tue Feb 9 22:16:12 2010 +++ src/lib/libterminfo/Makefile Thu Feb 11 00:27:09 2010 @@ -1,17 +1,29 @@ -# $NetBSD: Makefile,v 1.4 2010/02/09 22:16:12 roy Exp $ +# $NetBSD: Makefile,v 1.5 2010/02/11 00:27:09 roy Exp $ USE_SHLIBDIR= yes LIB= terminfo WARNS= 4 -CPPFLAGS+= -I${.CURDIR} +CPPFLAGS+= -I${.CURDIR} -I${.OBJDIR} SRCS= term.c ti.c setupterm.c curterm.c tparm.c tputs.c SRCS+= hash.c INCS= term.h INCSDIR= /usr/include +.include <bsd.own.mk> + +rescue.c: ${NETBSDSRCDIR}/share/terminfo/terminfo + @echo "static const char *rescue_terms[] = {" >$@ + ${TOOL_TIC} -Sx ${NETBSDSRCDIR}/share/terminfo/terminfo \ + ansi dumb vt100 vt220 wsvt25 >>$@ + @echo " NULL," >>$@ + @echo " NULL" >>$@ + @echo "};" >>$@ + +term.c: rescue.c + MAN= terminfo.3 terminfo.5 MLINKS= terminfo.3 setupterm.3 \ terminfo.3 set_curterm.3 terminfo.3 del_curterm.3 \ @@ -46,7 +58,6 @@ gen: hash man -.include <bsd.own.mk> .include <bsd.shlib.mk> .if ${MKLINKLIB} != "no" Index: src/lib/libterminfo/term.c diff -u src/lib/libterminfo/term.c:1.4 src/lib/libterminfo/term.c:1.5 --- src/lib/libterminfo/term.c:1.4 Fri Feb 5 19:21:02 2010 +++ src/lib/libterminfo/term.c Thu Feb 11 00:27:09 2010 @@ -1,7 +1,7 @@ -/* $NetBSD: term.c,v 1.4 2010/02/05 19:21:02 roy Exp $ */ +/* $NetBSD: term.c,v 1.5 2010/02/11 00:27:09 roy Exp $ */ /* - * Copyright (c) 2009 The NetBSD Foundation, Inc. + * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc. * * This code is derived from software contributed to The NetBSD Foundation * by Roy Marples. @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: term.c,v 1.4 2010/02/05 19:21:02 roy Exp $"); +__RCSID("$NetBSD: term.c,v 1.5 2010/02/11 00:27:09 roy Exp $"); #include <sys/stat.h> @@ -45,14 +45,25 @@ #include <term.h> #define TERMINFO_DIRS "/usr/share/misc/terminfo" -#define TERMINFO_RESCUE "/rescue/terminfo" static char database[PATH_MAX]; static char pathbuf[PATH_MAX]; const char *_ti_database; +/* rescue.c is generated from /usr/src/share/terminfo/terminfo + * at build time as an array of strings. + * static const char *rescue_terms[] = { + * "ansi", + * "\002\005\000\141\156\163\151\000\000\000\043\000\141\156\163\151\057", + * NULL, + * NULL + * }; + */ + +#include "rescue.c" + static int -_ti_readterm(TERMINAL *term, char *cap, size_t caplen, int flags) +_ti_readterm(TERMINAL *term, const char *cap, size_t caplen, int flags) { uint8_t ver; uint16_t ind, num; @@ -76,10 +87,11 @@ term->strs = calloc(TISTRMAX + 1, sizeof(char *)); if (term->strs == NULL) goto err; - term->_area = malloc(caplen); + term->_arealen = caplen; + term->_area = malloc(term->_arealen); if (term->_area == NULL) goto err; - memcpy(term->_area, cap, caplen); + memcpy(term->_area, cap, term->_arealen); cap = term->_area; len = le16dec(cap); @@ -280,12 +292,14 @@ { int r; char *e, h[PATH_MAX]; + const char **p; _DIAGASSERT(term != NULL); _DIAGASSERT(name != NULL); database[0] = '\0'; _ti_database = NULL; + e = getenv("TERMINFO"); if (e != NULL) return _ti_dbgetterm(term, e, name, flags); @@ -302,12 +316,12 @@ if (r == 1) return 1; - /* If we don't find the term in the rescue db and there is - * no error, then report the last database accessed. */ - strlcpy(h, database, sizeof(h)); - r = _ti_dbgetterm(term, TERMINFO_RESCUE, name, flags); - if (r == 0 && h[0] != '\0') - strlcpy(database, h, sizeof(h)); + for (p = rescue_terms; *p != NULL; p++, p++) + if (strcmp(name, *p) == 0) { + r = _ti_readterm(term, *(p + 1), 4096, flags); + break; + } + return r; } Index: src/lib/libterminfo/term_private.h diff -u src/lib/libterminfo/term_private.h:1.4 src/lib/libterminfo/term_private.h:1.5 --- src/lib/libterminfo/term_private.h:1.4 Fri Feb 5 14:39:07 2010 +++ src/lib/libterminfo/term_private.h Thu Feb 11 00:27:09 2010 @@ -1,7 +1,7 @@ -/* $NetBSD: term_private.h,v 1.4 2010/02/05 14:39:07 he Exp $ */ +/* $NetBSD: term_private.h,v 1.5 2010/02/11 00:27:09 roy Exp $ */ /* - * Copyright (c) 2009 The NetBSD Foundation, Inc. + * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc. * * This code is derived from software contributed to The NetBSD Foundation * by Roy Marples. @@ -82,13 +82,14 @@ typedef struct terminal { int fildes; /* We need to expose these so that the macros work */ - char *name; - char *desc; + const char *name; + const char *desc; signed char *flags; short *nums; const char **strs; /* Storage area for terminfo data */ char *_area; + size_t _arealen; size_t _nuserdefs; TERMUSERDEF *_userdefs; /* So we don't rely on the global ospeed */ @@ -100,7 +101,7 @@ /* A-Z static variables for tparm */ long _snums[26]; /* aliases of the terminal, | separated */ - char *_alias; + const char *_alias; } TERMINAL; extern const char * _ti_database; Index: src/lib/libterminfo/curterm.c diff -u src/lib/libterminfo/curterm.c:1.1 src/lib/libterminfo/curterm.c:1.2 --- src/lib/libterminfo/curterm.c:1.1 Wed Feb 3 15:16:32 2010 +++ src/lib/libterminfo/curterm.c Thu Feb 11 00:27:09 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: curterm.c,v 1.1 2010/02/03 15:16:32 roy Exp $ */ +/* $NetBSD: curterm.c,v 1.2 2010/02/11 00:27:09 roy Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -28,14 +28,14 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: curterm.c,v 1.1 2010/02/03 15:16:32 roy Exp $"); +__RCSID("$NetBSD: curterm.c,v 1.2 2010/02/11 00:27:09 roy Exp $"); #include <assert.h> #include <stdlib.h> #include <term_private.h> #include <term.h> #include <termios.h> - +#include <stdio.h> TERMINAL *cur_term; static const speed_t bauds[] = { @@ -71,6 +71,7 @@ oterm = cur_term; cur_term = nterm; + printf ("%s\n", nterm->name); ospeed = 0; if (cur_term == NULL) PC = '\0'; Index: src/lib/libterminfo/setupterm.c diff -u src/lib/libterminfo/setupterm.c:1.1 src/lib/libterminfo/setupterm.c:1.2 --- src/lib/libterminfo/setupterm.c:1.1 Wed Feb 3 15:16:32 2010 +++ src/lib/libterminfo/setupterm.c Thu Feb 11 00:27:09 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: setupterm.c,v 1.1 2010/02/03 15:16:32 roy Exp $ */ +/* $NetBSD: setupterm.c,v 1.2 2010/02/11 00:27:09 roy Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: setupterm.c,v 1.1 2010/02/03 15:16:32 roy Exp $"); +__RCSID("$NetBSD: setupterm.c,v 1.2 2010/02/11 00:27:09 roy Exp $"); #include <assert.h> #include <err.h> @@ -69,8 +69,10 @@ if (term == NULL) term = getenv("TERM"); - if (term == NULL || *term == '\0') - reterr(-1, "TERM environment variable not set"); + if (term == NULL || *term == '\0') { + *nterm = NULL; + reterr(0, "TERM environment variable not set"); + } if (fildes == STDOUT_FILENO && !isatty(fildes)) fildes = STDERR_FILENO; Index: src/lib/libterminfo/term.h diff -u src/lib/libterminfo/term.h:1.3 src/lib/libterminfo/term.h:1.4 --- src/lib/libterminfo/term.h:1.3 Fri Feb 5 14:39:07 2010 +++ src/lib/libterminfo/term.h Thu Feb 11 00:27:09 2010 @@ -1,7 +1,7 @@ -/* $NetBSD: term.h,v 1.3 2010/02/05 14:39:07 he Exp $ */ +/* $NetBSD: term.h,v 1.4 2010/02/11 00:27:09 roy Exp $ */ /* - * Copyright (c) 2009 The NetBSD Foundation, Inc. + * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc. * * This code is derived from software contributed to The NetBSD Foundation * by Roy Marples. @@ -1452,10 +1452,10 @@ typedef struct terminal { int fildes; /* We need to expose these so that the macros work */ - char *name; - char *desc; - signed char *flags; - short *nums; + const char *name; + const char *desc; + const signed char *flags; + const short *nums; const char **strs; } TERMINAL; #endif