home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / unixtex-6.1b-src.tgz / tar.out / contrib / unixtex / web2c / lib / cpascal.h < prev    next >
C/C++ Source or Header  |  1996-09-28  |  5KB  |  132 lines

  1. /* cpascal.h: implement various bits of standard Pascal that we use.
  2.    This is the top-level include file for all the web2c-generated C
  3.    programs except TeX and Metafont themselves, which use texmf.h.  */
  4.  
  5. #ifndef CPASCAL_H
  6. #define CPASCAL_H
  7.  
  8. /* We must include this first, to resolve many C issues.  */
  9. #include "config.h"
  10.  
  11.  
  12. /* Absolute value.  Without the casts to integer here, the Ultrix and
  13.    AIX compilers (at least) produce bad code (or maybe it's that I don't
  14.    understand all the casting rules in C) for tests on memory fields. 
  15.    Specifically, a test in diag_round (in Metafont) on a quarterword
  16.    comes out differently without the cast, thus causing the trap test to
  17.    fail.  (A path at line 86 is constructed slightly differently).  */
  18. #ifdef abs
  19. /* If the system had an abs #define already, get rid of it.  */
  20. #undef abs
  21. #endif
  22. #define    abs(x) ((integer)(x) >= 0 ? (integer)(x) : (integer)-(x))
  23.  
  24. /* Other standard predefined routines.  */
  25. #define    chr(x)        (x)
  26. #define ord(x)        (x)
  27. #define    odd(x)        ((x) % 2)
  28. #define    round(x)    zround ((double) (x))
  29. #define trunc(x)    ((integer) (x))
  30.  
  31. /* File routines.  These are used for both binary and text files, but
  32.    binary is more common.  If you want it 100% right, fix the change
  33.    files to pass the fopen mode to reset in all cases and send me the
  34.    changes; it doesn't matter for Unix, so I'm not going to spend any
  35.    more time on it.  */
  36. #define    reset(f, n)    ((f) ? fclose (f) : 0), \
  37.              (f) = xfopen_pas ((char *) (n), FOPEN_RBIN_MODE)
  38. #define rewrite(f, n)    (f) = xfopen_pas ((char *) (n), FOPEN_WBIN_MODE)
  39. #define flush(f)    (void) fflush (f)
  40.  
  41. #define read(f, b)    ((b) = getc (f))
  42. #define    readln(f)    { register c; \
  43.                           while ((c = getc (f)) != '\n' && c != EOF); }
  44.  
  45. /* We hope this will be efficient than the `x = x - 1' that decr would
  46.    otherwise be translated to.  Likewise for incr.  */
  47. #define    decr(x)        --(x)
  48. #define    incr(x)        ++(x)
  49.  
  50. /* PatGen 2 uses this.  */
  51. #define    input2ints(a, b)  zinput2ints (&a, &b)
  52.  
  53. /* We need this routine only if TeX is being debugged.  */
  54. #define    input3ints(a, b, c)  zinput3ints (&a, &b, &c)
  55.  
  56. /* Pascal has no address-of operator, and we need pointers to integers
  57.    to set up the option table.  */
  58. #define addressofint(x)    (&(x))
  59.  
  60. /* Not all C libraries have fabs, so we'll roll our own.  */
  61. #ifdef fabs
  62. #undef fabs
  63. #endif
  64. #define    fabs(x)        ((x) >= 0.0 ? (x) : -(x))
  65.  
  66. /* The fixwrites program outputs this.  */
  67. #define    Fputs(f, s)    (void) fputs (s, f)
  68.  
  69. /* Tangle removes underscores from names, but the `struct option'
  70.    structure has a field name with an underscore.  So we have to put it
  71.    back.  Ditto for the other names.  */
  72. #define getoptlongonly    getopt_long_only
  73. #define hasarg        has_arg
  74.  
  75. /* Same underscore problem.  */
  76. #define PATHMAX        PATH_MAX
  77.  
  78. /* We need a new type for the argument parsing, too.  */
  79. typedef struct option getoptstruct;
  80.  
  81. #define printreal(r, n, m)  fprintreal (stdout, r, n, m)
  82. #define    putbyte(x, f)    putc ((char) (x) & 255, f)
  83.  
  84. #define    toint(x)    ((integer) (x))
  85.  
  86. /* For throwing away input from the file F.  */
  87. #define vgetc(f)    (void) getc (f)
  88.  
  89. /* If we don't care that strcpy(3) returns A.  Likewise for strcat.  */
  90. #define vstrcpy(a, b)    (void) strcpy (a, b)
  91. #define vstrcat(a, b)    (void) strcat (a, b)
  92.  
  93. /* Write out elements START through END of BUF to the file F.  */
  94. #define writechunk(f, buf, start, end) \
  95.   (void) fwrite (&buf[start], sizeof (buf[start]), end - start + 1, f)
  96.  
  97. /* Like fseek(3), but cast the arguments and ignore the return value.  */
  98. #define checkedfseek(f, n, w)  (void) fseek(f, (long) n, (int) w)
  99.  
  100. /* For faking arrays.  */
  101. typedef unsigned char *pointertobyte;
  102. #define casttobytepointer(e) ((pointertobyte) e)
  103.  
  104. /* For some initializations of constant strings.  */
  105. typedef char *ccharpointer;
  106.  
  107. /* For interacting with getopt, etc.  */
  108. #define cinttype int
  109.  
  110. /* `real' is used for noncritical floating-point stuff.  */
  111. typedef double real;
  112.  
  113. /* C doesn't distinguish between text files and other files.  */
  114. typedef FILE *text, *file_ptr, *alphafile;
  115.  
  116. /* `aopenin' is used both for input files and pool files, so it
  117.    needs to know what path to use.  */
  118. #define aopenin(f, p)    open_input (&(f), p, FOPEN_R_MODE)
  119. #define aopenout(f)    open_output (&(f), FOPEN_W_MODE)
  120.  
  121. /* Closing files is even easier; we don't bother to check the return
  122.    status from fclose(3).  */
  123. #define aclose(f)    if (f) (void) fclose (f)
  124.  
  125. #ifdef BibTeX
  126. /* See bibtex.ch for why these are necessary.  */
  127. extern FILE *standardinput;
  128. extern FILE *standardoutput;
  129. #endif
  130.  
  131. #endif /* not CPASCAL_H */
  132.