home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d524 / kamin.lha / Kamin / src.lzh / p2c / p2c.h next >
C/C++ Source or Header  |  1991-06-28  |  9KB  |  318 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 Dave Gillespie.
  8.  * This file may be copied, modified, etc. in any way.  It is not restricted
  9.  * by the licence agreement accompanying p2c itself.
  10.  */
  11.  
  12.  
  13. #include <stdio.h>
  14.  
  15.  
  16. #ifdef __STDC__
  17. # include <stddef.h>
  18. # include <stdlib.h>
  19. # define HAS_STDLIB
  20. # define __CAT__(a,b)a##b
  21. #else
  22. # ifndef BSD
  23. #  include <memory.h>
  24. # endif
  25. # include <sys/types.h>
  26. # define __ID__(a)a
  27. # define __CAT__(a,b)__ID__(a)b
  28. #endif
  29.  
  30.  
  31. #ifdef BSD
  32. # include <strings.h>
  33. # define memcpy(a,b,n) (bcopy(b,a,n),a)
  34. # define memcmp(a,b,n) bcmp(a,b,n)
  35. # define strchr(s,c) index(s,c)
  36. # define strrchr(s,c) rindex(s,c)
  37. #else
  38. # include <string.h>
  39. #endif
  40.  
  41. #include <ctype.h>
  42. #include <math.h>
  43. #include <setjmp.h>
  44.  
  45.  
  46. typedef struct __p2c_jmp_buf {
  47.     struct __p2c_jmp_buf *next;
  48.     jmp_buf jbuf;
  49. } __p2c_jmp_buf;
  50.  
  51.  
  52. /* Warning: The following will not work if setjmp is used simultaneously.
  53.    This also violates the ANSI restriction about using vars after longjmp,
  54.    but a typical implementation of longjmp will get it right anyway. */
  55.  
  56. #ifndef FAKE_TRY
  57. # define TRY(x)         do { __p2c_jmp_buf __try_jb;  \
  58.                  __try_jb.next = __top_jb;  \
  59.                  if (!setjmp((__top_jb = &__try_jb)->jbuf)) {
  60. # define RECOVER(x)    __top_jb = __try_jb.next; } else {
  61. # define RECOVER2(x,L)  __top_jb = __try_jb.next; } else {  \
  62.                  if (0) { L: __top_jb = __try_jb.next; }
  63. # define ENDTRY(x)      } } while (0) 
  64. #else
  65. # define TRY(x)         if (1) {
  66. # define RECOVER(x)     } else do {
  67. # define RECOVER2(x,L)  } else do { L:
  68. # define ENDTRY(x)      } while (0)
  69. #endif
  70.  
  71.  
  72.  
  73. /* The following definitions work only on twos-complement machines */
  74. #ifndef SHORT_MAX
  75. # define SHORT_MAX  (((unsigned short) -1) >> 1)
  76. # define SHORT_MIN  (~SHORT_MAX)
  77. #endif
  78.  
  79. #ifndef INT_MAX
  80. # define INT_MAX    (((unsigned int) -1) >> 1)
  81. # define INT_MIN    (~INT_MAX)
  82. #endif
  83.  
  84. #ifndef LONG_MAX
  85. # define LONG_MAX   (((unsigned long) -1) >> 1)
  86. # define LONG_MIN   (~LONG_MAX)
  87. #endif
  88.  
  89. #ifndef SEEK_SET
  90. # define SEEK_SET   0
  91. # define SEEK_CUR   1
  92. # define SEEK_END   2
  93. #endif
  94.  
  95. #ifndef EXIT_SUCCESS
  96. # define EXIT_SUCCESS  0
  97. # define EXIT_FAILURE  1
  98. #endif
  99.  
  100.  
  101. #define SETBITS  32
  102.  
  103.  
  104. #ifdef __STDC__
  105. # define Signed     signed
  106. # define Const      const
  107. # define Volatile   volatile
  108. # define Void       void      /* Void f() = procedure */
  109. # define PP(x)      x         /* function prototype */
  110. # define PV()       (void)    /* null function prototype */
  111. typedef void *Anyptr;
  112. #else
  113. # define Signed
  114. # define Const
  115. # define Volatile
  116. # define Void       void
  117. # define PP(x)      ()
  118. # define PV()       ()
  119. typedef char *Anyptr;
  120. #endif
  121.  
  122. #ifdef __GNUC__
  123. # define Inline     inline
  124. #else
  125. # define Inline
  126. #endif
  127.  
  128. #define Register    register  /* Register variables */
  129. #define Static      static    /* Private global funcs and vars */
  130. #define Local       static    /* Nested functions */
  131. #define Char        char      /* Characters (not bytes) */
  132.  
  133.  
  134. typedef Signed   char schar;
  135. typedef unsigned char uchar;
  136. typedef unsigned char boolean;
  137.  
  138. #ifndef true
  139. # define true    1
  140. # define false   0
  141. #endif
  142.  
  143.  
  144. typedef struct {
  145.     Anyptr proc, link;
  146. } _PROCEDURE;
  147.  
  148. #define _FNSIZE  120
  149.  
  150.  
  151. extern Void    PASCAL_MAIN  PP( (int, Char **) );
  152. extern Char    **P_argv;
  153. extern int     P_argc;
  154. extern short   P_escapecode;
  155. extern int     P_ioresult;
  156. extern __p2c_jmp_buf *__top_jb;
  157.  
  158.  
  159. #if 0   /* use this if you have Ansi C but non-prototyped header files */
  160. extern Char    *strcat      PP( (Char *, Const Char *) );
  161. extern Char    *strchr      PP( (Const Char *, int) );
  162. extern int      strcmp      PP( (Const Char *, Const Char *) );
  163. extern Char    *strcpy      PP( (Char *, Const Char *) );
  164. extern size_t   strlen      PP( (Const Char *) );
  165. extern Char    *strncat     PP( (Char *, Const Char *, size_t) );
  166. extern int      strncmp     PP( (Const Char *, Const Char *, size_t) );
  167. extern Char    *strncpy     PP( (Char *, Const Char *, size_t) );
  168. extern Char    *strrchr     PP( (Const Char *, int) );
  169.  
  170. extern Anyptr   memchr      PP( (Const Anyptr, int, size_t) );
  171. extern Anyptr   memmove     PP( (Anyptr, Const Anyptr, size_t) );
  172. extern Anyptr   memset      PP( (Anyptr, int, size_t) );
  173. #ifndef memcpy
  174. extern Anyptr   memcpy      PP( (Anyptr, Const Anyptr, size_t) );
  175. extern int      memcmp      PP( (Const Anyptr, Const Anyptr, size_t) );
  176. #endif
  177.  
  178. extern int      atoi        PP( (Const Char *) );
  179. extern double   atof        PP( (Const Char *) );
  180. extern long     atol        PP( (Const Char *) );
  181. extern double   strtod      PP( (Const Char *, Char **) );
  182. extern long     strtol      PP( (Const Char *, Char **, int) );
  183. #endif
  184.  
  185. #ifndef HAS_STDLIB
  186. extern Anyptr   malloc      PP( (size_t) );
  187. extern Void     free        PP( (Anyptr) );
  188. #endif
  189.  
  190. extern int      _OutMem     PV();
  191. extern int      _CaseCheck  PV();
  192. extern int      _NilCheck   PV();
  193. extern int    _Escape     PP( (int) );
  194. extern int    _EscIO      PP( (int) );
  195.  
  196. extern long     ipow        PP( (long, long) );
  197. extern Char    *strsub      PP( (Char *, Char *, int, int) );
  198. extern Char    *strltrim    PP( (Char *) );
  199. extern Char    *strrtrim    PP( (Char *) );
  200. extern Char    *strrpt      PP( (Char *, Char *, int) );
  201. extern Char    *strpad      PP( (Char *, Char *, int, int) );
  202. extern int      strpos2     PP( (Char *, Char *, int) );
  203. extern long     memavail    PV();
  204. extern int      P_peek      PP( (FILE *) );
  205. extern int      P_eof       PP( (FILE *) );
  206. extern int      P_eoln      PP( (FILE *) );
  207. extern long     P_maxpos    PP( (FILE *) );
  208. extern long    *P_setunion  PP( (long *, long *, long *) );
  209. extern long    *P_setint    PP( (long *, long *, long *) );
  210. extern long    *P_setdiff   PP( (long *, long *, long *) );
  211. extern long    *P_setxor    PP( (long *, long *, long *) );
  212. extern int      P_inset     PP( (unsigned, long *) );
  213. extern int      P_setequal  PP( (long *, long *) );
  214. extern int      P_subset    PP( (long *, long *) );
  215. extern long    *P_addset    PP( (long *, unsigned) );
  216. extern long    *P_addsetr   PP( (long *, unsigned, unsigned) );
  217. extern long    *P_remset    PP( (long *, unsigned) );
  218. extern long    *P_setcpy    PP( (long *, long *) );
  219. extern long    *P_expset    PP( (long *, long) );
  220. extern long     P_packset   PP( (long *) );
  221.  
  222.  
  223. /* I/O error handling */
  224. #define _CHKIO(cond,ior,val,def)  ((cond) ? P_ioresult=0,(val)  \
  225.                       : P_ioresult=(ior),(def))
  226. #define _SETIO(cond,ior)          (P_ioresult = (cond) ? 0 : (ior))
  227.  
  228. /* Following defines are suitable for the HP Pascal operating system */
  229. #define FileNotFound     10
  230. #define FileNotOpen      13
  231. #define FileWriteError   38
  232. #define BadInputFormat   14
  233. #define EndOfFile        30
  234.  
  235. /* File buffers */
  236. #define FILEBUF(f,sc,type) sc int __CAT__(f,_BFLAGS);   \
  237.                sc type __CAT__(f,_BUFFER);
  238.  
  239. #define RESETBUF(f,type)   (__CAT__(f,_BFLAGS) = 1)
  240. #define SETUPBUF(f,type)   (__CAT__(f,_BFLAGS) = 0)
  241.  
  242. #define GETFBUF(f,type)    (*((__CAT__(f,_BFLAGS) == 1 &&   \
  243.                    ((__CAT__(f,_BFLAGS) = 2),   \
  244.                 fread(&__CAT__(f,_BUFFER),  \
  245.                       sizeof(type),1,(f)))),\
  246.                   &__CAT__(f,_BUFFER)))
  247.  
  248. #define PUTFBUF(f,type,v)  (GETFBUF(f,type) = (v))
  249.  
  250. #define GET(f,type)        (__CAT__(f,_BFLAGS) == 1 ?   \
  251.                 fread(&__CAT__(f,_BUFFER),sizeof(type),1,(f)) :  \
  252.                 (__CAT__(f,_BFLAGS) = 1))
  253.  
  254. #define PUT(f,type)        (fwrite(&__CAT__(f,_BUFFER),sizeof(type),1,(f)),  \
  255.                 (__CAT__(f,_BFLAGS) = 0))
  256.  
  257.  
  258. /* Memory allocation */
  259. #ifdef __GCC__
  260. # define Malloc(n)  (malloc(n) ?: (Anyptr)_OutMem())
  261. #else
  262. extern Anyptr __MallocTemp__;
  263. # define Malloc(n)  ((__MallocTemp__ = malloc(n)) ? __MallocTemp__ : (Anyptr)_OutMem())
  264. #endif
  265. #define Free(p)     (free((Anyptr)(p)), (p)=NULL)
  266.  
  267. /* sign extension */
  268. #define SEXT(x,n)   ((x) | -(((x) & (1L<<((n)-1))) << 1))
  269.  
  270. /* packed arrays */   /* BEWARE: these are untested! */
  271. #define P_getbits_UB(a,i,n,L)   ((int)((a)[(i)>>(L)-(n)] >>   \
  272.                        (((~(i))&((1<<(L)-(n))-1)) << (n)) &  \
  273.                        (1<<(1<<(n)))-1))
  274.  
  275. #define P_getbits_SB(a,i,n,L)   ((int)((a)[(i)>>(L)-(n)] <<   \
  276.                        (16 - ((((~(i))&((1<<(L)-(n))-1))+1) <<\
  277.                           (n)) >> (16-(1<<(n))))))
  278.  
  279. #define P_putbits_UB(a,i,x,n,L) ((a)[(i)>>(L)-(n)] |=   \
  280.                  (x) << (((~(i))&((1<<(L)-(n))-1)) << (n)))
  281.  
  282. #define P_putbits_SB(a,i,x,n,L) ((a)[(i)>>(L)-(n)] |=   \
  283.                  ((x) & (1<<(1<<(n)))-1) <<   \
  284.                  (((~(i))&((1<<(L)-(n))-1)) << (n)))
  285.  
  286. #define P_clrbits_B(a,i,n,L)    ((a)[(i)>>(L)-(n)] &=   \
  287.                  ~( (1<<(1<<(n)))-1 <<   \
  288.                    (((~(i))&((1<<(L)-(n))-1)) << (n))) )
  289.  
  290. /* small packed arrays */
  291. #define P_getbits_US(v,i,n)     ((int)((v) >> (~(i) << (n)) & (1<<(1<<(n)))-1))
  292. #define P_getbits_SS(v,i,n)     ((int)((long)(v) << (32 - (((~(i))+1) << (n))) >> (32-(1<<(n)))))
  293. #define P_putbits_US(v,i,x,n)   ((v) |= (x) << (~(i) << (n)))
  294. #define P_putbits_SS(v,i,x,n)   ((v) |= ((x) & (1<<(1<<(n)))-1) << (~(i) << (n)))
  295. #define P_clrbits_S(v,i,n)      ((v) &= ~( (1<<(1<<(n)))-1 << (~(i) << (n)) ))
  296.  
  297.  
  298.  
  299. /* Fix toupper/tolower on Suns and other stupid BSD systems */
  300. #ifdef toupper
  301. # undef toupper
  302. # undef tolower
  303. # define toupper(c)   my_toupper(c)
  304. # define tolower(c)   my_tolower(c)
  305. # define _toupper(c)  ((c)-'a'+'A')
  306. # define _tolower(c)  ((c)-'A'+'a')
  307. #endif
  308.  
  309.  
  310.  
  311. #endif    /* P2C_H */
  312.  
  313.  
  314.  
  315. /* End. */
  316.  
  317.  
  318.