Mercurial > forge
changeset 3985:6cd8abe49182 octave-forge
add Win32-specific tricks to allow running octave in a thread with pipe communication and catching terminal resize
author | goffioul |
---|---|
date | Wed, 31 Oct 2007 15:10:57 +0000 |
parents | 5d2f8a7eb3ea |
children | eb223a3b9f7e |
files | admin/Windows/msvc/libs/readline-5.2.diff |
diffstat | 1 files changed, 98 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/admin/Windows/msvc/libs/readline-5.2.diff Tue Oct 30 20:05:32 2007 +0000 +++ b/admin/Windows/msvc/libs/readline-5.2.diff Wed Oct 31 15:10:57 2007 +0000 @@ -584,7 +584,7 @@ } diff -urN readline-5.2/input.c readline-5.2-new/input.c --- readline-5.2/input.c Wed Aug 16 21:15:16 2006 -+++ readline-5.2-new/input.c Fri Oct 26 11:32:50 2007 ++++ readline-5.2-new/input.c Wed Oct 31 12:09:00 2007 @@ -61,6 +61,11 @@ #include <stdio.h> #include <errno.h> @@ -607,7 +607,7 @@ #define any_typein (push_index != pop_index) -@@ -164,6 +172,127 @@ +@@ -164,6 +172,181 @@ return (push_index != pop_index); } @@ -712,6 +712,60 @@ +#endif +} + ++static int win32_read (int fh, void *buf, int size) ++{ ++ static HANDLE evt = NULL; ++ static int tried_with_event = 0; ++ ++ if (evt || !tried_with_event) ++ { ++ tried_with_event = 1; ++ if (!evt) ++ { ++ char evt_name[128]; ++ _snprintf (evt_name, 127, "readline-event-%d", GetCurrentProcessId ()); ++ evt = OpenEvent (EVENT_MODIFY_STATE|SYNCHRONIZE, FALSE, evt_name); ++ } ++ ++ if (evt) ++ { ++ DWORD waitResult; ++ if ((waitResult = WaitForSingleObject (evt, INFINITE)) == WAIT_OBJECT_0) ++ { ++ int result = read (fh, buf, size); ++ DWORD nb = 0; ++ ++ if (PeekNamedPipe ((HANDLE)_get_osfhandle (fh), NULL, 0, NULL, &nb, NULL) && nb == 0) ++ ResetEvent (evt); ++ return result; ++ } ++ else ++ { ++ if (waitResult == WAIT_FAILED) ++ { ++ int err = GetLastError(); ++ printf("%d\n", err); ++ } ++ return EOF; ++ } ++ } ++ } ++ ++ return read (fh, buf, size); ++ ++ /* ++ HANDLE hnd = _get_osfhandle (fh); ++ DWORD bytesRead; ++ BOOL ret; ++ ++ ret = ReadFile (hnd, buf, size, &bytesRead, NULL); ++ if (ret) ++ return bytesRead; ++ else ++ return 0; ++ */ ++} ++ +DWORD WINAPI tty_reader_proc (LPVOID param) +{ + int tty = fileno (rl_instream); @@ -721,7 +775,7 @@ + int result; + unsigned char c; + -+ result = read (tty, &c, sizeof (unsigned char)); ++ result = win32_read (tty, &c, sizeof (unsigned char)); + if (result == sizeof (unsigned char)) + return c; + else @@ -735,7 +789,7 @@ /* If a character is available to be read, then read it and stuff it into IBUFFER. Otherwise, just return. Returns number of characters read (0 if none available) and -1 on error (EIO). */ -@@ -221,13 +350,70 @@ +@@ -221,13 +404,70 @@ } #endif /* O_NDELAY */ @@ -807,7 +861,7 @@ /* If there's nothing available, don't waste time trying to read something. */ if (chars_avail <= 0) -@@ -459,7 +645,96 @@ +@@ -459,9 +699,98 @@ { #if defined (__MINGW32__) if (isatty (fileno (stream))) @@ -903,8 +957,11 @@ + return (_getch ()); +#endif #endif - result = read (fileno (stream), &c, sizeof (unsigned char)); +- result = read (fileno (stream), &c, sizeof (unsigned char)); ++ result = win32_read (fileno (stream), &c, sizeof (unsigned char)); + if (result == sizeof (unsigned char)) + return (c); diff -urN readline-5.2/keymaps.h readline-5.2-new/keymaps.h --- readline-5.2/keymaps.h Tue Nov 20 18:42:49 2001 +++ readline-5.2-new/keymaps.h Wed Oct 24 11:13:33 2007 @@ -1050,7 +1107,7 @@ _rl_insert_char (count, invoking_key); diff -urN readline-5.2/readline.c readline-5.2-new/readline.c --- readline-5.2/readline.c Wed Aug 16 21:00:36 2006 -+++ readline-5.2-new/readline.c Thu Oct 25 15:35:55 2007 ++++ readline-5.2-new/readline.c Wed Oct 31 15:19:47 2007 @@ -220,7 +220,11 @@ /* The style of `bell' notification preferred. This can be set to NO_BELL, @@ -1063,7 +1120,38 @@ /* String inserted into the line by rl_insert_comment (). */ char *_rl_comment_begin; -@@ -1115,11 +1119,18 @@ +@@ -1084,6 +1088,30 @@ + } + } + ++#ifdef _MSC_VER ++static int ++_rl_update_terminal_size (count, key) ++ int count, key; ++{ ++ int rows, cols; ++ ++ rl_get_screen_size (&rows, &cols); ++ switch (key) ++ { ++ case 'X': ++ rows = count; ++ break; ++ case 'Y': ++ cols = count; ++ break; ++ default: ++ return -1; ++ } ++ rl_set_screen_size (rows, cols); ++ sh_set_lines_and_columns (rows, cols); ++} ++#endif ++ + /* Bind some common arrow key sequences in MAP. */ + static void + bind_arrow_keys_internal (map) +@@ -1115,11 +1143,20 @@ rl_bind_keyseq_if_unbound ("\033OH", rl_beg_of_line); rl_bind_keyseq_if_unbound ("\033OF", rl_end_of_line); @@ -1080,6 +1168,8 @@ + +#ifdef _MSC_VER + rl_bind_keyseq_if_unbound ("\033[3~", rl_delete); ++ rl_bind_keyseq_if_unbound ("\033[X", _rl_update_terminal_size); ++ rl_bind_keyseq_if_unbound ("\033[Y", _rl_update_terminal_size); #endif _rl_keymap = xkeymap;