From 1d8bec8909b11d3092dcb6a39bfc362f470949e1 Mon Sep 17 00:00:00 2001 From: Giles Atkinson <“gatk555@gmail.com”> Date: Tue, 4 Feb 2025 18:08:18 +0000 Subject: [PATCH] Do not include term.h and curses.h in terminal.c without checking that they exist. Modern ncurses does not need curses.h to compile term.h so that header has been removed. Also make ncurses the last choice when looking for tputs(). --- configure.ac | 8 ++++---- src/frontend/terminal.c | 29 ++++++++++++++++------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index 8a51c2cf9..868aa9da4 100644 --- a/configure.ac +++ b/configure.ac @@ -1274,7 +1274,7 @@ else AC_CHECK_HEADERS([readline/readline.h readline/history.h], [AC_DEFINE([HAVE_GNUREADLINE], [], [Define if we have GNU readline])], [AC_MSG_ERROR([Couldn't find GNU readline headers.])]) - AC_SEARCH_LIBS([tputs], [ncurses tinfo termcap], + AC_SEARCH_LIBS([tputs], [tinfo termcap ncurses], [AC_DEFINE([HAVE_TERMCAP], [], [Define if we have ncurses/terminfo or termcap])], [AC_MSG_ERROR([Found neither ncurses/terminfo or termcap])]) AC_CHECK_LIB([readline], [readline], @@ -1290,7 +1290,7 @@ else if test -f $dir/include/readline/readline.h && test -f $dir/include/readline/history.h ; then AC_DEFINE([HAVE_GNUREADLINE], [], [Define if we have GNU readline]) - AC_SEARCH_LIBS([tputs], [ncurses tinfo termcap], + AC_SEARCH_LIBS([tputs], [tinfo termcap ncurses], [AC_DEFINE([HAVE_TERMCAP], [], [Define if we have ncurses/terminfo or termcap])], [AC_MSG_ERROR([Found neither ncurses/terminfo or termcap])]) AC_CHECK_LIB([readline], [readline], @@ -1312,7 +1312,7 @@ else AC_CHECK_HEADERS([editline/readline.h], [AC_DEFINE([HAVE_BSDEDITLINE], [1], [Define to enable BSD editline])], [AC_MSG_ERROR([Couldn't find BSD editline headers.])]) - AC_SEARCH_LIBS([tputs], [ncurses tinfo termcap], + AC_SEARCH_LIBS([tputs], [tinfo termcap ncurses], [AC_DEFINE([HAVE_TERMCAP], [], [Define if we have ncurses/terminfo or termcap])], [AC_MSG_ERROR([Found neither ncurses/terminfo or termcap])]) AC_CHECK_LIB([edit], [readline], @@ -1323,7 +1323,7 @@ else fi # Use AC_CHECK_HEADERS so the HAVE_*_H symbol gets defined -AC_CHECK_HEADERS([ncurses/termcap.h termcap.h]) +AC_CHECK_HEADERS([ncurses/termcap.h termcap.h term.h]) AC_CHECK_HEADERS([sys/sysctl.h]) # Add OpenMP to ngspice. diff --git a/src/frontend/terminal.c b/src/frontend/terminal.c index bdfe23992..b4d6dfb12 100644 --- a/src/frontend/terminal.c +++ b/src/frontend/terminal.c @@ -25,19 +25,6 @@ Author: 1986 Wayne A. Christopher, U. C. Berkeley CAD Group #include #endif - -#ifdef HAVE_TERMCAP -#include -#include -#endif - - -#ifdef HAVE_TERMCAP_H -#include -#elif HAVE_NCURSES_TERMCAP_H -#include -#endif - #include "ngspice/cpdefs.h" #include "variable.h" @@ -49,6 +36,22 @@ bool out_isatty = TRUE; #if !defined (TCL_MODULE) && !defined (SHARED_MODULE) +#ifdef HAVE_TERMCAP +/* The tputs() function was found in a library, but there are several + * candidates for the header file location. + */ + +#if HAVE_TERM_H +#include +#elif HAVE_TERMCAP_H +#include +#elif HAVE_NCURSES_TERMCAP_H +#include +#else +#undef HAVE_TERMCAP +#endif +#endif + #ifdef HAVE_TERMCAP static char *motion_chars; static char *clear_chars;