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

Diff of /lbbs/src/io.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.4 by sysadm, Wed Mar 2 16:33:49 2005 UTC Revision 1.11 by sysadm, Sat May 7 09:28:12 2005 UTC
# Line 17  Line 17 
17    
18  #include "io.h"  #include "io.h"
19  #include "common.h"  #include "common.h"
20    #include "tcplib.h"
21  #include <stdio.h>  #include <stdio.h>
22  #include <stdarg.h>  #include <stdarg.h>
23    #include <time.h>
24    #include <fcntl.h>
25    #include <unistd.h>
26    #include <sys/ioctl.h>
27    
28  int  int
29  outc(char c)  outc (char c)
30  {  {
31    int retval;    int retval;
32    
33    retval = fprintf(stdout, "%c", c);    retval = fprintf (stdout, "%c", c);
34    
35    return retval;    return retval;
36  }  }
37    
38  int  int
39  prints(const char * format, ...)  prints (const char *format, ...)
40  {  {
41    va_list args;    va_list args;
42    int retval;    int retval;
# Line 44  prints(const char * format, ...) Line 49  prints(const char * format, ...)
49  }  }
50    
51  int  int
52  iflush()  iflush ()
53  {  {
54    int retval;    int retval;
55      
56    retval = fflush (stdout);    retval = fflush (stdout);
57      
58    return retval;    return retval;
59  }  }
60    
# Line 58  igetch () Line 63  igetch ()
63  {  {
64    static char buf[256];    static char buf[256];
65    unsigned char c, tmp[256];    unsigned char c, tmp[256];
66    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 =
67    static int len = 0 , pos = 0;      0, j, result;
68      static int len = 0, pos = 0;
69      fd_set testfds;
70      struct timeval timeout;
71    
72    if (pos >= len)    if (pos >= len)
73    {      {
74      len = s_receive (socket_client, buf, 255, "");        pos = 0;
75      pos = 0;        len = 0;
76    
77      //For debug        FD_ZERO (&testfds);
78      for (j = 0; j < len; j++)        FD_SET (0, &testfds);
79        log_std ("<--[%u]\n", (buf[j] + 256) % 256);  
80    }        timeout.tv_sec = 1;
81          timeout.tv_usec = 0;
82    
83          result = SignalSafeSelect (FD_SETSIZE, &testfds, (fd_set *) NULL,
84                           (fd_set *) NULL, &timeout);
85    
86          if (result == 0)
87            {
88              return KEY_TIMEOUT;
89            }
90          if (result < 0)
91            {
92              log_error ("select() error!\n");
93              return KEY_NULL;
94            }
95          if (result > 0)
96            {
97              if (FD_ISSET (0, &testfds))
98                {
99                  len = read (0, buf, 255);
100                }
101            }
102    
103          //For debug
104          //for (j = 0; j < len; j++)
105          //  log_std ("<--[%u]\n", (buf[j] + 256) % 256);
106        }
107    
108    while (pos < len)    while (pos < len)
109      {      {
110        c = buf[pos++];        c = buf[pos++];
111    
112        if (c == '\0')        if (c == '\0')
113        {          {
114          out = c;            out = c;
115          break;            break;
116        }          }
117    
118        if (c == KEY_CONTROL)        if (c == KEY_CONTROL)
119          {          {
120            if (in_control == 0)            if (in_control == 0)
121              {              {
122                in_control = 1;                in_control = 1;
123                i = 0;                i = 0;
124                continue;                continue;
125              }              }
126          }          }
127          
128        if (in_control)        if (in_control)
129        {          {
130          tmp[i++] = c;            tmp[i++] = c;
131          if (i >= 2)            if (i >= 2)
132          {              {
133            out = (int)tmp[0] * 256 + tmp[1];                out = (int) tmp[0] * 256 + tmp[1];
134            in_control = 0;                in_control = 0;
135            break;                break;
136          }              }
137          continue;            continue;
138        }          }
139    
140        if (c == ESC_KEY)        if (c == ESC_KEY)
141          {          {
# Line 168  igetch () Line 202  igetch ()
202                    out = KEY_PGUP;                    out = KEY_PGUP;
203                    break;                    break;
204                  case 54:                  case 54:
205                    out = KEY_PGDOWN;                    out = KEY_PGDN;
206                    break;                    break;
207                  }                  }
208                break;                break;
# Line 176  igetch () Line 210  igetch ()
210            continue;            continue;
211          }          }
212    
213        out = ((int)c + 256) % 256;        out = ((int) c + 256) % 256;
214        break;        break;
215      }      }
216    
217    //for debug    //for debug
218    log_std ("-->[%u]\n", out);    //log_std ("-->[%u]\n", out);
219    
220    return out;    return out;
221  }  }
222    
223    int
224    igetch_t (long int sec)
225    {
226      int ch;
227      time_t t_begin = time (0);
228    
229      do
230        {
231          ch = igetch ();
232        }
233      while ((ch == KEY_TIMEOUT) && (time (0) - t_begin < sec));
234    
235      return ch;
236    }
237    
238    int
239    ikbhit ()
240    {
241      int len;
242    
243      ioctl (0, FIONREAD, &len);
244    
245      return len;
246    }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

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