[PATCH] To: wine-patches at winehq.org
Eric Pouech
eric.pouech at orange.fr
Thu Jan 20 14:57:05 CST 2011
[Kernel32]: in bare console with curses, ensure control stream is sent to tty (even when some fd:s are redirected)
A+
---
dlls/kernel32/term.c | 25 +++++++++++++++++++------
1 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/dlls/kernel32/term.c b/dlls/kernel32/term.c
index a7e18ec..889d8a0 100644
--- a/dlls/kernel32/term.c
+++ b/dlls/kernel32/term.c
@@ -157,7 +157,7 @@ static void *nc_handle = NULL;
#define MAKE_FUNCPTR(f) static typeof(f) * p_##f;
-MAKE_FUNCPTR(putp)
+MAKE_FUNCPTR(tputs)
MAKE_FUNCPTR(setupterm)
MAKE_FUNCPTR(tigetstr)
MAKE_FUNCPTR(tparm)
@@ -188,7 +188,7 @@ static BOOL TERM_bind_libcurses(void)
goto sym_not_found; \
}
- LOAD_FUNCPTR(putp)
+ LOAD_FUNCPTR(tputs)
LOAD_FUNCPTR(setupterm)
LOAD_FUNCPTR(tigetstr)
LOAD_FUNCPTR(tparm)
@@ -207,7 +207,7 @@ sym_not_found:
return FALSE;
}
-#define putp p_putp
+#define tputs p_tputs
#define setupterm p_setupterm
#define tigetstr p_tigetstr
#define tparm p_tparm
@@ -317,20 +317,33 @@ static BOOL TERM_BuildKeyDB(void)
return TRUE;
}
+static int TERM_output_fd;
+
+static int TERM_putchar(int ich)
+{
+ char ch = ich;
+ return write(TERM_output_fd, &ch, 1);
+}
+
BOOL TERM_Init(void)
{
+ /* if output is redirected from shell to a file or pipe, still enforce control
+ * flows to be sent to TTY
+ */
+ TERM_output_fd = open("/dev/tty", O_RDWR);
if (!TERM_bind_libcurses()) return FALSE;
- if (setupterm(NULL, 1 /* really ?? */, NULL) == -1) return FALSE;
+ if (setupterm(NULL, TERM_output_fd, NULL) == -1) return FALSE;
TERM_BuildKeyDB();
/* set application key mode */
- putp(tigetstr("smkx"));
+ tputs(tigetstr("smkx"), 1, TERM_putchar);
return TRUE;
}
BOOL TERM_Exit(void)
{
/* put back the cursor key mode */
- putp(tigetstr("rmkx"));
+ tputs(tigetstr("rmkx"), 1, TERM_putchar);
+ close(TERM_output_fd);
return TRUE;
}
More information about the wine-patches
mailing list