Mercurial > mxe-octave
view src/readline-2-event-hook.patch @ 4449:1933a9113e65
of-*: add octave as a dependancy to the of packages is binary enable is set (Bug #46235)
* src/of-actuarial.mk, src/of-communications.mk, src/of-control.mk, src/of-data-smoothing.mk,
src/of-database.mk, src/of-dataframe.mk, src/of-dicom.mk, src/of-financial.mk, src/of-fits.mk,
src/of-fl-core.mk, src/of-fuzzy-logic-toolkit.mk, src/of-ga.mk, src/of-general.mk, src/of-generate_html.mk,
src/of-geometry.mk, src/of-gsl.mk, src/of-image.mk, src/of-instrument-control.mk, src/of-interval.mk,
src/of-io.mk, src/of-linear-algebra.mk, src/of-lssa.mk, src/of-ltfat.mk, src/of-mapping.mk,
src/of-miscellaneous.mk, src/of-nan.mk, src/of-netcdf.mk, src/of-nurbs.mk, src/of-ocs.mk, src/of-octcdf.mk,
src/of-odepkg.mk, src/of-optim.mk, src/of-quaternion.mk, src/of-queueing.mk, src/of-signal.mk, src/of-sockets.mk,
src/of-sparsersb.mk, src/of-specfun.mk, src/of-splines.mk, src/of-statistics.mk, src/of-stk.mk,
src/of-strings.mk, src/of-struct.mk, src/of-tisean.mk, src/of-tsa.mk, src/of-video.mk, src/of-windows.mk,
src/of-zenity.mk, src/of-zeromq.mk: add $(PKG)_DEPS += $(OCTAVE_TARGET) if ENABLE_BINARY_PACKAGES = yes
author | John D |
---|---|
date | Mon, 14 Aug 2017 09:12:34 -0400 |
parents | 098ca5276ab8 |
children |
line wrap: on
line source
diff -ur readline-6.2-orig/input.c readline-6.2/input.c --- readline-6.2-orig/input.c 2013-11-24 19:19:30 -0500 +++ readline-6.2/input.c 2013-11-29 11:19:59 -0500 @@ -54,6 +54,11 @@ #include <stdio.h> #include <errno.h> +#if defined (__MINGW32__) +# define WIN32_LEAN_AND_MEAN +# include <windows.h> +#endif + #if !defined (errno) extern int errno; #endif /* !errno */ @@ -96,6 +101,11 @@ static unsigned char ibuffer[512]; static int ibuffer_len = sizeof (ibuffer) - 1; +#if defined (__MINGW32__) +static int _win32_getch (void); +static int _win32_kbhit (void); +#endif + #define any_typein (push_index != pop_index) int @@ -219,8 +229,8 @@ #if defined (__MINGW32__) /* Use getch/_kbhit to check for available console input, in the same way that we read it normally. */ - chars_avail = isatty (tty) ? _kbhit () : 0; - result = 0; + chars_avail = isatty (tty) ? _win32_kbhit () : 0; + result = 0; #endif /* If there's nothing available, don't waste time trying to read @@ -457,6 +467,123 @@ return (c); } +#if defined (__MINGW32__) + +#define _WIN32_READ_NOCHAR (-2) + +static char _win32_buf[16] = {'0'}; +static int _win32_bufidx = 0; + +static int +_win32_getch_internal (int block) +{ + INPUT_RECORD rec; + DWORD evRead, waitResult; + HANDLE hInput = (HANDLE) _get_osfhandle (fileno (rl_instream)); + + if (_win32_bufidx > 0) + return _win32_buf[--_win32_bufidx]; + + hInput = (HANDLE) _get_osfhandle (fileno (rl_instream)); + + do + { + if (! block) + { + if (WaitForSingleObject(hInput, _keyboard_input_timeout/1000) != WAIT_OBJECT_0) + return _WIN32_READ_NOCHAR; + } + + if (!ReadConsoleInput(hInput, &rec, 1, &evRead) || evRead != 1) + return EOF; + + switch (rec.EventType) + { + case KEY_EVENT: + if ((rec.Event.KeyEvent.bKeyDown && + (rec.Event.KeyEvent.wVirtualKeyCode < VK_SHIFT || + rec.Event.KeyEvent.wVirtualKeyCode > VK_MENU)) || + (!rec.Event.KeyEvent.bKeyDown && + rec.Event.KeyEvent.wVirtualKeyCode == VK_MENU && + rec.Event.KeyEvent.uChar.AsciiChar)) + { + if (rec.Event.KeyEvent.uChar.AsciiChar) + { + if (rec.Event.KeyEvent.uChar.AsciiChar < 0 || + (rec.Event.KeyEvent.uChar.AsciiChar < 32 && + !(rec.Event.KeyEvent.dwControlKeyState & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED)))) + { + char c = rec.Event.KeyEvent.uChar.AsciiChar; + if (GetOEMCP () == GetConsoleCP ()) + OemToCharBuff (&c, &c, 1); + return (int)(unsigned char)c; + } + else + return (int)rec.Event.KeyEvent.uChar.UnicodeChar; + } + else + switch (rec.Event.KeyEvent.wVirtualKeyCode) + { + case VK_UP: + _win32_buf[_win32_bufidx++] = 'H'; + return 0340; + case VK_DOWN: + _win32_buf[_win32_bufidx++] = 'P'; + return 0340; + case VK_RIGHT: + _win32_buf[_win32_bufidx++] = 'M'; + return 0340; + case VK_LEFT: + _win32_buf[_win32_bufidx++] = 'K'; + return 0340; + case VK_HOME: + _win32_buf[_win32_bufidx++] = 'G'; + return 0340; + case VK_END: + _win32_buf[_win32_bufidx++] = 'O'; + return 0340; + case VK_DELETE: + _win32_buf[_win32_bufidx++] = 'S'; + return 0340; + default: + break; + } + } + break; + + case WINDOW_BUFFER_SIZE_EVENT: + rl_resize_terminal (); + break; + + default: + break; + } + } + while (1); +} + +static int +_win32_kbhit (void) +{ + int result; + + result = _win32_getch_internal (0); + if (result == _WIN32_READ_NOCHAR + || result == EOF) + return 0; + _win32_buf[_win32_bufidx++] = result; + + return _win32_bufidx; +} + +static int +_win32_getch (void) +{ + return _win32_getch_internal (1); +} + +#endif + int rl_getc (stream) FILE *stream; @@ -471,9 +598,9 @@ #if defined (__MINGW32__) if (isatty (fileno (stream))) { - int c = _getch (); + int c = _win32_getch (); if (c == 0xe0) - rl_execute_next (_getch ()); + rl_execute_next (_win32_getch ()); return (c); } #endif