]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - progs/dump_entry.c
ncurses 6.0 - patch 20150704
[ncurses.git] / progs / dump_entry.c
index 65de9f9bc1f10f9c648e1341075789a0c81a824b..f8b4c22e9f816b47ac3a414751b043327805d3bb 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2014,2015 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            *
@@ -39,7 +39,7 @@
 #include "termsort.c"          /* this C file is generated */
 #include <parametrized.h>      /* so is this */
 
-MODULE_ID("$Id: dump_entry.c,v 1.111 2013/12/15 01:05:20 tom Exp $")
+MODULE_ID("$Id: dump_entry.c,v 1.117 2015/07/05 00:01:04 tom Exp $")
 
 #define INDENT                 8
 #define DISCARD(string) string = ABSENT_STRING
@@ -61,6 +61,7 @@ static int height = 65535;    /* max number of lines for listings */
 static int column;             /* current column, limited by 'width' */
 static int oldcol;             /* last value of column before wrap */
 static bool pretty;            /* true if we format if-then-else strings */
+static bool checking;          /* true if we are checking for tic */
 
 static char *save_sgr;
 
@@ -155,17 +156,17 @@ _nc_leaks_dump_entry(void)
 #endif
 
 #define NameTrans(check,result) \
-           if (OkIndex(np->nte_index, check) \
+           if ((np->nte_index <= OK_ ## check) \
                && check[np->nte_index]) \
                return (result[np->nte_index])
 
 NCURSES_CONST char *
 nametrans(const char *name)
-/* translate a capability name from termcap to terminfo */
+/* translate a capability name to termcap from terminfo */
 {
     const struct name_table_entry *np;
 
-    if ((np = _nc_find_entry(name, _nc_get_hash_table(0))) != 0)
+    if ((np = _nc_find_entry(name, _nc_get_hash_table(0))) != 0) {
        switch (np->nte_type) {
        case BOOLEAN:
            NameTrans(bool_from_termcap, boolcodes);
@@ -179,6 +180,7 @@ nametrans(const char *name)
            NameTrans(str_from_termcap, strcodes);
            break;
        }
+    }
 
     return (0);
 }
@@ -190,12 +192,14 @@ dump_init(const char *version,
          int twidth,
          int theight,
          unsigned traceval,
-         bool formatted)
+         bool formatted,
+         bool check)
 /* set up for entry display */
 {
     width = twidth;
     height = theight;
     pretty = formatted;
+    checking = check;
 
     /* versions */
     if (version == 0)
@@ -470,7 +474,7 @@ indent_DYN(DYNBUF * buffer, int level)
        strncpy_DYN(buffer, "\t", (size_t) 1);
 }
 
-static bool
+bool
 has_params(const char *src)
 {
     bool result = FALSE;
@@ -537,9 +541,10 @@ fmt_complex(TERMTYPE *tterm, const char *capability, char *src, int level)
                            indent_DYN(&tmpbuf, level + 1);
                        }
                    } else if (level == 1) {
-                       _nc_warning("%s: %%%c without %%? in %s",
-                                   _nc_first_name(tterm->term_names),
-                                   *src, capability);
+                       if (checking)
+                           _nc_warning("%s: %%%c without %%? in %s",
+                                       _nc_first_name(tterm->term_names),
+                                       *src, capability);
                    }
                }
                continue;
@@ -561,9 +566,10 @@ fmt_complex(TERMTYPE *tterm, const char *capability, char *src, int level)
                    }
                    return src;
                }
-               _nc_warning("%s: %%; without %%? in %s",
-                           _nc_first_name(tterm->term_names),
-                           capability);
+               if (checking)
+                   _nc_warning("%s: %%; without %%? in %s",
+                               _nc_first_name(tterm->term_names),
+                               capability);
            }
            break;
        case 'p':
@@ -772,6 +778,8 @@ fmt_entry(TERMTYPE *tterm,
                    trimmed_sgr0 = _nc_trim_sgr0(tterm);
                    if (strcmp(capability, trimmed_sgr0))
                        capability = trimmed_sgr0;
+                   else
+                       free(trimmed_sgr0);
 
                    set_attributes = my_sgr;
                }
@@ -791,10 +799,13 @@ fmt_entry(TERMTYPE *tterm,
                            "%s@", name);
                WRAP_CONCAT;
            } else if (outform == F_TERMCAP || outform == F_TCONVERR) {
-               int params = ((i < (int) SIZEOF(parametrized))
-                             ? parametrized[i]
-                             : 0);
                char *srccap = _nc_tic_expand(capability, TRUE, numbers);
+               int params = (((i < (int) SIZEOF(parametrized)) &&
+                              (i < STRCOUNT))
+                             ? parametrized[i]
+                             : ((*srccap == 'k')
+                                ? 0
+                                : has_params(srccap)));
                char *cv = _nc_infotocap(name, srccap, params);
 
                if (cv == 0) {