]> ncurses.scripts.mit.edu Git - ncurses.git/commitdiff
ncurses 5.9 - patch 20120622
authorThomas E. Dickey <dickey@invisible-island.net>
Sat, 23 Jun 2012 00:36:11 +0000 (00:36 +0000)
committerThomas E. Dickey <dickey@invisible-island.net>
Sat, 23 Jun 2012 00:36:11 +0000 (00:36 +0000)
+ 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).

NEWS
dist.mk
ncurses/tinfo/db_iterator.c
package/debian/changelog
package/ncurses.spec
test/demo_termcap.c
test/demo_terminfo.c

diff --git a/NEWS b/NEWS
index 0f2653eea9f8c461eb084269070ffe0f03d0f434..48e246172cded45d5705d10c5d6ab9c753c6863a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -25,7 +25,7 @@
 -- sale, use or other dealings in this Software without prior written        --
 -- authorization.                                                            --
 -------------------------------------------------------------------------------
 -- 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
 -------------------------------------------------------------------------------
 
 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.
 
 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
 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 c1ea291304725ac7a72f79c3a50ece2b0a24e6f6..2214f3ec1f4cc545ee48d8c8bb3ceb855c0fc2f0 100644 (file)
--- a/dist.mk
+++ b/dist.mk
@@ -25,7 +25,7 @@
 # use or other dealings in this Software without prior written               #
 # authorization.                                                             #
 ##############################################################################
 # 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
 # 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
 # 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)
 
 # We don't append the patch to the version, since this only applies to releases
 VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR)
index 8af267bcb8559fb504b0be2f62692744b58f4dd6..943104c5dc0f6e6c0d10baf4fd67b260e3dbd8d5 100644 (file)
@@ -43,7 +43,7 @@
 #include <hashed_db.h>
 #endif
 
 #include <hashed_db.h>
 #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
 
 #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;
 update_getenv(const char *name, DBDIRS which)
 {
     bool result = FALSE;
-    char *value = getenv(name);
 
     if (which < dbdLAST) {
 
     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;
            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;
            FreeIfNeeded(my_vars[which].value);
            my_vars[which].value = value;
            result = TRUE;
+       } else {
+           free(value);
        }
     }
     return result;
        }
     }
     return result;
@@ -240,6 +245,7 @@ _nc_next_db(DBDIRS * state, int *offset)
 NCURSES_EXPORT(void)
 _nc_first_db(DBDIRS * state, int *offset)
 {
 NCURSES_EXPORT(void)
 _nc_first_db(DBDIRS * state, int *offset)
 {
+    bool cache_has_expired = FALSE;
     *state = dbdTIC;
     *offset = 0;
 
     *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.
      */
     /* 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;
 
        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;
 
        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)
 {
 void
 _nc_db_iterator_leaks(void)
 {
+    DBDIRS which;
+
     if (my_blob != 0)
        FreeAndNull(my_blob);
     if (my_list != 0)
        FreeAndNull(my_list);
     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
 }
 #endif
index 1d7056299d655f276a10a3634aa1c7e0464d9d19..c9a0f3dc84ab9aa16a81e06da737123872157e5d 100644 (file)
@@ -1,8 +1,8 @@
-ncurses6 (5.9-20120616) unstable; urgency=low
+ncurses6 (5.9-20120622) unstable; urgency=low
 
   * latest weekly patch
 
 
   * latest weekly patch
 
- -- Thomas E. Dickey <dickey@invisible-island.net>  Sat, 16 Jun 2012 18:00:23 -0400
+ -- Thomas E. Dickey <dickey@invisible-island.net>  Fri, 22 Jun 2012 13:52:38 -0400
 
 ncurses6 (5.9-20120608) unstable; urgency=low
 
 
 ncurses6 (5.9-20120608) unstable; urgency=low
 
index eae7346973530bb13816fed97cc6ba521d90ab55..1d62fe5aee593de08fdd4fecf9b83f68b6cc8cd7 100644 (file)
@@ -1,7 +1,7 @@
 Summary: shared libraries for terminal handling
 Name: ncurses6
 Release: 5.9
 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
 License: X11
 Group: Development/Libraries
 Source: ncurses-%{release}-%{version}.tgz
index b14454de0249eed9ec18f660b7975e26770a457a..dc6da3463e81392d360a916ec1d5bd690bc00eb8 100644 (file)
@@ -29,7 +29,7 @@
 /*
  * Author: Thomas E. Dickey
  *
 /*
  * 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.
  */
  *
  * A simple demo of the termcap interface.
  */
 #if USE_CODE_LISTS
 static bool b_opt = FALSE;
 static bool n_opt = FALSE;
 #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 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
 #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
 
 #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)
 {
 static void
 dumpit(NCURSES_CONST char *cap)
 {
@@ -92,66 +171,77 @@ dumpit(NCURSES_CONST char *cap)
     int num;
 
     if ((str = tgetstr(cap, &ap)) != 0) {
     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) {
     } 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) {
     } 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
 }
 
 static void
@@ -159,6 +249,9 @@ brute_force(const char *name)
 {
     char buffer[1024];
 
 {
     char buffer[1024];
 
+    if (db_list) {
+       putenv(next_dbitem());
+    }
     printf("Terminal type %s\n", name);
     if (tgetent(buffer, name) >= 0) {
        char cap[3];
     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;
 
     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);
     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",
        "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",
        " -n       print numeric-capabilities",
+       " -q       quiet (prints only counts)",
        " -r COUNT repeat for given count",
        " -s       print string-capabilities",
     };
        " -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;
 
     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;
        switch (n) {
        case 'a':
            a_opt = TRUE;
@@ -266,9 +365,18 @@ main(int argc, char *argv[])
        case 'b':
            b_opt = TRUE;
            break;
        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 'n':
            n_opt = TRUE;
            break;
+       case 'q':
+           q_opt = TRUE;
+           break;
        case 'r':
            if ((r_opt = atoi(optarg)) <= 0)
                usage();
        case 'r':
            if ((r_opt = atoi(optarg)) <= 0)
                usage();
@@ -291,6 +399,8 @@ main(int argc, char *argv[])
     a_opt = TRUE;
 #endif
 
     a_opt = TRUE;
 #endif
 
+    make_dblist();
+
     if (a_opt) {
        if (optind < argc) {
            for (n = optind; n < argc; ++n) {
     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 */
 
     }
 #endif /* USE_CODE_LISTS */
 
+    printf("%ld values\n", total_values);
+
+    free_dblist();
+
     ExitProgram(EXIT_SUCCESS);
 }
 
     ExitProgram(EXIT_SUCCESS);
 }
 
@@ -343,6 +457,6 @@ main(int argc GCC_UNUSED,
      char *argv[]GCC_UNUSED)
 {
     printf("This program requires termcap\n");
      char *argv[]GCC_UNUSED)
 {
     printf("This program requires termcap\n");
-    exit(EXIT_FAILURE);
+    ExitProgram(EXIT_FAILURE);
 }
 #endif
 }
 #endif
index 2ee5b4c40857a64e9ab831da6a0ee3c46ee2c23d..ebca898a80b2f7d10f31b95b1b83f60e347a5a5e 100644 (file)
@@ -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            *
  *                                                                          *
  * 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
  *
 /*
  * 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.
  */
  *
  * A simple demo of the terminfo interface.
  */
 static bool b_opt = FALSE;
 static bool f_opt = FALSE;
 static bool n_opt = FALSE;
 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 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
 
 #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)
 {
 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)) {
     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) {
     } 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) {
     } 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
 }
 
 static void
@@ -140,6 +229,9 @@ demo_terminfo(char *name)
     unsigned n;
     NCURSES_CONST char *cap;
 
     unsigned n;
     NCURSES_CONST char *cap;
 
+    if (db_list) {
+       putenv(next_dbitem());
+    }
     printf("Terminal type \"%s\"\n", name);
     setupterm(name, 1, (int *) 0);
 
     printf("Terminal type \"%s\"\n", name);
     setupterm(name, 1, (int *) 0);
 
@@ -224,8 +316,11 @@ usage(void)
        "",
        "Options:",
        " -b       print boolean-capabilities",
        "",
        "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",
        " -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
        " -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;
 
     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;
        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 '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();
        case 'r':
            if ((r_opt = atoi(optarg)) <= 0)
                usage();
@@ -283,6 +387,8 @@ main(int argc, char *argv[])
        s_opt = TRUE;
     }
 
        s_opt = TRUE;
     }
 
+    make_dblist();
+
     for (repeat = 0; repeat < r_opt; ++repeat) {
        if (optind < argc) {
            for (n = optind; n < argc; ++n) {
     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);
 }
 
     ExitProgram(EXIT_SUCCESS);
 }