Wild Life  2.29
 All Data Structures Files Functions Variables Typedefs Macros
Functions | Variables
raw.c File Reference

Go to the source code of this file.

Functions

long c_begin_raw ()
 
long c_get_raw ()
 
long c_put_raw ()
 
long c_end_raw ()
 
long c_in_raw ()
 
long c_window_flag ()
 
long c_reset_window_flag ()
 
void raw_setup_builtins ()
 

Variables

static struct sgttyb param_input
 
static long mode_raw = FALSE
 
static char bufbuf [BUFSIZ+1] = {0}
 

Function Documentation

long c_begin_raw ( )

Definition at line 32 of file raw.c.

References bufbuf, Errorline(), FALSE, mode_raw, param_input, stdin_fileno, TANDEM, and TRUE.

34 {
35  struct sgttyb param;
36  struct termio argio;
37 
38  if (mode_raw)
39  {
40  Errorline ("in begin_raw: already in mode raw\n");
41  return FALSE;
42  }
43 
44  if (ioctl (stdin_fileno, TIOCGETP, &param_input) == -1)
45  Errorline ("in begin_raw: cannot get the input parameters\n");
46 
47  bcopy ((char*)&param_input, (char*)&param, sizeof (param));
48 
49 #if 0
50  /* with RAW, we catch everything (eg: ^C is 3) */
51  param.sg_flags |= CBREAK | TANDEM | RAW;
52 #else
53  param.sg_flags |= CBREAK | TANDEM;
54 #endif
55 
56  param.sg_flags &= ~ECHO;
57 
58  if (ioctl (stdin_fileno, TIOCSETN, &param) == -1)
59  Errorline ("in begin_raw: cannot set the input parameters\n");
60 
61  if (ioctl (stdin_fileno, TCGETA, &argio) == -1)
62  Errorline ("in begin_raw: cannot get the terminal\n");
63 
64  /* do not strip the characters (the 8th bit is used for the key Compose) */
65 #if 1
66  /* catch every character */
67  argio.c_lflag &= ~(ICANON|ISIG);
68  argio.c_cc[VMIN] = 1;
69  argio.c_cc[VTIME] = 0;
70 
71  /* with IXON, do not interpret ctrl-S and ctrl-Q */
72  argio.c_iflag &= ~(ISTRIP|IXON);
73 
74  /* map LF to CR-LF */
75  argio.c_oflag |= OPOST|ONLCR;
76 #else
77  argio.c_iflag &= ~(ISTRIP);
78 #endif
79 
80  if (ioctl (stdin_fileno, TCSETA, &argio) == -1)
81  Errorline ("in begin_raw: cannot set the terminal\n");
82 
83  (void)setvbuf (stdin, bufbuf, _IOFBF, BUFSIZ);
84 
85  bzero (bufbuf, BUFSIZ+1);
86 
87  mode_raw = TRUE;
88  return TRUE;
89 }
#define stdin_fileno
Definition: def_const.h:343
static long mode_raw
Definition: raw.c:17
void Errorline(char *format,...)
Definition: error.c:414
#define TRUE
Definition: def_const.h:127
#define FALSE
Definition: def_const.h:128
static char bufbuf[BUFSIZ+1]
Definition: raw.c:18
static struct sgttyb param_input
Definition: raw.c:16
#define TANDEM
Definition: defs.h:26
long c_end_raw ( )

Definition at line 232 of file raw.c.

References bufbuf, Errorline(), FALSE, mode_raw, param_input, stdin_fileno, and TRUE.

234 {
235  if (!mode_raw)
236  {
237  Errorline ("in c_end_raw: not in mode raw\n");
238  return FALSE;
239  }
240 
241  if (ioctl (stdin_fileno, TIOCSETN, &param_input) == -1)
242  Errorline ("in end_raw: cannot reset mode raw\n");
243 
244  (void)setvbuf (stdin, bufbuf, _IONBF, BUFSIZ);
245  bzero (bufbuf, BUFSIZ);
246 
247  mode_raw = FALSE;
248  return TRUE;
249 }
#define stdin_fileno
Definition: def_const.h:343
static long mode_raw
Definition: raw.c:17
void Errorline(char *format,...)
Definition: error.c:414
#define TRUE
Definition: def_const.h:127
#define FALSE
Definition: def_const.h:128
static char bufbuf[BUFSIZ+1]
Definition: raw.c:18
static struct sgttyb param_input
Definition: raw.c:16
long c_get_raw ( )

Definition at line 103 of file raw.c.

References aim, begin_builtin, boolean, bufbuf, Errorline(), exit_life(), FALSE, include_var_builtin, interrupt(), REAL, real, release_resid(), stdin_fileno, TRUE, unify_real_result(), and xevent_existing.

104 {
106  ptr_definition types[2];
107  long nfds;
108  fd_set readfd, writefd, exceptfd;
109  struct timeval timeout;
110  long char_flag = FALSE, event_flag = FALSE;
111  long c = 0;
112  // ptr_psi_term key_code;
113  long level;
114 
115  types[0] = real;
116  types[1] = boolean;
117 
118  begin_builtin (c_get_raw, 2, 0, types);
119 
120  if ((int)strlen (bufbuf) == 0)
121  {
122  level = (unsigned long) aim->c;
123 
124 
125  do
126  {
127  FD_ZERO(&readfd);
128  FD_SET(stdin_fileno, &readfd);
129  FD_ZERO(&writefd);
130  FD_ZERO(&exceptfd);
131  timeout.tv_sec = 0;
132  timeout.tv_usec = 100000;
133 
134  nfds = select (32, &readfd, &writefd, &exceptfd, &timeout);
135  if (nfds == -1)
136  {
137  if (errno != EINTR)
138  {
139  Errorline ("it is not possible to read characters or X events\n");
140  exit_life(TRUE);
141  }
142  else
143  interrupt ();
144  }
145  else
146  if (nfds == 0)
147  {
148 #ifdef X11
149  if (x_exist_event ())
150  {
151  event_flag = TRUE;
153  }
154 #endif
155  }
156  else
157  {
158  if (FD_ISSET(stdin_fileno, &readfd) != 0)
159  {
160  /* c cna be equal to 0 with the mouse's selection */
161  /* first the selection is inside the buffer bufbuf */
162  /* later fgetc returns zeros */
163  /* I don't understand - jch - Fri Aug 28 1992 */
164  if ((c = fgetc (stdin)) != 0)
165  {
166  (void)unify_real_result (args[0], (REAL) c);
167  char_flag = TRUE;
168  /* the shift is done below */
169  }
170  }
171  else
172  Errorline ("in select: unknown descriptor\n");
173  }
174  } while (!(char_flag || event_flag));
175  }
176  else
177  {
178  (void)unify_real_result (args[0], (REAL) bufbuf[0]);
179  char_flag = TRUE;
180  }
181 
182  /* shift */
183  if (char_flag)
184  bcopy (&bufbuf[1], bufbuf, BUFSIZ-1);
185 
186  /* return if an X event has occured */
187  unify_bool_result (args[1], event_flag);
188 
189  success = TRUE;
190  end_builtin ();
191 }
void interrupt()
Definition: interrupt.c:13
void exit_life(long nl_flag)
Definition: built_ins.c:2090
long c_get_raw()
Definition: raw.c:103
void unify_bool_result(ptr_psi_term t, long v)
Definition: built_ins.c:329
#define stdin_fileno
Definition: def_const.h:343
#define REAL
Definition: def_const.h:72
#define begin_builtin(FUNCNAME, NBARGS, NBARGSIN, TYPES)
Definition: def_macro.h:198
void release_resid(ptr_psi_term t)
Definition: lefun.c:414
void Errorline(char *format,...)
Definition: error.c:414
ptr_definition real
Definition: def_glob.h:102
#define TRUE
Definition: def_const.h:127
#define FALSE
Definition: def_const.h:128
static char bufbuf[BUFSIZ+1]
Definition: raw.c:18
ptr_goal aim
Definition: def_glob.h:49
long unify_real_result(ptr_psi_term t, REAL v)
Definition: built_ins.c:371
ptr_definition boolean
Definition: def_glob.h:73
ptr_psi_term xevent_existing
Definition: def_glob.h:208
#define include_var_builtin(NBARGS)
Definition: def_macro.h:191
#define end_builtin()
Definition: def_macro.h:254
long c_in_raw ( )

Definition at line 263 of file raw.c.

References aim, deref_ptr, mode_raw, TRUE, and unify_bool_result().

265 {
266  deref_ptr (aim->a);
268 
269  return TRUE;
270 }
void unify_bool_result(ptr_psi_term t, long v)
Definition: built_ins.c:329
static long mode_raw
Definition: raw.c:17
#define deref_ptr(P)
Definition: def_macro.h:95
#define TRUE
Definition: def_const.h:127
ptr_goal aim
Definition: def_glob.h:49
long c_put_raw ( )

Definition at line 205 of file raw.c.

References begin_builtin, end_builtin, include_var_builtin, real, and TRUE.

206 {
208  ptr_definition types[1];
209 
210  types[0] = real;
211 
212  begin_builtin (c_put_raw, 1, 0, types);
213 
214  (void)putchar ((char) val[0]);
215  (void)fflush (stdout);
216  success = TRUE;
217  end_builtin ();
218 }
#define begin_builtin(FUNCNAME, NBARGS, NBARGSIN, TYPES)
Definition: def_macro.h:198
long c_put_raw()
Definition: raw.c:205
ptr_definition real
Definition: def_glob.h:102
#define TRUE
Definition: def_const.h:127
#define include_var_builtin(NBARGS)
Definition: def_macro.h:191
#define end_builtin()
Definition: def_macro.h:254
long c_reset_window_flag ( )

Definition at line 309 of file raw.c.

References aim, deref_ptr, FALSE, TRUE, and x_window_creation.

311 {
312  deref_ptr (aim->a);
313 #ifdef X11
315 #endif
316 
317  return TRUE;
318 }
long x_window_creation
Definition: def_glob.h:217
#define deref_ptr(P)
Definition: def_macro.h:95
#define TRUE
Definition: def_const.h:127
#define FALSE
Definition: def_const.h:128
ptr_goal aim
Definition: def_glob.h:49
long c_window_flag ( )

Definition at line 284 of file raw.c.

References aim, deref_ptr, FALSE, TRUE, unify_bool_result(), and x_window_creation.

286 {
287  deref_ptr (aim->a);
288 #ifdef X11
290 #else
292 #endif
293 
294  return TRUE;
295 }
void unify_bool_result(ptr_psi_term t, long v)
Definition: built_ins.c:329
long x_window_creation
Definition: def_glob.h:217
#define deref_ptr(P)
Definition: def_macro.h:95
#define TRUE
Definition: def_const.h:127
#define FALSE
Definition: def_const.h:128
ptr_goal aim
Definition: def_glob.h:49
void raw_setup_builtins ( )

Definition at line 327 of file raw.c.

References bi_module, c_begin_raw(), c_end_raw(), c_get_raw(), c_in_raw(), c_put_raw(), c_reset_window_flag(), c_window_flag(), function_it, new_built_in(), and predicate.

329 {
330 #ifndef NORAW
337  new_built_in(bi_module,"reset_window_flag", predicate, c_reset_window_flag);
338 #endif
339 }
void new_built_in(ptr_module m, char *s, def_type t, long(*r)())
Definition: built_ins.c:5054
#define predicate
Definition: def_const.h:361
#define function_it
Definition: def_const.h:362
long c_get_raw()
Definition: raw.c:103
long c_begin_raw()
Definition: raw.c:32
long c_put_raw()
Definition: raw.c:205
long c_window_flag()
Definition: raw.c:284
long c_end_raw()
Definition: raw.c:232
long c_in_raw()
Definition: raw.c:263
long c_reset_window_flag()
Definition: raw.c:309
ptr_module bi_module
Definition: def_glob.h:155

Variable Documentation

char bufbuf[BUFSIZ+1] = {0}
static

Definition at line 18 of file raw.c.

long mode_raw = FALSE
static

Definition at line 17 of file raw.c.

struct sgttyb param_input
static

Definition at line 16 of file raw.c.