| 22 |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
| 23 |
|
|
| 24 |
int |
int |
| 25 |
outc(char c) |
outc (char c) |
| 26 |
{ |
{ |
| 27 |
int retval; |
int retval; |
| 28 |
|
|
| 29 |
retval = fprintf(stdout, "%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 |
|
|
| 59 |
{ |
{ |
| 60 |
static char buf[256]; |
static char buf[256]; |
| 61 |
unsigned char c, tmp[256]; |
unsigned char c, tmp[256]; |
| 62 |
int out = 0, loop = 1, in_esc = 0, in_ascii = 0, in_control = 0, i = 0, j; |
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; |
static int len = 0, pos = 0; |
| 64 |
|
|
| 65 |
if (pos >= len) |
if (pos >= len) |
| 66 |
{ |
{ |
| 67 |
pos = 0; |
pos = 0; |
| 68 |
|
|
| 69 |
//len = s_receive (socket_client, buf, 255, ""); |
//len = s_receive (socket_client, buf, 255, ""); |
| 70 |
len = read (0, buf, 255); |
len = read (0, buf, 255); |
| 71 |
|
|
| 72 |
//For debug |
//For debug |
| 73 |
//for (j = 0; j < len; j++) |
//for (j = 0; j < len; j++) |
| 74 |
// log_std ("<--[%u]\n", (buf[j] + 256) % 256); |
// 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) |
if (c == KEY_CONTROL) |
| 88 |
{ |
{ |
| 89 |
if (in_control == 0) |
if (in_control == 0) |
| 90 |
{ |
{ |
| 91 |
in_control = 1; |
in_control = 1; |
| 92 |
i = 0; |
i = 0; |
| 93 |
continue; |
continue; |
| 94 |
} |
} |
| 95 |
} |
} |
| 96 |
|
|
| 97 |
if (in_control) |
if (in_control) |
| 98 |
{ |
{ |
| 99 |
tmp[i++] = c; |
tmp[i++] = c; |
| 100 |
if (i >= 2) |
if (i >= 2) |
| 101 |
{ |
{ |
| 102 |
out = (int)tmp[0] * 256 + tmp[1]; |
out = (int) tmp[0] * 256 + tmp[1]; |
| 103 |
in_control = 0; |
in_control = 0; |
| 104 |
break; |
break; |
| 105 |
} |
} |
| 106 |
continue; |
continue; |
| 107 |
} |
} |
| 108 |
|
|
| 109 |
if (c == ESC_KEY) |
if (c == ESC_KEY) |
| 110 |
{ |
{ |
| 179 |
continue; |
continue; |
| 180 |
} |
} |
| 181 |
|
|
| 182 |
out = ((int)c + 256) % 256; |
out = ((int) c + 256) % 256; |
| 183 |
break; |
break; |
| 184 |
} |
} |
| 185 |
|
|
| 190 |
} |
} |
| 191 |
|
|
| 192 |
int |
int |
| 193 |
ikbhit() |
ikbhit () |
| 194 |
{ |
{ |
| 195 |
int len; |
int len; |
| 196 |
|
|
| 197 |
ioctl (0, FIONREAD, &len); |
ioctl (0, FIONREAD, &len); |
| 198 |
|
|
| 199 |
return len; |
return len; |
| 200 |
} |
} |