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

Contents of /lbbs/src/io.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations)
Sun Mar 20 17:37:14 2005 UTC (21 years ago) by sysadm
Branch: MAIN
Changes since 1.5: +42 -42 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 = 0, loop = 1, in_esc = 0, in_ascii = 0, in_control = 0, i = 0, j;
63 static int len = 0, pos = 0;
64
65 if (pos >= len)
66 {
67 pos = 0;
68
69 //len = s_receive (socket_client, buf, 255, "");
70 len = read (0, buf, 255);
71
72 //For debug
73 //for (j = 0; j < len; j++)
74 // log_std ("<--[%u]\n", (buf[j] + 256) % 256);
75 }
76
77 while (pos < len)
78 {
79 c = buf[pos++];
80
81 if (c == '\0')
82 {
83 out = c;
84 break;
85 }
86
87 if (c == KEY_CONTROL)
88 {
89 if (in_control == 0)
90 {
91 in_control = 1;
92 i = 0;
93 continue;
94 }
95 }
96
97 if (in_control)
98 {
99 tmp[i++] = c;
100 if (i >= 2)
101 {
102 out = (int) tmp[0] * 256 + tmp[1];
103 in_control = 0;
104 break;
105 }
106 continue;
107 }
108
109 if (c == ESC_KEY)
110 {
111 if (in_esc == 0)
112 {
113 in_esc = 1;
114 in_ascii = 1;
115 i = 0;
116 continue;
117 }
118 else
119 {
120 out = ESC_KEY;
121 in_esc = 0;
122 break;
123 }
124 }
125
126 in_esc = 0;
127
128 if (in_ascii)
129 {
130 tmp[i++] = c;
131 if (c == 'm')
132 {
133 in_ascii = 0;
134 continue;
135 }
136 if (i == 2 && c >= 'A' && c <= 'D')
137 {
138 in_ascii = 0;
139 switch (c)
140 {
141 case 'A':
142 out = KEY_UP;
143 break;
144 case 'B':
145 out = KEY_DOWN;
146 break;
147 case 'C':
148 out = KEY_RIGHT;
149 break;
150 case 'D':
151 out = KEY_LEFT;
152 break;
153 }
154 break;
155 }
156 if (i == 3 && tmp[0] == 91 && tmp[2] == 126)
157 {
158 in_ascii = 0;
159 switch (tmp[1])
160 {
161 case 49:
162 out = KEY_HOME;
163 break;
164 case 51:
165 out = KEY_DEL;
166 break;
167 case 52:
168 out = KEY_END;
169 break;
170 case 53:
171 out = KEY_PGUP;
172 break;
173 case 54:
174 out = KEY_PGDOWN;
175 break;
176 }
177 break;
178 }
179 continue;
180 }
181
182 out = ((int) c + 256) % 256;
183 break;
184 }
185
186 //for debug
187 //log_std ("-->[%u]\n", out);
188
189 return out;
190 }
191
192 int
193 ikbhit ()
194 {
195 int len;
196
197 ioctl (0, FIONREAD, &len);
198
199 return len;
200 }

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