source: tags/initial/GDE/PHYLIP/p2c.h

Last change on this file was 2, checked in by oldcode, 24 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.2 KB
Line 
1#ifndef P2C_H
2#define P2C_H
3
4
5/* Header file for code generated by "p2c", the Pascal-to-C translator */
6
7/* "p2c"  Copyright (C) 1989, 1990, 1991 Free Software Foundation.
8 * By Dave Gillespie, daveg@csvax.cs.caltech.edu.  Version 1.20.
9 * This file may be copied, modified, etc. in any way.  It is not restricted
10 * by the licence agreement accompanying p2c itself.
11 */
12
13
14#include <stdio.h>
15
16
17
18/* If the following heuristic fails, compile -DBSD=0 for non-BSD systems,
19   or -DBSD=1 for BSD systems. */
20
21#ifdef M_XENIX
22# define BSD 0
23#endif
24
25#ifdef vms
26# define BSD 0
27# ifndef __STDC__
28#  define __STDC__ 1
29# endif
30#endif
31
32#ifdef __TURBOC__
33# define MSDOS 1
34#endif
35
36#ifdef MSDOS
37# define BSD 0
38#endif
39
40#ifdef FILE       /* a #define in BSD, a typedef in SYSV (hp-ux, at least) */
41# ifndef BSD      /*  (a convenient, but horrible kludge!) */
42#  define BSD 1
43# endif
44#endif
45
46#ifdef BSD
47# if !BSD
48#  undef BSD
49# endif
50#endif
51
52
53#if (defined(__STDC__) && !defined(M_XENIX)) || defined(__TURBOC__)
54# include <stddef.h>
55# include <stdlib.h>
56# define HAS_STDLIB
57# if defined(vms) || defined(__TURBOC__)
58#  define __ID__(a)a
59# endif
60#else
61# ifndef BSD
62#  ifndef __TURBOC__
63#   include <memory.h>
64#  endif
65# endif
66# ifdef hpux
67#  define HAS_STDLIB
68#  ifdef _INCLUDE__STDC__
69#   include <stddef.h>
70#   include <stdlib.h>
71#  endif
72# endif
73# include <sys/types.h>
74# if !defined(MSDOS) || defined(__TURBOC__)
75#  define __ID__(a)a
76# endif
77#endif
78
79#ifdef __ID__
80# define __CAT__(a,b)__ID__(a)b
81#else
82# define __CAT__(a,b)a##b
83#endif
84
85
86#ifdef BSD
87# include <strings.h>
88# define memcpy(a,b,n) (bcopy(b,a,n),a)
89# define memcmp(a,b,n) bcmp(a,b,n)
90# define strchr(s,c) index(s,c)
91# define strrchr(s,c) rindex(s,c)
92#else
93# include <string.h>
94#endif
95
96#include <ctype.h>
97#include <math.h>
98#include <setjmp.h>
99#include <assert.h>
100
101
102#ifndef NO_LACK
103#ifdef vms
104
105#define LACK_LABS
106#define LACK_MEMMOVE
107#define LACK_MEMCPY
108
109#else
110
111#define LACK_LABS       /* Undefine these if your library has these */
112#define LACK_MEMMOVE
113
114#endif
115#endif
116
117
118typedef struct __p2c_jmp_buf {
119    struct __p2c_jmp_buf *next;
120    jmp_buf jbuf;
121} __p2c_jmp_buf;
122
123
124/* Warning: The following will not work if setjmp is used simultaneously.
125   This also violates the ANSI restriction about using vars after longjmp,
126   but a typical implementation of longjmp will get it right anyway. */
127
128#ifndef FAKE_TRY
129# define TRY(x)         do { __p2c_jmp_buf __try_jb;  \
130                             __try_jb.next = __top_jb;  \
131                             if (!setjmp((__top_jb = &__try_jb)->jbuf)) {
132# define RECOVER(x)     __top_jb = __try_jb.next; } else {
133# define RECOVER2(x,L)  __top_jb = __try_jb.next; } else {  \
134                             if (0) { L: __top_jb = __try_jb.next; }
135# define ENDTRY(x)      } } while (0)
136#else
137# define TRY(x)         if (1) {
138# define RECOVER(x)     } else do {
139# define RECOVER2(x,L)  } else do { L: ;
140# define ENDTRY(x)      } while (0)
141#endif
142
143
144
145#ifdef M_XENIX  /* avoid compiler bug */
146# define SHORT_MAX  (32767)
147# define SHORT_MIN  (-32768)
148#endif
149
150
151/* The following definitions work only on twos-complement machines */
152#ifndef SHORT_MAX
153# define SHORT_MAX  ((short)(((unsigned short) -1) >> 1))
154# define SHORT_MIN  (~SHORT_MAX)
155#endif
156
157#ifndef INT_MAX
158# define INT_MAX    ((int)(((unsigned int) -1) >> 1))
159# define INT_MIN    (~INT_MAX)
160#endif
161
162#ifndef LONG_MAX
163# define LONG_MAX   ((long)(((unsigned long) -1) >> 1))
164# define LONG_MIN   (~LONG_MAX)
165#endif
166
167#ifndef SEEK_SET
168# define SEEK_SET   0
169# define SEEK_CUR   1
170# define SEEK_END   2
171#endif
172
173#ifndef EXIT_SUCCESS
174# ifdef vms
175#  define EXIT_SUCCESS  1
176#  define EXIT_FAILURE  (02000000000L)
177# else
178#  define EXIT_SUCCESS  0
179#  define EXIT_FAILURE  1
180# endif
181#endif
182
183
184#define SETBITS  32
185
186
187#if defined(__STDC__) || defined(__TURBOC__)
188# if !defined(vms) && !defined(M_LINT)
189#  define Signed    signed
190# else
191#  define Signed
192# endif
193# define Void       void      /* Void f() = procedure */
194# ifndef Const
195#  define Const     const
196# endif
197# ifndef Volatile
198# define Volatile   volatile
199# endif
200# ifdef M_LINT
201#  define PP(x)     ()
202#  define PV()      ()
203typedef char *Anyptr;
204# else
205#  define PP(x)     x         /* function prototype */
206#  define PV()      (void)    /* null function prototype */
207typedef void *Anyptr;
208# endif
209#else
210# define Signed
211# define Void       void
212# ifndef Const
213#  define Const
214# endif
215# ifndef Volatile
216#  define Volatile
217# endif
218# define PP(x)      ()
219# define PV()       ()
220typedef char *Anyptr;
221#endif
222
223#ifdef __GNUC__
224# define Inline     inline
225#else
226# define Inline
227#endif
228
229#define Register    register  /* Register variables */
230#define Char        char      /* Characters (not bytes) */
231
232#ifndef Static
233# define Static     static    /* Private global funcs and vars */
234#endif
235
236#ifndef Local
237# define Local      static    /* Nested functions */
238#endif
239
240typedef Signed   char schar;
241typedef unsigned char uchar;
242typedef unsigned char boolean;
243
244#ifndef true
245# define true    1
246# define false   0
247#endif
248
249#ifndef TRUE
250# define TRUE    1
251# define FALSE   0
252#endif
253
254
255typedef struct {
256    Anyptr proc, link;
257} _PROCEDURE;
258
259#ifndef _FNSIZE
260# define _FNSIZE  120
261#endif
262
263
264extern Void    PASCAL_MAIN  PP( (int, Char **) );
265extern Char    **P_argv;
266extern int     P_argc;
267extern short   P_escapecode;
268extern int     P_ioresult;
269extern __p2c_jmp_buf *__top_jb;
270
271
272#ifdef P2C_H_PROTO   /* if you have Ansi C but non-prototyped header files */
273extern Char    *strcat      PP( (Char *, Const Char *) );
274extern Char    *strchr      PP( (Const Char *, int) );
275extern int      strcmp      PP( (Const Char *, Const Char *) );
276extern Char    *strcpy      PP( (Char *, Const Char *) );
277extern size_t   strlen      PP( (Const Char *) );
278extern Char    *strncat     PP( (Char *, Const Char *, size_t) );
279extern int      strncmp     PP( (Const Char *, Const Char *, size_t) );
280extern Char    *strncpy     PP( (Char *, Const Char *, size_t) );
281extern Char    *strrchr     PP( (Const Char *, int) );
282
283extern Anyptr   memchr      PP( (Const Anyptr, int, size_t) );
284extern Anyptr   memmove     PP( (Anyptr, Const Anyptr, size_t) );
285extern Anyptr   memset      PP( (Anyptr, int, size_t) );
286#ifndef memcpy
287extern Anyptr   memcpy      PP( (Anyptr, Const Anyptr, size_t) );
288extern int      memcmp      PP( (Const Anyptr, Const Anyptr, size_t) );
289#endif
290
291extern int      atoi        PP( (Const Char *) );
292extern double   atof        PP( (Const Char *) );
293extern long     atol        PP( (Const Char *) );
294extern double   strtod      PP( (Const Char *, Char **) );
295extern long     strtol      PP( (Const Char *, Char **, int) );
296#endif /*P2C_H_PROTO*/
297
298#ifndef HAS_STDLIB
299extern Anyptr   malloc      PP( (size_t) );
300extern Void     free        PP( (Anyptr) );
301#endif
302
303extern int      _OutMem     PV();
304extern int      _CaseCheck  PV();
305extern int      _NilCheck   PV();
306extern int      _Escape     PP( (int) );
307extern int      _EscIO      PP( (int) );
308
309extern long     ipow        PP( (long, long) );
310extern Char    *strsub      PP( (Char *, Char *, int, int) );
311extern Char    *strltrim    PP( (Char *) );
312extern Char    *strrtrim    PP( (Char *) );
313extern Char    *strrpt      PP( (Char *, Char *, int) );
314extern Char    *strpad      PP( (Char *, Char *, int, int) );
315extern int      strpos2     PP( (Char *, Char *, int) );
316extern long     memavail    PV();
317extern int      P_peek      PP( (FILE *) );
318extern int      P_eof       PP( (FILE *) );
319extern int      P_eoln      PP( (FILE *) );
320extern Void     P_readpaoc  PP( (FILE *, Char *, int) );
321extern Void     P_readlnpaoc PP( (FILE *, Char *, int) );
322extern long     P_maxpos    PP( (FILE *) );
323extern Char    *P_trimname  PP( (Char *, int) );
324extern long    *P_setunion  PP( (long *, long *, long *) );
325extern long    *P_setint    PP( (long *, long *, long *) );
326extern long    *P_setdiff   PP( (long *, long *, long *) );
327extern long    *P_setxor    PP( (long *, long *, long *) );
328extern int      P_inset     PP( (unsigned, long *) );
329extern int      P_setequal  PP( (long *, long *) );
330extern int      P_subset    PP( (long *, long *) );
331extern long    *P_addset    PP( (long *, unsigned) );
332extern long    *P_addsetr   PP( (long *, unsigned, unsigned) );
333extern long    *P_remset    PP( (long *, unsigned) );
334extern long    *P_setcpy    PP( (long *, long *) );
335extern long    *P_expset    PP( (long *, long) );
336extern long     P_packset   PP( (long *) );
337extern int      P_getcmdline PP( (int, int, Char *) );
338extern Void     TimeStamp   PP( (int *, int *, int *,
339                                 int *, int *, int *) );
340extern Void     P_sun_argv  PP( (char *, int, int) );
341
342
343/* I/O error handling */
344#define _CHKIO(cond,ior,val,def)  ((cond) ? P_ioresult=0,(val)  \
345                                          : P_ioresult=(ior),(def))
346#define _SETIO(cond,ior)          (P_ioresult = (cond) ? 0 : (ior))
347
348/* Following defines are suitable for the HP Pascal operating system */
349#define FileNotFound     10
350#define FileNotOpen      13
351#define FileWriteError   38
352#define BadInputFormat   14
353#define EndOfFile        30
354
355#define FILENOTFOUND     10
356#define FILENOTOPEN      13
357#define FILEWRITEERROR   38
358#define BADINPUTFORMAT   14
359#define ENDOFFILE        30
360
361/* Creating temporary files */
362#if (defined(BSD) || defined(NO_TMPFILE)) && !defined(HAVE_TMPFILE)
363# define tmpfile()  (fopen(tmpnam(NULL), "w+"))
364#endif
365
366/* File buffers */
367#define FILEBUF(f,sc,type) sc int __CAT__(f,_BFLAGS);   \
368                           sc type __CAT__(f,_BUFFER)
369#define FILEBUFNC(f,type)  int __CAT__(f,_BFLAGS);   \
370                           type __CAT__(f,_BUFFER)
371
372#define RESETBUF(f,type)   (__CAT__(f,_BFLAGS) = 1)
373#define SETUPBUF(f,type)   (__CAT__(f,_BFLAGS) = 0)
374
375#define GETFBUF(f,type)    (*((__CAT__(f,_BFLAGS) == 1 &&   \
376                               ((__CAT__(f,_BFLAGS) = 2),   \
377                                fread(&__CAT__(f,_BUFFER),  \
378                                      sizeof(type),1,(f)))),\
379                              &__CAT__(f,_BUFFER)))
380#define AGETFBUF(f,type)   ((__CAT__(f,_BFLAGS) == 1 &&   \
381                             ((__CAT__(f,_BFLAGS) = 2),   \
382                              fread(__CAT__(f,_BUFFER),  \
383                                    sizeof(type),1,(f)))),\
384                            __CAT__(f,_BUFFER))
385
386#define PUTFBUF(f,type,v)  (GETFBUF(f,type) = (v))
387#define CPUTFBUF(f,v)      (PUTFBUF(f,char,v))
388#define APUTFBUF(f,type,v) (memcpy(AGETFBUF(f,type), (v),  \
389                                   sizeof(__CAT__(f,_BUFFER))))
390
391#define GET(f,type)        (__CAT__(f,_BFLAGS) == 1 ?   \
392                            fread(&__CAT__(f,_BUFFER),sizeof(type),1,(f)) :  \
393                            (__CAT__(f,_BFLAGS) = 1))
394
395#define PUT(f,type)        (fwrite(&__CAT__(f,_BUFFER),sizeof(type),1,(f)),  \
396                            (__CAT__(f,_BFLAGS) = 0))
397#define CPUT(f)            (PUT(f,char))
398
399#define BUFEOF(f)          (__CAT__(f,_BFLAGS) != 2 && P_eof(f))
400#define BUFFPOS(f)         (ftell(f) - (__CAT__(f,_BFLAGS) == 2))
401
402typedef struct {
403    FILE *f;
404    FILEBUFNC(f,Char);
405    Char name[_FNSIZE];
406} _TEXT;
407
408/* Memory allocation */
409#ifdef __GCC__
410# define Malloc(n)  (malloc(n) ?: (Anyptr)_OutMem())
411#else
412extern Anyptr __MallocTemp__;
413# define Malloc(n)  ((__MallocTemp__ = malloc(n)) ? __MallocTemp__ : (Anyptr)_OutMem())
414#endif
415#define FreeR(p)    (free((Anyptr)(p)))    /* used if arg is an rvalue */
416#define Free(p)     (free((Anyptr)(p)), (p)=NULL)
417
418/* sign extension */
419#define SEXT(x,n)   ((x) | -(((x) & (1L<<((n)-1))) << 1))
420
421/* packed arrays */   /* BEWARE: these are untested! */
422#define P_getbits_UB(a,i,n,L)   ((int)((a)[(i)>>(L)-(n)] >>   \
423                                       (((~(i))&((1<<(L)-(n))-1)) << (n)) &  \
424                                       (1<<(1<<(n)))-1))
425
426#define P_getbits_SB(a,i,n,L)   ((int)((a)[(i)>>(L)-(n)] <<   \
427                                       (16 - ((((~(i))&((1<<(L)-(n))-1))+1) <<\
428                                              (n)) >> (16-(1<<(n))))))
429
430#define P_putbits_UB(a,i,x,n,L) ((a)[(i)>>(L)-(n)] |=   \
431                                 (x) << (((~(i))&((1<<(L)-(n))-1)) << (n)))
432
433#define P_putbits_SB(a,i,x,n,L) ((a)[(i)>>(L)-(n)] |=   \
434                                 ((x) & (1<<(1<<(n)))-1) <<   \
435                                 (((~(i))&((1<<(L)-(n))-1)) << (n)))
436
437#define P_clrbits_B(a,i,n,L)    ((a)[(i)>>(L)-(n)] &=   \
438                                 ~( ((1<<(1<<(n)))-1) <<   \
439                                   (((~(i))&((1<<(L)-(n))-1)) << (n))) )
440
441/* small packed arrays */
442#define P_getbits_US(v,i,n)     ((int)((v) >> ((i)<<(n)) & (1<<(1<<(n)))-1))
443#define P_getbits_SS(v,i,n)     ((int)((long)(v) << (SETBITS - (((i)+1) << (n))) >> (SETBITS-(1<<(n)))))
444#define P_putbits_US(v,i,x,n)   ((v) |= (x) << ((i) << (n)))
445#define P_putbits_SS(v,i,x,n)   ((v) |= ((x) & (1<<(1<<(n)))-1) << ((i)<<(n)))
446#define P_clrbits_S(v,i,n)      ((v) &= ~( ((1<<(1<<(n)))-1) << ((i)<<(n)) ))
447
448#define P_max(a,b)   ((a) > (b) ? (a) : (b))
449#define P_min(a,b)   ((a) < (b) ? (a) : (b))
450
451
452/* Fix ANSI-isms */
453
454#ifdef LACK_LABS
455# ifndef labs
456#  define labs  my_labs
457   extern long my_labs PP( (long) );
458# endif
459#endif
460
461#ifdef LACK_MEMMOVE
462# ifndef memmove
463#  define memmove  my_memmove
464   extern Anyptr my_memmove PP( (Anyptr, Const Anyptr, size_t) );
465# endif
466#endif
467
468#ifdef LACK_MEMCPY
469# ifndef memcpy
470#  define memcpy  my_memcpy
471   extern Anyptr my_memcpy PP( (Anyptr, Const Anyptr, size_t) );
472# endif
473# ifndef memcmp
474#  define memcmp  my_memcmp
475   extern int my_memcmp PP( (Const Anyptr, Const Anyptr, size_t) );
476# endif
477# ifndef memset
478#  define memset  my_memset
479   extern Anyptr my_memset PP( (Anyptr, int, size_t) );
480# endif
481#endif
482
483/* Fix toupper/tolower on Suns and other stupid BSD systems */
484#ifdef toupper
485# undef toupper
486# undef tolower
487# define toupper(c)   my_toupper(c)
488# define tolower(c)   my_tolower(c)
489#endif
490
491#ifndef _toupper
492# if 'A' == 65 && 'a' == 97
493#  define _toupper(c)  ((c)-'a'+'A')
494#  define _tolower(c)  ((c)-'A'+'a')
495# else
496#  ifdef toupper
497#   undef toupper   /* hope these are shadowing real functions, */
498#   undef tolower   /* because my_toupper calls _toupper! */
499#  endif
500#  define _toupper(c)  toupper(c)
501#  define _tolower(c)  tolower(c)
502# endif
503#endif
504
505
506#endif    /* P2C_H */
507
508
509
510/* End. */
511
512
Note: See TracBrowser for help on using the repository browser.