/[LeafOK_CVS]/lbbs/src/io.c
ViewVC logotype

Contents of /lbbs/src/io.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations)
Mon Mar 21 17:08:21 2005 UTC (21 years ago) by sysadm
Branch: MAIN
Changes since 1.7: +3 -2 lines
Content type: text/x-csrc
*** empty log message ***

1 /***************************************************************************
2 io.c - description
3 -------------------
4 begin : Mon Oct 18 2004
5 copyright : (C) 2004 by Leaflet
6 email : leaflet@leafok.com
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include "io.h"
19 #include "common.h"
20 #include <stdio.h>
21 #include <stdarg.h>
22 #include <sys/ioctl.h>
23
24 int
25 outc (char c)
26 {
27 int retval;
28
29 retval = fprintf (stdout, "%c", c);
30
31 return retval;
32 }
33
34 int
35 prints (const char *format, ...)
36 {
37 va_list args;
38 int retval;
39
40 va_start (args, format);
41 retval = vfprintf (stdout, format, args);
42 va_end (args);
43
44 return retval;
45 }
46
47 int
48 iflush ()
49 {
50 int retval;
51
52 retval = fflush (stdout);
53
54 return retval;
55 }
56
57 int
58 igetch ()
59 {
60 static char buf[256];
61 unsigned char c, tmp[256];
62 int out = KEY_NULL, loop = 1, in_esc = 0, in_ascii = 0, in_control = 0, i =
63 0, j;
64 static int len = 0, pos = 0;
65
66 if (pos >= len)
67 {
68 pos = 0;
69
70 //len = s_receive (socket_client, buf, 255, "");
71 len = read (0, buf, 255);
72
73 //For debug
74 //for (j = 0; j < len; j++)
75 // log_std ("<--[%u]\n", (buf[j] + 256) % 256);
76 }
77
78 while (pos < len)
79 {
80 c = buf[pos++];
81
82 if (c == '\0')
83 {
84 out = c;
85 break;
86 }
87
88 if (c == KEY_CONTROL)
89 {
90 if (in_control == 0)
91 {
92 in_control = 1;
93 i = 0;
94 continue;
95 }
96 }
97
98 if (in_control)
99 {
100 tmp[i++] = c;
101 if (i >= 2)
102 {
103 out = (int) tmp[0] * 256 + tmp[1];
104 in_control = 0;
105 break;
106 }
107 continue;
108 }
109
110 if (c == ESC_KEY)
111 {
112 if (in_esc == 0)
113 {
114 in_esc = 1;
115 in_ascii = 1;
116 i = 0;
117 continue;
118 }
119 else
120 {
121 out = ESC_KEY;
122 in_esc = 0;
123 break;
124 }
125 }
126
127 in_esc = 0;
128
129 if (in_ascii)
130 {
131 tmp[i++] = c;
132 if (c == 'm')
133 {
134 in_ascii = 0;
135 continue;
136 }
137 if (i == 2 && c >= 'A' && c <= 'D')
138 {
139 in_ascii = 0;
140 switch (c)
141 {
142 case 'A':
143 out = KEY_UP;
144 break;
145 case 'B':
146 out = KEY_DOWN;
147 break;
148 case 'C':
149 out = KEY_RIGHT;
150 break;
151 case 'D':
152 out = KEY_LEFT;
153 break;
154 }
155 break;
156 }
157 if (i == 3 && tmp[0] == 91 && tmp[2] == 126)
158 {
159 in_ascii = 0;
160 switch (tmp[1])
161 {
162 case 49:
163 out = KEY_HOME;
164 break;
165 case 51:
166 out = KEY_DEL;
167 break;
168 case 52:
169 out = KEY_END;
170 break;
171 case 53:
172 out = KEY_PGUP;
173 break;
174 case 54:
175 out = KEY_PGDN;
176 break;
177 }
178 break;
179 }
180 continue;
181 }
182
183 out = ((int) c + 256) % 256;
184 break;
185 }
186
187 //for debug
188 //log_std ("-->[%u]\n", out);
189
190 return out;
191 }
192
193 int
194 ikbhit ()
195 {
196 int len;
197
198 ioctl (0, FIONREAD, &len);
199
200 return len;
201 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1