]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - progs/dump_entry.c
ncurses 5.9 - patch 20111001
[ncurses.git] / progs / dump_entry.c
index 485bbbd91d64a785e0022f441b69ef1673861214..12bef2c279f2038b0750ef02091876681e2aaf27 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2008,2010 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2011 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.89 2010/05/01 22:04:08 tom Exp $")
+MODULE_ID("$Id: dump_entry.c,v 1.95 2011/08/07 22:10:17 tom Exp $")
 
 #define INDENT                 8
 #define DISCARD(string) string = ABSENT_STRING
@@ -57,6 +57,7 @@ static int tversion;          /* terminfo version */
 static int outform;            /* output format to use */
 static int sortmode;           /* sort mode to use */
 static int width = 60;         /* max line width for listings */
+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 */
@@ -172,11 +173,17 @@ nametrans(const char *name)
 }
 
 void
-dump_init(const char *version, int mode, int sort, int twidth, int traceval,
+dump_init(const char *version,
+         int mode,
+         int sort,
+         int twidth,
+         int theight,
+         unsigned traceval,
          bool formatted)
 /* set up for entry display */
 {
     width = twidth;
+    height = theight;
     pretty = formatted;
 
     /* versions */
@@ -201,7 +208,7 @@ dump_init(const char *version, int mode, int sort, int twidth, int traceval,
        bool_names = boolnames;
        num_names = numnames;
        str_names = strnames;
-       separator = twidth ? ", " : ",";
+       separator = (twidth > 0 && theight > 1) ? ", " : ",";
        trailer = "\n\t";
        break;
 
@@ -209,7 +216,7 @@ dump_init(const char *version, int mode, int sort, int twidth, int traceval,
        bool_names = boolfnames;
        num_names = numfnames;
        str_names = strfnames;
-       separator = twidth ? ", " : ",";
+       separator = (twidth > 0 && theight > 1) ? ", " : ",";
        trailer = "\n\t";
        break;
 
@@ -393,8 +400,8 @@ force_wrap(void)
 static void
 wrap_concat(const char *src)
 {
-    unsigned need = strlen(src);
-    unsigned want = strlen(separator) + need;
+    size_t need = strlen(src);
+    size_t want = strlen(separator) + need;
 
     if (column > INDENT
        && column + (int) want > width) {
@@ -593,14 +600,28 @@ fmt_entry(TERMTYPE *tterm,
        column = INDENT;        /* FIXME: workaround to prevent empty lines */
     } else {
        strcpy_DYN(&outbuf, tterm->term_names);
+
+       /*
+        * Colon is legal in terminfo descriptions, but not in termcap.
+        */
+       if (!infodump) {
+           char *p = outbuf.text;
+           while (*p) {
+               if (*p == ':') {
+                   *p = '=';
+               }
+               ++p;
+           }
+       }
        strcpy_DYN(&outbuf, separator);
        column = (int) outbuf.used;
-       force_wrap();
+       if (height > 1)
+           force_wrap();
     }
 
     for_each_boolean(j, tterm) {
        i = BoolIndirect(j);
-       name = ExtBoolname(tterm, i, bool_names);
+       name = ExtBoolname(tterm, (int) i, bool_names);
        assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
 
        if (!version_filter(BOOLEAN, i))
@@ -619,12 +640,12 @@ fmt_entry(TERMTYPE *tterm,
        }
     }
 
-    if (column != INDENT)
+    if (column != INDENT && height > 1)
        force_wrap();
 
     for_each_number(j, tterm) {
        i = NumIndirect(j);
-       name = ExtNumname(tterm, i, num_names);
+       name = ExtNumname(tterm, (int) i, num_names);
        assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
 
        if (!version_filter(NUMBER, i))
@@ -645,7 +666,7 @@ fmt_entry(TERMTYPE *tterm,
        }
     }
 
-    if (column != INDENT)
+    if (column != INDENT && height > 1)
        force_wrap();
 
     len += (int) (num_bools
@@ -670,7 +691,7 @@ fmt_entry(TERMTYPE *tterm,
 
     for_each_string(j, tterm) {
        i = StrIndirect(j);
-       name = ExtStrname(tterm, i, str_names);
+       name = ExtStrname(tterm, (int) i, str_names);
        assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
 
        capability = tterm->Strings[i];
@@ -846,7 +867,7 @@ fmt_entry(TERMTYPE *tterm,
      */
     if (outcount) {
        bool trimmed = FALSE;
-       j = outbuf.used;
+       j = (PredIdx) outbuf.used;
        if (j >= 2
            && outbuf.text[j - 1] == '\t'
            && outbuf.text[j - 2] == '\n') {
@@ -1064,7 +1085,7 @@ dump_entry(TERMTYPE *tterm,
             */
            unsigned n;
            for (n = STRCOUNT; n < NUM_STRINGS(tterm); n++) {
-               const char *name = ExtStrname(tterm, n, strnames);
+               const char *name = ExtStrname(tterm, (int) n, strnames);
 
                if (VALID_STRING(tterm->Strings[n])) {
                    set_attributes = ABSENT_STRING;
@@ -1151,14 +1172,37 @@ dump_uses(const char *name, bool infodump)
 int
 show_entry(void)
 {
-    trim_trailing();
+    /*
+     * Trim any remaining whitespace.
+     */
+    if (outbuf.used != 0) {
+       bool infodump = (outform != F_TERMCAP && outform != F_TCONVERR);
+       char delim = infodump ? ',' : ':';
+       int j;
+
+       for (j = (int) outbuf.used - 1; j > 0; --j) {
+           char ch = outbuf.text[j];
+           if (ch == '\n') {
+               ;
+           } else if (isspace(UChar(ch))) {
+               outbuf.used = j;
+           } else if (!infodump && ch == '\\') {
+               outbuf.used = j;
+           } else if (ch == delim && (j == 0 || outbuf.text[j - 1] != '\\')) {
+               outbuf.used = (j + 1);
+           } else {
+               break;
+           }
+       }
+       outbuf.text[outbuf.used] = '\0';
+    }
     (void) fputs(outbuf.text, stdout);
     putchar('\n');
     return (int) outbuf.used;
 }
 
 void
-compare_entry(void (*hook) (PredType t, PredIdx i, const char *name),
+compare_entry(PredHook hook,
              TERMTYPE *tp GCC_UNUSED,
              bool quiet)
 /* compare two entries */
@@ -1170,7 +1214,7 @@ compare_entry(void (*hook) (PredType t, PredIdx i, const char *name),
        fputs("    comparing booleans.\n", stdout);
     for_each_boolean(j, tp) {
        i = BoolIndirect(j);
-       name = ExtBoolname(tp, i, bool_names);
+       name = ExtBoolname(tp, (int) i, bool_names);
 
        if (isObsolete(outform, name))
            continue;
@@ -1182,7 +1226,7 @@ compare_entry(void (*hook) (PredType t, PredIdx i, const char *name),
        fputs("    comparing numbers.\n", stdout);
     for_each_number(j, tp) {
        i = NumIndirect(j);
-       name = ExtNumname(tp, i, num_names);
+       name = ExtNumname(tp, (int) i, num_names);
 
        if (isObsolete(outform, name))
            continue;
@@ -1194,7 +1238,7 @@ compare_entry(void (*hook) (PredType t, PredIdx i, const char *name),
        fputs("    comparing strings.\n", stdout);
     for_each_string(j, tp) {
        i = StrIndirect(j);
-       name = ExtStrname(tp, i, str_names);
+       name = ExtStrname(tp, (int) i, str_names);
 
        if (isObsolete(outform, name))
            continue;