summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-09-09 06:57:07 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-09-09 06:57:07 -0700
commitc6c05649f5d3890281e6fe95694794d39f6f0841 (patch)
tree670470fb28f3eadc43006019e04d6847555ca1f4
parent6e8cecf1f958af3b46365b8f41ceea500d9f2019 (diff)
downloadtxr-c6c05649f5d3890281e6fe95694794d39f6f0841.tar.gz
txr-c6c05649f5d3890281e6fe95694794d39f6f0841.tar.bz2
txr-c6c05649f5d3890281e6fe95694794d39f6f0841.zip
Reveal struct winsize on Solaris.
On Solaris 10, we need __EXTENSIONS__ defined to make struct winsize appear out of <termios.h>. This commit adds detection for what preprocessor symbol needs to be defined for struct winsize to appear, if it appears at all. Then this symbol is defined on the compiler command line when compiling linenoise. * Makefile (CFLAGS): Add -D$(termios_define) for linenoise.o target. * configure (have_winsize, termios_define): New variables. Detect whether struct winsize is available, and what preprocessor symbol, if any, is required to reveal the feature. * linenoise/linenoise.c: Need to include TXR's "config.h" for HAVE_WINSIZE. (get_columns): Reorganized so that use of struct winsize is guarded by HAVE_WINSIZE and fallback code is used if either obtaining the size fails or the feature is completely unavailable.
-rw-r--r--Makefile1
-rwxr-xr-xconfigure29
-rw-r--r--linenoise/linenoise.c13
3 files changed, 39 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index c05ecb75..bc0b488e 100644
--- a/Makefile
+++ b/Makefile
@@ -233,6 +233,7 @@ dbg/txr-win.o: CFLAGS += -DPROG_NAME=\"$(PROG)-win-dbg\" \
$(call EACH_CONF,txr.o txr-win.o): CFLAGS += -DEXE_SUFF=\"$(EXE)\"
$(call EACH_CONF,txr.o txr-win.o): CFLAGS += -DTXR_VER=\"$(txr_ver)\"
+$(call EACH_CONF,linenoise/linenoise.o): CFLAGS += -D$(termios_define)
.PHONY: rebuild clean repatch distclean
ifeq ($(PROG),)
diff --git a/configure b/configure
index 36992329..fa72e0e0 100755
--- a/configure
+++ b/configure
@@ -124,6 +124,8 @@ have_git=
have_pwuid=
have_alloca=
have_termios=
+have_winsize=
+termios_define=
conf_dir=config
config_h=$conf_dir/config.h
config_make=$conf_dir/config.make
@@ -651,6 +653,7 @@ have_glob := $have_glob
have_posix_sigs := $have_posix_sigs
have_termios := $have_termios
+termios_define := $termios_define
# do we compile in debug support?
debug_support := $debug_support
@@ -2153,6 +2156,32 @@ else
printf "no\n"
fi
+printf "Checking for struct winsize ... "
+
+for termios_define in NOTHING __EXTENSIONS__ ; do
+ cat > conftest.c <<!
+#define $termios_define
+#include <sys/ioctl.h>
+#include <termios.h>
+
+int main(int argc, char **argv)
+{
+ struct winsize ws;
+ return 0;
+}
+!
+ if conftest ; then
+ printf "yes\n"
+ printf "#define HAVE_WINSIZE 1\n" >> $config_h
+ have_winsize=y
+ break;
+ fi
+done
+
+if [ -z "$have_winsize" ] ; then
+ printf "no\n"
+fi
+
#
# Dependent variables
#
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c
index 63abef6c..791d99ed 100644
--- a/linenoise/linenoise.c
+++ b/linenoise/linenoise.c
@@ -53,6 +53,7 @@
#include <sys/ioctl.h>
#include <unistd.h>
#include <signal.h>
+#include "config.h"
#include "linenoise.h"
#define LINENOISE_DEFAULT_HISTORY_MAX_LEN 100
@@ -211,10 +212,16 @@ static int get_cursor_position(int ifd, int ofd) {
/* Try to get the number of columns in the current terminal, or assume 80
* if it fails. */
static int get_columns(int ifd, int ofd) {
+#if HAVE_WINSIZE
struct winsize ws;
- if (ioctl(1, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) {
- /* ioctl() failed. Try to query the terminal itself. */
+ if (ioctl(1, TIOCGWINSZ, &ws) == 0 && ws.ws_col != 0)
+ return ws.ws_col;
+#endif
+
+ {
+ /* ioctl() failed or we don't have struct winsize.
+ Try to query the terminal itself. */
int start, cols;
/* Get the initial position so we can restore it later. */
@@ -235,8 +242,6 @@ static int get_columns(int ifd, int ofd) {
}
}
return cols;
- } else {
- return ws.ws_col;
}
failed: