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

raw i/o More...

Go to the source code of this file.

Functions

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

Variables

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

Detailed Description

raw i/o

Definition in file raw.c.

Function Documentation

long c_begin_raw ( )

c_begin_raw

Definition at line 39 of file raw.c.

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

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

c_end_raw

EndRaw end_raw () reset the keyboard in the previous state before xcInitModeRaw. this built-in should be used only by the life-shell of Kathleen.

Definition at line 230 of file raw.c.

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

231 {
232  if (!mode_raw)
233  {
234  Errorline ("in c_end_raw: not in mode raw\n");
235  return FALSE;
236  }
237 
238  if (ioctl (stdin_fileno, TIOCSETN, &param_input) == -1)
239  Errorline ("in end_raw: cannot reset mode raw\n");
240 
241  (void)setvbuf (stdin, bufbuf, _IONBF, BUFSIZ);
242  bzero (bufbuf, BUFSIZ);
243 
244  mode_raw = FALSE;
245  return TRUE;
246 }
#define stdin_fileno
Definition: def_const.h:343
static long mode_raw
Definition: raw.c:19
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:20
static struct sgttyb param_input
Definition: raw.c:18
long c_get_raw ( )

c_get_raw

GetRaw c_get_raw (-Char, -EventFlag) return the next key pressed in Char or if a X event has occured this built-in should be used only by the life-shell of Kathleen.

Definition at line 107 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.

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

InRaw in_raw() return TRUE if mode raw this built-in should be used only by the life-shell of Kathleen.

Definition at line 256 of file raw.c.

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

257 {
258  deref_ptr (aim->a);
260 
261  return TRUE;
262 }
void unify_bool_result(ptr_psi_term t, long v)
unify_bool_result
Definition: built_ins.c:345
static long mode_raw
Definition: raw.c:19
#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 ( )

c_put_raw

PutRaw c_put_raw (+Char) write the specified char on the standard output this built-in should be used only by the life-shell of Kathleen.

Definition at line 206 of file raw.c.

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

207 {
209  ptr_definition types[1];
210 
211  types[0] = real;
212 
213  begin_builtin (c_put_raw, 1, 0, types);
214 
215  (void)putchar ((char) val[0]);
216  (void)fflush (stdout);
217  success = TRUE;
218  end_builtin ();
219 }
#define begin_builtin(FUNCNAME, NBARGS, NBARGSIN, TYPES)
Definition: def_macro.h:198
long c_put_raw()
c_put_raw
Definition: raw.c:206
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 ( )

c_reset_window_flag

ResetWindowFlag reset_window_flag () return the flag x_window_creation this built-in should be used only by the life-shell of Kathleen.

Definition at line 294 of file raw.c.

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

295 {
296  deref_ptr (aim->a);
297 #ifdef X11
299 #endif
300 
301  return TRUE;
302 }
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 ( )

c_window_flag

WindowFlag window_flag () return TRUE if a window has been created this built-in should be used only by the life-shell of Kathleen.

Definition at line 273 of file raw.c.

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

274 {
275  deref_ptr (aim->a);
276 #ifdef X11
278 #else
280 #endif
281 
282  return TRUE;
283 }
void unify_bool_result(ptr_psi_term t, long v)
unify_bool_result
Definition: built_ins.c:345
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 ( )

raw_setup_builtins

set up the built-ins for the mode raw

Definition at line 311 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.

312 {
313 #ifndef NORAW
320  new_built_in(bi_module,"reset_window_flag", predicate, c_reset_window_flag);
321 #endif
322 }
void new_built_in(ptr_module m, char *s, def_type t, long(*r)())
new_built_in
Definition: built_ins.c:5371
#define predicate
Definition: def_const.h:361
#define function_it
Definition: def_const.h:362
long c_get_raw()
c_get_raw
Definition: raw.c:107
long c_begin_raw()
c_begin_raw
Definition: raw.c:39
long c_put_raw()
c_put_raw
Definition: raw.c:206
long c_window_flag()
c_window_flag
Definition: raw.c:273
long c_end_raw()
c_end_raw
Definition: raw.c:230
long c_in_raw()
Definition: raw.c:256
long c_reset_window_flag()
c_reset_window_flag
Definition: raw.c:294
ptr_module bi_module
Definition: def_glob.h:155

Variable Documentation

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

Definition at line 20 of file raw.c.

long mode_raw = FALSE
static

Definition at line 19 of file raw.c.

struct sgttyb param_input
static

Definition at line 18 of file raw.c.