From: Thomas E. Dickey Date: Sat, 11 Jul 2009 23:12:47 +0000 (+0000) Subject: ncurses 5.7 - patch 20090711 X-Git-Tag: v5.8~83 X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=commitdiff_plain;h=ccb812c9ce7d5859d06b01ce88b331b2a70ad520;hp=5b7f4de105080e2a715b0564ede4bb7eb6767659 ncurses 5.7 - patch 20090711 + improve performance of tigetstr, etc., by using hashing code from tic. + minor fixes for memory-leak checking. + add test/demo_terminfo, for comparison with demo_termcap --- diff --git a/MANIFEST b/MANIFEST index 948dc803..b1e1b556 100644 --- a/MANIFEST +++ b/MANIFEST @@ -988,6 +988,7 @@ ./test/demo_menus.c ./test/demo_panels.c ./test/demo_termcap.c +./test/demo_terminfo.c ./test/ditto.c ./test/dots.c ./test/dots_mvcur.c diff --git a/NEWS b/NEWS index 8de73713..ef8e3f40 100644 --- a/NEWS +++ b/NEWS @@ -25,7 +25,7 @@ -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------- --- $Id: NEWS,v 1.1400 2009/07/04 22:12:46 tom Exp $ +-- $Id: NEWS,v 1.1403 2009/07/11 18:26:12 tom Exp $ ------------------------------------------------------------------------------- This is a log of changes that ncurses has gone through since Zeyd started @@ -45,6 +45,11 @@ See the AUTHORS file for the corresponding full names. Changes through 1.9.9e did not credit all contributions; it is not possible to add this information. +20090711 + + improve performance of tigetstr, etc., by using hashing code from tic. + + minor fixes for memory-leak checking. + + add test/demo_terminfo, for comparison with demo_termcap + 20090704 + remove wide-character checks from unctrl() (patch by Clemens Ladisch). + revise wadd_wch() and wecho_wchar() to eliminate dependency on diff --git a/dist.mk b/dist.mk index 79f76e23..cce5c94f 100644 --- a/dist.mk +++ b/dist.mk @@ -25,7 +25,7 @@ # use or other dealings in this Software without prior written # # authorization. # ############################################################################## -# $Id: dist.mk,v 1.707 2009/07/04 17:04:26 tom Exp $ +# $Id: dist.mk,v 1.708 2009/07/11 12:41:36 tom Exp $ # Makefile for creating ncurses distributions. # # This only needs to be used directly as a makefile by developers, but @@ -37,7 +37,7 @@ SHELL = /bin/sh # These define the major/minor/patch versions of ncurses. NCURSES_MAJOR = 5 NCURSES_MINOR = 7 -NCURSES_PATCH = 20090704 +NCURSES_PATCH = 20090711 # We don't append the patch to the version, since this only applies to releases VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR) diff --git a/include/term_entry.h b/include/term_entry.h index 7b034cf9..4770f865 100644 --- a/include/term_entry.h +++ b/include/term_entry.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc. * + * Copyright (c) 1998-2008,2009 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 * @@ -32,7 +32,7 @@ * and: Thomas E. Dickey 1998-on * ****************************************************************************/ -/* $Id: term_entry.h,v 1.36 2008/11/16 00:19:59 juergen Exp $ */ +/* $Id: term_entry.h,v 1.37 2009/07/11 16:52:29 tom Exp $ */ /* * term_entry.h -- interface to entry-manipulation code @@ -87,6 +87,12 @@ ENTRY; #define for_each_number(n,tp) for(n = 0; n < NUM_NUMBERS(tp); n++) #define for_each_string(n,tp) for(n = 0; n < NUM_STRINGS(tp); n++) +#if NCURSES_XNAMES +#define for_each_ext_boolean(n,tp) for(n = BOOLCOUNT; n < NUM_BOOLEANS(tp); n++) +#define for_each_ext_number(n,tp) for(n = NUMCOUNT; n < NUM_NUMBERS(tp); n++) +#define for_each_ext_string(n,tp) for(n = STRCOUNT; n < NUM_STRINGS(tp); n++) +#endif + #define ExtBoolname(tp,i,names) EXT_NAMES(tp, i, BOOLCOUNT, (i - (tp->num_Booleans - tp->ext_Booleans)), names) #define ExtNumname(tp,i,names) EXT_NAMES(tp, i, NUMCOUNT, (i - (tp->num_Numbers - tp->ext_Numbers)) + tp->ext_Booleans, names) #define ExtStrname(tp,i,names) EXT_NAMES(tp, i, STRCOUNT, (i - (tp->num_Strings - tp->ext_Strings)) + (tp->ext_Numbers + tp->ext_Booleans), names) diff --git a/include/tic.h b/include/tic.h index 4e103993..f91d771d 100644 --- a/include/tic.h +++ b/include/tic.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2009 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 * @@ -33,7 +33,7 @@ ****************************************************************************/ /* - * $Id: tic.h,v 1.62 2007/08/11 16:12:43 tom Exp $ + * $Id: tic.h,v 1.63 2009/07/11 18:11:15 tom Exp $ * tic.h - Global variables and structures for the terminfo * compiler. */ @@ -246,7 +246,7 @@ extern NCURSES_EXPORT(char *) _nc_rootname (char *); extern NCURSES_EXPORT(struct name_table_entry const *) _nc_find_entry (const char *, const short *); extern NCURSES_EXPORT(struct name_table_entry const *) _nc_find_type_entry - (const char *, int, const struct name_table_entry *); + (const char *, int, bool); /* comp_scan.c: lexical analysis */ extern NCURSES_EXPORT(int) _nc_get_token (bool); diff --git a/ncurses/modules b/ncurses/modules index f28ef81a..e4c96192 100644 --- a/ncurses/modules +++ b/ncurses/modules @@ -1,6 +1,6 @@ -# $Id: modules,v 1.112 2007/09/08 22:03:34 tom Exp $ +# $Id: modules,v 1.113 2009/07/11 17:45:32 tom Exp $ ############################################################################## -# Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. # +# Copyright (c) 1998-2007,2009 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 "Software"), # @@ -162,7 +162,9 @@ access lib $(tinfo) add_tries lib $(tinfo) alloc_ttype lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h codes lib . +comp_captab lib . $(INCDIR)/tic.h ../include/term.h ../include/hashsize.h comp_error lib $(tinfo) $(INCDIR)/tic.h +comp_hash lib $(tinfo) ../include/term.h $(INCDIR)/tic.h ../include/hashsize.h db_iterator lib $(tinfo) $(INCDIR)/tic.h doalloc lib $(tinfo) entries lib $(tinfo) ../include/term.h $(INCDIR)/tic.h @@ -212,9 +214,7 @@ visbuf lib $(trace) $(INCDIR)/tic.h @ ticlib alloc_entry lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h captoinfo lib $(tinfo) $(INCDIR)/tic.h -comp_captab lib . $(INCDIR)/tic.h ../include/term.h ../include/hashsize.h comp_expand lib $(tinfo) $(INCDIR)/tic.h -comp_hash lib $(tinfo) ../include/term.h $(INCDIR)/tic.h ../include/hashsize.h comp_parse lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h comp_scan lib $(tinfo) $(INCDIR)/tic.h parse_entry lib $(tinfo) ../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h ../include/parametrized.h $(INCDIR)/capdefaults.c diff --git a/ncurses/tinfo/comp_hash.c b/ncurses/tinfo/comp_hash.c index b7fbd061..96846bbe 100644 --- a/ncurses/tinfo/comp_hash.c +++ b/ncurses/tinfo/comp_hash.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * + * Copyright (c) 1998-2008,2009 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 * @@ -50,7 +50,7 @@ #define DEBUG(level, params) /*nothing */ #endif -MODULE_ID("$Id: comp_hash.c,v 1.36 2008/08/16 17:06:53 tom Exp $") +MODULE_ID("$Id: comp_hash.c,v 1.39 2009/07/11 18:27:26 tom Exp $") static int hash_function(const char *); @@ -131,6 +131,19 @@ hash_function(const char *string) */ #ifndef MAIN_PROGRAM + +#define SameName(a,b,termcap) (termcap ? !strncmp(a,b,2) : !strcmp(a,b)) +#if 0 +static bool +same_name(const char *a, const char *b, bool termcap) +{ + fprintf(stderr, "compare(%s,%s)\n", a, b); + return SameName(a, b, termcap); +} +#else +#define same_name(a,b,termcap) SameName(a,b,termcap) +#endif + NCURSES_EXPORT(struct name_table_entry const *) _nc_find_entry(const char *string, const short *hash_table) @@ -142,9 +155,11 @@ _nc_find_entry(const char *string, hashvalue = hash_function(string); if (hash_table[hashvalue] >= 0) { - real_table = _nc_get_table(hash_table != _nc_get_hash_table(FALSE)); + bool termcap = (hash_table != _nc_get_hash_table(FALSE)); + + real_table = _nc_get_table(termcap); ptr = real_table + hash_table[hashvalue]; - while (strcmp(ptr->nte_name, string) != 0) { + while (!same_name(ptr->nte_name, string, termcap)) { if (ptr->nte_link < 0) return 0; ptr = real_table + (ptr->nte_link + hash_table[HASHTABSIZE]); @@ -168,16 +183,21 @@ _nc_find_entry(const char *string, NCURSES_EXPORT(struct name_table_entry const *) _nc_find_type_entry(const char *string, int type, - const struct name_table_entry *table) + bool termcap) { + struct name_table_entry const *result = NULL; + const struct name_table_entry *const table = _nc_get_table(termcap); struct name_table_entry const *ptr; for (ptr = table; ptr < table + CAPTABSIZE; ptr++) { - if (ptr->nte_type == type && strcmp(string, ptr->nte_name) == 0) - return (ptr); + if (ptr->nte_type == type) { + if (same_name(ptr->nte_name, string, termcap)) { + result = ptr; + } + } } - return ((struct name_table_entry *) NULL); + return result; } #endif diff --git a/ncurses/tinfo/entries.c b/ncurses/tinfo/entries.c index 746d69a3..6433d9e8 100644 --- a/ncurses/tinfo/entries.c +++ b/ncurses/tinfo/entries.c @@ -38,7 +38,7 @@ #include #include -MODULE_ID("$Id: entries.c,v 1.12 2009/06/06 18:54:42 tom Exp $") +MODULE_ID("$Id: entries.c,v 1.15 2009/07/11 14:42:42 tom Exp $") /**************************************************************************** * @@ -121,8 +121,9 @@ _nc_leaks_tinfo(void) _nc_free_tparm(); _nc_tgetent_leaks(); - if (HasTerminal(CURRENT_SCREEN)) + if (TerminalOf(CURRENT_SCREEN) != 0) { del_curterm(TerminalOf(CURRENT_SCREEN)); + } _nc_free_entries(_nc_head); _nc_get_type(0); @@ -136,6 +137,12 @@ _nc_leaks_tinfo(void) if ((s = _nc_home_terminfo()) != 0) free(s); + +#ifdef TRACE + trace(0); + _nc_trace_buf(-1, 0); +#endif + #endif /* NO_LEAKS */ returnVoid; } diff --git a/ncurses/tinfo/lib_termcap.c b/ncurses/tinfo/lib_termcap.c index af4d8f84..064383db 100644 --- a/ncurses/tinfo/lib_termcap.c +++ b/ncurses/tinfo/lib_termcap.c @@ -50,7 +50,7 @@ #define CUR SP_TERMTYPE #endif -MODULE_ID("$Id: lib_termcap.c,v 1.67 2009/05/30 20:05:20 tom Exp $") +MODULE_ID("$Id: lib_termcap.c,v 1.69 2009/07/11 18:14:21 tom Exp $") NCURSES_EXPORT_VAR(char *) UP = 0; NCURSES_EXPORT_VAR(char *) BC = 0; @@ -202,6 +202,17 @@ tgetent(char *bufp, const char *name) } #endif +#if 0 +static bool +same_tcname(const char *a, const char *b) +{ + fprintf(stderr, "compare(%s,%s)\n", a, b); + return !strncmp(a, b, 2); +} +#else +#define same_tcname(a,b) !strncmp(a,b,2) +#endif + /*************************************************************************** * * tgetflag(str) @@ -214,20 +225,36 @@ tgetent(char *bufp, const char *name) NCURSES_EXPORT(int) NCURSES_SP_NAME(tgetflag) (NCURSES_SP_DCLx NCURSES_CONST char *id) { - unsigned i; + int result = 0; /* Solaris returns zero for missing flag */ + int i, j; T((T_CALLED("tgetflag(%p, %s)"), SP_PARM, id)); if (HasTInfoTerminal(SP_PARM)) { TERMTYPE *tp = &(TerminalOf(SP_PARM)->type); - for_each_boolean(i, tp) { - const char *capname = ExtBoolname(tp, i, boolcodes); - if (!strncmp(id, capname, 2)) { - /* setupterm forces invalid booleans to false */ - returnCode(tp->Booleans[i]); + struct name_table_entry const *entry_ptr; + + entry_ptr = _nc_find_type_entry(id, BOOLEAN, TRUE); + if (entry_ptr != 0) { + j = entry_ptr->nte_index; + } +#if NCURSES_XNAMES + else { + j = -1; + for_each_ext_boolean(i, tp) { + const char *capname = ExtBoolname(tp, i, boolcodes); + if (same_tcname(id, capname)) { + j = i; + break; + } } } +#endif + if (j >= 0) { + /* note: setupterm forces invalid booleans to false */ + result = tp->Booleans[j]; + } } - returnCode(0); /* Solaris does this */ + returnCode(result); } #if NCURSES_SP_FUNCS @@ -250,21 +277,36 @@ tgetflag(NCURSES_CONST char *id) NCURSES_EXPORT(int) NCURSES_SP_NAME(tgetnum) (NCURSES_SP_DCLx NCURSES_CONST char *id) { - unsigned i; + int result = ABSENT_NUMERIC; + int i, j; T((T_CALLED("tgetnum(%p, %s)"), SP_PARM, id)); if (HasTInfoTerminal(SP_PARM)) { TERMTYPE *tp = &(TerminalOf(SP_PARM)->type); - for_each_number(i, tp) { - const char *capname = ExtNumname(tp, i, numcodes); - if (!strncmp(id, capname, 2)) { - if (!VALID_NUMERIC(tp->Numbers[i])) - returnCode(ABSENT_NUMERIC); - returnCode(tp->Numbers[i]); + struct name_table_entry const *entry_ptr; + + entry_ptr = _nc_find_type_entry(id, NUMBER, TRUE); + if (entry_ptr != 0) { + j = entry_ptr->nte_index; + } +#if NCURSES_XNAMES + else { + j = -1; + for_each_ext_number(i, tp) { + const char *capname = ExtNumname(tp, i, numcodes); + if (same_tcname(id, capname)) { + j = i; + break; + } } } +#endif + if (j >= 0) { + if (VALID_NUMERIC(tp->Numbers[j])) + result = tp->Numbers[j]; + } } - returnCode(ABSENT_NUMERIC); + returnCode(result); } #if NCURSES_SP_FUNCS @@ -287,32 +329,46 @@ tgetnum(NCURSES_CONST char *id) NCURSES_EXPORT(char *) NCURSES_SP_NAME(tgetstr) (NCURSES_SP_DCLx NCURSES_CONST char *id, char **area) { - unsigned i; char *result = NULL; + int i, j; T((T_CALLED("tgetstr(%s,%p)"), id, area)); if (HasTInfoTerminal(SP_PARM)) { TERMTYPE *tp = &(TerminalOf(SP_PARM)->type); - for_each_string(i, tp) { - const char *capname = ExtStrname(tp, i, strcodes); - if (!strncmp(id, capname, 2)) { - result = tp->Strings[i]; - TR(TRACE_DATABASE, ("found match : %s", _nc_visbuf(result))); - /* setupterm forces canceled strings to null */ - if (VALID_STRING(result)) { - if (result == exit_attribute_mode - && FIX_SGR0 != 0) { - result = FIX_SGR0; - TR(TRACE_DATABASE, ("altered to : %s", _nc_visbuf(result))); - } - if (area != 0 - && *area != 0) { - (void) strcpy(*area, result); - result = *area; - *area += strlen(*area) + 1; - } + struct name_table_entry const *entry_ptr; + + entry_ptr = _nc_find_type_entry(id, STRING, TRUE); + if (entry_ptr != 0) { + j = entry_ptr->nte_index; + } +#if NCURSES_XNAMES + else { + j = -1; + for_each_ext_string(i, tp) { + const char *capname = ExtStrname(tp, i, strcodes); + if (same_tcname(id, capname)) { + j = i; + break; + } + } + } +#endif + if (j >= 0) { + result = tp->Strings[j]; + TR(TRACE_DATABASE, ("found match : %s", _nc_visbuf(result))); + /* setupterm forces canceled strings to null */ + if (VALID_STRING(result)) { + if (result == exit_attribute_mode + && FIX_SGR0 != 0) { + result = FIX_SGR0; + TR(TRACE_DATABASE, ("altered to : %s", _nc_visbuf(result))); + } + if (area != 0 + && *area != 0) { + (void) strcpy(*area, result); + result = *area; + *area += strlen(*area) + 1; } - break; } } } diff --git a/ncurses/tinfo/lib_ti.c b/ncurses/tinfo/lib_ti.c index 355310ec..76001d2c 100644 --- a/ncurses/tinfo/lib_ti.c +++ b/ncurses/tinfo/lib_ti.c @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1992,1995 * * and: Eric S. Raymond * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ #include @@ -36,27 +37,54 @@ #include #include -MODULE_ID("$Id: lib_ti.c,v 1.24 2009/04/18 17:37:50 tom Exp $") +MODULE_ID("$Id: lib_ti.c,v 1.26 2009/07/11 18:14:21 tom Exp $") + +#if 0 +static bool +same_name(const char *a, const char *b) +{ + fprintf(stderr, "compare(%s,%s)\n", a, b); + return !strcmp(a, b); +} +#else +#define same_name(a,b) !strcmp(a,b) +#endif NCURSES_EXPORT(int) NCURSES_SP_NAME(tigetflag) (NCURSES_SP_DCLx NCURSES_CONST char *str) { - unsigned i; + int result = ABSENT_BOOLEAN; + int i, j; T((T_CALLED("tigetflag(%p, %s)"), SP_PARM, str)); if (HasTInfoTerminal(SP_PARM)) { TERMTYPE *tp = &(TerminalOf(SP_PARM)->type); - for_each_boolean(i, tp) { - const char *capname = ExtBoolname(tp, i, boolnames); - if (!strcmp(str, capname)) { - /* setupterm forces invalid booleans to false */ - returnCode(tp->Booleans[i]); + struct name_table_entry const *entry_ptr; + + entry_ptr = _nc_find_type_entry(str, BOOLEAN, FALSE); + if (entry_ptr != 0) { + j = entry_ptr->nte_index; + } +#if NCURSES_XNAMES + else { + j = -1; + for_each_ext_boolean(i, tp) { + const char *capname = ExtBoolname(tp, i, boolnames); + if (same_name(str, capname)) { + j = i; + break; + } } } +#endif + if (j >= 0) { + /* note: setupterm forces invalid booleans to false */ + result = tp->Booleans[j]; + } } - returnCode(ABSENT_BOOLEAN); + returnCode(result); } #if NCURSES_SP_FUNCS @@ -70,23 +98,38 @@ tigetflag(NCURSES_CONST char *str) NCURSES_EXPORT(int) NCURSES_SP_NAME(tigetnum) (NCURSES_SP_DCLx NCURSES_CONST char *str) { - unsigned i; + int i, j; + int result = CANCELLED_NUMERIC; /* Solaris returns a -1 on error */ T((T_CALLED("tigetnum(%p, %s)"), SP_PARM, str)); if (HasTInfoTerminal(SP_PARM)) { TERMTYPE *tp = &(TerminalOf(SP_PARM)->type); - for_each_number(i, tp) { - const char *capname = ExtNumname(tp, i, numnames); - if (!strcmp(str, capname)) { - if (!VALID_NUMERIC(tp->Numbers[i])) - returnCode(ABSENT_NUMERIC); - returnCode(tp->Numbers[i]); + struct name_table_entry const *entry_ptr; + + entry_ptr = _nc_find_type_entry(str, NUMBER, FALSE); + if (entry_ptr != 0) { + j = entry_ptr->nte_index; + } +#if NCURSES_XNAMES + else { + j = -1; + for_each_ext_number(i, tp) { + const char *capname = ExtNumname(tp, i, numnames); + if (same_name(str, capname)) { + j = i; + break; + } } } +#endif + if (j >= 0 && VALID_NUMERIC(tp->Numbers[j])) + result = tp->Numbers[j]; + else + result = ABSENT_NUMERIC; } - returnCode(CANCELLED_NUMERIC); /* Solaris returns a -1 instead */ + returnCode(result); } #if NCURSES_SP_FUNCS @@ -100,22 +143,38 @@ tigetnum(NCURSES_CONST char *str) NCURSES_EXPORT(char *) NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx NCURSES_CONST char *str) { - unsigned i; + char *result = CANCELLED_STRING; + int i, j; T((T_CALLED("tigetstr(%p, %s)"), SP_PARM, str)); if (HasTInfoTerminal(SP_PARM)) { TERMTYPE *tp = &(TerminalOf(SP_PARM)->type); - for_each_string(i, tp) { - const char *capname = ExtStrname(tp, i, strnames); - if (!strcmp(str, capname)) { - /* setupterm forces cancelled strings to null */ - returnPtr(tp->Strings[i]); + struct name_table_entry const *entry_ptr; + + entry_ptr = _nc_find_type_entry(str, STRING, FALSE); + if (entry_ptr != 0) { + j = entry_ptr->nte_index; + } +#if NCURSES_XNAMES + else { + j = -1; + for_each_ext_string(i, tp) { + const char *capname = ExtStrname(tp, i, strnames); + if (same_name(str, capname)) { + j = i; + break; + } } } +#endif + if (j >= 0) { + /* note: setupterm forces cancelled strings to null */ + result = tp->Strings[j]; + } } - returnPtr(CANCELLED_STRING); + returnPtr(result); } #if NCURSES_SP_FUNCS diff --git a/ncurses/tinfo/parse_entry.c b/ncurses/tinfo/parse_entry.c index cfa7b356..6e59775b 100644 --- a/ncurses/tinfo/parse_entry.c +++ b/ncurses/tinfo/parse_entry.c @@ -48,7 +48,7 @@ #include #include -MODULE_ID("$Id: parse_entry.c,v 1.70 2009/04/18 21:01:38 tom Exp $") +MODULE_ID("$Id: parse_entry.c,v 1.71 2009/07/11 18:14:21 tom Exp $") #ifdef LINT static short const parametrized[] = @@ -383,16 +383,14 @@ _nc_parse_entry(struct entry *entryp, int literal, bool silent) && !strcmp("ma", _nc_curr_token.tk_name)) { /* tell max_attributes from arrow_key_map */ entry_ptr = _nc_find_type_entry("ma", NUMBER, - _nc_get_table(_nc_syntax - != 0)); + _nc_syntax != 0); assert(entry_ptr != 0); } else if (token_type == STRING && !strcmp("MT", _nc_curr_token.tk_name)) { /* map terminfo's string MT to MT */ entry_ptr = _nc_find_type_entry("MT", STRING, - _nc_get_table(_nc_syntax - != 0)); + _nc_syntax != 0); assert(entry_ptr != 0); } else if (token_type == BOOLEAN diff --git a/ncurses/trace/visbuf.c b/ncurses/trace/visbuf.c index bf9fb147..0b64ccc6 100644 --- a/ncurses/trace/visbuf.c +++ b/ncurses/trace/visbuf.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc. * + * Copyright (c) 2001-2008,2009 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 * @@ -42,7 +42,9 @@ #include #include -MODULE_ID("$Id: visbuf.c,v 1.32 2008/08/04 23:07:39 tom Exp $") +MODULE_ID("$Id: visbuf.c,v 1.33 2009/07/11 14:44:20 tom Exp $") + +#define NUM_VISBUFS 4 #define NormalLen(len) (size_t) (((size_t)(len) + 1) * 4) #define WideLen(len) (size_t) (((size_t)(len) + 1) * 4 * MB_CUR_MAX) @@ -108,9 +110,16 @@ _nc_visbuf2n(int bufnum, const char *buf, int len) vbuf = tp = _nc_trace_buf(bufnum, NormalLen(len)); #else { - static char *mybuf[4]; - mybuf[bufnum] = typeRealloc(char, NormalLen(len), mybuf[bufnum]); - vbuf = tp = mybuf[bufnum]; + static char *mybuf[NUM_VISBUFS]; + if (bufnum < 0) { + for (c = 0; c < NUM_VISBUFS; ++c) { + FreeAndNull(mybuf[c]); + } + tp = 0; + } else { + mybuf[bufnum] = typeRealloc(char, NormalLen(len), mybuf[bufnum]); + vbuf = tp = mybuf[bufnum]; + } } #endif if (tp != 0) { @@ -177,7 +186,7 @@ _nc_viswbuf2n(int bufnum, const wchar_t *buf, int len) vbuf = tp = _nc_trace_buf(bufnum, WideLen(len)); #else { - static char *mybuf[2]; + static char *mybuf[NUM_VISBUFS]; mybuf[bufnum] = typeRealloc(char, WideLen(len), mybuf[bufnum]); vbuf = tp = mybuf[bufnum]; } @@ -293,7 +302,8 @@ _nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len) PUTC_ch = buf[j].chars[PUTC_i]; if (PUTC_ch == L'\0') break; - PUTC_n = (int) wcrtomb(PUTC_buf, buf[j].chars[PUTC_i], &PUT_st); + PUTC_n = (int) wcrtomb(PUTC_buf, + buf[j].chars[PUTC_i], &PUT_st); if (PUTC_n <= 0) break; for (k = 0; k < PUTC_n; k++) { diff --git a/test/README b/test/README index ece475ab..0b21a49e 100644 --- a/test/README +++ b/test/README @@ -25,7 +25,7 @@ -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------- --- $Id: README,v 1.39 2008/12/20 23:38:13 tom Exp $ +-- $Id: README,v 1.40 2009/07/11 19:09:01 tom Exp $ ------------------------------------------------------------------------------- The programs in this directory are designed to test your newest toy :-) @@ -218,7 +218,7 @@ ESCDELAY test: test_opaque LINES test: cardfile demo_defkey demo_keyok demo_menus demo_panels ditto echochar edit_field firework hanoi hashtest inch_wide inchs ins_wide inserts lrtest movewindow ncurses newdemo rain savescreen tclock test_get_wstr test_getstr test_instr test_inwstr test_opaque testcurs view worm xmas PAIR_NUMBER test: ncurses PC lib: ncurses -SP lib: ncurses +SP lib: menu TABSIZE test: test_opaque UP - acs_map test: gdc ins_wide inserts knight movewindow ncurses newdemo testcurs @@ -247,8 +247,8 @@ bkgdset test: background ncurses testaddch bkgrnd test: ncurses bkgrndset test: ncurses boolcodes test: test_arrays progs: dump_entry -boolfnames test: test_arrays progs: dump_entry -boolnames test: test_arrays progs: dump_entry infocmp +boolfnames test: demo_terminfo test_arrays progs: dump_entry +boolnames test: demo_terminfo test_arrays progs: dump_entry infocmp border - border_set - box test: cardfile chgat clip_printw demo_forms demo_menus demo_panels ditto edit_field inch_wide inchs ins_wide insdelln inserts lrtest ncurses newdemo redraw test_get_wstr test_getstr test_instr test_inwstr test_opaque testcurs @@ -263,7 +263,7 @@ clrtoeol test: blue bs demo_altkeys demo_menus foldkeys hanoi hashtest movewin color_content test: ncurses color_set test: color_set ncurses copywin test: ncurses testcurs -cur_term test: dots dots_mvcur lrtest progs: clear tabs tput tset +cur_term test: demo_terminfo dots dots_mvcur lrtest progs: clear tabs tput tset curs_set test: echochar firework gdc hanoi lrtest ncurses newdemo rain savescreen tclock testcurs worm xmas curscr test: demo_panels edit_field knight lrtest ncurses savescreen tclock view curses_version test: ncurses progs: infocmp tic toe tput tset @@ -289,6 +289,7 @@ erasewchar - filter test: filter flash test: cardfile lrtest ncurses tclock testcurs flushinp test: ncurses newdemo testcurs +get_escdelay - get_wch - get_wstr test: test_get_wstr getattrs - @@ -470,8 +471,8 @@ noqiflush - noraw test: demo_forms demo_menus ncurses testcurs notimeout test: test_opaque numcodes test: test_arrays progs: dump_entry -numfnames test: test_arrays progs: dump_entry -numnames test: test_arrays progs: dump_entry infocmp +numfnames test: demo_terminfo test_arrays progs: dump_entry +numnames test: demo_terminfo test_arrays progs: dump_entry infocmp ospeed progs: tset overlay test: ncurses testcurs xmas overwrite test: ncurses savescreen @@ -509,7 +510,7 @@ set_tabsize test: test_opaque set_term lib: ncurses setcchar test: demo_panels ins_wide ncurses view setscrreg test: view -setupterm test: dots progs: clear tabs tput tset +setupterm test: demo_terminfo dots progs: clear tabs tput tset slk_attr - slk_attr_off - slk_attr_on - @@ -532,8 +533,8 @@ standout test: blue ncurses start_color test: background blue bs cardfile chgat clip_printw color_set demo_forms demo_menus demo_panels echochar filter firework gdc hanoi ins_wide insdelln inserts knight ncurses newdemo rain savescreen tclock testaddch testcurs view worm xmas stdscr test: bs chgat clip_printw demo_altkeys demo_forms demo_menus demo_panels ditto filter firework foldkeys gdc hanoi hashtest inch_wide inchs ins_wide insdelln inserts key_names keynames knight lrtest movewindow ncurses rain redraw savescreen tclock test_get_wstr test_getstr test_instr test_inwstr test_opaque testcurs testscanw view worm xmas strcodes test: test_arrays progs: dump_entry -strfnames test: test_arrays progs: dump_entry -strnames test: foldkeys test_arrays progs: dump_entry infocmp tic +strfnames test: demo_terminfo test_arrays progs: dump_entry +strnames test: demo_terminfo foldkeys test_arrays progs: dump_entry infocmp tic subpad test: testcurs subwin test: movewindow ncurses newdemo testcurs syncok test: test_opaque @@ -545,9 +546,9 @@ tgetflag test: demo_termcap tgetnum test: demo_termcap railroad tgetstr test: demo_termcap railroad tgoto test: railroad -tigetflag progs: tput -tigetnum test: ncurses progs: tput -tigetstr test: blue demo_defkey foldkeys testcurs progs: tput +tigetflag test: demo_terminfo progs: tput +tigetnum test: demo_terminfo ncurses progs: tput +tigetstr test: blue demo_defkey demo_terminfo foldkeys testcurs progs: tput timeout test: rain savescreen touchline test: chgat clip_printw insdelln touchwin test: chgat clip_printw demo_menus edit_field filter firstlast inch_wide inchs ins_wide insdelln inserts movewindow ncurses redraw test_get_wstr test_getstr test_instr test_inwstr test_opaque xmas @@ -563,7 +564,7 @@ ungetmouse - untouchwin lib: form use_default_colors test: filter firework gdc hanoi knight ncurses rain tclock worm xmas use_env progs: tput -use_extended_names progs: infocmp tic +use_extended_names test: demo_terminfo progs: infocmp tic use_legacy_coding - use_screen test: ditto use_window test: rain worm diff --git a/test/demo_terminfo.c b/test/demo_terminfo.c new file mode 100644 index 00000000..d045fb75 --- /dev/null +++ b/test/demo_terminfo.c @@ -0,0 +1,293 @@ +/**************************************************************************** + * Copyright (c) 2009 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 * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/* + * Author: Thomas E. Dickey + * + * $Id: demo_terminfo.c,v 1.5 2009/07/11 17:39:41 tom Exp $ + * + * A simple demo of the terminfo interface. + */ +#define USE_TINFO +#include + +#ifdef NCURSES_VERSION +#if NCURSES_XNAMES +#include +#endif +#endif + +static bool b_opt = FALSE; +static bool f_opt = FALSE; +static bool n_opt = FALSE; +static bool s_opt = FALSE; +static bool x_opt = FALSE; + +#define FCOLS 8 +#define FNAME(type) "%s %-*s = ", #type, FCOLS + +static void +dumpit(NCURSES_CONST char *cap) +{ + /* + * One of the limitations of the termcap interface is that the library + * cannot determine the size of the buffer passed via tgetstr(), nor the + * amount of space remaining. This demo simply reuses the whole buffer + * for each call; a normal termcap application would try to use the buffer + * to hold all of the strings extracted from the terminal entry. + */ + const char *str; + int num; + + if ((str = tigetstr(cap)) != 0 && (str != (char *) -1)) { + /* + * Note that the strings returned are mostly terminfo format, since + * ncurses does not convert except for a handful of special cases. + */ + printf(FNAME(str), cap); + while (*str != 0) { + int ch = UChar(*str++); + switch (ch) { + case '\177': + fputs("^?", stdout); + break; + case '\033': + fputs("\\E", stdout); + break; + case '\b': + fputs("\\b", stdout); + break; + case '\f': + fputs("\\f", stdout); + break; + case '\n': + fputs("\\n", stdout); + break; + case '\r': + fputs("\\r", stdout); + break; + case ' ': + fputs("\\s", stdout); + break; + case '\t': + fputs("\\t", stdout); + break; + case '^': + fputs("\\^", stdout); + break; + case ':': + fputs("\\072", stdout); + break; + case '\\': + fputs("\\\\", stdout); + break; + default: + if (isgraph(ch)) + fputc(ch, stdout); + else if (ch < 32) + printf("^%c", ch + '@'); + else + printf("\\%03o", ch); + break; + } + } + printf("\n"); + } else if ((num = tigetnum(cap)) >= 0) { + printf(FNAME(num), cap); + printf(" %d\n", num); + } else if ((num = tigetflag(cap)) >= 0) { + printf(FNAME(flg), cap); + printf("%s\n", num ? "true" : "false"); + } + fflush(stdout); +} + +static void +demo_terminfo(char *name) +{ + unsigned n; + NCURSES_CONST char *cap; + + printf("Terminal type \"%s\"\n", name); + setupterm(name, 1, (int *) 0); + + if (b_opt) { + for (n = 0;; ++n) { + cap = f_opt ? boolfnames[n] : boolnames[n]; + if (cap == 0) + break; + dumpit(cap); + } + } + + if (n_opt) { + for (n = 0;; ++n) { + cap = f_opt ? numfnames[n] : numnames[n]; + if (cap == 0) + break; + dumpit(cap); + } + } + + if (s_opt) { + for (n = 0;; ++n) { + cap = f_opt ? strfnames[n] : strnames[n]; + if (cap == 0) + break; + dumpit(cap); + } + } +#ifdef NCURSES_VERSION + if (x_opt) { + int mod; + if (f_opt) { +#if NCURSES_XNAMES + TERMTYPE *term = &(cur_term->type); + if (term != 0 + && ((NUM_BOOLEANS(term) != BOOLCOUNT) + || (NUM_NUMBERS(term) != NUMCOUNT) + || (NUM_STRINGS(term) != STRCOUNT))) { + for (n = BOOLCOUNT; n < NUM_BOOLEANS(term); ++n) { + dumpit(ExtBoolname(term, n, boolnames)); + } + for (n = NUMCOUNT; n < NUM_NUMBERS(term); ++n) { + dumpit(ExtNumname(term, n, numnames)); + } + for (n = STRCOUNT; n < NUM_STRINGS(term); ++n) { + dumpit(ExtStrname(term, n, strnames)); + } + } +#endif + } else { + char temp[10]; + static const char *xterm_keys[] = + { + "kDC", "kDN", "kEND", "kHOM", "kIC", + "kLFT", "kNXT", "kPRV", "kRIT", "kUP", + }; + for (n = 0; n < SIZEOF(xterm_keys); ++n) { + for (mod = 0; mod < 8; ++mod) { + if (mod == 0) + strcpy(temp, xterm_keys[n]); + else + sprintf(temp, "%s%d", xterm_keys[n], mod); + dumpit(temp); + } + } + } + } +#endif + +} + +static void +usage(void) +{ + static const char *msg[] = + { + "Usage: demo_terminfo [options] [terminal]", + "", + "If no options are given, print all (boolean, numeric, string)", + "capabilities for the given terminal, using short names.", + "", + "Options:", + " -b print boolean-capabilities", + " -f print full names", + " -n print numeric-capabilities", + " -r COUNT repeat for given count", + " -s print string-capabilities", +#ifdef NCURSES_VERSION + " -x print extended capabilities", +#endif + }; + unsigned n; + for (n = 0; n < SIZEOF(msg); ++n) { + fprintf(stderr, "%s\n", msg[n]); + } + ExitProgram(EXIT_FAILURE); +} + +int +main(int argc, char *argv[]) +{ + int n; + int repeat; + char *name; + int r_opt = 1; + + while ((n = getopt(argc, argv, "bfnr:sx")) != -1) { + switch (n) { + case 'b': + b_opt = TRUE; + break; + case 'f': + f_opt = TRUE; + break; + case 'n': + n_opt = TRUE; + break; + case 'r': + if ((r_opt = atoi(optarg)) <= 0) + usage(); + break; + case 's': + s_opt = TRUE; + break; +#ifdef NCURSES_VERSION + case 'x': + x_opt = TRUE; + use_extended_names(TRUE); + break; +#endif + default: + usage(); + break; + } + } + + if (!(b_opt || n_opt || s_opt || x_opt)) { + b_opt = TRUE; + n_opt = TRUE; + s_opt = TRUE; + } + + for (repeat = 0; repeat < r_opt; ++repeat) { + if (optind < argc) { + for (n = optind; n < argc; ++n) { + demo_terminfo(argv[n]); + } + } else if ((name = getenv("TERM")) != 0) { + demo_terminfo(name); + } else { + static char dumb[] = "dumb"; + demo_terminfo(dumb); + } + } + + ExitProgram(EXIT_SUCCESS); +} diff --git a/test/modules b/test/modules index 8e97e8be..08a2f71f 100644 --- a/test/modules +++ b/test/modules @@ -1,6 +1,6 @@ -# $Id: modules,v 1.37 2008/12/20 21:38:44 tom Exp $ +# $Id: modules,v 1.38 2009/07/11 12:43:09 tom Exp $ ############################################################################## -# Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. # +# Copyright (c) 1998-2008,2009 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 "Software"), # @@ -46,6 +46,7 @@ demo_keyok progs $(srcdir) $(HEADER_DEPS) demo_menus progs $(srcdir) $(HEADER_DEPS) ../include/menu.h demo_panels progs $(srcdir) $(HEADER_DEPS) ../include/panel.h demo_termcap progs $(srcdir) $(HEADER_DEPS) +demo_terminfo progs $(srcdir) $(HEADER_DEPS) ditto progs $(srcdir) $(HEADER_DEPS) dots progs $(srcdir) $(HEADER_DEPS) dots_mvcur progs $(srcdir) $(HEADER_DEPS) diff --git a/test/programs b/test/programs index f6bca34e..2ebf4ed0 100644 --- a/test/programs +++ b/test/programs @@ -1,6 +1,6 @@ -# $Id: programs,v 1.15 2008/12/20 21:38:44 tom Exp $ +# $Id: programs,v 1.16 2009/07/11 12:47:15 tom Exp $ ############################################################################## -# Copyright (c) 2006-2007,2008 Free Software Foundation, Inc. # +# Copyright (c) 2006-2008,2009 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 "Software"), # @@ -44,6 +44,7 @@ demo_keyok $(LDFLAGS_CURSES) $(LOCAL_LIBS) demo_keyok demo_menus $(LDFLAGS_DEFAULT) $(LOCAL_LIBS) demo_menus demo_panels $(LDFLAGS_DEFAULT) $(LOCAL_LIBS) demo_panels demo_termcap $(LDFLAGS_TINFO) $(LOCAL_LIBS) demo_termcap +demo_terminfo $(LDFLAGS_TINFO) $(LOCAL_LIBS) demo_terminfo ditto $(LDFLAGS_THREADS) $(LOCAL_LIBS) ditto dots $(LDFLAGS_TINFO) $(LOCAL_LIBS) dots dots_mvcur $(LDFLAGS_CURSES) $(LOCAL_LIBS) dots_mvcur