]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - progs/tic.c
ncurses 5.9 - patch 20120128
[ncurses.git] / progs / tic.c
index 739e7ed71ac4aa7fab979c6fdca22d176391e4a8..04ab3e528aba3ea7f971d08ceaa2eaf8e47092be 100644 (file)
@@ -35,6 +35,7 @@
 /*
  *     tic.c --- Main program for terminfo compiler
  *                     by Eric S. Raymond
+ *                     and Thomas E Dickey
  *
  */
 
@@ -44,7 +45,7 @@
 #include <dump_entry.h>
 #include <transform.h>
 
-MODULE_ID("$Id: tic.c,v 1.150 2011/05/21 18:15:45 tom Exp $")
+MODULE_ID("$Id: tic.c,v 1.157 2011/12/31 21:11:59 tom Exp $")
 
 const char *_nc_progname = "tic";
 
@@ -69,11 +70,13 @@ static const char usage_string[] = "\
 1\
 a\
 C\
+D\
 c\
 f\
 G\
 g\
 I\
+K\
 L\
 N\
 r\
@@ -133,7 +136,9 @@ usage(void)
 #if NCURSES_XNAMES
        "  -a         retain commented-out capabilities (sets -x also)",
 #endif
+       "  -K         translate entries to termcap source form with BSD syntax",
        "  -C         translate entries to termcap source form",
+       "  -D         print list of tic's database locations (first must be writable)",
        "  -c         check only, validate input without compiling or translating",
        "  -e<names>  translate/compile only entries named by comma-separated list",
        "  -f         format complex strings for readability",
@@ -173,7 +178,7 @@ usage(void)
 
 #define L_BRACE '{'
 #define R_BRACE '}'
-#define S_QUOTE '\'';
+#define S_QUOTE '\''
 
 static void
 write_it(ENTRY * ep)
@@ -471,6 +476,25 @@ open_tempfile(char *name)
     return result;
 }
 
+/*
+ * Show the databases that tic knows about.  The location to which it writes is
+ * always the first one.  If that is not writable, then tic errors out before
+ * reaching this function.
+ */
+static void
+show_databases(void)
+{
+    DBDIRS state;
+    int offset;
+    const char *path;
+
+    _nc_first_db(&state, &offset);
+    while ((path = _nc_next_db(&state, &offset)) != 0) {
+       printf("%s\n", path);
+    }
+    _nc_last_db();
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -487,6 +511,7 @@ main(int argc, char *argv[])
     int sortmode = S_TERMINFO; /* sort_mode */
 
     int width = 60;
+    int height = 65535;
     bool formatted = FALSE;    /* reformat complex strings? */
     bool literal = FALSE;      /* suppress post-processing? */
     int numbers = 0;           /* format "%'char'" to/from "%{number}" */
@@ -514,6 +539,7 @@ main(int argc, char *argv[])
 #if NCURSES_XNAMES
     use_extended_names(FALSE);
 #endif
+    _nc_strict_bsd = 0;
 
     /*
      * Processing arguments is a little complicated, since someone made a
@@ -521,7 +547,7 @@ main(int argc, char *argv[])
      * be optional.
      */
     while ((this_opt = getopt(argc, argv,
-                             "0123456789CILNR:TUVace:fGgo:rstvwx")) != -1) {
+                             "0123456789CDIKLNR:TUVace:fGgo:rstvwx")) != -1) {
        if (isdigit(this_opt)) {
            switch (last_opt) {
            case 'v':
@@ -531,19 +557,39 @@ main(int argc, char *argv[])
                width = (width * 10) + (this_opt - '0');
                break;
            default:
-               if (this_opt != '1')
+               switch (this_opt) {
+               case '0':
+                   last_opt = this_opt;
+                   width = 65535;
+                   height = 1;
+                   break;
+               case '1':
+                   last_opt = this_opt;
+                   width = 0;
+                   break;
+               default:
                    usage();
-               last_opt = this_opt;
-               width = 0;
+               }
            }
            continue;
        }
        switch (this_opt) {
+       case 'K':
+           _nc_strict_bsd = 1;
+           /* the initial version of -K in 20110730 fell-thru here, but the
+            * same flag is useful when reading sources -TD
+            */
+           break;
        case 'C':
            capdump = TRUE;
            outform = F_TERMCAP;
            sortmode = S_TERMCAP;
            break;
+       case 'D':
+           _nc_set_writedir(outdir);
+           show_databases();
+           ExitProgram(EXIT_SUCCESS);
+           break;
        case 'I':
            infodump = TRUE;
            outform = F_TERMINFO;
@@ -696,11 +742,11 @@ main(int argc, char *argv[])
                  smart_defaults
                  ? outform
                  : F_LITERAL,
-                 sortmode, width, debug_level, formatted);
+                 sortmode, width, height, debug_level, formatted);
     else if (capdump)
        dump_init(tversion,
                  outform,
-                 sortmode, width, debug_level, FALSE);
+                 sortmode, width, height, debug_level, FALSE);
 
     /* parse entries out of the source file */
     _nc_set_source(source_file);