X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fread_termcap.c;h=a5d5a2cd2939f5dbb50121d69de4dde3f0867d5e;hp=c6e7e358ad911b56106ab2cbe9188f156864635a;hb=55ccd2b959766810cf7db8d1c4462f338ce0afc8;hpb=46722468f47c2b77b3987729b4bcf2321cccfd01 diff --git a/ncurses/tinfo/read_termcap.c b/ncurses/tinfo/read_termcap.c index c6e7e358..a5d5a2cd 100644 --- a/ncurses/tinfo/read_termcap.c +++ b/ncurses/tinfo/read_termcap.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. * + * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1992,1995 * * and: Eric S. Raymond * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -57,11 +58,11 @@ #include #include -MODULE_ID("$Id: read_termcap.c,v 1.58 2001/10/28 01:11:34 tom Exp $") +MODULE_ID("$Id: read_termcap.c,v 1.67 2005/06/04 21:49:20 tom Exp $") #if !PURE_TERMINFO -#ifdef __EMX__ +#if defined(__EMX__) || defined(__DJGPP__) #define is_pathname(s) ((((s) != 0) && ((s)[0] == '/')) \ || (((s)[0] != 0) && ((s)[1] == ':'))) #else @@ -74,10 +75,10 @@ MODULE_ID("$Id: read_termcap.c,v 1.58 2001/10/28 01:11:34 tom Exp $") #define TC_SYS_ERR -3 #define TC_REF_LOOP -4 -static char * +static NCURSES_CONST char * get_termpath(void) { - char *result; + NCURSES_CONST char *result; if (!use_terminfo_vars() || (result = getenv("TERMPATH")) == 0) result = TERMPATH; @@ -720,7 +721,7 @@ get_tc_token(char **srcp, int *endp) if (*s == '\0') { break; } else if (*s++ == '\n') { - while (isspace(*s)) + while (isspace(UChar(*s))) s++; } else { found = TRUE; @@ -734,7 +735,7 @@ get_tc_token(char **srcp, int *endp) break; } base = s; - } else if (isgraph(ch)) { + } else if (isgraph(UChar(ch))) { found = TRUE; } } @@ -754,7 +755,7 @@ copy_tc_token(char *dst, const char *src, size_t len) while ((ch = *src++) != '\0') { if (ch == '\\' && *src == '\n') { - while (isspace(*src)) + while (isspace(UChar(*src))) src++; continue; } @@ -784,7 +785,7 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) char pathbuf[PBUFSIZ]; /* holds raw path of filenames */ char *pathvec[PVECSIZ]; /* to point to names in pathbuf */ char **pvec; /* holds usable tail of path vector */ - char *termpath; + NCURSES_CONST char *termpath; string_desc desc; fname = pathvec; @@ -932,7 +933,7 @@ add_tc(char *termpaths[], char *path, int count) #endif /* !USE_GETCAP */ NCURSES_EXPORT(int) -_nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp) +_nc_read_termcap_entry(const char *const tn, TERMTYPE *const tp) { int found = FALSE; ENTRY *ep; @@ -945,6 +946,15 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp) static int lineno; T(("read termcap entry for %s", tn)); + + if (strlen(tn) == 0 + || strcmp(tn, ".") == 0 + || strcmp(tn, "..") == 0 + || _nc_pathlast(tn) != 0) { + T(("illegal or missing entry name '%s'", tn)); + return 0; + } + if (use_terminfo_vars() && (p = getenv("TERMCAP")) != 0 && !is_pathname(p) && _nc_name_match(p, tn, "|:")) { /* TERMCAP holds a termcap entry */ @@ -1038,7 +1048,7 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp) * Probably /etc/termcap is a symlink to /usr/share/misc/termcap. * Avoid reading the same file twice. */ -#ifdef HAVE_LINK +#if HAVE_LINK for (j = 0; j < filecount; j++) { bool omit = FALSE; if (stat(termpaths[j], &test_stat[j]) != 0 @@ -1103,7 +1113,7 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp) return (ERR); /* resolve all use references */ - _nc_resolve_uses(TRUE); + _nc_resolve_uses2(TRUE, FALSE); /* find a terminal matching tn, if we can */ #if USE_GETCAP_CACHE @@ -1113,13 +1123,12 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp) for_entry_list(ep) { if (_nc_name_match(ep->tterm.term_names, tn, "|:")) { /* - * Make a local copy of the terminal capabilities. Free all - * entry storage except the string table for the loaded type - * (which we disconnected from the list by NULLing out - * ep->tterm.str_table above). + * Make a local copy of the terminal capabilities, delinked + * from the list. */ *tp = ep->tterm; - ep->tterm.str_table = (char *) 0; + _nc_delink_entry(_nc_head, &(ep->tterm)); + free(ep); /* * OK, now try to write the type to user's terminfo directory. @@ -1145,7 +1154,6 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp) } #endif - _nc_free_entries(_nc_head); return (found); } #else