zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: curses and term headers yet again
@ 2008-03-13 11:00 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2008-03-13 11:00 UTC (permalink / raw)
  To: Zsh hackers list

The aim of this is twofold.  First, identify the actual curses header
we are going to be using and stick to it throughout configuration and
building.  Second, identify the appropriate term.h to go along with
the curses header.  This should fix Zvi's problem.  As a side effect,
a certain amount of nastiness associated with whether or not a curses
header was needed with term.h has gone, since we always include the
appropriate version of the curses header.

I was quite cautious in the way I made the headers available for
#include, since the gcc manual implies #include using macros isn't
completely trivial.  So there are intermediate headers.  They're created
by building the main shell to make them available for all libraries, but
they're not included by the main shell so they're not listed in its
headers.

Index: configure.ac
===================================================================
RCS file: /cvsroot/zsh/zsh/configure.ac,v
retrieving revision 1.94
diff -u -r1.94 configure.ac
--- configure.ac	3 Mar 2008 12:29:55 -0000	1.94
+++ configure.ac	13 Mar 2008 10:38:10 -0000
@@ -685,20 +685,6 @@
   AC_DEFINE(ZSH_CURSES_NEEDS_XOPEN)
 fi
 
-AH_TEMPLATE([HAVE_BOOLCODES],
-[Define if you have the termcap boolcodes symbol.])
-AH_TEMPLATE([HAVE_NUMCODES],
-[Define if you have the termcap numcodes symbol.])
-AH_TEMPLATE([HAVE_STRCODES],
-[Define if you have the termcap strcodes symbol.])
-AH_TEMPLATE([HAVE_BOOLNAMES],
-[Define if you have the terminfo boolnames symbol.])
-AH_TEMPLATE([HAVE_NUMNAMES],
-[Define if you have the terminfo numnames symbol.])
-AH_TEMPLATE([HAVE_STRNAMES],
-[Define if you have the terminfo strnames symbol.])
-AH_TEMPLATE([TERM_H_NEEDS_CURSES_H],
-[Define if term.h chokes without curses.h.])
 dnl Check for tigetflag (terminfo) before tgetent (termcap).
 dnl That's so that on systems where termcap and [n]curses are
 dnl both available and both contain termcap functions, while
@@ -721,69 +707,18 @@
 if test x$ac_cv_header_curses_solaris = xyes; then
 AC_DEFINE(HAVE_CURSES_H)
 fi])
-AC_CHECK_HEADERS(term.h,
-[AC_MSG_CHECKING(if term.h needs curses.h)
-AC_TRY_COMPILE([#include <term.h>], [char **test = boolcodes;], boolcodes_with_only_term_h=yes,
-boolcodes_with_only_term_h=no)
-AC_TRY_COMPILE([#include <curses.h>
-#include <term.h>], [char **test = boolcodes;], boolcodes_with_curses_h_and_term_h=yes,
-boolcodes_with_curses_h_and_term_h=no)
-if test "x$boolcodes_with_curses_h_and_term_h" = xyes && test "x$boolcodes_with_only_term_h" = xno;
-then
-AC_DEFINE(TERM_H_NEEDS_CURSES_H)
-AC_MSG_RESULT(yes)
-else
-AC_MSG_RESULT(no)
-fi
-
-AC_MSG_CHECKING(if boolcodes is available)
-AC_TRY_LINK([#ifdef TERM_H_NEEDS_CURSES_H
-#include <curses.h>
-#endif
-#include <term.h>], [char **test = boolcodes; printf(*test);],
-AC_DEFINE(HAVE_BOOLCODES) boolcodes=yes, boolcodes=no)
-AC_MSG_RESULT($boolcodes)
-AC_MSG_CHECKING(if numcodes is available)
-AC_TRY_LINK([#ifdef TERM_H_NEEDS_CURSES_H
-#include <curses.h>
-#endif
-#include <term.h>], [char **test = numcodes; printf(*test);],
-AC_DEFINE(HAVE_NUMCODES) numcodes=yes, numcodes=no)
-AC_MSG_RESULT($numcodes)
-AC_MSG_CHECKING(if strcodes is available)
-AC_TRY_LINK([#ifdef TERM_H_NEEDS_CURSES_H
-#include <curses.h>
-#endif
-#include <term.h>], [char **test = strcodes; printf(*test);],
-AC_DEFINE(HAVE_STRCODES) strcodes=yes, strcodes=no)
-AC_MSG_RESULT($strcodes)
-AC_MSG_CHECKING(if boolnames is available)
-AC_TRY_LINK([#include <curses.h>
-#include <term.h>], [char **test = boolnames; printf(*test);],
-AC_DEFINE(HAVE_BOOLNAMES) boolnames=yes, boolnames=no)
-AC_MSG_RESULT($boolnames)
-AC_MSG_CHECKING(if numnames is available)
-AC_TRY_LINK([#include <curses.h>
-#include <term.h>], [char **test = numnames; printf(*test);],
-AC_DEFINE(HAVE_NUMNAMES) numnames=yes, numnames=no)
-AC_MSG_RESULT($numnames)
-AC_MSG_CHECKING(if strnames is available)
-AC_TRY_LINK([#include <curses.h>
-#include <term.h>], [char **test = strnames; printf(*test);],
-AC_DEFINE(HAVE_STRNAMES) strnames=yes, strnames=no)
-AC_MSG_RESULT($strnames)
-])
-
 
 dnl If our terminal library is not ncurses, don't try including
 dnl any ncurses headers.
-AH_TEMPLATE([ZSH_IGNORE_NCURSES],
-[Define to 1 to ignore any ncurses library headers found on the system.])
-case $LIBS in
-  *-lncurses*) ;;
+AC_CACHE_CHECK(if we need to ignore ncurses, zsh_cv_ignore_ncurses,
+[case $LIBS in
+  *-lncurses*)
+  zsh_cv_ignore_ncurses=no
+  ;;
   *)
-  AC_DEFINE(ZSH_IGNORE_NCURSES) ;;
-esac
+  zsh_cv_ignore_ncurses=yes
+  ;;
+esac])
 
 AC_SEARCH_LIBS(getpwnam, nsl)
 
@@ -1407,20 +1342,42 @@
 ERRNO_H="$zsh_cv_path_errno_h"
 AC_SUBST(ERRNO_H)dnl
 
+AC_CACHE_CHECK(location of curses header, zsh_cv_path_curses_header,
+[if test x$zsh_cv_ignore_ncurses = xyes; then
+  if test x$ac_cv_header_curses_h = xyes; then
+    zsh_cv_path_curses_header=curses.h
+  else
+    zsh_cv_path_curses_header=none
+  fi
+elif test x$ac_cv_header_ncursesw_ncurses_h = xyes; then
+  zsh_cv_path_curses_header=ncursesw/ncurses.h
+elif test x$ac_cv_header_ncurses_ncurses_h = xyes; then
+  zsh_cv_path_curses_header=ncurses/ncurses.h
+elif test x$ac_cv_header_ncurses_h = xyes; then
+  zsh_cv_path_curses_header=ncurses.h
+elif test x$ac_cv_header_curses_h = xyes; then
+  zsh_cv_path_curses_header=curses.h
+else
+  zsh_cv_path_curses_header=none
+fi])
+AH_TEMPLATE([ZSH_HAVE_CURSES_H],
+[Define to 1 if some variant of a curses header can be included])
+if test x$zsh_cv_path_curses_header != xnone; then
+  AC_DEFINE(ZSH_HAVE_CURSES_H)
+  ZSH_CURSES_H=$zsh_cv_path_curses_header
+else
+  ZSH_CURSES_H=
+fi
+AC_SUBST(ZSH_CURSES_H)
+
 dnl Where are curses key definitions located?  Need for keypad() mode.
 AC_CACHE_CHECK(where curses key definitions are located, zsh_cv_path_curses_keys_h,
 [dnl This is an identical trick to errno.h, except we use ncurses.h
 dnl if we can.
-if test x$ac_cv_header_ncurses_h = xyes; then
-  echo "#include <ncurses.h>" >nametmp.c
-elif test x$ac_cv_header_ncurses_ncurses_h = xyes; then
-  echo "#include <ncurses/ncurses.h>" >nametmp.c
-elif test x$ac_cv_header_ncursesw_ncurses_h = xyes; then
-  echo "#include <ncursesw/ncurses.h>" >nametmp.c
-elif test x$ac_cv_header_curses_h = xyes; then
-  echo "#include <curses.h>" >nametmp.c
-else
+if test x$zsh_cv_path_curses_header = xnone; then
   echo >nametmp.c
+else
+  echo "#include <$zsh_cv_path_curses_header>" >nametmp.c
 fi
 
 curses_list="`$CPP nametmp.c |
@@ -1446,6 +1403,97 @@
 CURSES_KEYS_H="$zsh_cv_path_curses_keys_h"
 AC_SUBST(CURSES_KEYS_H)dnl
 
+dnl See if there are variants of term.h.  For testing each one
+dnl we include the most likely variant of the curses header.
+AC_CHECK_HEADERS(ncursesw/term.h,
+true, true,
+[#include <ncursesw/ncurses.h>])
+AC_CHECK_HEADERS(ncurses/term.h,
+true, true,
+[#include <ncurses/ncurses.h>])
+AC_CHECK_HEADERS(term.h,
+true, true,
+[#include <curses.h>])
+
+dnl See if term.h is bundled along with the curses library we
+dnl are using.  If this isn't the default system curses, compilation
+dnl could barf unless we include from the right subdirectory.
+AC_CACHE_CHECK(where term.h is located, zsh_cv_path_term_header,
+[case x$zsh_cv_path_curses_header in
+  xncursesw/*)
+  if test x$ac_cv_header_ncursesw_term_h = xyes; then
+    zsh_cv_path_term_header=ncursesw/term.h
+  fi
+  ;;
+  xncurses/*)
+  if test x$ac_cv_header_ncurses_term_h = xyes; then
+    zsh_cv_path_term_header=ncurses/term.h
+  fi
+  ;;
+esac
+if test x$zsh_cv_path_term_header = x; then
+  if test x$ac_cv_header_term_h = xyes; then
+    zsh_cv_path_term_header=term.h
+  else
+    zsh_cv_path_term_header=none
+  fi
+fi])
+
+AH_TEMPLATE([ZSH_HAVE_TERM_H],
+[Define to 1 if some variant of term.h can be included])
+AH_TEMPLATE([HAVE_BOOLCODES],
+[Define if you have the termcap boolcodes symbol.])
+AH_TEMPLATE([HAVE_NUMCODES],
+[Define if you have the termcap numcodes symbol.])
+AH_TEMPLATE([HAVE_STRCODES],
+[Define if you have the termcap strcodes symbol.])
+AH_TEMPLATE([HAVE_BOOLNAMES],
+[Define if you have the terminfo boolnames symbol.])
+AH_TEMPLATE([HAVE_NUMNAMES],
+[Define if you have the terminfo numnames symbol.])
+AH_TEMPLATE([HAVE_STRNAMES],
+[Define if you have the terminfo strnames symbol.])
+
+if test x$zsh_cv_path_term_header != xnone; then
+  AC_DEFINE(ZSH_HAVE_TERM_H)
+  ZSH_TERM_H=$zsh_cv_path_term_header
+  if test x$zsh_cv_path_curses_header != xnone; then
+    term_includes="#include <$zsh_cv_path_curses_header>
+#include <$zsh_cv_path_term_header>"
+  else
+    term_includes="#include <$zsh_cv_path_term_header>"
+  fi
+
+  AC_MSG_CHECKING(if boolcodes is available)
+  AC_TRY_LINK($term_includes, [char **test = boolcodes; printf(*test);],
+  AC_DEFINE(HAVE_BOOLCODES) boolcodes=yes, boolcodes=no)
+  AC_MSG_RESULT($boolcodes)
+  AC_MSG_CHECKING(if numcodes is available)
+  AC_TRY_LINK($term_includes, [char **test = numcodes; printf(*test);],
+  AC_DEFINE(HAVE_NUMCODES) numcodes=yes, numcodes=no)
+  AC_MSG_RESULT($numcodes)
+  AC_MSG_CHECKING(if strcodes is available)
+  AC_TRY_LINK($term_includes, [char **test = strcodes; printf(*test);],
+  AC_DEFINE(HAVE_STRCODES) strcodes=yes, strcodes=no)
+  AC_MSG_RESULT($strcodes)
+  AC_MSG_CHECKING(if boolnames is available)
+  AC_TRY_LINK($term_includes, [char **test = boolnames; printf(*test);],
+  AC_DEFINE(HAVE_BOOLNAMES) boolnames=yes, boolnames=no)
+  AC_MSG_RESULT($boolnames)
+  AC_MSG_CHECKING(if numnames is available)
+  AC_TRY_LINK($term_includes, [char **test = numnames; printf(*test);],
+  AC_DEFINE(HAVE_NUMNAMES) numnames=yes, numnames=no)
+  AC_MSG_RESULT($numnames)
+  AC_MSG_CHECKING(if strnames is available)
+  AC_TRY_LINK($term_includes, [char **test = strnames; printf(*test);],
+  AC_DEFINE(HAVE_STRNAMES) strnames=yes, strnames=no)
+  AC_MSG_RESULT($strnames)
+else
+  ZSH_TERM_H=
+fi
+AC_SUBST(ZSH_TERM_H)
+
+
 dnl -----------------------------------------------------
 dnl Look for the file containing the RLIMIT_* definitions
 dnl -----------------------------------------------------
Index: Config/defs.mk.in
===================================================================
RCS file: /cvsroot/zsh/zsh/Config/defs.mk.in,v
retrieving revision 1.13
diff -u -r1.13 defs.mk.in
--- Config/defs.mk.in	15 Jan 2007 16:36:41 -0000	1.13
+++ Config/defs.mk.in	13 Mar 2008 10:38:11 -0000
@@ -29,6 +29,10 @@
 @SET_MAKE@
 EXEEXT = @EXEEXT@
 
+# headers
+ZSH_CURSES_H = @ZSH_CURSES_H@
+ZSH_TERM_H = @ZSH_TERM_H@
+
 # install basename
 tzsh            = @tzsh@
 
Index: Src/zsh.mdd
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.mdd,v
retrieving revision 1.16
diff -u -r1.16 zsh.mdd
--- Src/zsh.mdd	23 Apr 2007 16:44:27 -0000	1.16
+++ Src/zsh.mdd	13 Mar 2008 10:38:11 -0000
@@ -33,9 +33,26 @@
 
 init.o params.o parse.o: version.h
 
-version.h: $(sdir_top)/Config/version.mk
+# The main shell doesn't currently need zshcurses.h and zshterm.h,
+# but make sure these are built with the headers.
+# If it did need need them they would be in headers at the top instead.
+version.h: $(sdir_top)/Config/version.mk zshcurses.h zshterm.h
 	echo '#define ZSH_VERSION "'$(VERSION)'"' > $@
 
+zshcurses.h: ../config.h
+	@if test x$(ZSH_CURSES_H) != x; then \
+	  echo "#include <$(ZSH_CURSES_H)>" >zshcurses.h; \
+	else \
+	  echo >zshcurses.h; \
+	fi
+
+zshterm.h: ../config.h
+	@if test x$(ZSH_TERM_H) != x; then \
+	  echo "#include <$(ZSH_TERM_H)>" >zshterm.h; \
+	else \
+	  echo >zshterm.h; \
+	fi
+
 zshpaths.h: Makemod $(CONFIG_INCS)
 	@echo '#define MODULE_DIR "'$(MODDIR)'"' > zshpaths.h.tmp
 	@if test x$(sitescriptdir) != xno; then \
Index: Src/Modules/curses.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/curses.c,v
retrieving revision 1.44
diff -u -r1.44 curses.c
--- Src/Modules/curses.c	17 Dec 2007 09:41:09 -0000	1.44
+++ Src/Modules/curses.c	13 Mar 2008 10:38:12 -0000
@@ -41,26 +41,8 @@
 # undef HAVE_NCURSESW_NCURSES_H
 #endif
 
-#ifdef ZSH_IGNORE_NCURSES
-# ifdef HAVE_CURSES_H
-#  include <curses.h>
-# endif
-#else
-# ifdef HAVE_NCURSESW_NCURSES_H
-#  include <ncursesw/ncurses.h>
-# else
-#  ifdef HAVE_NCURSES_NCURSES_H
-#   include <ncurses/ncurses.h>
-#  else
-#   ifdef HAVE_NCURSES_H
-#    include <ncurses.h>
-#   else
-#    ifdef HAVE_CURSES_H
-#     include <curses.h>
-#    endif
-#   endif
-#  endif
-# endif
+#ifdef ZSH_HAVE_CURSES_H
+# include "../zshcurses.h"
 #endif
 
 #ifdef HAVE_SETCCHAR
Index: Src/Modules/termcap.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/termcap.c,v
retrieving revision 1.24
diff -u -r1.24 termcap.c
--- Src/Modules/termcap.c	6 Jul 2007 21:52:40 -0000	1.24
+++ Src/Modules/termcap.c	13 Mar 2008 10:38:12 -0000
@@ -36,7 +36,7 @@
 #include "../../config.h"
 
 #ifdef HAVE_TGETENT
-# if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
+# if defined(ZSH_HAVE_CURSES_H) && defined(ZSH_HAVE_TERM_H)
 #  define USES_TERM_H 1
 # else
 #  ifdef HAVE_TERMCAP_H
@@ -54,10 +54,10 @@
 #  ifdef HAVE_TERMIO_H
 #   include <termio.h>
 #  endif
-#  ifdef TERM_H_NEEDS_CURSES_H
-#   include <curses.h>
+#  ifdef ZSH_HAVE_CURSES_H
+#   include "../zshcurses.h"
 #  endif
-#  include <term.h>
+#  include "../zshterm.h"
 # else
 #  ifdef USES_TERMCAP_H
 #   include <termcap.h>
Index: Src/Modules/terminfo.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/terminfo.c,v
retrieving revision 1.33
diff -u -r1.33 terminfo.c
--- Src/Modules/terminfo.c	7 Dec 2007 03:15:17 -0000	1.33
+++ Src/Modules/terminfo.c	13 Mar 2008 10:38:12 -0000
@@ -30,7 +30,7 @@
 #define USES_TERM_H 1
 #include "terminfo.mdh"
 
-#if defined(HAVE_TIGETFLAG) && (defined(HAVE_CURSES_H) || defined(HAVE_NCURSES_H) || defined(HAVE_NCURSES_NCURSES_H) || defined(HAVE_NCURSESW_NCURSES_H))
+#if defined(HAVE_TIGETFLAG) && defined(ZSH_HAVE_CURSES_H)
 # define USE_TERMINFO_MODULE 1
 #else
 # undef USE_TERMINFO_MODULE
@@ -49,30 +49,12 @@
 #  undef offsetof
 # endif
 
-#ifdef ZSH_IGNORE_NCURSES
-# ifdef HAVE_CURSES_H
-#  include <curses.h>
-# endif
-#else
-# ifdef HAVE_NCURSESW_NCURSES_H
-#  include <ncursesw/ncurses.h>
-# else
-#  ifdef HAVE_NCURSES_NCURSES_H
-#   include <ncurses/ncurses.h>
-#  else
-#   ifdef HAVE_NCURSES_H
-#    include <ncurses.h>
-#   else
-#    ifdef HAVE_CURSES_H
-#     include <curses.h>
-#    endif
-#   endif
-#  endif
-# endif
+#ifdef ZSH_HAVE_CURSES_H
+# include "../zshcurses.h"
 #endif
 
-# ifdef HAVE_TERM_H
-#  include <term.h>
+# ifdef ZSH_HAVE_TERM_H
+#  include "../zshterm.h"
 # endif
 
 /* echoti: output a terminfo capability */


-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-03-13 11:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-13 11:00 PATCH: curses and term headers yet again Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).