home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / pascal2c / p2c.h < prev    next >
C/C++ Source or Header  |  1992-08-03  |  14KB  |  512 lines

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