| 19 |
#include "common.h" |
#include "common.h" |
| 20 |
#include <stdio.h> |
#include <stdio.h> |
| 21 |
#include <stdarg.h> |
#include <stdarg.h> |
| 22 |
|
#include <sys/ioctl.h> |
| 23 |
|
|
| 24 |
int |
int |
| 25 |
outc(char c) |
outc (char c) |
| 26 |
{ |
{ |
| 27 |
int retval; |
int retval; |
| 28 |
|
|
| 29 |
retval = printf("%c",c); |
retval = fprintf (stdout, "%c", c); |
| 30 |
|
|
| 31 |
return retval; |
return retval; |
| 32 |
} |
} |
| 33 |
|
|
| 34 |
int |
int |
| 35 |
prints(const char * format, ...) |
prints (const char *format, ...) |
| 36 |
{ |
{ |
| 37 |
va_list args; |
va_list args; |
| 38 |
int retval; |
int retval; |
| 45 |
} |
} |
| 46 |
|
|
| 47 |
int |
int |
| 48 |
iflush() |
iflush () |
| 49 |
{ |
{ |
| 50 |
int retval; |
int retval; |
| 51 |
|
|
| 52 |
retval = fflush (stdout); |
retval = fflush (stdout); |
| 53 |
|
|
| 54 |
return retval; |
return retval; |
| 55 |
} |
} |
| 56 |
|
|
| 57 |
int |
int |
| 58 |
igetch () |
igetch () |
| 59 |
{ |
{ |
|
char c, tmp[256]; |
|
| 60 |
static char buf[256]; |
static char buf[256]; |
| 61 |
int out = 0, loop = 1, in_esc = 0, in_ascii = 0, i = 0, j; |
unsigned char c, tmp[256]; |
| 62 |
static int len =0 , pos = 0; |
int out = KEY_NULL, 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) |
if (pos >= len) |
| 66 |
{ |
{ |
| 67 |
len = s_receive (socket_client, buf, 255, ""); |
pos = 0; |
| 68 |
pos = 0; |
|
| 69 |
|
//len = s_receive (socket_client, buf, 255, ""); |
| 70 |
//For debug |
len = read (0, buf, 255); |
| 71 |
//for (j = 0; j < len; j++) |
|
| 72 |
// log_std ("[%d]\n", buf[j]); |
//For debug |
| 73 |
} |
//for (j = 0; j < len; j++) |
| 74 |
|
// log_std ("<--[%u]\n", (buf[j] + 256) % 256); |
| 75 |
|
} |
| 76 |
|
|
| 77 |
while (pos < len) |
while (pos < len) |
| 78 |
{ |
{ |
| 79 |
c = buf[pos++]; |
c = buf[pos++]; |
| 80 |
|
|
| 81 |
if (c == '\0') |
if (c == '\0') |
| 82 |
{ |
{ |
| 83 |
out = c; |
out = c; |
| 84 |
break; |
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) |
if (c == ESC_KEY) |
| 110 |
{ |
{ |
| 161 |
case 49: |
case 49: |
| 162 |
out = KEY_HOME; |
out = KEY_HOME; |
| 163 |
break; |
break; |
| 164 |
|
case 51: |
| 165 |
|
out = KEY_DEL; |
| 166 |
|
break; |
| 167 |
case 52: |
case 52: |
| 168 |
out = KEY_END; |
out = KEY_END; |
| 169 |
break; |
break; |
| 179 |
continue; |
continue; |
| 180 |
} |
} |
| 181 |
|
|
| 182 |
out = ((int)c + 256) % 256; |
out = ((int) c + 256) % 256; |
| 183 |
break; |
break; |
| 184 |
} |
} |
| 185 |
|
|
| 186 |
//for debug |
//for debug |
| 187 |
//log_std ("[%d]\n", out); |
//log_std ("-->[%u]\n", out); |
| 188 |
|
|
| 189 |
return out; |
return out; |
| 190 |
} |
} |
| 191 |
|
|
| 192 |
|
int |
| 193 |
|
ikbhit () |
| 194 |
|
{ |
| 195 |
|
int len; |
| 196 |
|
|
| 197 |
|
ioctl (0, FIONREAD, &len); |
| 198 |
|
|
| 199 |
|
return len; |
| 200 |
|
} |