From 3b83bb5eeaee06a080fa936ea742501f370a286f Mon Sep 17 00:00:00 2001 From: William McBrine Date: Thu, 6 Jul 2006 23:50:13 +0000 Subject: [PATCH] Replaced core of flushinp() with platform-specific PDC_flushinp(), instead of a bunch of ifdefs. It's cleaner this way. To Do: I'm working toward complete separation -- i.e., no platform ifdefs in the pdcurses directory. --- curspriv.h | 5 ++--- doc/intro.man | 1 + dos/pdckbd.c | 27 ++++++++++++++++++++++++++- os2/pdckbd.c | 32 +++++++++++++++++++++++++++++++- pdcurses/util.c | 33 ++------------------------------- win32/pdckbd.c | 24 +++++++++++++++++++++++- x11/pdckbd.c | 25 ++++++++++++++++++++++++- x11/pdcx11.h | 5 ++++- 8 files changed, 113 insertions(+), 39 deletions(-) diff --git a/curspriv.h b/curspriv.h index a52d6f6b..6b0a91cb 100644 --- a/curspriv.h +++ b/curspriv.h @@ -15,7 +15,7 @@ * See the file maintain.er for details of the current maintainer. * ************************************************************************/ -/* $Id: curspriv.h,v 1.69 2006/07/02 19:03:59 wmcbrine Exp $ */ +/* $Id: curspriv.h,v 1.70 2006/07/06 23:50:10 wmcbrine Exp $ */ /* CURSPRIV.H @@ -214,6 +214,7 @@ int PDC_cursor_off(void); int PDC_cursor_on(void); int PDC_curs_set(int); int PDC_fix_cursor(int); +void PDC_flushinp(void); int PDC_get_bios_key(void); int PDC_get_columns(void); bool PDC_get_ctrl_break(void); @@ -265,8 +266,6 @@ int PDC_query_adapter_type(void); #endif #ifdef XCURSES -int XCurses_rawgetch(void); -bool XCurses_kbhit(void); int XCursesInstruct(int); int XCursesInstructAndWait(int); int XCursesInitscr(const char *, int, char **); diff --git a/doc/intro.man b/doc/intro.man index 94eb59e0..a8c5671f 100644 --- a/doc/intro.man +++ b/doc/intro.man @@ -533,6 +533,7 @@ FUNCTIONS PDC_cursor_on pdcdisp PDC_debug pdcdebug PDC_fix_cursor pdcdisp + PDC_flushinp pdckbd PDC_getch getch PDC_get_attribute pdcgetsc PDC_get_bios_key pdckbd diff --git a/dos/pdckbd.c b/dos/pdckbd.c index 3f86416a..5942b216 100644 --- a/dos/pdckbd.c +++ b/dos/pdckbd.c @@ -24,7 +24,7 @@ #define CURSES_LIBRARY 1 #include -RCSID("$Id: pdckbd.c,v 1.23 2006/03/29 20:06:40 wmcbrine Exp $"); +RCSID("$Id: pdckbd.c,v 1.24 2006/07/06 23:50:12 wmcbrine Exp $"); /************************************************************************ * Table for key code translation of function keys in keypad mode * @@ -581,3 +581,28 @@ unsigned long PDC_get_key_modifiers(void) return pdc_key_modifiers; } + +/*man-start************************************************************** + + PDC_flushinp() - Low-level input flush + + PDCurses Description: + This is a private PDCurses routine. + + Discards any pending keyboard and mouse input. Called by + flushinp(). + + Portability: + PDCurses void PDC_flushinp(void); + +**man-end****************************************************************/ + +void PDC_flushinp(void) +{ + PDC_LOG(("PDC_flushinp() - called\n")); + + /* Force the BIOS kbd buf head/tail pointers to be the + same... Real nasty trick... */ + + setdosmemword(0x41a, getdosmemword (0x41c)); +} diff --git a/os2/pdckbd.c b/os2/pdckbd.c index d5b35b04..4dbb7adc 100644 --- a/os2/pdckbd.c +++ b/os2/pdckbd.c @@ -26,7 +26,11 @@ # include #endif -RCSID("$Id: pdckbd.c,v 1.24 2006/03/29 20:06:40 wmcbrine Exp $"); +#ifdef EMXVIDEO +# include +#endif + +RCSID("$Id: pdckbd.c,v 1.25 2006/07/06 23:50:12 wmcbrine Exp $"); /************************************************************************ * Table for key code translation of function keys in keypad mode * @@ -687,3 +691,29 @@ unsigned long PDC_get_key_modifiers(void) return pdc_key_modifiers; } + +/*man-start************************************************************** + + PDC_flushinp() - Low-level input flush + + PDCurses Description: + This is a private PDCurses routine. + + Discards any pending keyboard and mouse input. Called by + flushinp(). + + Portability: + PDCurses void PDC_flushinp(void); + +**man-end****************************************************************/ + +void PDC_flushinp(void) +{ + PDC_LOG(("PDC_flushinp() - called\n")); + +#ifdef EMXVIDEO + tcflush(0, TCIFLUSH); +#else + KbdFlushBuffer(0); +#endif +} diff --git a/pdcurses/util.c b/pdcurses/util.c index 4a0eb08e..39888248 100644 --- a/pdcurses/util.c +++ b/pdcurses/util.c @@ -16,13 +16,8 @@ ************************************************************************/ #define CURSES_LIBRARY 1 -#define INCLUDE_WINDOWS_H #include -#if defined(OS2) && defined(EMXVIDEO) -# include -#endif - /* undefine any macros for functions defined in this module */ #undef unctrl #undef keyname @@ -32,7 +27,7 @@ #undef delay_output #undef flushinp -RCSID("$Id: util.c,v 1.34 2006/04/23 02:56:38 wmcbrine Exp $"); +RCSID("$Id: util.c,v 1.35 2006/07/06 23:50:13 wmcbrine Exp $"); /*man-start************************************************************** @@ -230,38 +225,14 @@ int delay_output(int ms) int flushinp(void) { -#ifdef WIN32 - extern HANDLE hConIn; -#endif extern int c_pindex; /* putter index */ extern int c_gindex; /* getter index */ extern int c_ungind; /* wungetch() push index */ PDC_LOG(("flushinp() - called\n")); -#ifdef DOS - /* Force the BIOS kbd buf head/tail pointers to be the - same... Real nasty trick... */ + PDC_flushinp(); - setdosmemword(0x41a, getdosmemword (0x41c)); -#endif - -#ifdef OS2 -# ifdef EMXVIDEO - tcflush(0, TCIFLUSH); -# else - KbdFlushBuffer(0); -# endif -#endif - -#ifdef WIN32 - FlushConsoleInputBuffer(hConIn); -#endif - -#ifdef XCURSES - while (XCurses_kbhit()) - XCurses_rawgetch(); -#endif c_gindex = 1; /* set indices to kill buffer */ c_pindex = 0; c_ungind = 0; /* clear c_ungch array */ diff --git a/win32/pdckbd.c b/win32/pdckbd.c index f8d14650..f6ee0036 100644 --- a/win32/pdckbd.c +++ b/win32/pdckbd.c @@ -19,7 +19,7 @@ #define INCLUDE_WINDOWS_H #include -RCSID("$Id: pdckbd.c,v 1.44 2006/07/04 03:51:38 wmcbrine Exp $"); +RCSID("$Id: pdckbd.c,v 1.45 2006/07/06 23:50:13 wmcbrine Exp $"); #define KEY_STATE TRUE #define MS_MOUSE_MOVED 1 @@ -1385,6 +1385,28 @@ unsigned long PDC_get_key_modifiers(void) return pdc_key_modifiers; } +/*man-start************************************************************** + + PDC_flushinp() - Low-level input flush + + PDCurses Description: + This is a private PDCurses routine. + + Discards any pending keyboard and mouse input. Called by + flushinp(). + + Portability: + PDCurses void PDC_flushinp(void); + +**man-end****************************************************************/ + +void PDC_flushinp(void) +{ + PDC_LOG(("PDC_flushinp() - called\n")); + + FlushConsoleInputBuffer(hConIn); +} + #ifdef PDC_THREAD_BUILD LONG InputThread(LPVOID lpThreadData) diff --git a/x11/pdckbd.c b/x11/pdckbd.c index 08edeaa9..ae454053 100644 --- a/x11/pdckbd.c +++ b/x11/pdckbd.c @@ -17,7 +17,7 @@ #include "pdcx11.h" -RCSID("$Id: pdckbd.c,v 1.22 2006/07/02 19:03:59 wmcbrine Exp $"); +RCSID("$Id: pdckbd.c,v 1.23 2006/07/06 23:50:13 wmcbrine Exp $"); /*man-start************************************************************** @@ -205,3 +205,26 @@ unsigned long PDC_get_key_modifiers(void) return pdc_key_modifier; } + +/*man-start************************************************************** + + PDC_flushinp() - Low-level input flush + + PDCurses Description: + This is a private PDCurses routine. + + Discards any pending keyboard and mouse input. Called by + flushinp(). + + Portability: + PDCurses void PDC_flushinp(void); + +**man-end****************************************************************/ + +void PDC_flushinp(void) +{ + PDC_LOG(("PDC_flushinp() - called\n")); + + while (XCurses_kbhit()) + XCurses_rawgetch(); +} diff --git a/x11/pdcx11.h b/x11/pdcx11.h index 4d7ec027..4d9410f2 100644 --- a/x11/pdcx11.h +++ b/x11/pdcx11.h @@ -15,7 +15,7 @@ * See the file maintain.er for details of the current maintainer. * ************************************************************************/ -/* $Id: pdcx11.h,v 1.29 2006/07/02 19:03:59 wmcbrine Exp $ */ +/* $Id: pdcx11.h,v 1.30 2006/07/06 23:50:13 wmcbrine Exp $ */ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H @@ -288,6 +288,9 @@ int XCursesDisplayText(const chtype *, int, int, int, bool); void XCursesDisplayScreen(bool); void XCursesDisplayCursor(int, int, int, int); +int XCurses_rawgetch(void); +bool XCurses_kbhit(void); + int XCurses_display_cursor(int, int, int, int, int); void XCursesStructureNotify(Widget, XtPointer, XEvent *, Boolean *);