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.
14 unsigned int SLang_Input_Buffer_Len
= 0;
15 unsigned char SLang_Input_Buffer
[MAX_INPUT_BUFFER_LEN
];
17 int SLang_Abort_Char
= 7;
18 int SLang_Ignore_User_Abort
= 0;
20 /* This has the effect of mapping all characters in the range 128-169 to
24 # if defined(__unix__) || defined(vms)
25 # define DEC_8BIT_HACK 64
29 #ifdef OS2_NT /* see the replacement in src/slint.c */
30 unsigned int SLang_getkey (void)
35 if (SLang_Input_Buffer_Len
)
37 ch
= (unsigned int) *SLang_Input_Buffer
;
38 SLang_Input_Buffer_Len
--;
39 imax
= SLang_Input_Buffer_Len
;
41 SLMEMCPY ((char *) SLang_Input_Buffer
,
42 (char *) (SLang_Input_Buffer
+ 1), imax
);
44 else if (0xFFFF == (ch
= SLsys_getkey ())) return ch
;
50 i
= (unsigned char) (ch
& 0x7F);
63 void SLang_ungetkey_string (unsigned char *s
, unsigned int n
)
65 register unsigned char *bmax
, *b
, *b1
;
66 if (SLang_Input_Buffer_Len
+ n
+ 3 > MAX_INPUT_BUFFER_LEN
) return;
68 b
= SLang_Input_Buffer
;
69 bmax
= (b
- 1) + SLang_Input_Buffer_Len
;
71 while (bmax
>= b
) *b1
-- = *bmax
--;
73 while (b
< bmax
) *b
++ = *s
++;
74 SLang_Input_Buffer_Len
+= n
;
77 void SLang_buffer_keystring (unsigned char *s
, unsigned int n
)
80 if (n
+ SLang_Input_Buffer_Len
+ 3 > MAX_INPUT_BUFFER_LEN
) return;
82 SLMEMCPY ((char *) SLang_Input_Buffer
+ SLang_Input_Buffer_Len
,
84 SLang_Input_Buffer_Len
+= n
;
87 void SLang_ungetkey (unsigned char ch
)
89 SLang_ungetkey_string(&ch
, 1);
92 #ifdef OS2_NT /* see the replacement in src/slint.c */
93 int SLang_input_pending (int tsecs
)
97 if (SLang_Input_Buffer_Len
) return (int) SLang_Input_Buffer_Len
;
99 n
= SLsys_input_pending (tsecs
);
101 if (n
<= 0) return 0;
103 c
= (unsigned char) SLang_getkey ();
104 SLang_ungetkey_string (&c
, 1);
110 void SLang_flush_input (void)
112 int quit
= SLKeyBoard_Quit
;
114 SLang_Input_Buffer_Len
= 0;
116 while (SLsys_input_pending (0) > 0)
118 (void) SLsys_getkey ();
119 /* Set this to 0 because SLsys_getkey may stuff keyboard buffer if
120 * key sends key sequence (OS/2, DOS, maybe VMS).
122 SLang_Input_Buffer_Len
= 0;
124 SLKeyBoard_Quit
= quit
;