From 759188eae5651f1fbca45be310b0b9b46d876080 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 2 Aug 2016 15:53:24 +0100 Subject: stty: changes required to build for WIN32 --- configs/mingw32_defconfig | 6 +++--- configs/mingw64_defconfig | 6 +++--- include/mingw.h | 2 ++ win32/ioctl.c | 4 ++++ win32/termios.c | 43 +++++++++++++++++++++++++++++++++++++++---- win32/termios.h | 17 +++++++++++++++++ win32/winansi.c | 17 +++++++++++++++++ 7 files changed, 85 insertions(+), 10 deletions(-) diff --git a/configs/mingw32_defconfig b/configs/mingw32_defconfig index 34ce09e78..b81dce789 100644 --- a/configs/mingw32_defconfig +++ b/configs/mingw32_defconfig @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # Busybox version: 1.26.0.git -# Thu Jul 7 14:45:07 2016 +# Tue Aug 2 15:42:24 2016 # CONFIG_HAVE_DOT_CONFIG=y # CONFIG_PLATFORM_POSIX is not set @@ -294,7 +294,7 @@ CONFIG_SORT=y CONFIG_FEATURE_SORT_BIG=y CONFIG_SPLIT=y CONFIG_FEATURE_SPLIT_FANCY=y -# CONFIG_STTY is not set +CONFIG_STTY=y CONFIG_SUM=y CONFIG_TAC=y CONFIG_TAIL=y @@ -760,7 +760,7 @@ CONFIG_MAN=y CONFIG_STRINGS=y # CONFIG_TIME is not set # CONFIG_TIMEOUT is not set -# CONFIG_TTYSIZE is not set +CONFIG_TTYSIZE=y # CONFIG_VOLNAME is not set # CONFIG_WATCHDOG is not set diff --git a/configs/mingw64_defconfig b/configs/mingw64_defconfig index b0fb0c0d4..8434cd2b7 100644 --- a/configs/mingw64_defconfig +++ b/configs/mingw64_defconfig @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # Busybox version: 1.26.0.git -# Thu Jul 7 14:45:07 2016 +# Tue Aug 2 15:42:24 2016 # CONFIG_HAVE_DOT_CONFIG=y # CONFIG_PLATFORM_POSIX is not set @@ -294,7 +294,7 @@ CONFIG_SORT=y CONFIG_FEATURE_SORT_BIG=y CONFIG_SPLIT=y CONFIG_FEATURE_SPLIT_FANCY=y -# CONFIG_STTY is not set +CONFIG_STTY=y CONFIG_SUM=y CONFIG_TAC=y CONFIG_TAIL=y @@ -760,7 +760,7 @@ CONFIG_MAN=y CONFIG_STRINGS=y # CONFIG_TIME is not set # CONFIG_TIMEOUT is not set -# CONFIG_TTYSIZE is not set +CONFIG_TTYSIZE=y # CONFIG_VOLNAME is not set # CONFIG_WATCHDOG is not set diff --git a/include/mingw.h b/include/mingw.h index 04700963c..729a08db0 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -178,6 +178,7 @@ int winansi_getc(FILE *stream); #define getc winansi_getc int winansi_get_terminal_width_height(struct winsize *win); +int winansi_set_terminal_width_height(struct winsize *win); /* * stdlib.h @@ -225,6 +226,7 @@ int ffs(int i); */ #define TIOCGWINSZ 0x5413 +#define TIOCSWINSZ 0x5414 int ioctl(int fd, int code, ...); diff --git a/win32/ioctl.c b/win32/ioctl.c index 73ceeedec..f3657966d 100644 --- a/win32/ioctl.c +++ b/win32/ioctl.c @@ -13,6 +13,10 @@ int ioctl(int fd UNUSED_PARAM, int code, ...) arg = va_arg(ap, void *); ret = winansi_get_terminal_width_height((struct winsize *)arg); break; + case TIOCSWINSZ: + arg = va_arg(ap, void *); + ret = winansi_set_terminal_width_height((struct winsize *)arg); + break; default: ret = -1; errno = EINVAL; diff --git a/win32/termios.c b/win32/termios.c index 658af4a26..108a746ef 100644 --- a/win32/termios.c +++ b/win32/termios.c @@ -1,13 +1,26 @@ #include "libbb.h" -int tcsetattr(int fd UNUSED_PARAM, int mode UNUSED_PARAM, const struct termios *t UNUSED_PARAM) +static struct termios dummy = { + 0, /* c_iflag */ + 0, /* c_oflag */ + 0, /* c_cflag */ + 0, /* c_lflag */ + '\0', /* c_line */ + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", /* c_cc[NCCS] */ + B9600, /* c_ispeed */ + B9600 /* c_ospeed */ +}; + +int tcsetattr(int fd UNUSED_PARAM, int mode UNUSED_PARAM, const struct termios *t) { - return -1; + dummy = *t; + return 0; } -int tcgetattr(int fd UNUSED_PARAM, struct termios *t UNUSED_PARAM) +int tcgetattr(int fd UNUSED_PARAM, struct termios *t) { - return -1; + *t = dummy; + return 0; } int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout) @@ -81,3 +94,25 @@ int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout) SetConsoleMode(cin, mode); return ret; } + +speed_t cfgetispeed(const struct termios *termios_p) +{ + return termios_p->c_ispeed; +} + +speed_t cfgetospeed(const struct termios *termios_p) +{ + return termios_p->c_ospeed; +} + +int cfsetispeed(struct termios *termios_p, speed_t speed) +{ + termios_p->c_ispeed = speed; + return 0; +} + +int cfsetospeed(struct termios *termios_p, speed_t speed) +{ + termios_p->c_ospeed = speed; + return 0; +} diff --git a/win32/termios.h b/win32/termios.h index 011a37eb9..9255e0141 100644 --- a/win32/termios.h +++ b/win32/termios.h @@ -100,6 +100,18 @@ #define B2400 0000013 #define B4800 0000014 #define B9600 0000015 +#define CSIZE 0000060 +#define CS5 0000000 +#define CS6 0000020 +#define CS7 0000040 +#define CS8 0000060 +#define CSTOPB 0000100 +#define CREAD 0000200 +#define PARENB 0000400 +#define PARODD 0001000 +#define HUPCL 0002000 +#define CLOCAL 0004000 + typedef unsigned char cc_t; typedef unsigned int tcflag_t; @@ -127,3 +139,8 @@ struct winsize { int tcflush(int fd, int queue_selector); int tcgetattr(int fd, struct termios *t); int tcsetattr(int fd, int mode, const struct termios *t); + +speed_t cfgetispeed(const struct termios *termios_p); +speed_t cfgetospeed(const struct termios *termios_p); +int cfsetispeed(struct termios *termios_p, speed_t speed); +int cfsetospeed(struct termios *termios_p, speed_t speed); diff --git a/win32/winansi.c b/win32/winansi.c index c0493c77e..757a3509d 100644 --- a/win32/winansi.c +++ b/win32/winansi.c @@ -596,6 +596,23 @@ int winansi_get_terminal_width_height(struct winsize *win) return ret ? 0 : -1; } +int winansi_set_terminal_width_height(struct winsize *win) +{ + BOOL ret; + CONSOLE_SCREEN_BUFFER_INFOEX sbi; + + init(); + + sbi.cbSize = sizeof(sbi); + if ((ret=GetConsoleScreenBufferInfoEx(console, &sbi)) != 0) { + sbi.srWindow.Bottom = sbi.srWindow.Top + win->ws_row; + sbi.srWindow.Right = sbi.srWindow.Left + win->ws_col; + ret = SetConsoleScreenBufferInfoEx(console, &sbi); + } + + return ret ? 0 : -1; +} + static int ansi_emulate_write(int fd, const void *buf, size_t count) { int rv = 0, i; -- cgit v1.2.3-55-g6feb