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


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

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