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

Contents of /lbbs/src/io.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Wed Mar 2 16:33:49 2005 UTC (21 years ago) by sysadm
Branch: MAIN
Changes since 1.3: +6 -3 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
23 int
24 outc(char c)
25 {
26 int retval;
27
28 retval = fprintf(stdout, "%c", c);
29
30 return retval;
31 }
32
33 int
34 prints(const char * format, ...)
35 {
36 va_list args;
37 int retval;
38
39 va_start (args, format);
40 retval = vfprintf (stdout, format, args);
41 va_end (args);
42
43 return retval;
44 }
45
46 int
47 iflush()
48 {
49 int retval;
50
51 retval = fflush (stdout);
52
53 return retval;
54 }
55
56 int
57 igetch ()
58 {
59 static char buf[256];
60 unsigned char c, tmp[256];
61 int out = 0, loop = 1, in_esc = 0, in_ascii = 0, in_control = 0, i = 0, j;
62 static int len = 0 , pos = 0;
63
64 if (pos >= len)
65 {
66 len = s_receive (socket_client, buf, 255, "");
67 pos = 0;
68
69 //For debug
70 for (j = 0; j < len; j++)
71 log_std ("<--[%u]\n", (buf[j] + 256) % 256);
72 }
73
74 while (pos < len)
75 {
76 c = buf[pos++];
77
78 if (c == '\0')
79 {
80 out = c;
81 break;
82 }
83
84 if (c == KEY_CONTROL)
85 {
86 if (in_control == 0)
87 {
88 in_control = 1;
89 i = 0;
90 continue;
91 }
92 }
93
94 if (in_control)
95 {
96 tmp[i++] = c;
97 if (i >= 2)
98 {
99 out = (int)tmp[0] * 256 + tmp[1];
100 in_control = 0;
101 break;
102 }
103 continue;
104 }
105
106 if (c == ESC_KEY)
107 {
108 if (in_esc == 0)
109 {
110 in_esc = 1;
111 in_ascii = 1;
112 i = 0;
113 continue;
114 }
115 else
116 {
117 out = ESC_KEY;
118 in_esc = 0;
119 break;
120 }
121 }
122
123 in_esc = 0;
124
125 if (in_ascii)
126 {
127 tmp[i++] = c;
128 if (c == 'm')
129 {
130 in_ascii = 0;
131 continue;
132 }
133 if (i == 2 && c >= 'A' && c <= 'D')
134 {
135 in_ascii = 0;
136 switch (c)
137 {
138 case 'A':
139 out = KEY_UP;
140 break;
141 case 'B':
142 out = KEY_DOWN;
143 break;
144 case 'C':
145 out = KEY_RIGHT;
146 break;
147 case 'D':
148 out = KEY_LEFT;
149 break;
150 }
151 break;
152 }
153 if (i == 3 && tmp[0] == 91 && tmp[2] == 126)
154 {
155 in_ascii = 0;
156 switch (tmp[1])
157 {
158 case 49:
159 out = KEY_HOME;
160 break;
161 case 51:
162 out = KEY_DEL;
163 break;
164 case 52:
165 out = KEY_END;
166 break;
167 case 53:
168 out = KEY_PGUP;
169 break;
170 case 54:
171 out = KEY_PGDOWN;
172 break;
173 }
174 break;
175 }
176 continue;
177 }
178
179 out = ((int)c + 256) % 256;
180 break;
181 }
182
183 //for debug
184 log_std ("-->[%u]\n", out);
185
186 return out;
187 }

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