From: Thomas E. Dickey Date: Sat, 23 Jun 2012 00:36:11 +0000 (+0000) Subject: ncurses 5.9 - patch 20120622 X-Git-Tag: v6.0~149 X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=commitdiff_plain;h=c2ed42e6ca28e6c2703548274dc2a777be27f580 ncurses 5.9 - patch 20120622 + add -d, -e and -q options to test/demo_terminfo and test/demo_termcap + fix caching of environment variables in database-iterator (patch by Philippe Troin, Redhat #831366). --- diff --git a/NEWS b/NEWS index 0f2653ee..48e24617 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.1918 2012/06/16 19:19:48 tom Exp $ +-- $Id: NEWS,v 1.1919 2012/06/22 23:10:32 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. +20120622 + + add -d, -e and -q options to test/demo_terminfo and test/demo_termcap + + fix caching of environment variables in database-iterator (patch by + Philippe Troin, Redhat #831366). + 20120616 + add configure check to distinguish clang from gcc to eliminate warnings about unused command-line parameters when compiler warnings diff --git a/dist.mk b/dist.mk index c1ea2913..2214f3ec 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.878 2012/06/16 14:25:35 tom Exp $ +# $Id: dist.mk,v 1.879 2012/06/22 17:51:21 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 = 9 -NCURSES_PATCH = 20120616 +NCURSES_PATCH = 20120622 # We don't append the patch to the version, since this only applies to releases VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR) diff --git a/ncurses/tinfo/db_iterator.c b/ncurses/tinfo/db_iterator.c index 8af267bc..943104c5 100644 --- a/ncurses/tinfo/db_iterator.c +++ b/ncurses/tinfo/db_iterator.c @@ -43,7 +43,7 @@ #include #endif -MODULE_ID("$Id: db_iterator.c,v 1.31 2012/02/22 22:40:24 tom Exp $") +MODULE_ID("$Id: db_iterator.c,v 1.33 2012/06/23 00:16:58 tom Exp $") #define HaveTicDirectory _nc_globals.have_tic_directory #define KeepTicDirectory _nc_globals.keep_tic_directory @@ -96,10 +96,13 @@ static bool update_getenv(const char *name, DBDIRS which) { bool result = FALSE; - char *value = getenv(name); if (which < dbdLAST) { - if (my_vars[which].name == 0 || strcmp(my_vars[which].name, name)) { + char *value = getenv(name); + + if ((value = getenv(name)) == 0 || (value = strdup(value)) == 0) { + ; + } else if (my_vars[which].name == 0 || strcmp(my_vars[which].name, name)) { FreeIfNeeded(my_vars[which].value); my_vars[which].name = name; my_vars[which].value = value; @@ -112,6 +115,8 @@ update_getenv(const char *name, DBDIRS which) FreeIfNeeded(my_vars[which].value); my_vars[which].value = value; result = TRUE; + } else { + free(value); } } return result; @@ -240,6 +245,7 @@ _nc_next_db(DBDIRS * state, int *offset) NCURSES_EXPORT(void) _nc_first_db(DBDIRS * state, int *offset) { + bool cache_has_expired = FALSE; *state = dbdTIC; *offset = 0; @@ -248,12 +254,15 @@ _nc_first_db(DBDIRS * state, int *offset) /* build a blob containing all of the strings we will use for a lookup * table. */ - if (my_blob == 0) { + if (my_blob == 0 || (cache_has_expired = cache_expired())) { size_t blobsize = 0; const char *values[dbdLAST]; struct stat *my_stat; int j, k; + if (cache_has_expired) + free_cache(); + for (j = 0; j < dbdLAST; ++j) values[j] = 0; @@ -387,9 +396,16 @@ _nc_first_db(DBDIRS * state, int *offset) void _nc_db_iterator_leaks(void) { + DBDIRS which; + if (my_blob != 0) FreeAndNull(my_blob); if (my_list != 0) FreeAndNull(my_list); + for (which = 0; which < dbdLAST; ++which) { + my_vars[which].name = 0; + FreeIfNeeded(my_vars[which].value); + my_vars[which].value = 0; + } } #endif diff --git a/package/debian/changelog b/package/debian/changelog index 1d705629..c9a0f3dc 100644 --- a/package/debian/changelog +++ b/package/debian/changelog @@ -1,8 +1,8 @@ -ncurses6 (5.9-20120616) unstable; urgency=low +ncurses6 (5.9-20120622) unstable; urgency=low * latest weekly patch - -- Thomas E. Dickey Sat, 16 Jun 2012 18:00:23 -0400 + -- Thomas E. Dickey Fri, 22 Jun 2012 13:52:38 -0400 ncurses6 (5.9-20120608) unstable; urgency=low diff --git a/package/ncurses.spec b/package/ncurses.spec index eae73469..1d62fe5a 100644 --- a/package/ncurses.spec +++ b/package/ncurses.spec @@ -1,7 +1,7 @@ Summary: shared libraries for terminal handling Name: ncurses6 Release: 5.9 -Version: 20120616 +Version: 20120622 License: X11 Group: Development/Libraries Source: ncurses-%{release}-%{version}.tgz diff --git a/test/demo_termcap.c b/test/demo_termcap.c index b14454de..dc6da346 100644 --- a/test/demo_termcap.c +++ b/test/demo_termcap.c @@ -29,7 +29,7 @@ /* * Author: Thomas E. Dickey * - * $Id: demo_termcap.c,v 1.17 2012/03/01 01:09:30 tom Exp $ + * $Id: demo_termcap.c,v 1.20 2012/06/22 22:37:05 tom Exp $ * * A simple demo of the termcap interface. */ @@ -50,9 +50,17 @@ #if USE_CODE_LISTS static bool b_opt = FALSE; static bool n_opt = FALSE; +static bool q_opt = FALSE; static bool s_opt = FALSE; #endif +static char *d_opt; +static char *e_opt; +static char **db_list; +static int db_item; + +static long total_values; + #define isCapName(c) (isgraph(c) && strchr("^#=:\\", c) == 0) #if NO_LEAKS && USE_CODE_LISTS @@ -77,6 +85,77 @@ save_screen(void) #define save_screen() /* nothing */ #endif +static char * +make_dbitem(char *p, char *q) +{ + char *result = malloc(strlen(e_opt) + 2 + p - q); + sprintf(result, "%s=%.*s", e_opt, p - q, q); + return result; +} + +static void +make_dblist(void) +{ + if (d_opt && e_opt) { + int pass; + + for (pass = 0; pass < 2; ++pass) { + char *p, *q; + size_t count = 0; + + for (p = q = d_opt; *p != '\0'; ++p) { + if (*p == ':') { + if (p != q + 1) { + if (pass) { + db_list[count] = make_dbitem(p, q); + } + count++; + } + q = p + 1; + } + } + if (p != q + 1) { + if (pass) { + db_list[count] = make_dbitem(p, q); + } + count++; + } + if (!pass) { + db_list = typeCalloc(char *, count + 1); + } + } + } +} + +static char * +next_dbitem(void) +{ + char *result = 0; + + if (db_list) { + if ((result = db_list[db_item]) == 0) { + db_item = 0; + result = db_list[0]; + } else { + db_item++; + } + } + printf("** %s\n", result); + return result; +} + +static void +free_dblist(void) +{ + if (db_list) { + int n; + for (n = 0; db_list[n]; ++n) + free(db_list[n]); + free(db_list); + db_list = 0; + } +} + static void dumpit(NCURSES_CONST char *cap) { @@ -92,66 +171,77 @@ dumpit(NCURSES_CONST char *cap) int num; if ((str = tgetstr(cap, &ap)) != 0) { - /* - * 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; + total_values++; + if (!q_opt) { + /* + * 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"); } - printf("\n"); } else if ((num = tgetnum(cap)) >= 0) { - printf(FNAME(num), cap); - printf(" %d\n", num); + total_values++; + if (!q_opt) { + printf(FNAME(num), cap); + printf(" %d\n", num); + } } else if (tgetflag(cap) > 0) { - printf(FNAME(flg), cap); - printf("%s\n", "true"); + ++total_values; + if (!q_opt) { + printf(FNAME(flg), cap); + printf("%s\n", "true"); + } } - fflush(stdout); + + if (!q_opt) + fflush(stdout); } static void @@ -159,6 +249,9 @@ brute_force(const char *name) { char buffer[1024]; + if (db_list) { + putenv(next_dbitem()); + } printf("Terminal type %s\n", name); if (tgetent(buffer, name) >= 0) { char cap[3]; @@ -186,6 +279,9 @@ demo_termcap(NCURSES_CONST char *name) unsigned n; NCURSES_CONST char *cap; + if (db_list) { + putenv(next_dbitem()); + } printf("Terminal type \"%s\"\n", name); #if HAVE_SETUPTERM setupterm(name, 1, (int *) 0); @@ -235,7 +331,10 @@ usage(void) "Options:", " -a try all names, print capabilities found", " -b print boolean-capabilities", + " -d LIST colon-separated list of databases to use", + " -e NAME environment variable to set with -d option", " -n print numeric-capabilities", + " -q quiet (prints only counts)", " -r COUNT repeat for given count", " -s print string-capabilities", }; @@ -258,7 +357,7 @@ main(int argc, char *argv[]) int repeat; int r_opt = 1; - while ((n = getopt(argc, argv, "abnr:s")) != -1) { + while ((n = getopt(argc, argv, "abd:e:nqr:s")) != -1) { switch (n) { case 'a': a_opt = TRUE; @@ -266,9 +365,18 @@ main(int argc, char *argv[]) case 'b': b_opt = TRUE; break; + case 'd': + d_opt = optarg; + break; + case 'e': + e_opt = optarg; + break; case 'n': n_opt = TRUE; break; + case 'q': + q_opt = TRUE; + break; case 'r': if ((r_opt = atoi(optarg)) <= 0) usage(); @@ -291,6 +399,8 @@ main(int argc, char *argv[]) a_opt = TRUE; #endif + make_dblist(); + if (a_opt) { if (optind < argc) { for (n = optind; n < argc; ++n) { @@ -334,6 +444,10 @@ main(int argc, char *argv[]) } #endif /* USE_CODE_LISTS */ + printf("%ld values\n", total_values); + + free_dblist(); + ExitProgram(EXIT_SUCCESS); } @@ -343,6 +457,6 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) { printf("This program requires termcap\n"); - exit(EXIT_FAILURE); + ExitProgram(EXIT_FAILURE); } #endif diff --git a/test/demo_terminfo.c b/test/demo_terminfo.c index 2ee5b4c4..ebca898a 100644 --- a/test/demo_terminfo.c +++ b/test/demo_terminfo.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2009,2010 Free Software Foundation, Inc. * + * Copyright (c) 2009-2010,2012 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,7 +29,7 @@ /* * Author: Thomas E. Dickey * - * $Id: demo_terminfo.c,v 1.9 2010/11/28 00:15:27 tom Exp $ + * $Id: demo_terminfo.c,v 1.11 2012/06/22 23:04:03 tom Exp $ * * A simple demo of the terminfo interface. */ @@ -52,12 +52,90 @@ static bool b_opt = FALSE; static bool f_opt = FALSE; static bool n_opt = FALSE; +static bool q_opt = FALSE; static bool s_opt = FALSE; static bool x_opt = FALSE; +static char *d_opt; +static char *e_opt; +static char **db_list; +static int db_item; + +static long total_values; + #define FCOLS 8 #define FNAME(type) "%s %-*s = ", #type, FCOLS +static char * +make_dbitem(char *p, char *q) +{ + char *result = malloc(strlen(e_opt) + 2 + p - q); + sprintf(result, "%s=%.*s", e_opt, p - q, q); + return result; +} + +static void +make_dblist(void) +{ + if (d_opt && e_opt) { + int pass; + + for (pass = 0; pass < 2; ++pass) { + char *p, *q; + size_t count = 0; + + for (p = q = d_opt; *p != '\0'; ++p) { + if (*p == ':') { + if (p != q + 1) { + if (pass) { + db_list[count] = make_dbitem(p, q); + } + count++; + } + q = p + 1; + } + } + if (p != q + 1) { + if (pass) { + db_list[count] = make_dbitem(p, q); + } + count++; + } + if (!pass) { + db_list = typeCalloc(char *, count + 1); + } + } + } +} + +static char * +next_dbitem(void) +{ + char *result = 0; + + if (db_list) { + if ((result = db_list[db_item]) == 0) { + db_item = 0; + result = db_list[0]; + } else { + db_item++; + } + } + printf("** %s\n", result); + return result; +} + +static void +free_dblist(void) +{ + if (db_list) { + int n; + for (n = 0; db_list[n]; ++n) + free(db_list[n]); + free(db_list); + db_list = 0; + } +} static void dumpit(NCURSES_CONST char *cap) { @@ -72,66 +150,77 @@ dumpit(NCURSES_CONST char *cap) 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; + total_values++; + if (!q_opt) { + /* + * 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"); } - printf("\n"); } else if ((num = tigetnum(cap)) >= 0) { - printf(FNAME(num), cap); - printf(" %d\n", num); + total_values++; + if (!q_opt) { + printf(FNAME(num), cap); + printf(" %d\n", num); + } } else if ((num = tigetflag(cap)) >= 0) { - printf(FNAME(flg), cap); - printf("%s\n", num ? "true" : "false"); + total_values++; + if (!q_opt) { + printf(FNAME(flg), cap); + printf("%s\n", num ? "true" : "false"); + } } - fflush(stdout); + + if (!q_opt) + fflush(stdout); } static void @@ -140,6 +229,9 @@ demo_terminfo(char *name) unsigned n; NCURSES_CONST char *cap; + if (db_list) { + putenv(next_dbitem()); + } printf("Terminal type \"%s\"\n", name); setupterm(name, 1, (int *) 0); @@ -224,8 +316,11 @@ usage(void) "", "Options:", " -b print boolean-capabilities", + " -d LIST colon-separated list of databases to use", + " -e NAME environment variable to set with -d option", " -f print full names", " -n print numeric-capabilities", + " -q quiet (prints only counts)", " -r COUNT repeat for given count", " -s print string-capabilities", #ifdef NCURSES_VERSION @@ -247,17 +342,26 @@ main(int argc, char *argv[]) char *name; int r_opt = 1; - while ((n = getopt(argc, argv, "bfnr:sx")) != -1) { + while ((n = getopt(argc, argv, "bd:e:fnqr:sx")) != -1) { switch (n) { case 'b': b_opt = TRUE; break; + case 'd': + d_opt = optarg; + break; + case 'e': + e_opt = optarg; + break; case 'f': f_opt = TRUE; break; case 'n': n_opt = TRUE; break; + case 'q': + q_opt = TRUE; + break; case 'r': if ((r_opt = atoi(optarg)) <= 0) usage(); @@ -283,6 +387,8 @@ main(int argc, char *argv[]) s_opt = TRUE; } + make_dblist(); + for (repeat = 0; repeat < r_opt; ++repeat) { if (optind < argc) { for (n = optind; n < argc; ++n) { @@ -296,6 +402,10 @@ main(int argc, char *argv[]) } } + printf("%ld values\n", total_values); + + free_dblist(); + ExitProgram(EXIT_SUCCESS); }