]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/demo_terminfo.c
ncurses 6.0 - patch 20160903
[ncurses.git] / test / demo_terminfo.c
index 533a5f0a1960ac00e84b724d39a54a3155748d46..e2f771a98bbad7052bca76f127a43303941416a6 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 2009-2013,2014 Free Software Foundation, Inc.              *
+ * Copyright (c) 2009-2015,2016 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.34 2014/08/31 23:11:39 tom Exp $
+ * $Id: demo_terminfo.c,v 1.42 2016/06/18 23:57:33 tom Exp $
  *
  * A simple demo of the terminfo interface.
  */
  *
  * A simple demo of the terminfo interface.
  */
@@ -46,6 +46,8 @@
 #endif
 #endif
 
 #endif
 #endif
 
+static void failed(const char *) GCC_NORETURN;
+
 static void
 failed(const char *msg)
 {
 static void
 failed(const char *msg)
 {
@@ -88,7 +90,7 @@ static long total_n_values;
 static long total_s_values;
 
 #define FCOLS 8
 static long total_s_values;
 
 #define FCOLS 8
-#define FNAME(type) "%s %-*s = ", #type, FCOLS
+#define FNAME(type) "%s %-*s = ", #type, f_opt ? 24 : FCOLS
 
 static char *
 make_dbitem(char *p, char *q)
 
 static char *
 make_dbitem(char *p, char *q)
@@ -164,7 +166,7 @@ free_dblist(void)
 #endif
 
 static void
 #endif
 
 static void
-dumpit(NCURSES_CONST char *cap)
+dumpit(NCURSES_CONST char *cap, const char *show)
 {
     const char *str;
     int num;
 {
     const char *str;
     int num;
@@ -173,7 +175,7 @@ dumpit(NCURSES_CONST char *cap)
        total_values++;
        total_s_values++;
        if (!q_opt) {
        total_values++;
        total_s_values++;
        if (!q_opt) {
-           printf(FNAME(str), cap);
+           printf(FNAME(str), show ? show : cap);
            while (*str != 0) {
                int ch = UChar(*str++);
                switch (ch) {
            while (*str != 0) {
                int ch = UChar(*str++);
                switch (ch) {
@@ -226,14 +228,14 @@ dumpit(NCURSES_CONST char *cap)
        total_values++;
        total_n_values++;
        if (!q_opt) {
        total_values++;
        total_n_values++;
        if (!q_opt) {
-           printf(FNAME(num), cap);
+           printf(FNAME(num), show ? show : cap);
            printf(" %d\n", num);
        }
     } else if ((num = tigetflag(cap)) >= 0) {
        total_values++;
        total_b_values++;
        if (!q_opt) {
            printf(" %d\n", num);
        }
     } else if ((num = tigetflag(cap)) >= 0) {
        total_values++;
        total_b_values++;
        if (!q_opt) {
-           printf(FNAME(flg), cap);
+           printf(FNAME(flg), show ? show : cap);
            printf("%s\n", num ? "true" : "false");
        }
     }
            printf("%s\n", num ? "true" : "false");
        }
     }
@@ -266,6 +268,10 @@ abcdefghijklmnopqrstuvwxyz_";
     if (!q_opt)
        printf("Terminal type \"%s\"\n", name);
     setupterm((NCURSES_CONST char *) name, 1, (int *) 0);
     if (!q_opt)
        printf("Terminal type \"%s\"\n", name);
     setupterm((NCURSES_CONST char *) name, 1, (int *) 0);
+    if (!q_opt) {
+       if (strcmp(name, ttytype))
+           printf("... actual \"%s\"\n", ttytype);
+    }
 
     for (length = 1; length <= MAX_FORCE; ++length) {
        /* set all digits to zeros */
 
     for (length = 1; length <= MAX_FORCE; ++length) {
        /* set all digits to zeros */
@@ -280,7 +286,7 @@ abcdefghijklmnopqrstuvwxyz_";
                cap[j] = legal[item[j]];
            }
            cap[length] = '\0';
                cap[j] = legal[item[j]];
            }
            cap[length] = '\0';
-           dumpit(cap);
+           dumpit(cap, NULL);
 
            k = length - 1;
            do {
 
            k = length - 1;
            do {
@@ -306,6 +312,12 @@ abcdefghijklmnopqrstuvwxyz_";
     del_curterm(cur_term);
 }
 
     del_curterm(cur_term);
 }
 
+#if USE_CODE_LISTS
+#define fullname(type,n) f_opt ? type##fnames[n] : cap
+#else
+#define fullname(type,n) cap
+#endif
+
 static void
 demo_terminfo(char *name)
 {
 static void
 demo_terminfo(char *name)
 {
@@ -321,28 +333,28 @@ demo_terminfo(char *name)
 
     if (b_opt) {
        for (n = 0;; ++n) {
 
     if (b_opt) {
        for (n = 0;; ++n) {
-           cap = f_opt ? boolfnames[n] : my_boolcodes[n];
+           cap = my_boolcodes[n];
            if (cap == 0)
                break;
            if (cap == 0)
                break;
-           dumpit(cap);
+           dumpit(cap, fullname(bool, n));
        }
     }
 
     if (n_opt) {
        for (n = 0;; ++n) {
        }
     }
 
     if (n_opt) {
        for (n = 0;; ++n) {
-           cap = f_opt ? numfnames[n] : my_numcodes[n];
+           cap = my_numcodes[n];
            if (cap == 0)
                break;
            if (cap == 0)
                break;
-           dumpit(cap);
+           dumpit(cap, fullname(num, n));
        }
     }
 
     if (s_opt) {
        for (n = 0;; ++n) {
        }
     }
 
     if (s_opt) {
        for (n = 0;; ++n) {
-           cap = f_opt ? strfnames[n] : my_strcodes[n];
+           cap = my_strcodes[n];
            if (cap == 0)
                break;
            if (cap == 0)
                break;
-           dumpit(cap);
+           dumpit(cap, fullname(str, n));
        }
     }
 #ifdef NCURSES_VERSION
        }
     }
 #ifdef NCURSES_VERSION
@@ -356,13 +368,13 @@ demo_terminfo(char *name)
                    || (NUM_NUMBERS(term) != NUMCOUNT)
                    || (NUM_STRINGS(term) != STRCOUNT))) {
                for (n = BOOLCOUNT; n < NUM_BOOLEANS(term); ++n) {
                    || (NUM_NUMBERS(term) != NUMCOUNT)
                    || (NUM_STRINGS(term) != STRCOUNT))) {
                for (n = BOOLCOUNT; n < NUM_BOOLEANS(term); ++n) {
-                   dumpit(ExtBoolname(term, (int) n, boolnames));
+                   dumpit(ExtBoolname(term, (int) n, boolnames), NULL);
                }
                for (n = NUMCOUNT; n < NUM_NUMBERS(term); ++n) {
                }
                for (n = NUMCOUNT; n < NUM_NUMBERS(term); ++n) {
-                   dumpit(ExtNumname(term, (int) n, numnames));
+                   dumpit(ExtNumname(term, (int) n, numnames), NULL);
                }
                for (n = STRCOUNT; n < NUM_STRINGS(term); ++n) {
                }
                for (n = STRCOUNT; n < NUM_STRINGS(term); ++n) {
-                   dumpit(ExtStrname(term, (int) n, strnames));
+                   dumpit(ExtStrname(term, (int) n, strnames), NULL);
                }
            }
 #endif
                }
            }
 #endif
@@ -388,7 +400,7 @@ demo_terminfo(char *name)
                    } else {
                        sprintf(temp, "%.*s%d", 8, xterm_keys[n], mod);
                    }
                    } else {
                        sprintf(temp, "%.*s%d", 8, xterm_keys[n], mod);
                    }
-                   dumpit(temp);
+                   dumpit(temp, NULL);
                }
            }
        }
                }
            }
        }
@@ -411,6 +423,8 @@ typedef enum {
 static void
 parse_description(const char *input_name)
 {
 static void
 parse_description(const char *input_name)
 {
+    static char empty[1];
+
     FILE *fp;
     struct stat sb;
     size_t count_bools = 0;
     FILE *fp;
     struct stat sb;
     size_t count_bools = 0;
@@ -445,6 +459,7 @@ parse_description(const char *input_name)
     if ((fp = fopen(input_name, "r")) == 0)
        failed("cannot open input-file");
     len = fread(my_blob, sizeof(char), (size_t) sb.st_size, fp);
     if ((fp = fopen(input_name, "r")) == 0)
        failed("cannot open input-file");
     len = fread(my_blob, sizeof(char), (size_t) sb.st_size, fp);
+    my_blob[sb.st_size] = '\0';
     fclose(fp);
 
     /*
     fclose(fp);
 
     /*
@@ -628,10 +643,10 @@ parse_description(const char *input_name)
                         * known order.
                         */
                        if (count_strs) {
                         * known order.
                         */
                        if (count_strs) {
-                           my_strvalues[count_strs] = "";
+                           my_strvalues[count_strs] = empty;
                            my_strcodes[count_strs++] = &my_blob[j];
                        } else if (count_nums) {
                            my_strcodes[count_strs++] = &my_blob[j];
                        } else if (count_nums) {
-                           my_numvalues[count_nums] = "";
+                           my_numvalues[count_nums] = empty;
                            my_numcodes[count_nums++] = &my_blob[j];
                        } else {
                            my_boolcodes[count_bools++] = &my_blob[j];
                            my_numcodes[count_nums++] = &my_blob[j];
                        } else {
                            my_boolcodes[count_bools++] = &my_blob[j];
@@ -706,7 +721,7 @@ copy_code_list(NCURSES_CONST char *const *list)
 {
     int pass;
     size_t count;
 {
     int pass;
     size_t count;
-    size_t length = 0;
+    size_t length = 1;
     char **result = 0;
     char *blob = 0;
     char *unused = 0;
     char **result = 0;
     char *blob = 0;
     char *unused = 0;
@@ -825,7 +840,7 @@ main(int argc, char *argv[])
        }
     }
 
        }
     }
 
-#if NCURSES_XNAMES
+#if HAVE_USE_EXTENDED_NAMES
     use_extended_names(x_opt);
 #endif
 
     use_extended_names(x_opt);
 #endif
 
@@ -879,8 +894,12 @@ main(int argc, char *argv[])
        }
     }
 
        }
     }
 
-    printf("%ld values (%ld booleans, %ld numbers, %ld strings)\n",
-          total_values, total_b_values, total_n_values, total_s_values);
+#define PLURAL(n) n, (n != 1) ? "s" : ""
+    printf("%ld value%s (%ld boolean%s, %ld number%s, %ld string%s)\n",
+          PLURAL(total_values),
+          PLURAL(total_b_values),
+          PLURAL(total_n_values),
+          PLURAL(total_s_values));
 
 #ifdef NO_LEAKS
     free_dblist();
 
 #ifdef NO_LEAKS
     free_dblist();
@@ -901,7 +920,7 @@ main(int argc, char *argv[])
 int
 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
 {
 int
 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
 {
-    printf("This program requires the terminfo functions such as tigetstr\n");
+    failed("This program requires the terminfo functions such as tigetstr");
     ExitProgram(EXIT_FAILURE);
 }
 #endif /* HAVE_TIGETSTR */
     ExitProgram(EXIT_FAILURE);
 }
 #endif /* HAVE_TIGETSTR */