home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / tools / cpx_acc / cpxbasic / sources / p2c.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  11.7 KB  |  472 lines

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