Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtterm / tests / shared / p2c.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: p2c.h /main/3 1995/10/31 12:00:53 rswiston $ */
24 #ifndef P2C_H
25 #define P2C_H
26
27
28 /* Header file for code generated by "p2c", the Pascal-to-C translator */
29
30 /* "p2c"  Copyright (C) 1989 Dave Gillespie, version 1.14.
31  * This file may be copied, modified, etc. in any way.  It is not restricted
32  * by the licence agreement accompanying p2c itself.
33  */
34
35
36 #include <stdio.h>
37
38
39
40 /* If the following heuristic fails, compile -DBSD=0 for non-BSD systems,
41    or -DBSD=1 for BSD systems. */
42
43 #ifdef M_XENIX
44 # define BSD 0
45 #endif
46
47 #ifdef FILE       /* a #define in BSD, a typedef in SYSV (hp-ux, at least) */
48 # ifndef BSD      /*  (a convenient, but horrible kludge!) */
49 #  define BSD 1
50 # endif
51 #endif
52
53 #ifdef BSD
54 # if !BSD
55 #  undef BSD
56 # endif
57 #endif
58
59
60 #ifdef __STDC__
61 # include <stddef.h>
62 # include <stdlib.h>
63 # define HAS_STDLIB
64 # define __CAT__(a,b)a##b
65 #else
66 # ifndef BSD
67 #  include <memory.h>
68 # endif
69 # include <sys/types.h>
70 # define __ID__(a)a
71 # define __CAT__(a,b)__ID__(a)b
72 #endif
73
74
75 #ifdef BSD
76 # include <strings.h>
77 # define memcpy(a,b,n) (bcopy(b,a,n),a)
78 # define memcmp(a,b,n) bcmp(a,b,n)
79 # define strchr(s,c) index(s,c)
80 # define strrchr(s,c) rindex(s,c)
81 #else
82 # include <string.h>
83 #endif
84
85 #include <ctype.h>
86 #include <math.h>
87 #include <setjmp.h>
88 #include <assert.h>
89
90
91 typedef struct __p2c_jmp_buf {
92     struct __p2c_jmp_buf *next;
93     jmp_buf jbuf;
94 } __p2c_jmp_buf;
95
96
97 /* Warning: The following will not work if setjmp is used simultaneously.
98    This also violates the ANSI restriction about using vars after longjmp,
99    but a typical implementation of longjmp will get it right anyway. */
100
101 #ifndef FAKE_TRY
102 # define TRY(x)         do { __p2c_jmp_buf __try_jb;  \
103                              __try_jb.next = __top_jb;  \
104                              if (!setjmp((__top_jb = &__try_jb)->jbuf)) {
105 # define RECOVER(x)     __top_jb = __try_jb.next; } else {
106 # define RECOVER2(x,L)  __top_jb = __try_jb.next; } else {  \
107                              if (0) { L: __top_jb = __try_jb.next; }
108 # define ENDTRY(x)      } } while (0) 
109 #else
110 # define TRY(x)         if (1) {
111 # define RECOVER(x)     } else do {
112 # define RECOVER2(x,L)  } else do { L: ;
113 # define ENDTRY(x)      } while (0)
114 #endif
115
116
117
118 #ifdef M_XENIX  /* avoid compiler bug */
119 # define SHORT_MAX  (32767)
120 # define SHORT_MIN  (-32768)
121 #endif
122
123
124 /* The following definitions work only on twos-complement machines */
125 #ifndef SHORT_MAX
126 # define SHORT_MAX  (((unsigned short) -1) >> 1)
127 # define SHORT_MIN  (~SHORT_MAX)
128 #endif
129
130 #ifndef INT_MAX
131 # define INT_MAX    (((unsigned int) -1) >> 1)
132 # define INT_MIN    (~INT_MAX)
133 #endif
134
135 #ifndef LONG_MAX
136 # define LONG_MAX   (((unsigned long) -1) >> 1)
137 # define LONG_MIN   (~LONG_MAX)
138 #endif
139
140 #ifndef SEEK_SET
141 # define SEEK_SET   0
142 # define SEEK_CUR   1
143 # define SEEK_END   2
144 #endif
145
146 #ifndef EXIT_SUCCESS
147 # define EXIT_SUCCESS  0
148 # define EXIT_FAILURE  1
149 #endif
150
151
152 #define SETBITS  32
153
154
155 #ifdef __STDC__
156 # define Signed     signed
157 # define Void       void      /* Void f() = procedure */
158 # ifndef Const
159 #  define Const     const
160 # endif
161 # ifndef Volatile
162 # define Volatile  volatile
163 # endif
164 # define PP(x)      x         /* function prototype */
165 # define PV()       (void)    /* null function prototype */
166 typedef void *Anyptr;
167 #else
168 # define Signed
169 # define Void       void
170 # ifndef Const
171 #  define Const
172 # endif
173 # ifndef Volatile
174 #  define Volatile
175 # endif
176 # define PP(x)      ()
177 # define PV()       ()
178 typedef char *Anyptr;
179 #endif
180
181 #ifdef __GNUC__
182 # define Inline     inline
183 #else
184 # define Inline
185 #endif
186
187 #define Register    register  /* Register variables */
188 #define Char        char      /* Characters (not bytes) */
189
190 #ifndef Static
191 # define Static     static    /* Private global funcs and vars */
192 #endif
193
194 #ifndef Local
195 # define Local      static    /* Nested functions */
196 #endif
197
198 typedef Signed   char schar;
199 #ifndef _AIX
200 typedef unsigned char uchar;
201 #endif /* _AIX */
202 typedef unsigned char boolean;
203
204 #ifndef true
205 # define true    1
206 # define false   0
207 #endif
208
209
210 typedef struct {
211     Anyptr proc, link;
212 } _PROCEDURE;
213
214 #ifndef _FNSIZE
215 # define _FNSIZE  120
216 #endif
217
218 /*  Most of the following vars were "Unsatisfied symbols at load time 
219 extern Void    PASCAL_MAIN  PP( (int, Char **) );
220 extern Char    **P_argv;
221 extern int     P_argc;
222 extern short   P_escapecode;
223 extern int     P_ioresult;
224 extern __p2c_jmp_buf *__top_jb;
225 */
226
227 #ifdef P2C_H_PROTO   /* if you have Ansi C but non-prototyped header files */
228 extern Char    *strcat      PP( (Char *, Const Char *) );
229 extern Char    *strchr      PP( (Const Char *, int) );
230 extern int      strcmp      PP( (Const Char *, Const Char *) );
231 extern Char    *strcpy      PP( (Char *, Const Char *) );
232 extern size_t   strlen      PP( (Const Char *) );
233 extern Char    *strncat     PP( (Char *, Const Char *, size_t) );
234 extern int      strncmp     PP( (Const Char *, Const Char *, size_t) );
235 extern Char    *strncpy     PP( (Char *, Const Char *, size_t) );
236 extern Char    *strrchr     PP( (Const Char *, int) );
237
238 extern Anyptr   memchr      PP( (Const Anyptr, int, size_t) );
239 extern Anyptr   memmove     PP( (Anyptr, Const Anyptr, size_t) );
240 extern Anyptr   memset      PP( (Anyptr, int, size_t) );
241 #ifndef memcpy
242 extern Anyptr   memcpy      PP( (Anyptr, Const Anyptr, size_t) );
243 extern int      memcmp      PP( (Const Anyptr, Const Anyptr, size_t) );
244 #endif
245
246 extern int      atoi        PP( (Const Char *) );
247 extern double   atof        PP( (Const Char *) );
248 extern long     atol        PP( (Const Char *) );
249 extern double   strtod      PP( (Const Char *, Char **) );
250 extern long     strtol      PP( (Const Char *, Char **, int) );
251 #endif /*P2C_H_PROTO*/
252
253 #ifndef HAS_STDLIB
254 #ifndef _AIX
255 extern Anyptr   malloc      PP( (size_t) );
256 #endif /* _AIX */
257 extern Void     free        PP( (Anyptr) );
258 #endif /* HAS_STDLIB */
259
260 extern int      _OutMem     PV();
261 extern int      _CaseCheck  PV();
262 extern int      _NilCheck   PV();
263 extern int      _Escape     PP( (int) );
264 extern int      _EscIO      PP( (int) );
265
266 extern long     ipow        PP( (long, long) );
267 /* strsub defined in qalib.c                                     */
268 /* extern Char    *strsub      PP( (Char *, Char *, int, int) ); */
269 extern Char    *strltrim    PP( (Char *) );
270 extern Char    *strrtrim    PP( (Char *) );
271 extern Char    *strrpt      PP( (Char *, Char *, int) );
272 extern Char    *strpad      PP( (Char *, Char *, int, int) );
273
274 /* strpos2 defined in qalib.c                                     */
275 /*  extern int      strpos2     PP( (Char *, Char *, int) );  */
276 extern long     memavail    PV();
277 extern int      P_peek      PP( (FILE *) );
278 extern int      P_eof       PP( (FILE *) );
279 extern int      P_eoln      PP( (FILE *) );
280 extern Void     P_readpaoc  PP( (FILE *, Char *, int) );
281 extern Void     P_readlnpaoc PP( (FILE *, Char *, int) );
282 extern long     P_maxpos    PP( (FILE *) );
283 extern long    *P_setunion  PP( (long *, long *, long *) );
284 extern long    *P_setint    PP( (long *, long *, long *) );
285 extern long    *P_setdiff   PP( (long *, long *, long *) );
286 extern long    *P_setxor    PP( (long *, long *, long *) );
287 extern int      P_inset     PP( (unsigned, long *) );
288 extern int      P_setequal  PP( (long *, long *) );
289 extern int      P_subset    PP( (long *, long *) );
290 extern long    *P_addset    PP( (long *, unsigned) );
291 extern long    *P_addsetr   PP( (long *, unsigned, unsigned) );
292 extern long    *P_remset    PP( (long *, unsigned) );
293 extern long    *P_setcpy    PP( (long *, long *) );
294 extern long    *P_expset    PP( (long *, long) );
295 extern long     P_packset   PP( (long *) );
296 extern int      P_getcmdline PP( (int l, int h, Char *line) );
297 extern Void     TimeStamp   PP( (int *Day, int *Month, int *Year,
298                                  int *Hour, int *Min, int *Sec) );
299 extern Void     P_sun_argv  PP( (char *, int, int) );
300
301
302 /* I/O error handling */
303 #define _CHKIO(cond,ior,val,def)  ((cond) ? P_ioresult=0,(val)  \
304                                           : P_ioresult=(ior),(def))
305 #define _SETIO(cond,ior)          (P_ioresult = (cond) ? 0 : (ior))
306
307 /* Following defines are suitable for the HP Pascal operating system */
308 #define FileNotFound     10
309 #define FileNotOpen      13
310 #define FileWriteError   38
311 #define BadInputFormat   14
312 #define EndOfFile        30
313
314 /* Creating temporary files */
315 #if (defined(BSD) || defined(NO_TMPFILE)) && !defined(HAVE_TMPFILE)
316 # define tmpfile()  (fopen(tmpnam(NULL), "w+"))
317 #endif
318
319 /* File buffers */
320 #define FILEBUF(f,sc,type) sc int __CAT__(f,_BFLAGS);   \
321                            sc type __CAT__(f,_BUFFER)
322
323 #define RESETBUF(f,type)   (__CAT__(f,_BFLAGS) = 1)
324 #define SETUPBUF(f,type)   (__CAT__(f,_BFLAGS) = 0)
325
326 #define GETFBUF(f,type)    (*((__CAT__(f,_BFLAGS) == 1 &&   \
327                                ((__CAT__(f,_BFLAGS) = 2),   \
328                                 fread(&__CAT__(f,_BUFFER),  \
329                                       sizeof(type),1,(f)))),\
330                               &__CAT__(f,_BUFFER)))
331 #define AGETFBUF(f,type)   ((__CAT__(f,_BFLAGS) == 1 &&   \
332                              ((__CAT__(f,_BFLAGS) = 2),   \
333                               fread(&__CAT__(f,_BUFFER),  \
334                                     sizeof(type),1,(f)))),\
335                             __CAT__(f,_BUFFER))
336
337 #define PUTFBUF(f,type,v)  (GETFBUF(f,type) = (v))
338 #define CPUTFBUF(f,v)      (PUTFBUF(f,char,v))
339 #define APUTFBUF(f,type,v) (memcpy(GETFBUF(f,type), (v),  \
340                                    sizeof(__CAT__(f,_BUFFER))))
341
342 #define GET(f,type)        (__CAT__(f,_BFLAGS) == 1 ?   \
343                             fread(&__CAT__(f,_BUFFER),sizeof(type),1,(f)) :  \
344                             (__CAT__(f,_BFLAGS) = 1))
345
346 #define PUT(f,type)        (fwrite(&__CAT__(f,_BUFFER),sizeof(type),1,(f)),  \
347                             (__CAT__(f,_BFLAGS) = 0))
348 #define CPUT(f)            (PUT(f,char))
349
350 /* Memory allocation */
351 #ifdef __GCC__
352 # define Malloc(n)  (malloc(n) ?: (Anyptr)_OutMem())
353 #else
354 extern Anyptr __MallocTemp__;
355 # define Malloc(n)  ((__MallocTemp__ = malloc(n)) ? __MallocTemp__ : (Anyptr)_OutMem())
356 #endif
357 #define FreeR(p)    (free((Anyptr)(p)))    /* used if arg is an rvalue */
358 #define Free(p)     (free((Anyptr)(p)), (p)=NULL)
359
360 /* sign extension */
361 #define SEXT(x,n)   ((x) | -(((x) & (1L<<((n)-1))) << 1))
362
363 /* packed arrays */   /* BEWARE: these are untested! */
364 #define P_getbits_UB(a,i,n,L)   ((int)((a)[(i)>>(L)-(n)] >>   \
365                                        (((~(i))&((1<<(L)-(n))-1)) << (n)) &  \
366                                        (1<<(1<<(n)))-1))
367
368 #define P_getbits_SB(a,i,n,L)   ((int)((a)[(i)>>(L)-(n)] <<   \
369                                        (16 - ((((~(i))&((1<<(L)-(n))-1))+1) <<\
370                                               (n)) >> (16-(1<<(n))))))
371
372 #define P_putbits_UB(a,i,x,n,L) ((a)[(i)>>(L)-(n)] |=   \
373                                  (x) << (((~(i))&((1<<(L)-(n))-1)) << (n)))
374
375 #define P_putbits_SB(a,i,x,n,L) ((a)[(i)>>(L)-(n)] |=   \
376                                  ((x) & (1<<(1<<(n)))-1) <<   \
377                                  (((~(i))&((1<<(L)-(n))-1)) << (n)))
378
379 #define P_clrbits_B(a,i,n,L)    ((a)[(i)>>(L)-(n)] &=   \
380                                  ~( ((1<<(1<<(n)))-1) <<   \
381                                    (((~(i))&((1<<(L)-(n))-1)) << (n))) )
382
383 /* small packed arrays */
384 #define P_getbits_US(v,i,n)     ((int)((v) >> (~(i) << (n)) & (1<<(1<<(n)))-1))
385 #define P_getbits_SS(v,i,n)     ((int)((long)(v) << (32 - (((~(i))+1) << (n))) >> (32-(1<<(n)))))
386 #define P_putbits_US(v,i,x,n)   ((v) |= (x) << (~(i) << (n)))
387 #define P_putbits_SS(v,i,x,n)   ((v) |= ((x) & (1<<(1<<(n)))-1) << (~(i) << (n)))
388 #define P_clrbits_S(v,i,n)      ((v) &= ~( ((1<<(1<<(n)))-1) << (~(i) << (n)) ))
389
390 #define P_max(a,b)   ((a) > (b) ? (a) : (b))
391 #define P_min(a,b)   ((a) < (b) ? (a) : (b))
392
393
394 /* Fix toupper/tolower on Suns and other stupid BSD systems */
395 #ifdef toupper
396 # undef toupper
397 # undef tolower
398 # define toupper(c)   my_toupper(c)
399 # define tolower(c)   my_tolower(c)
400 #endif
401
402 #ifndef _toupper
403 # if 'A' == 65 && 'a' == 97
404 #  define _toupper(c)  ((c)-'a'+'A')
405 #  define _tolower(c)  ((c)-'A'+'a')
406 # else
407 #  define _toupper(c)  toupper(c)
408 #  define _tolower(c)  tolower(c)
409 # endif
410 #endif
411
412
413 #endif    /* P2C_H */
414
415
416
417 /* End. */
418
419