>From 76ffea39e9d8a8997c5ded5f74a57a4296ba016e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 30 Jan 2022 23:30:33 +0100 Subject: [PATCH 2/3] Prefer terminfo over termcap when both are available. * gnulib: Update to newest. * bootstrap.conf (gnulib_modules): Use terminfo, terminfo-h instead of termcap, termcap-h. * poke/pk-term.c: Include terminfo.h instead of termcap.h. (pk_term_init): Use the terminfo API if possible. Use the termcap API only as second choice. (pk_puts_paged): Don't test HAVE_TERMCAP. * poke/Makefile.am (poke_LDADD): Use LTLIBTERMINFO instead of LTLIBTERMCAP. --- ChangeLog | 14 +++++++++++++ bootstrap.conf | 6 +++--- gnulib | 2 +- poke/Makefile.am | 2 +- poke/pk-term.c | 51 ++++++++++++++++++++++++++++-------------------- 5 files changed, 49 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index e865cdf3..1830073b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2022-01-30 Bruno Haible + + Prefer terminfo over termcap when both are available. + + * gnulib: Update to newest. + * bootstrap.conf (gnulib_modules): Use terminfo, terminfo-h instead of + termcap, termcap-h. + * poke/pk-term.c: Include terminfo.h instead of termcap.h. + (pk_term_init): Use the terminfo API if possible. Use the termcap API + only as second choice. + (pk_puts_paged): Don't test HAVE_TERMCAP. + * poke/Makefile.am (poke_LDADD): Use LTLIBTERMINFO instead of + LTLIBTERMCAP. + 2022-01-30 Sergio Durigan Junior * poke/Makefile.am (dist_pkgdata_DATA): Always install diff --git a/bootstrap.conf b/bootstrap.conf index d6aa1cfd..e86197a9 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -1,7 +1,7 @@ # Bootstrap configuration. # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, -# 2015, 2016, 2017, 2018, 2019, 2020, 2021 Free Software Foundation, +# 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Free Software Foundation, # Inc. # This program is free software: you can redistribute it and/or modify @@ -49,8 +49,8 @@ gnulib_modules=" stdbool strchrnul streq - termcap - termcap-h + terminfo + terminfo-h termios tmpdir unlink diff --git a/gnulib b/gnulib index 8b060fc2..6ef3d783 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit 8b060fc2d173cec7c26d44fa3fb1d938894ae554 +Subproject commit 6ef3d783333346333f35bb181ba90f5bc46c0b29 diff --git a/poke/Makefile.am b/poke/Makefile.am index db192dd1..c5b4e634 100644 --- a/poke/Makefile.am +++ b/poke/Makefile.am @@ -57,7 +57,7 @@ poke_LDADD = $(top_builddir)/gl/libgnu.la \ $(top_builddir)/libpoke/libpoke.la \ $(LTLIBREADLINE) \ $(LTLIBTEXTSTYLE) \ - $(LTLIBTERMCAP) + $(LTLIBTERMINFO) poke_LDFLAGS = diff --git a/poke/pk-term.c b/poke/pk-term.c index a9654b5f..799bf234 100644 --- a/poke/pk-term.c +++ b/poke/pk-term.c @@ -21,24 +21,25 @@ #include /* For exit and getenv. */ #include /* For assert. */ #include -#include /* For isatty */ +#include /* For isatty, STDOUT_FILENO */ #include #include #include #include #include #include -#if defined HAVE_TERMCAP -# include -#endif +#include "terminfo.h" #include "poke.h" #include "pk-utils.h" /* Several variables related to the pager. */ +/* Terminal control sequence that erases to the end of the current line or of + the entire screen. */ static const char *erase_line_str; +/* Current screen dimensions. */ static int screen_lines = 25; static int screen_cols = 80; @@ -262,23 +263,34 @@ pk_term_init (int argc, char *argv[]) } #endif -#if defined HAVE_TERMCAP - /* Get the terminal dimensions using termcap. */ + /* Get the terminal dimensions and some terminal control sequences. */ { - char *termtype = getenv ("TERM"); - static char term_buffer[2048]; - - if (termtype != NULL - && tgetent (term_buffer, termtype) == 1) + const char *termtype = getenv ("TERM"); + if (termtype != NULL && *termtype != '\0') { - screen_cols = tgetnum ("co"); - screen_lines = tgetnum ("li"); +#if defined HAVE_TERMINFO + int err = 1; + if (setupterm (termtype, STDOUT_FILENO, &err) == 0 || err == 1) + { + erase_line_str = tigetstr ("el"); + if (erase_line_str == NULL) + erase_line_str = tigetstr ("ed"); + screen_lines = tigetnum ("lines"); + screen_cols = tigetnum ("cols"); + } +#elif defined HAVE_TERMCAP + static char termcap_buffer[2048]; + if (tgetent (termcap_buffer, termtype) > 0) + { + erase_line_str = tgetstr ("ce"); + if (erase_line_str == NULL) + erase_line_str = tgetstr ("cd"); + screen_lines = tgetnum ("li"); + screen_cols = tgetnum ("co"); + } +#endif } } - - /* Get the terminal command to erase the line. */ - erase_line_str = tigetstr ("ed"); -#endif } void @@ -380,7 +392,6 @@ pk_puts_paged (const char *lines) /* Restore stdin to buffered-mode. */ tcsetattr (0, TCSANOW, &old_termios); -#if HAVE_TERMCAP if (erase_line_str) { /* Erase --More-- */ @@ -389,9 +400,7 @@ pk_puts_paged (const char *lines) ostream_flush (pk_ostream, FLUSH_THIS_STREAM); } else -#else - ostream_write_str (pk_ostream, "\n"); -#endif + ostream_write_str (pk_ostream, "\n"); if (pager_inhibited_p) return; -- 2.25.1