-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_key.c
54 lines (44 loc) · 1.12 KB
/
func_key.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <signal.h>
#include <unistd.h>
#include "curses.h"
#include "screen.h"
#include "window.h"
#include "privfunc.h"
static void dummy(int s) {s=s;}
/*
This routine is an internal routine which handles the mapping
of characters from the input stream to the function keys.
*/
int
_keymap(WINDOW *win, int ch)
{
int ret;
_KEYNODE *kptr;
char *s;
char str[INPUT_BUFFER_LEN+1];
void (*sigsav)() = 0;
int save_alarm = 0;
for(s = str, ret = ch, kptr = _screen->_keys; kptr; )
{
if(kptr->ch != ch) {kptr = kptr->left; continue;}
/* reset push-back buffer */
if(kptr->val!=0) {s = str; ret = kptr->val;}
if((kptr = kptr->right) == 0) break;
if(win->_flags & F_TIMEOUT)
{
sigsav = signal(SIGALRM, dummy);
save_alarm = alarm(1);
}
ch = _getchar();
if(win->_flags & F_TIMEOUT)
{
(void)alarm(save_alarm);
(void)signal(SIGALRM, sigsav);
}
if(ch < 0) break;
*(++s) = ch; /* save character in push-back buffer */
}
/* must now put any characters not matched onto the input stream */
while(s != str) _ungetchar((int)*s--);
return(ret);
}