p2c.h
上传用户:upcnvip
上传日期:2007-01-06
资源大小:474k
文件大小:11k
源码类别:

编译器/解释器

开发平台:

C/C++

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