#include <locale.h>
#endif
-MODULE_ID("$Id: lib_setup.c,v 1.233 2024/03/16 23:39:28 tom Exp $")
+MODULE_ID("$Id: lib_setup.c,v 1.241 2024/05/11 19:07:34 tom Exp $")
/****************************************************************************
*
}
static bool
-set_position(TERMINAL *termp, int fd, int row, int col)
+set_position(NCURSES_SP_DCLx TERMINAL *termp, int row, int col)
{
- bool result = FALSE;
+ bool result;
char *actual = TIPARM_2(cursor_address, row, col);
- T(("set_position %d,%d", row, col));
+ T((T_CALLED("set_position %d,%d)"), row, col));
+#if NCURSES_SP_FUNCS
+ result = (NCURSES_SP_NAME(_nc_putp) (NCURSES_SP_ARGx "set_position",
+ actual) == OK);
+ NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
+#else
+ /* This does not support padding because without sp-funcs, we have only
+ * the interface using stdio, but we are not guaranteed that Filedes
+ * is the same as fileno(stdout).
+ */
+ result = FALSE;
if (actual != NULL) {
size_t want = strlen(actual);
- int have = (int) write(fd, actual, want); /* FIXME - padding */
+ int have = (int) write(termp->Filedes, actual, want);
result = ((int) want == have);
}
- return result;
+#endif
+ returnBool(result);
}
/*
* So we do a simple check to exclude pseudo-terminals.
*/
static void
-_nc_check_screensize(TERMINAL *termp, int *linep, int *colp)
+_nc_check_screensize(SCREEN *sp, TERMINAL *termp, int *linep, int *colp)
{
int fd = termp->Filedes;
TTY saved;
- const char *name;
+ const char *name = NULL;
- if (NC_ISATTY(fd)
- && (name = ttyname(fd)) != NULL
- && strncmp(name, "/dev/pts/", 9)
+ if (IsRealTty(fd, name)
&& VALID_STRING(cursor_address)
&& is_expected(user7, "6n")
&& (is_expected(user6, "%i%d;%dR") ||
int updated_y = -1, updated_x = -1;
TTY alter = saved;
- T(("checking screensize of %s", name));
+#if NCURSES_SP_FUNCS
+ if (sp == NULL) {
+ sp = new_prescr();
+ sp->_term = termp;
+ NCURSES_SP_NAME(baudrate) (NCURSES_SP_ARG);
+ }
+#else
+ (void) sp;
+#endif
+
+ T(("trying CPR (u7/u6) with %s", name));
alter.c_lflag &= (unsigned) ~(ECHO | ICANON | ISIG | IEXTEN);
alter.c_iflag &= (unsigned) ~(IXON | BRKINT | PARMRK);
alter.c_cc[VMIN] = 0;
SET_TTY(fd, &alter);
if (get_position(termp, fd, ¤t_y, ¤t_x)
- && set_position(termp, fd, 9999, 9999)
+ && set_position(NCURSES_SP_ARGx termp, 9999, 9999)
&& get_position(termp, fd, &updated_y, &updated_x)) {
*linep = updated_y;
*colp = updated_x;
- set_position(termp, fd, current_y, current_x);
+ set_position(NCURSES_SP_ARGx termp, current_y, current_x);
}
/* restore tty modes */
SET_TTY(fd, &saved);
+ } else {
+ T(("NOT trying CPR with fd %d (%s): %s",
+ fd, NonNull(name), NC_ISATTY(fd) ? "tty" : "not a tty"));
}
_nc_default_screensize(termp, linep, colp);
}
#else /* !USE_CHECK_SIZE */
-#define _nc_check_screensize(termp, linep, colp) /* nothing */
+#define _nc_check_screensize(sp, termp, linep, colp) /* nothing */
#endif
#endif /* !(defined(USE_TERM_DRIVER) || defined(EXP_WIN32_DRIVER)) */
bool useEnv = _nc_prescreen.use_env;
bool useTioctl = _nc_prescreen.use_tioctl;
- T((T_CALLED("_nc_get_screensize (%p)"), sp));
+ T((T_CALLED("_nc_get_screensize (%p)"), (void *) sp));
#ifdef EXP_WIN32_DRIVER
/* If we are here, then Windows console is used in terminfo mode.
We need to figure out the size using the console API
* variable.
*/
if ((value = _nc_getenv_num("LINES")) > 0) {
- *linep = value;
+ *linep = Min(value, MAX_ENV_LINES);
T(("screen size: environment LINES = %d", *linep));
}
if ((value = _nc_getenv_num("COLUMNS")) > 0) {
- *colp = value;
+ *colp = Min(value, MAX_ENV_COLUMNS);
T(("screen size: environment COLUMNS = %d", *colp));
}
_nc_default_screensize(termp, linep, colp);
} else {
- _nc_check_screensize(termp, linep, colp);
+ _nc_check_screensize(sp, termp, linep, colp);
}
/*
OldNumber(termp, columns) = (short) (*colp);
#endif
} else {
- _nc_check_screensize(termp, linep, colp);
+ _nc_check_screensize(sp, termp, linep, colp);
}
T(("screen size is %dx%d", *linep, *colp));