]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - progs/tput.c
ncurses 6.2 - patch 20210619
[ncurses.git] / progs / tput.c
index 76370cbcb74cc8cb3355da93d041d67a17935a03..027fab9c8fbbe9f465477443788fdeae77c8fc1b 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc.              *
+ * Copyright 2018-2020,2021 Thomas E. Dickey                                *
+ * Copyright 1998-2016,2017 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            *
 #include <clear_cmd.h>
 #include <reset_cmd.h>
 
-#if !PURE_TERMINFO
-#include <dump_entry.h>
-#include <termsort.c>
-#endif
 #include <transform.h>
 #include <tty_settings.h>
 
-MODULE_ID("$Id: tput.c,v 1.77 2017/10/07 23:51:01 tom Exp $")
+MODULE_ID("$Id: tput.c,v 1.90 2021/04/18 17:18:19 tom Exp $")
 
 #define PUTS(s)                fputs(s, stdout)
 
@@ -61,8 +58,8 @@ static bool is_init = FALSE;
 static bool is_reset = FALSE;
 static bool is_clear = FALSE;
 
-static void
-quit(int status, const char *fmt,...)
+static GCC_NORETURN void
+quit(int status, const char *fmt, ...)
 {
     va_list argp;
 
@@ -74,7 +71,7 @@ quit(int status, const char *fmt,...)
     ExitProgram(status);
 }
 
-static void
+static GCC_NORETURN void
 usage(void)
 {
 #define KEEP(s) s "\n"
@@ -224,13 +221,14 @@ tput_cmd(int fd, TTY * saved_settings, bool opt_x, int argc, char *argv[])
            long numbers[1 + NUM_PARM];
            char *strings[1 + NUM_PARM];
            char *p_is_s[NUM_PARM];
+           TParams paramType;
 
            /* Nasty hack time. The tparm function needs to see numeric
             * parameters as numbers, not as pointers to their string
             * representations
             */
 
-           for (k = 1; k < argc; k++) {
+           for (k = 1; (k < argc) && (k <= NUM_PARM); k++) {
                char *tmp = 0;
                strings[k] = argv[k];
                numbers[k] = strtol(argv[k], &tmp, 0);
@@ -242,7 +240,21 @@ tput_cmd(int fd, TTY * saved_settings, bool opt_x, int argc, char *argv[])
                strings[k] = 0;
            }
 
-           switch (tparm_type(name)) {
+           paramType = tparm_type(name);
+#if NCURSES_XNAMES
+           /*
+            * If the capability is an extended one, analyze the string.
+            */
+           if (paramType == Numbers) {
+               struct name_table_entry const *entry_ptr;
+               entry_ptr = _nc_find_type_entry(name, STRING, FALSE);
+               if (entry_ptr == NULL) {
+                   paramType = Other;
+               }
+           }
+#endif
+
+           switch (paramType) {
            case Num_Str:
                s = TPARM_2(s, numbers[1], strings[2]);
                break;
@@ -250,6 +262,21 @@ tput_cmd(int fd, TTY * saved_settings, bool opt_x, int argc, char *argv[])
                s = TPARM_3(s, numbers[1], strings[2], strings[3]);
                break;
            case Numbers:
+#define myParam(n) numbers[n]
+               s = TIPARM_9(s,
+                            myParam(1),
+                            myParam(2),
+                            myParam(3),
+                            myParam(4),
+                            myParam(5),
+                            myParam(6),
+                            myParam(7),
+                            myParam(8),
+                            myParam(9));
+#undef myParam
+               break;
+           case Other:
+               /* FALLTHRU */
            default:
                (void) _nc_tparm_analyze(s, p_is_s, &ignored);
 #define myParam(n) (p_is_s[n - 1] != 0 ? ((TPARM_ARG) strings[n]) : numbers[n])
@@ -263,6 +290,7 @@ tput_cmd(int fd, TTY * saved_settings, bool opt_x, int argc, char *argv[])
                            myParam(7),
                            myParam(8),
                            myParam(9));
+#undef myParam
                break;
            }
        }
@@ -293,7 +321,7 @@ main(int argc, char **argv)
 
     term = getenv("TERM");
 
-    while ((c = getopt(argc, argv, "ST:V")) != -1) {
+    while ((c = getopt(argc, argv, "ST:Vx")) != -1) {
        switch (c) {
        case 'S':
            cmdline = FALSE;
@@ -316,7 +344,10 @@ main(int argc, char **argv)
     }
 
     is_alias = (is_clear || is_reset || is_init);
-    need_tty = (is_reset || is_init);
+    need_tty = ((is_reset || is_init) ||
+               (optind < argc &&
+                (!strcmp(argv[optind], "reset") ||
+                 !strcmp(argv[optind], "init"))));
 
     /*
      * Modify the argument list to omit the options we processed.