/[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.2 by sysadm, Sat Oct 23 18:41:41 2004 UTC Revision 1.13 by sysadm, Mon Mar 15 07:30:21 2010 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 = printf("%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    
61  int  int
62  igetch ()  igetch ()
63  {  {
   char c, tmp[256];  
64    static char buf[256];    static char buf[256];
65    int out = 0, loop = 1, in_esc = 0, in_ascii = 0, i = 0, j;    unsigned char c, tmp[256];
66    static int len =0 , pos = 0;    int out = KEY_NULL, loop = 1, in_esc = 0, in_ascii = 0, in_control = 0, i =
67        0, j, result;
68      static int len = 0, pos = 0;
69      fd_set testfds;
70      struct timeval timeout;
71    
72      //Stop on system exit
73      if (SYS_exit)
74        return KEY_NULL;
75    
76    if (pos >= len)    if (pos >= len)
77    {      {
78      len = s_receive (socket_client, buf, 255, "");        pos = 0;
79      pos = 0;        len = 0;
80    
81      //For debug        FD_ZERO (&testfds);
82      //for (j = 0; j < len; j++)        FD_SET (0, &testfds);
83      //  log_std ("[%d]\n", buf[j]);  
84    }        timeout.tv_sec = 1;
85          timeout.tv_usec = 0;
86    
87          result = SignalSafeSelect (FD_SETSIZE, &testfds, (fd_set *) NULL,
88                           (fd_set *) NULL, &timeout);
89    
90          if (result == 0)
91            {
92              return KEY_TIMEOUT;
93            }
94          if (result < 0)
95            {
96              log_error ("select() error (%d) !\n", result);
97              return KEY_NULL;
98            }
99          if (result > 0)
100            {
101              if (FD_ISSET (0, &testfds))
102                {
103                  len = read (0, buf, 255);
104                }
105            }
106    
107          //For debug
108          //for (j = 0; j < len; j++)
109          //  log_std ("<--[%u]\n", (buf[j] + 256) % 256);
110        }
111    
112    while (pos < len)    while (pos < len)
113      {      {
114        c = buf[pos++];        c = buf[pos++];
115    
116        if (c == '\0')        if (c == '\0')
117        {          {
118          out = c;            out = c;
119          break;            break;
120        }          }
121    
122          if (c == KEY_CONTROL)
123            {
124              if (in_control == 0)
125                {
126                  in_control = 1;
127                  i = 0;
128                  continue;
129                }
130            }
131    
132          if (in_control)
133            {
134              tmp[i++] = c;
135              if (i >= 2)
136                {
137                  out = (int) tmp[0] * 256 + tmp[1];
138                  in_control = 0;
139                  break;
140                }
141              continue;
142            }
143    
144        if (c == ESC_KEY)        if (c == ESC_KEY)
145          {          {
# Line 136  igetch () Line 196  igetch ()
196                  case 49:                  case 49:
197                    out = KEY_HOME;                    out = KEY_HOME;
198                    break;                    break;
199                    case 51:
200                      out = KEY_DEL;
201                      break;
202                  case 52:                  case 52:
203                    out = KEY_END;                    out = KEY_END;
204                    break;                    break;
# Line 143  igetch () Line 206  igetch ()
206                    out = KEY_PGUP;                    out = KEY_PGUP;
207                    break;                    break;
208                  case 54:                  case 54:
209                    out = KEY_PGDOWN;                    out = KEY_PGDN;
210                    break;                    break;
211                  }                  }
212                break;                break;
# Line 151  igetch () Line 214  igetch ()
214            continue;            continue;
215          }          }
216    
217        out = ((int)c + 256) % 256;        out = ((int) c + 256) % 256;
218        break;        break;
219      }      }
220    
221    //for debug    //for debug
222    //log_std ("[%d]\n", out);    //log_std ("-->[%u]\n", out);
223    
224    return out;    return out;
225  }  }
226    
227    int
228    igetch_t (long int sec)
229    {
230      int ch;
231      time_t t_begin = time (0);
232    
233      do
234        {
235          ch = igetch ();
236        }
237      while ((ch == KEY_TIMEOUT || ch == 0xa) && (time (0) - t_begin < sec));
238    
239      return ch;
240    }
241    
242    int
243    ikbhit ()
244    {
245      int len;
246    
247      ioctl (0, FIONREAD, &len);
248    
249      return len;
250    }


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

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