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 --- win32/ioctl.c | 4 ++++ win32/termios.c | 43 +++++++++++++++++++++++++++++++++++++++---- win32/termios.h | 17 +++++++++++++++++ win32/winansi.c | 17 +++++++++++++++++ 4 files changed, 77 insertions(+), 4 deletions(-) (limited to 'win32') 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