summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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: