1 /* Copyright (c) 1992, 1995 John E. Davis
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Perl Artistic License.
13 unsigned int SLang_Input_Buffer_Len
= 0;
14 unsigned char SLang_Input_Buffer
[MAX_INPUT_BUFFER_LEN
];
16 int SLang_Abort_Char
= 7;
17 int SLang_Ignore_User_Abort
= 0;
19 /* This has the effect of mapping all characters in the range 128-169 to
23 # if defined(__unix__) || defined(vms)
24 # define DEC_8BIT_HACK 64
28 #ifdef NATIVE_WIN32 /* see the replacement in src/slint.c */
29 unsigned int SLang_getkey (void)
34 if (SLang_Input_Buffer_Len
)
36 ch
= (unsigned int) *SLang_Input_Buffer
;
37 SLang_Input_Buffer_Len
--;
38 imax
= SLang_Input_Buffer_Len
;
40 SLMEMCPY ((char *) SLang_Input_Buffer
,
41 (char *) (SLang_Input_Buffer
+ 1), imax
);
43 else if (0xFFFF == (ch
= SLsys_getkey ())) return ch
;
49 i
= (unsigned char) (ch
& 0x7F);
60 #endif /* NATIVE_WIN32 */
62 void SLang_ungetkey_string (unsigned char *s
, unsigned int n
)
64 register unsigned char *bmax
, *b
, *b1
;
65 if (SLang_Input_Buffer_Len
+ n
+ 3 > MAX_INPUT_BUFFER_LEN
) return;
67 b
= SLang_Input_Buffer
;
68 bmax
= (b
- 1) + SLang_Input_Buffer_Len
;
70 while (bmax
>= b
) *b1
-- = *bmax
--;
72 while (b
< bmax
) *b
++ = *s
++;
73 SLang_Input_Buffer_Len
+= n
;
76 void SLang_buffer_keystring (unsigned char *s
, unsigned int n
)
79 if (n
+ SLang_Input_Buffer_Len
+ 3 > MAX_INPUT_BUFFER_LEN
) return;
81 SLMEMCPY ((char *) SLang_Input_Buffer
+ SLang_Input_Buffer_Len
,
83 SLang_Input_Buffer_Len
+= n
;
86 void SLang_ungetkey (unsigned char ch
)
88 SLang_ungetkey_string(&ch
, 1);
91 #ifdef NATIVE_WIN32 /* see the replacement in src/slint.c */
92 int SLang_input_pending (int tsecs
)
96 if (SLang_Input_Buffer_Len
) return (int) SLang_Input_Buffer_Len
;
98 n
= SLsys_input_pending (tsecs
);
100 if (n
<= 0) return 0;
102 c
= (unsigned char) SLang_getkey ();
103 SLang_ungetkey_string (&c
, 1);
107 #endif /* NATIVE_WIN32 */
109 void SLang_flush_input (void)
111 int quit
= SLKeyBoard_Quit
;
113 SLang_Input_Buffer_Len
= 0;
115 while (SLsys_input_pending (0) > 0)
117 (void) SLsys_getkey ();
118 /* Set this to 0 because SLsys_getkey may stuff keyboard buffer if
119 * key sends key sequence (OS/2, DOS, maybe VMS).
121 SLang_Input_Buffer_Len
= 0;
123 SLKeyBoard_Quit
= quit
;