]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - progs/tic.c
ncurses 5.9 - patch 20131019
[ncurses.git] / progs / tic.c
index 717a1fb35126bbb79b2544b03907c2c810d0d933..6ee1766604343a6f7b9b5e068bcc67b0622b34f4 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-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            *
@@ -46,7 +46,7 @@
 #include <hashed_db.h>
 #include <transform.h>
 
-MODULE_ID("$Id: tic.c,v 1.180 2012/12/08 22:17:22 tom Exp $")
+MODULE_ID("$Id: tic.c,v 1.188 2013/08/24 21:48:21 tom Exp $")
 
 #define STDIN_NAME "<stdin>"
 
@@ -380,11 +380,11 @@ open_tempfile(char *filename)
     _nc_STRCPY(filename, "/tmp/XXXXXX", PATH_MAX);
 #if HAVE_MKSTEMP
     {
-       int oldmask = umask(077);
+       int oldmask = (int) umask(077);
        int fd = mkstemp(filename);
        if (fd >= 0)
            result = fdopen(fd, "w");
-       umask(oldmask);
+       umask((mode_t) oldmask);
     }
 #else
     if (tmpnam(filename) != 0)
@@ -396,13 +396,17 @@ open_tempfile(char *filename)
 static FILE *
 copy_input(FILE *source, const char *filename, char *alt_file)
 {
+    char my_altfile[PATH_MAX];
     FILE *result = 0;
-    FILE *target = open_tempfile(alt_file);
+    FILE *target = 0;
     int ch;
 
+    if (alt_file == 0)
+       alt_file = my_altfile;
+
     if (source == 0) {
        failed("copy_input (source)");
-    } else if (target == 0) {
+    } else if ((target = open_tempfile(alt_file)) == 0) {
        failed("copy_input (target)");
     } else {
        clearerr(source);
@@ -428,7 +432,7 @@ copy_input(FILE *source, const char *filename, char *alt_file)
         */
        result = fopen(alt_file, "r+");
        fclose(target);
-       to_remove = alt_file;
+       to_remove = strdup(alt_file);
     }
     return result;
 }
@@ -552,7 +556,7 @@ matches(char **needle, const char *haystack)
     return (code);
 }
 
-static const char *
+static char *
 valid_db_path(const char *nominal)
 {
     struct stat sb;
@@ -623,7 +627,7 @@ static void
 show_databases(const char *outdir)
 {
     bool specific = (outdir != 0) || getenv("TERMINFO") != 0;
-    const char *result;
+    char *result;
     const char *tried = 0;
 
     if (outdir == 0) {
@@ -631,6 +635,7 @@ show_databases(const char *outdir)
     }
     if ((result = valid_db_path(outdir)) != 0) {
        printf("%s\n", result);
+       free(result);
     } else {
        tried = outdir;
     }
@@ -638,6 +643,7 @@ show_databases(const char *outdir)
     if ((outdir = _nc_home_terminfo())) {
        if ((result = valid_db_path(outdir)) != 0) {
            printf("%s\n", result);
+           free(result);
        } else if (!specific) {
            tried = outdir;
        }
@@ -1218,6 +1224,19 @@ check_ansi_cursor(char *list[4])
 }
 
 #define EXPECTED(name) if (!PRESENT(name)) _nc_warning("expected " #name)
+#define UNEXPECTED(name) if (PRESENT(name)) _nc_warning("unexpected " #name ", for %s", why)
+
+static void
+check_noaddress(TERMTYPE *tp, const char *why)
+{
+    UNEXPECTED(column_address);
+    UNEXPECTED(cursor_address);
+    UNEXPECTED(cursor_home);
+    UNEXPECTED(cursor_mem_address);
+    UNEXPECTED(cursor_to_ll);
+    UNEXPECTED(row_address);
+    UNEXPECTED(row_address);
+}
 
 static void
 check_cursor(TERMTYPE *tp)
@@ -1225,6 +1244,43 @@ check_cursor(TERMTYPE *tp)
     int count;
     char *list[4];
 
+    if (hard_copy) {
+       check_noaddress(tp, "hard_copy");
+    } else if (generic_type) {
+       check_noaddress(tp, "generic_type");
+    } else if (strchr(tp->term_names, '+') == 0) {
+       int y = 0;
+       int x = 0;
+       if (PRESENT(column_address))
+           ++y;
+       if (PRESENT(cursor_address))
+           y = x = 10;
+       if (PRESENT(cursor_home))
+           ++y, ++x;
+       if (PRESENT(cursor_mem_address))
+           y = x = 10;
+       if (PRESENT(cursor_to_ll))
+           ++y, ++x;
+       if (PRESENT(row_address))
+           ++x;
+       if (PRESENT(cursor_down))
+           ++y;
+       if (PRESENT(cursor_up))
+           ++y;
+       if (PRESENT(cursor_left))
+           ++x;
+       if (PRESENT(cursor_right))
+           ++x;
+       if (x < 2 && y < 2) {
+           _nc_warning("terminal lacks cursor addressing");
+       } else {
+           if (x < 2)
+               _nc_warning("terminal lacks cursor column-addressing");
+           if (y < 2)
+               _nc_warning("terminal lacks cursor row-addressing");
+       }
+    }
+
     /* it is rare to have an insert-line feature without a matching delete */
     ANDMISSING(parm_insert_line, insert_line);
     ANDMISSING(parm_delete_line, delete_line);
@@ -1406,7 +1462,7 @@ check_keypad(TERMTYPE *tp)
 
     /*
      * These warnings are useful for consistency checks - it is possible that
-     * there are real terminals with mismatches in these 
+     * there are real terminals with mismatches in these
      */
     ANDMISSING(key_ic, key_dc);
 }
@@ -1450,6 +1506,7 @@ uses_SGR_39_49(const char *value)
 static void
 check_screen(TERMTYPE *tp)
 {
+#if NCURSES_XNAMES
     if (_nc_user_definable) {
        int have_XT = tigetflag("XT");
        int have_XM = tigetflag("XM");
@@ -1501,6 +1558,7 @@ check_screen(TERMTYPE *tp)
                _nc_warning("Expected XT to be set, given kmous");
        }
     }
+#endif
 }
 
 /*