diff --git a/Makefile.in b/Makefile.in index 08cef5c..e590112 100644 --- a/Makefile.in +++ b/Makefile.in @@ -171,6 +171,7 @@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ +TERMLIBS = @TERMLIBS@ VERSION = @VERSION@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ diff --git a/config.h.in b/config.h.in index 28d0de8..8172766 100644 --- a/config.h.in +++ b/config.h.in @@ -18,6 +18,12 @@ /* Define to enable SIGSTOP (Ctrl-Z) key. */ #undef CONFIG_SIGSTOP +/* Define to use the termcap library for terminal size. */ +#undef CONFIG_USE_TERMCAP + +/* Define to 1 if `TIOCGWINSZ' requires . */ +#undef GWINSZ_IN_SYS_IOCTL + /* Define to 1 if you have the header file, and it defines `DIR'. */ #undef HAVE_DIRENT_H @@ -34,6 +40,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H +/* Define to 1 if you have the header file. */ +#undef HAVE_NCURSES_TERMCAP_H + /* Define to 1 if you have the header file, and it defines `DIR'. */ #undef HAVE_NDIR_H @@ -88,6 +97,9 @@ /* Define to 1 if you have the `tcgetattr' function. */ #undef HAVE_TCGETATTR +/* Define to 1 if you have the header file. */ +#undef HAVE_TERMCAP_H + /* Define to 1 if you have the header file. */ #undef HAVE_TERMIOS_H diff --git a/configure b/configure index dc8e93d..f3d57fb 100755 --- a/configure +++ b/configure @@ -746,6 +746,7 @@ ac_includes_default="\ ac_subst_vars='am__EXEEXT_FALSE am__EXEEXT_TRUE LTLIBOBJS +TERMLIBS AM_CFLAGS CONFIG_DEFAULT_COMPLETE_FALSE CONFIG_DEFAULT_COMPLETE_TRUE @@ -872,6 +873,7 @@ enable_default_complete enable_arrow_keys enable_sigstop enable_terminal_bell +enable_termcap enable_history ' ac_precious_vars='build_alias @@ -1515,6 +1517,7 @@ Optional Features: --enable-arrow-keys Enable ANSI arrow keys. --enable-sigstop Enable SIGSTOP key. --enable-terminal-bell Enable terminal bell on completion. + --enable-termcap Use the termcap library for terminal size. --enable-history=LINES Enable scrollback history, default off. Optional Packages: @@ -4557,13 +4560,13 @@ if test "${lt_cv_nm_interface+set}" = set; then : else lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext - (eval echo "\"\$as_me:4560: $ac_compile\"" >&5) + (eval echo "\"\$as_me:4563: $ac_compile\"" >&5) (eval "$ac_compile" 2>conftest.err) cat conftest.err >&5 - (eval echo "\"\$as_me:4563: $NM \\\"conftest.$ac_objext\\\"\"" >&5) + (eval echo "\"\$as_me:4566: $NM \\\"conftest.$ac_objext\\\"\"" >&5) (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) cat conftest.err >&5 - (eval echo "\"\$as_me:4566: output\"" >&5) + (eval echo "\"\$as_me:4569: output\"" >&5) cat conftest.out >&5 if $GREP 'External.*some_variable' conftest.out > /dev/null; then lt_cv_nm_interface="MS dumpbin" @@ -5769,7 +5772,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 5772 "configure"' > conftest.$ac_ext + echo '#line 5775 "configure"' > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -7299,11 +7302,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7302: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7305: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7306: \$? = $ac_status" >&5 + echo "$as_me:7309: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -7638,11 +7641,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7641: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7644: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7645: \$? = $ac_status" >&5 + echo "$as_me:7648: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -7743,11 +7746,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7746: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7749: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:7750: \$? = $ac_status" >&5 + echo "$as_me:7753: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -7798,11 +7801,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7801: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7804: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:7805: \$? = $ac_status" >&5 + echo "$as_me:7808: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -10182,7 +10185,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10185 "configure" +#line 10188 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -10278,7 +10281,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10281 "configure" +#line 10284 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -10822,7 +10825,7 @@ fi # Check for malloc.h instead of AC_FUNC_MALLOC/REALLOC AIX and others # mess up the traditional malloc check. -for ac_header in malloc.h signal.h sgtty.h stdlib.h string.h termio.h termios.h +for ac_header in malloc.h signal.h stdlib.h string.h termcap.h termio.h termios.h sgtty.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" @@ -10837,6 +10840,68 @@ fi done +# In termios.h or in sys/ioctl.g? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether termios.h defines TIOCGWINSZ" >&5 +$as_echo_n "checking whether termios.h defines TIOCGWINSZ... " >&6; } +if test "${ac_cv_sys_tiocgwinsz_in_termios_h+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#ifdef TIOCGWINSZ + yes +#endif + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "yes" >/dev/null 2>&1; then : + ac_cv_sys_tiocgwinsz_in_termios_h=yes +else + ac_cv_sys_tiocgwinsz_in_termios_h=no +fi +rm -f conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_tiocgwinsz_in_termios_h" >&5 +$as_echo "$ac_cv_sys_tiocgwinsz_in_termios_h" >&6; } + +if test $ac_cv_sys_tiocgwinsz_in_termios_h != yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether sys/ioctl.h defines TIOCGWINSZ" >&5 +$as_echo_n "checking whether sys/ioctl.h defines TIOCGWINSZ... " >&6; } +if test "${ac_cv_sys_tiocgwinsz_in_sys_ioctl_h+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#ifdef TIOCGWINSZ + yes +#endif + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "yes" >/dev/null 2>&1; then : + ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=yes +else + ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=no +fi +rm -f conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h" >&5 +$as_echo "$ac_cv_sys_tiocgwinsz_in_sys_ioctl_h" >&6; } + + if test $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h = yes; then + +$as_echo "#define GWINSZ_IN_SYS_IOCTL 1" >>confdefs.h + + fi +fi + + # Overrides and types, should be a check. $as_echo "#define SYS_UNIX 1" >>confdefs.h @@ -11103,6 +11168,14 @@ $as_echo "#define CONFIG_ANNOYING_NOISE /**/" >>confdefs.h fi +# Check whether --enable-termcap was given. +if test "${enable_termcap+set}" = set; then : + enableval=$enable_termcap; +$as_echo "#define CONFIG_USE_TERMCAP /**/" >>confdefs.h + +fi + + # Default history size 1, i.e. disabled. let HIST_SIZE=1 # Check whether --enable-history was given. @@ -11194,6 +11267,146 @@ CFLAGS="$saved_cflags" AM_CFLAGS="-std=gnu99 $inline_cflags -W -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow" +### The following magic for determining the location of termcap library is from GNU Texinfo +### http://www.tex.ac.uk/tex-archive/macros/texinfo/texinfo/configure.ac +# Some GNU/Linux systems (e.g., SuSE 4.3, 1996) don't have curses, but +# rather ncurses. So we check for it. +TERMLIBS= +# Check for termlib before termcap because Solaris termcap needs libucb. +TERMLIB_VARIANTS="termlib termcap terminfo ncurses curses" +for termlib in ${TERMLIB_VARIANTS}; do + as_ac_Lib=`$as_echo "ac_cv_lib_${termlib}''_tgetent" | $as_tr_sh` +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for tgetent in -l${termlib}" >&5 +$as_echo_n "checking for tgetent in -l${termlib}... " >&6; } +if { as_var=$as_ac_Lib; eval "test \"\${$as_var+set}\" = set"; }; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-l${termlib} $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char tgetent (); +int +main () +{ +return tgetent (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + eval "$as_ac_Lib=yes" +else + eval "$as_ac_Lib=no" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +eval ac_res=\$$as_ac_Lib + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +eval as_val=\$$as_ac_Lib + if test "x$as_val" = x""yes; then : + TERMLIBS="${TERMLIBS} -l${termlib}"; break +fi + +done +# don't bother warning on djgpp, it doesn't have a term library, it +# ports each termcap-needing program separately according to its needs. +if test -z "$TERMLIBS" && echo "$build" | grep -v djgpp >/dev/null; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: probably need a terminal library, one of: ${TERMLIB_VARIANTS}" >&5 +$as_echo "$as_me: WARNING: probably need a terminal library, one of: ${TERMLIB_VARIANTS}" >&2;} +fi + +# Checks for variables. +# HP-UX 9 (at least) needs -lncurses which defines termcap variables PC etc. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library with termcap variables" >&5 +$as_echo_n "checking for library with termcap variables... " >&6; } +if test "${ac_cv_var_ospeed+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + oldLIBS=$LIBS +for trylib in $termlib ${TERMLIB_VARIANTS}; do + if test "x$trylib" != "x$termlib"; then + LIBS="$oldLIBS -l$termlib -l$trylib" + else + LIBS="$oldLIBS -l$termlib" + fi + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifdef HAVE_NCURSES_TERMCAP_H +#include +#else +#ifdef HAVE_TERMCAP_H +#include +#else +#undef PC +char *BC; +char **UP; +char PC; +short ospeed; +#endif +#endif +/* Make sure all variables actually exist. AIX 4.3 has ospeed but no BC. + --Andreas Ley 24 Aug 2000. */ +BC++; +UP++; +PC++; +return ospeed != 0; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_var_ospeed=$trylib; break +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +done +LIBS=$oldLIBS + +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_var_ospeed" >&5 +$as_echo "$ac_cv_var_ospeed" >&6; } +if test -n "$ac_cv_var_ospeed" \ + && test "x$termlib" != "x$ac_cv_var_ospeed"; then + TERMLIBS="${TERMLIBS} -l${ac_cv_var_ospeed}" +fi +# + +# Do not use unless we're linking with ncurses. +# Must come after the termlib tests. +if test "x$termlib" = xncurses; then + # Use AC_CHECK_HEADERS so the HAVE_*_H symbol gets defined. + for ac_header in ncurses/termcap.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "ncurses/termcap.h" "ac_cv_header_ncurses_termcap_h" "$ac_includes_default" +if test "x$ac_cv_header_ncurses_termcap_h" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_NCURSES_TERMCAP_H 1 +_ACEOF + +fi + +done + +fi +### End-of-Termcap magic from http://www.tex.ac.uk/tex-archive/macros/texinfo/texinfo/configure.ac + ac_config_files="$ac_config_files Makefile src/Makefile include/Makefile man/Makefile examples/Makefile" cat >confcache <<\_ACEOF diff --git a/configure.ac b/configure.ac index d709418..48fa51c 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,16 @@ # Minix libeditline -*- Autoconf -*- +# +# Copyright (c) 2008-2010 Joachim Nilsson +# # Process this file with autoconf to produce a configure script. +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. AC_PREREQ(2.61) AC_INIT(editline, 1.13.0, troglobit@vmlinux.org) @@ -25,7 +36,10 @@ AC_HEADER_STAT AC_HEADER_STDC # Check for malloc.h instead of AC_FUNC_MALLOC/REALLOC AIX and others # mess up the traditional malloc check. -AC_CHECK_HEADERS([malloc.h signal.h sgtty.h stdlib.h string.h termio.h termios.h]) +AC_CHECK_HEADERS([malloc.h signal.h stdlib.h string.h termcap.h termio.h termios.h sgtty.h]) + +# In termios.h or in sys/ioctl.g? +AC_HEADER_TIOCGWINSZ # Overrides and types, should be a check. AC_DEFINE([SYS_UNIX], [1], [Default to UNIX backend, should be detected.]) @@ -55,6 +69,10 @@ AC_ARG_ENABLE(terminal-bell, [ --enable-terminal-bell Enable terminal bell on completion.], AC_DEFINE([CONFIG_ANNOYING_NOISE],, [Define to enable terminal bell on completion.])) +AC_ARG_ENABLE(termcap, + [ --enable-termcap Use the termcap library for terminal size.], + AC_DEFINE([CONFIG_USE_TERMCAP],, [Define to use the termcap library for terminal size.])) + # Default history size 1, i.e. disabled. let HIST_SIZE=1 AC_ARG_ENABLE(history, @@ -92,5 +110,71 @@ CFLAGS="$saved_cflags" AM_CFLAGS="-std=gnu99 $inline_cflags -W -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow" AC_SUBST(AM_CFLAGS) +### The following magic for determining the location of termcap library is from GNU Texinfo +### http://www.tex.ac.uk/tex-archive/macros/texinfo/texinfo/configure.ac +# Some GNU/Linux systems (e.g., SuSE 4.3, 1996) don't have curses, but +# rather ncurses. So we check for it. +TERMLIBS= +# Check for termlib before termcap because Solaris termcap needs libucb. +TERMLIB_VARIANTS="termlib termcap terminfo ncurses curses" +for termlib in ${TERMLIB_VARIANTS}; do + AC_CHECK_LIB(${termlib}, tgetent, + [TERMLIBS="${TERMLIBS} -l${termlib}"; break]) +done +# don't bother warning on djgpp, it doesn't have a term library, it +# ports each termcap-needing program separately according to its needs. +if test -z "$TERMLIBS" && echo "$build" | grep -v djgpp >/dev/null; then + AC_MSG_WARN([probably need a terminal library, one of: ${TERMLIB_VARIANTS}]) +fi + +# Checks for variables. +# HP-UX 9 (at least) needs -lncurses which defines termcap variables PC etc. +AC_MSG_CHECKING(for library with termcap variables) +AC_CACHE_VAL(ac_cv_var_ospeed, +[oldLIBS=$LIBS +for trylib in $termlib ${TERMLIB_VARIANTS}; do + if test "x$trylib" != "x$termlib"; then + LIBS="$oldLIBS -l$termlib -l$trylib" + else + LIBS="$oldLIBS -l$termlib" + fi + AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[#ifdef HAVE_NCURSES_TERMCAP_H +#include +#else +#ifdef HAVE_TERMCAP_H +#include +#else +#undef PC +char *BC; +char **UP; +char PC; +short ospeed; +#endif +#endif +/* Make sure all variables actually exist. AIX 4.3 has ospeed but no BC. + --Andreas Ley 24 Aug 2000. */ +BC++; +UP++; +PC++; +return ospeed != 0; +]])], [ac_cv_var_ospeed=$trylib; break]) +done +LIBS=$oldLIBS +]) +AC_MSG_RESULT($ac_cv_var_ospeed) +if test -n "$ac_cv_var_ospeed" \ + && test "x$termlib" != "x$ac_cv_var_ospeed"; then + TERMLIBS="${TERMLIBS} -l${ac_cv_var_ospeed}" +fi +AC_SUBST(TERMLIBS)# + +# Do not use unless we're linking with ncurses. +# Must come after the termlib tests. +if test "x$termlib" = xncurses; then + # Use AC_CHECK_HEADERS so the HAVE_*_H symbol gets defined. + AC_CHECK_HEADERS(ncurses/termcap.h) +fi +### End-of-Termcap magic from http://www.tex.ac.uk/tex-archive/macros/texinfo/texinfo/configure.ac + AC_OUTPUT(Makefile src/Makefile include/Makefile man/Makefile examples/Makefile) diff --git a/examples/Makefile.am b/examples/Makefile.am index 4e957c9..f64a1d3 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = foreign noinst_PROGRAMS = testit cli -LDADD = $(top_builddir)/src/libeditline.la +LDADD = $(top_builddir)/src/libeditline.la $(TERMLIBS) AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include diff --git a/examples/Makefile.in b/examples/Makefile.in index baf09b7..94be494 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -52,14 +52,17 @@ PROGRAMS = $(noinst_PROGRAMS) cli_SOURCES = cli.c cli_OBJECTS = cli.$(OBJEXT) cli_LDADD = $(LDADD) -cli_DEPENDENCIES = $(top_builddir)/src/libeditline.la +am__DEPENDENCIES_1 = +cli_DEPENDENCIES = $(top_builddir)/src/libeditline.la \ + $(am__DEPENDENCIES_1) AM_V_lt = $(am__v_lt_$(V)) am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) am__v_lt_0 = --silent testit_SOURCES = testit.c testit_OBJECTS = testit.$(OBJEXT) testit_LDADD = $(LDADD) -testit_DEPENDENCIES = $(top_builddir)/src/libeditline.la +testit_DEPENDENCIES = $(top_builddir)/src/libeditline.la \ + $(am__DEPENDENCIES_1) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -151,6 +154,7 @@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ +TERMLIBS = @TERMLIBS@ VERSION = @VERSION@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ @@ -205,7 +209,7 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = foreign -LDADD = $(top_builddir)/src/libeditline.la +LDADD = $(top_builddir)/src/libeditline.la $(TERMLIBS) all: all-am .SUFFIXES: diff --git a/include/Makefile.in b/include/Makefile.in index ce74ba4..b48feec 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -142,6 +142,7 @@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ +TERMLIBS = @TERMLIBS@ VERSION = @VERSION@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ diff --git a/man/Makefile.in b/man/Makefile.in index 157507b..a04b282 100644 --- a/man/Makefile.in +++ b/man/Makefile.in @@ -141,6 +141,7 @@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ +TERMLIBS = @TERMLIBS@ VERSION = @VERSION@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ diff --git a/src/Makefile.in b/src/Makefile.in index bcbaedb..ee5f05a 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -172,6 +172,7 @@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ +TERMLIBS = @TERMLIBS@ VERSION = @VERSION@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ diff --git a/src/complete.c b/src/complete.c index 974e4ab..420b0f0 100644 --- a/src/complete.c +++ b/src/complete.c @@ -240,3 +240,12 @@ int default_rl_list_possib(char *pathname, char ***avp) return ac; } + +/** + * Local Variables: + * version-control: t + * indent-tabs-mode: t + * c-file-style: "ellemtel" + * c-basic-offset: 4 + * End: + */ diff --git a/src/editline.c b/src/editline.c index be17564..71efcd2 100644 --- a/src/editline.c +++ b/src/editline.c @@ -27,7 +27,7 @@ /* ** Manifest constants. */ -#define SCREEN_WIDTH 80 +#define SCREEN_COLS 80 #define SCREEN_ROWS 24 #define NO_ARG (-1) #define DEL 127 @@ -107,7 +107,7 @@ static SIZE_T Length; static SIZE_T ScreenCount; static SIZE_T ScreenSize; static char *backspace; -static int tty_width; +static int tty_cols; static int tty_rows; /* Display print 8-bit chars as `M-x' or as the actual 8-bit char? */ @@ -122,11 +122,10 @@ int (*rl_list_possib)(char *token, char ***av); ** Declarations. */ static char *editinput(void); -#ifdef USE_TERMCAP -extern char *getenv(void); -extern char *tgetstr(void); -extern int tgetent(void); -extern int tgetnum(void); +#ifdef CONFIG_USE_TERMCAP +extern char *tgetstr(const char *, char **); +extern int tgetent(char *, const char *); +extern int tgetnum(const char *); #endif /* @@ -213,7 +212,7 @@ static void tty_backn(int n) static void tty_info(void) { static int init; -#ifdef USE_TERMCAP +#ifdef CONFIG_USE_TERMCAP char *term; char buff[2048]; char *bp; @@ -227,7 +226,7 @@ static void tty_info(void) /* Perhaps we got resized. */ if (ioctl(0, TIOCGWINSZ, &W) >= 0 && W.ws_col > 0 && W.ws_row > 0) { - tty_width = (int)W.ws_col; + tty_cols = (int)W.ws_col; tty_rows = (int)W.ws_row; } #endif @@ -235,32 +234,31 @@ static void tty_info(void) } init++; - tty_width = tty_rows = 0; -#ifdef USE_TERMCAP + /* Initialize to faulty values to trigger fallback if nothing else works. */ + tty_cols = tty_rows = -1; +#ifdef CONFIG_USE_TERMCAP bp = buff; if ((term = getenv("TERM")) == NULL) term = "dumb"; - if (tgetent(buff, term) < 0) { - tty_width = SCREEN_WIDTH; - tty_rows = SCREEN_ROWS; - return; + if (-1 != tgetent(buff, term)) { + if ((backspace = tgetstr("le", &bp)) != NULL) + backspace = strdup(backspace); + tty_cols = tgetnum("co"); + tty_rows = tgetnum("li"); } - if ((backspace = tgetstr("le", &bp)) != NULL) - backspace = strdup(backspace); - tty_width = tgetnum("co"); - tty_rows = tgetnum("li"); + /* Make sure to check width & rows and fallback to TIOCGWINSZ if available. */ #endif + if (tty_cols <= 0 || tty_rows <= 0) { #ifdef TIOCGWINSZ - if (ioctl(0, TIOCGWINSZ, &W) >= 0) { - tty_width = (int)W.ws_col; - tty_rows = (int)W.ws_row; - } + if (-1 != ioctl(0, TIOCGWINSZ, &W)) { + tty_cols = (int)W.ws_col; + tty_rows = (int)W.ws_row; + return; + } #endif - - if (tty_width <= 0 || tty_rows <= 0) { - tty_width = SCREEN_WIDTH; - tty_rows = SCREEN_ROWS; + tty_cols = SCREEN_COLS; + tty_rows = SCREEN_ROWS; } } @@ -283,7 +281,7 @@ static void columns(int ac, char **av) for (longest = 0, i = 0; i < ac; i++) if ((j = strlen((char *)av[i])) > longest) longest = j; - cols = tty_width / (longest + 3); + cols = tty_cols / (longest + 3); tty_puts(NEWLINE); for (skip = ac / cols + 1, i = 0; i < skip; i++) { @@ -1467,3 +1465,11 @@ static el_keymap_t MetaMap[]= { { 0, NULL } }; +/** + * Local Variables: + * version-control: t + * indent-tabs-mode: t + * c-file-style: "ellemtel" + * c-basic-offset: 4 + * End: + */ diff --git a/src/editline.h b/src/editline.h index d91d81c..fe68cc2 100644 --- a/src/editline.h +++ b/src/editline.h @@ -45,6 +45,13 @@ #ifdef SYS_OS9 #include "os9.h" #endif +/* The following two are for TIOCGWINSZ */ +#ifdef HAVE_TERMIOS_H +# include +#endif +#ifdef GWINSZ_IN_SYS_IOCTL +# include +#endif #ifndef SIZE_T #define SIZE_T unsigned int