1 /****************************************************************************
2 **
3 *W  utils.h                     XGAP Source                      Frank Celler
4 **
5 **
6 *Y  Copyright 1995-1997,  Lehrstuhl D fuer Mathematik,  RWTH Aachen,  Germany
7 *Y  Copyright 1997,       Frank Celler,                 Huerth,       Germany
8 **
9 **  This  file contains the  utility  functions  and  macros  used in   XGAP,
10 **  basically  the list functions  ('ELM', 'LEN',  'AddList', and 'List') and
11 **  the  debug  macro ('DEBUG').  This  file also  includes all the necessary
12 **  system and X11 include files and defines the following data types:
13 **
14 **      Boolean         "True" or "False" (defined by X11)
15 **      Char            a "Char" will be able to hold one character
16 **      Int             a 32-bit signed integer
17 **      Long            an integer able to hold a pointer
18 **      Pointer         a generic pointer
19 **      Short           a 16-bit signed integer
20 **      String          an array of chars
21 **      UChar           unsigned version of "Char"
22 **      UInt            a 32-bit unsigned integer
23 **      ULong           unsigned version of "Long"
24 **      UShort          a 16-bit unsigned integer
25 **
26 **  List( <len> )
27 **  -------------
28 **  'List' creates a new list able to hold <len> pointers of type 'Pointer'.
29 **
30 **  AddList( <lst>, <elm> )
31 **  -----------------------
32 **  'AddList' appends  the  new  element  <elm> of type  'Pointer'  to <lst>,
33 **  enlarging the list if necessary.
34 **
35 **  ELM( <lst>, <i> )
36 **  -----------------
37 **  'ELM' returns the <i>.th element of <lst>.
38 **
39 **  LEN( <lst> )
40 **  ------------
41 **  'LEN' returns the length of <lst>.
42 **
43 **  DEBUG( <type>, ( <debug-text>, ... ) )
44 **  --------------------------------------
45 **  'DEBUG' uses 'printf' to print the  <debug-text> in case that  'Debug' &&
46 **  <type> is true.  The text  is preceded by the line number  and the source
47 **  file name.  The following types are available:  D_LIST, D_XCMD, D_COMM.
48 */
49 #ifndef _utils_h
50 #define _utils_h
51 
52 
53 /****************************************************************************
54 **
55 *F  Include . . . . . . . . . . . . . . . . . . . . . .  system include files
56 */
57 #include <config.h>
58 
59 #if HAVE_TERMIO_H
60 #undef  HAVE_SGTTY_H
61 #define HAVE_SGTTY_H	0
62 #endif
63 
64 #include    <stdio.h>                   /* standard C i/o library          */
65 
66 #if STDC_HEADERS
67 # include   <stdlib.h>                  /* standard C library              */
68 # include   <stdarg.h>                  /* variable argument list          */
69 #endif
70 
71 #if HAVE_LIBC_H
72 # include   <libc.h>                    /* standard NeXT C library         */
73 #endif
74 
75 #if HAVE_UNISTD_H
76 # include   <unistd.h>                  /* another standard C library      */
77 #endif
78 
79 #include    <pwd.h>
80 
81 #if TIME_WITH_SYS_TIME
82 # include   <sys/time.h>
83 # include   <time.h>
84 #else
85 # if HAVE_SYS_TIME_H
86 #  include  <sys/time.h>
87 # else
88 #  include  <time.h>
89 # endif
90 #endif
91 
92 #if HAVE_FCNTL_H
93 #include    <fcntl.h>
94 #endif
95 
96 #include    <sys/errno.h>
97 #include    <sys/stat.h>
98 #include    <sys/types.h>
99 #include    <sys/resource.h>
100 
101 #if HAVE_SYS_WAIT_H
102 # include   <sys/wait.h>
103 #endif
104 
105 #include    <sys/param.h>
106 
107 #if HAVE_TERMIOS_H
108 # include   <termios.h>
109 #else
110 #if HAVE_TERMIO_H
111 # include   <termio.h>
112 #else
113 # include   <sgtty.h>
114 #endif
115 #endif
116 
117 #if HAVE_SIGNAL_H
118 # include   <signal.h>
119 #endif
120 
121 #if HAVE_SYS_SELECT_H
122 # include   <sys/select.h>
123 #endif
124 
125 
126 /****************************************************************************
127 **
128 *F  Include . . . . . . . . . . . . . . . . . . . . . . . . X11 include files
129 */
130 #include    <X11/X.h>                   /* X11 basic definition            */
131 #include    <X11/Xos.h>
132 #include    <X11/Xatom.h>
133 #include    <X11/Xlib.h>
134 #include    <X11/StringDefs.h>
135 #include    <X11/keysym.h>
136 
137 #include    <X11/Intrinsic.h>           /* X Intrinsic                     */
138 #include    <X11/IntrinsicP.h>
139 #include    <X11/CoreP.h>
140 #include    <X11/Composite.h>
141 #include    <X11/Shell.h>
142 
143 #include    <X11/cursorfont.h>          /* cursor font                     */
144 
145 #include    <X11/Xaw/AsciiText.h>       /* Athena widgets                  */
146 #include    <X11/Xaw/Box.h>
147 #include    <X11/Xaw/Cardinals.h>
148 #include    <X11/Xaw/Command.h>
149 #include    <X11/Xaw/Dialog.h>
150 #include    <X11/Xaw/Form.h>
151 #include    <X11/Xaw/Label.h>
152 #include    <X11/Xaw/List.h>
153 #include    <X11/Xaw/MenuButton.h>
154 #include    <X11/Xaw/Paned.h>
155 #include    <X11/Xaw/Scrollbar.h>
156 #include    <X11/Xaw/SimpleMenu.h>
157 #include    <X11/Xaw/SmeBSB.h>
158 #include    <X11/Xaw/SmeLine.h>
159 #include    <X11/Xaw/Text.h>
160 #include    <X11/Xaw/TextP.h>
161 #include    <X11/Xaw/TextSink.h>
162 #include    <X11/Xaw/TextSrc.h>
163 #include    <X11/Xaw/TextSrcP.h>
164 #include    <X11/Xaw/Viewport.h>
165 #include    <X11/Xaw/ViewportP.h>
166 #include    <X11/Xaw/XawInit.h>
167 
168 
169 /****************************************************************************
170 **
171 *F  Prototypes  . . . . . . . . . . . . . . . . . . . . . . system prototypes
172 */
173 #if ! HAVE_UNISTD_H && ! HAVE_LIBC_H
174 extern int write();
175 #endif
176 
177 extern pid_t wait3();
178 extern int   select();
179 
180 /* IRIX System V.4 running IRIX Release 5.3 already defines ioctl and  */
181 /* therefore doesn't like the declaration of ioctl                     */
182 
183 /* extern int ioctl(); */
184 
185 
186 /****************************************************************************
187 **
188 
189 *T  Char  . . . . . . . . . . . . . . . . . . . . . . . . . . . . a character
190 */
191 typedef char Char;
192 
193 
194 /****************************************************************************
195 **
196 *T  Int . . . . . . . . . . . . . . . . . . . . . . . . . . . a signed 32-bit
197 */
198 typedef int Int;
199 
200 
201 /****************************************************************************
202 **
203 *T  Long  . . . . . . . . . . . . . . a signed integer able to hold a pointer
204 */
205 typedef long Long;
206 
207 
208 /****************************************************************************
209 **
210 *T  Pointer . . . . . . . . . . . . . . . . . . . . . . . . a generic pointer
211 */
212 typedef void * Pointer;
213 
214 
215 /****************************************************************************
216 **
217 *T  Short . . . . . . . . . . . . . . . . . . . . . . . . . . a signed 16-bit
218 */
219 typedef short Short;
220 
221 
222 /****************************************************************************
223 **
224 *T  UChar . . . . . . . . . . . . . . . . . . . . . . . an unsigned character
225 */
226 typedef unsigned char UChar;
227 
228 
229 /****************************************************************************
230 **
231 *T  UInt  . . . . . . . . . . . . . . . . . . . . . . . .  an unsigned 32-bit
232 */
233 typedef unsigned int UInt;
234 
235 
236 /****************************************************************************
237 **
238 *T  ULong . . . . . . . . . . . .  an unsigned integer able to hold a pointer
239 */
240 typedef unsigned long ULong;
241 
242 
243 /****************************************************************************
244 **
245 *T  UShort  . . . . . . . . . . . . . . . . . . . . . . .  an unsigned 16-bit
246 */
247 typedef unsigned short UShort;
248 
249 
250 /****************************************************************************
251 **
252 
253 *F  DEBUG(( <str> ))  . . . . . . . . . . . . . . . print <str> as debug info
254 */
255 extern Int Debug;
256 
257 #define D_LIST		1
258 #define D_XCMD          2
259 #define D_COMM          4
260 
261 #define DEBUG(a,b) {                                       \
262             if ( Debug & a ) {                             \
263                 printf( "%04d:%s: ", __LINE__, __FILE__ ); \
264                 printf b;                                  \
265             }                                              \
266         } while(0)
267 
268 
269 /****************************************************************************
270 **
271 *F  MAX( <a>, <b> ) . . . . . . . . . . . . . . . . .  maximum of <a> and <b>
272 */
273 #undef  MAX
274 #define MAX(a,b)        (((a) < (b)) ? (b) : (a))
275 
276 
277 /****************************************************************************
278 **
279 *F  MIN( <a>, <b> ) . . . . . . . . . . . . . . . . .  minimum of <a> and <b>
280 */
281 #undef  MIN
282 #define MIN(a,b)        (((a) < (b)) ? (a) : (b))
283 
284 
285 /****************************************************************************
286 **
287 
288 *T  TypeList  . . . . . . . . . . . . . . . . . . . . . . . .  list structure
289 */
290 typedef struct _list
291 {
292     UInt        size;
293     UInt        len;
294     Pointer   * ptr;
295 }
296 * TypeList;
297 
298 
299 /****************************************************************************
300 **
301 *F  ELM( <lst>, <i> ) . . . . . . . . . . . . . . . . <i>th element of a list
302 */
303 #define ELM(lst,i)      (lst->ptr[i])
304 
305 
306 /****************************************************************************
307 **
308 *F  LEN( <lst> )  . . . . . . . . . . . . . . . . . . . . .  length of a list
309 */
310 #define LEN(lst)        (lst->len)
311 
312 
313 /****************************************************************************
314 **
315 *F  AddList( <lst>, <elm> ) . . . . . . . .  add list element <elm> to <list>
316 */
317 #ifdef DEBUG_ON
318     extern void 	ADD_LIST( String, Int, TypeList, Pointer );
319 #   define AddList(a,b)	ADD_LIST( __FILE__, __LINE__, a, b )
320 #else
321     extern void 	AddList( TypeList, Pointer );
322 #endif
323 
324 
325 /****************************************************************************
326 **
327 *F  List( <len> )   . . . . . . . . . . . . . . . . . . .   create a new list
328 */
329 #ifdef DEBUG_ON
330     extern TypeList 	LIST( String, Int, UInt );
331 #   define List(a) 	LIST( __FILE__, __LINE__, a )
332 #else
333     extern TypeList 	List( UInt );
334 #endif
335 
336 #endif
337 
338 
339 /****************************************************************************
340 **
341 
342 *E  utils.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here
343 */
344