"SfR Fresh" - the SfR Freeware/Shareware Archive 
Member "trafshow-3.1/keyb.c" of archive trafshow-3.1.tgz:
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1 /*
2 * Copyright (c) 1993-1997 JSC Rinet, Novosibirsk, Russia
3 *
4 * Redistribution and use in source forms, with and without modification,
5 * are permitted provided that this entire comment appears intact.
6 * Redistribution in binary form may occur without any restrictions.
7 *
8 * THIS SOFTWARE IS PROVIDED ``AS IS'' WITHOUT ANY WARRANTIES OF ANY KIND.
9 */
10
11 /* keyb.c -- keyboard functions */
12
13 #ifdef HAVE_CONFIG_H
14 #include <config.h>
15 #endif
16
17 #include <sys/types.h>
18 #include <sys/time.h>
19 #ifdef HAVE_SYS_IOCTL_H
20 #include <sys/ioctl.h>
21 #endif
22 #include <unistd.h>
23 #ifdef TIME_WITH_SYS_TIME
24 #include <time.h>
25 #endif
26
27 #include "trafshow.h"
28
29 /* Is input pending on fd */
30 int
31 kbhit(fd)
32 register int fd;
33 {
34 #if defined(FIONREAD)
35 int inqueue = 0;
36 ioctl(fd, FIONREAD, &inqueue);
37 return inqueue;
38 #elif defined(FIORDCHK)
39 int inqueue = 0;
40 ioctl(fd, FIORDCHK, &inqueue);
41 return inqueue;
42 #elif defined(HAVE_SELECT)
43 struct timeval timeout = {0, 0};
44 fd_set ready;
45
46 FD_ZERO(&ready);
47 FD_SET(fd, &ready);
48 if (select(fd + 1, &ready, NULL, NULL, &timeout) <= 0) return 0;
49 return FD_ISSET(fd, &ready);
50 #else
51 return 0;
52 #endif
53 }
54
55 int
56 get_arrowkey(get1ch)
57 int (*get1ch)();
58 {
59 int ch, ch1;
60
61 ch = (*get1ch)();
62 if (ch == '[' || ch == 'O')
63 ch = (*get1ch)();
64 switch (ch) {
65 case '\0': /* xterm */
66 return KEYMAP_HOME;
67 case 'A':
68 case 'i':
69 return KEYMAP_UP;
70
71 case 'B':
72 return KEYMAP_DOWN;
73
74 case 'D':
75 return KEYMAP_LEFT;
76
77 case 'C':
78 return KEYMAP_RIGHT;
79
80 case 'I': /* ansi PgUp */
81 case 'V': /* at386 PgUp */
82 case 'S': /* 97801 PgUp */
83 case 'v': /* emacs style */
84 return KEYMAP_PAGE_UP;
85
86 case 'G': /* ansi PgDn */
87 case 'U': /* at386 PgDn */
88 case 'T': /* 97801 PgDn */
89 return KEYMAP_PAGE_DOWN;
90
91 case 'H': /* at386 Home */
92 return KEYMAP_HOME;
93
94 case 'F': /* ansi End */
95 case 'Y': /* at386 End */
96 return KEYMAP_END;
97
98 case '5': /* vt200 PgUp */
99 ch = (*get1ch)(); /* eat the ~ (interesting use of words :) */
100 return KEYMAP_PAGE_UP;
101
102 case '6': /* vt200 PgUp */
103 ch = (*get1ch)(); /* eat the ~ */
104 return KEYMAP_PAGE_DOWN;
105
106 case '1': /* vt200 PgUp */
107 ch = (*get1ch)();
108 switch(ch) { /* xterm */
109 case '1':
110 ch1 = (*get1ch)(); /* eat the ~ */
111 return KEYMAP_F1;
112 case '2':
113 ch1 = (*get1ch)(); /* eat the ~ */
114 return KEYMAP_F2;
115 case '3':
116 ch1 = (*get1ch)(); /* eat the ~ */
117 return KEYMAP_F3;
118 case '4':
119 ch1 = (*get1ch)(); /* eat the ~ */
120 return KEYMAP_F4;
121 case '5': /* RS/6000 PgUp is 150g, PgDn is 154g */
122 ch = (*get1ch)();
123 ch1 = (*get1ch)(); /* eat the ~ */
124 if (ch == '0')
125 return KEYMAP_PAGE_UP;
126 if (ch == '4')
127 return KEYMAP_PAGE_DOWN;
128 }
129 return KEYMAP_HOME;
130
131 case '4': /* vt200 PgUp */
132 ch = (*get1ch)(); /* eat the ~ */
133 return KEYMAP_END;
134
135 case '2': /* xterm */
136 ch = (*get1ch)(); /* eat the ~ */
137 case 'L':
138 return KEYMAP_INS;
139 case 'M':
140 return KEYMAP_F1;
141 case 'N':
142 return KEYMAP_F2;
143 case 'O':
144 return KEYMAP_F3;
145 case 'P':
146 return KEYMAP_F4;
147
148 default:
149 return KEYMAP_UNKNOWN;
150 }
151 }