/****************************************************************************
- * Copyright 2018-2021,2022 Thomas E. Dickey *
+ * Copyright 2018-2023,2024 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
#include <transform.h>
#include <tty_settings.h>
-MODULE_ID("$Id: tput.c,v 1.99 2022/02/26 23:19:31 tom Exp $")
+MODULE_ID("$Id: tput.c,v 1.104 2024/04/20 22:20:51 tom Exp $")
#define PUTS(s) fputs(s, stdout)
const char *_nc_progname = "tput";
+static bool opt_v = FALSE; /* quiet, do not show warnings */
+static bool opt_x = FALSE; /* clear scrollback if possible */
+
static bool is_init = FALSE;
static bool is_reset = FALSE;
static bool is_clear = FALSE;
KEEP(" -S << read commands from standard input")
KEEP(" -T TERM use this instead of $TERM")
KEEP(" -V print curses-version")
+ KEEP(" -v verbose, show warnings")
KEEP(" -x do not try to clear scrollback")
KEEP("")
KEEP("Commands:")
* Returns nonzero on error.
*/
static int
-tput_cmd(int fd, TTY * settings, bool opt_x, int argc, char **argv, int *used)
+tput_cmd(int fd, TTY * settings, int argc, char **argv, int *used)
{
NCURSES_CONST char *name;
char *s;
}
#if HAVE_SIZECHANGE
- set_window_size(fd, &lines, &columns);
+ {
+ NCURSES_INT2 my_rows = lines;
+ NCURSES_INT2 my_cols = columns;
+ set_window_size(fd, &my_rows, &my_cols);
+ lines = my_rows;
+ columns = my_cols;
+ }
#else
(void) fd;
#endif
} else if (VALID_STRING(s)) {
if (argc > 1) {
int k;
+ int narg;
int analyzed;
+ int provided;
int popcount;
long numbers[1 + NUM_PARM];
char *strings[1 + NUM_PARM];
popcount = 0;
_nc_reset_tparm(NULL);
+ /*
+ * Count the number of numeric parameters which are provided.
+ */
+ provided = 0;
+ for (narg = 1; narg < argc; ++narg) {
+ char *ending = NULL;
+ long check = strtol(argv[narg], &ending, 0);
+ if (check < 0 || ending == argv[narg] || *ending != '\0')
+ break;
+ provided = narg;
+ }
switch (paramType) {
+ case Str:
+ s = TPARM_1(s, strings[1]);
+ analyzed = 1;
+ if (provided == 0 && argc >= 1)
+ provided++;
+ break;
+ case Str_Str:
+ s = TPARM_2(s, strings[1], strings[2]);
+ analyzed = 2;
+ if (provided == 0 && argc >= 1)
+ provided++;
+ if (provided == 1 && argc >= 2)
+ provided++;
+ break;
case Num_Str:
s = TPARM_2(s, numbers[1], strings[2]);
analyzed = 2;
+ if (provided == 1 && argc >= 2)
+ provided++;
break;
case Num_Str_Str:
s = TPARM_3(s, numbers[1], strings[2], strings[3]);
analyzed = 3;
+ if (provided == 1 && argc >= 2)
+ provided++;
+ if (provided == 2 && argc >= 3)
+ provided++;
break;
case Numbers:
analyzed = _nc_tparm_analyze(NULL, s, p_is_s, &popcount);
if (analyzed < popcount) {
analyzed = popcount;
}
- *used += analyzed;
+ if (opt_v && (analyzed != provided)) {
+ fprintf(stderr, "%s: %s parameters for \"%s\"\n",
+ _nc_progname,
+ (analyzed < provided ? "extra" : "missing"),
+ argv[0]);
+ }
+ *used += provided;
}
/* use putp() in order to perform padding */
int used;
TTY old_settings;
TTY tty_settings;
- bool opt_x = FALSE; /* clear scrollback if possible */
bool is_alias;
bool need_tty;
term = getenv("TERM");
- while ((c = getopt(argc, argv, is_alias ? "T:Vx" : "ST:Vx")) != -1) {
+ while ((c = getopt(argc, argv, is_alias ? "T:Vvx" : "ST:Vvx")) != -1) {
switch (c) {
case 'S':
cmdline = FALSE;
case 'V':
puts(curses_version());
ExitProgram(EXIT_SUCCESS);
+ case 'v': /* verbose */
+ opt_v = TRUE;
+ break;
case 'x': /* do not try to clear scrollback */
opt_x = TRUE;
break;
usage(NULL);
while (argc > 0) {
tty_settings = old_settings;
- code = tput_cmd(fd, &tty_settings, opt_x, argc, argv, &used);
+ code = tput_cmd(fd, &tty_settings, argc, argv, &used);
if (code != 0)
break;
argc -= used;
while (argnum > 0) {
int code;
tty_settings = old_settings;
- code = tput_cmd(fd, &tty_settings, opt_x, argnum, argnow, &used);
+ code = tput_cmd(fd, &tty_settings, argnum, argnow, &used);
if (code != 0) {
if (result == 0)
result = ErrSystem(0); /* will return value >4 */