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