]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/demo_termcap.c
ncurses 5.9 - patch 20131005
[ncurses.git] / test / demo_termcap.c
index dc6da3463e81392d360a916ec1d5bd690bc00eb8..6f35c17a63afe80c158d951e32c1d35b395bdf62 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 2005-2011,2012 Free Software Foundation, Inc.              *
+ * Copyright (c) 2005-2012,2013 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_termcap.c,v 1.20 2012/06/22 22:37:05 tom Exp $
+ * $Id: demo_termcap.c,v 1.24 2013/06/08 16:58:49 tom Exp $
  *
  * A simple demo of the termcap interface.
  */
  *
  * A simple demo of the termcap interface.
  */
@@ -63,33 +63,11 @@ static long total_values;
 
 #define isCapName(c) (isgraph(c) && strchr("^#=:\\", c) == 0)
 
 
 #define isCapName(c) (isgraph(c) && strchr("^#=:\\", c) == 0)
 
-#if NO_LEAKS && USE_CODE_LISTS
-
-#define MYSCR struct _myscr
-MYSCR {
-    MYSCR *next;
-    TERMINAL *term;
-};
-
-static MYSCR *my_screens;
-
-static void
-save_screen(void)
-{
-    MYSCR *obj = malloc(sizeof(MYSCR));
-    obj->next = my_screens;
-    obj->term = cur_term;
-    my_screens = obj;
-}
-#else
-#define save_screen()          /* nothing */
-#endif
-
 static char *
 make_dbitem(char *p, char *q)
 {
 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);
+    char *result = malloc(strlen(e_opt) + 2 + (size_t) (p - q));
+    sprintf(result, "%s=%.*s", e_opt, (int) (p - q), q);
     return result;
 }
 
     return result;
 }
 
@@ -278,42 +256,39 @@ demo_termcap(NCURSES_CONST char *name)
 {
     unsigned n;
     NCURSES_CONST char *cap;
 {
     unsigned n;
     NCURSES_CONST char *cap;
+    char buffer[1024];
 
     if (db_list) {
        putenv(next_dbitem());
     }
     printf("Terminal type \"%s\"\n", name);
 
     if (db_list) {
        putenv(next_dbitem());
     }
     printf("Terminal type \"%s\"\n", name);
-#if HAVE_SETUPTERM
-    setupterm(name, 1, (int *) 0);
-#else
-    setterm(name);
-#endif
-    save_screen();
-
-    if (b_opt) {
-       for (n = 0;; ++n) {
-           cap = boolcodes[n];
-           if (cap == 0)
-               break;
-           dumpit(cap);
+    if (tgetent(buffer, name) >= 0) {
+
+       if (b_opt) {
+           for (n = 0;; ++n) {
+               cap = boolcodes[n];
+               if (cap == 0)
+                   break;
+               dumpit(cap);
+           }
        }
        }
-    }
 
 
-    if (n_opt) {
-       for (n = 0;; ++n) {
-           cap = numcodes[n];
-           if (cap == 0)
-               break;
-           dumpit(cap);
+       if (n_opt) {
+           for (n = 0;; ++n) {
+               cap = numcodes[n];
+               if (cap == 0)
+                   break;
+               dumpit(cap);
+           }
        }
        }
-    }
 
 
-    if (s_opt) {
-       for (n = 0;; ++n) {
-           cap = strcodes[n];
-           if (cap == 0)
-               break;
-           dumpit(cap);
+       if (s_opt) {
+           for (n = 0;; ++n) {
+               cap = strcodes[n];
+               if (cap == 0)
+                   break;
+               dumpit(cap);
+           }
        }
     }
 }
        }
     }
 }
@@ -337,6 +312,9 @@ usage(void)
        " -q       quiet (prints only counts)",
        " -r COUNT repeat for given count",
        " -s       print string-capabilities",
        " -q       quiet (prints only counts)",
        " -r COUNT repeat for given count",
        " -s       print string-capabilities",
+#ifdef NCURSES_VERSION
+       " -y       disable extended capabilities",
+#endif
     };
     unsigned n;
     for (n = 0; n < SIZEOF(msg); ++n) {
     };
     unsigned n;
     for (n = 0; n < SIZEOF(msg); ++n) {
@@ -357,7 +335,7 @@ main(int argc, char *argv[])
     int repeat;
     int r_opt = 1;
 
     int repeat;
     int r_opt = 1;
 
-    while ((n = getopt(argc, argv, "abd:e:nqr:s")) != -1) {
+    while ((n = getopt(argc, argv, "abd:e:nqr:sy")) != -1) {
        switch (n) {
        case 'a':
            a_opt = TRUE;
        switch (n) {
        case 'a':
            a_opt = TRUE;
@@ -384,6 +362,11 @@ main(int argc, char *argv[])
        case 's':
            s_opt = TRUE;
            break;
        case 's':
            s_opt = TRUE;
            break;
+#if NCURSES_XNAMES
+       case 'y':
+           use_extended_names(FALSE);
+           break;
+#endif
        default:
            usage();
            break;
        default:
            usage();
            break;
@@ -427,20 +410,6 @@ main(int argc, char *argv[])
                demo_termcap(dumb);
            }
        }
                demo_termcap(dumb);
            }
        }
-#if NO_LEAKS
-       /*
-        * ncurses' tgetent() interface caches some entries and its no-leaks
-        * code discards those.  The calls to setupterm() on the other hand
-        * are not cached, and each call allocates a chunk of memory, even
-        * if the same terminal type is requested repeatedly.
-        */
-       while (my_screens != 0) {
-           MYSCR *next = my_screens->next;
-           del_curterm(my_screens->term);
-           free(my_screens);
-           my_screens = next;
-       }
-#endif
     }
 #endif /* USE_CODE_LISTS */
 
     }
 #endif /* USE_CODE_LISTS */