1 /* pascal.h: implement various bits of standard Pascal that we use. */
3 /* Copyright 1992 Karl Berry
4 Copyright 2007 TeX Users Group
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 /* Absolute value. Without the casts to integer here, the Ultrix and
25 AIX compilers (at least) produce bad code (or maybe it's that I don't
26 understand all the casting rules in C) for tests on memory fields.
27 Specifically, a test in diag_round (in Metafont) on a quarterword
28 comes out differently without the cast, thus causing the trap test to
29 fail. (A path at line 86 is constructed slightly differently). */
30 #define abs(x)((integer)(x)>=0?(integer)(x):(integer)-(x))
32 /* above conflicts with math.h ... */
34 /* Other standard predefined routines. */
37 #define odd(x) ((x) % 2)
38 #define round(x) zround ((double) (x))
39 #define trunc(x) ((integer) (x))
42 #define reset(f, n, mode) ((f) ? fclose (f) : 0), \
43 (f) = xfopen_pas ((char *) (n), "r" mode)
44 #define rewrite(f, n, mode) (f) = xfopen_pas ((char *) (n), "w" mode)
45 #define flush(f) (void) fflush (f)
47 /* flush - used only in itex.c and conflicts with io.h -- bkph 93/Nov/26 */
49 /* #define read(f, b) ((b) = getc (f)) */
50 /* #define readln(f) { register c; \
51 while ((c = getc (f)) != '\n' && c != EOF); } */
53 /* We hope this will be efficient than the `x = x - 1' that decr would
54 otherwise be translated to. Likewise for incr. */
58 /* PatGen 2 uses this. */
59 #define input2ints(a, b) zinput2ints (&a, &b)
61 /* We need this routine only if TeX is being debugged. */
62 #define input3ints(a, b, c) zinput3ints (&a, &b, &c)
64 /* Pascal has no address-of operator, and we need pointers to integers
65 to set up the option table. */
66 /* #define addressofint(x) ((int *) &(x)) */ /* not used */
68 /* Not all C libraries have fabs, so we'll roll our own. */
69 #define fabs(x) ((x) >= 0.0 ? (x) : -(x))
71 /* above conflicts with math.h ... */
73 /* The fixwrites program outputs this. */
74 #define Fputs(f, s) (void) fputs (s, f)
76 /* Tangle removes underscores from names, but the `struct option'
77 structure has a field name with an underscore. So we have to put it
78 back. Ditto for the other names. */
79 #define getoptlongonly getopt_long_only
80 #define hasarg has_arg
82 /* Same underscore problem. */
83 #define PATHMAX PATH_MAX
85 /* We need a new type for the argument parsing, too. */
86 typedef struct option getoptstruct;
88 #define printreal(r, n, m) fprintreal (stdout, r, n, m)
89 #define putbyte(x, f) putc ((char) (x) & 255, f)
91 #define toint(x) ((integer) (x))
93 /* For throwing away input from the file F. */
94 #define vgetc(f) (void) getc (f)
96 /* If we don't care that strcpy(3) returns A. Likewise for strcat. */
97 #define vstrcpy(a, b) (void) strcpy (a, b)
98 #define vstrcat(a, b) (void) strcat (a, b)
100 /* Write out elements START through END of BUF to the file F. */
101 /* could use some error checking --- but not used ... bkph */
102 #define writechunk(f, buf, start, end) \
103 (void) fwrite (&buf[start], sizeof (buf[start]), end - start + 1, f)
105 /* Like fseek(3), but cast the arguments and ignore the return value. */
106 #define checkedfseek(f, n, w) (void) fseek(f, (long) n, (int) w)
108 /* For faking arrays. */
109 typedef unsigned char *pointertobyte;
110 #define casttobytepointer(e) ((pointertobyte) e)
112 /* For some initializations of constant strings. */
113 typedef char *ccharpointer;
115 /* `real' is used for noncritical floating-point stuff. */
118 /* C doesn't distinguish between text files and other files. */
119 typedef FILE *text, *file_ptr, *alpha_file;
121 /* `a_open_in' is used both for input files and pool files, so it
122 needs to know what path to use. */
123 #define a_open_in(f, p) open_input (&(f), p, FOPEN_R_MODE)
124 #define a_open_out(f) open_output (&(f), FOPEN_W_MODE)
126 /* Closing files is even easier; we don't bother to check the return
127 status from fclose(3). */
128 /* #define a_close(f) if (f) (void) fclose (f) */
129 /* At least for output, we SHOULD check error status !!! */
130 /* Ideally should check this DURING output from time to time */
131 /* #define a_close(f) if (f) { if (ferror (f)) {perror(""); exit(1);} } if (f) (void) fclose (f) */
132 /* #define a_close(f) if (f) (void) checkfclose (f) */
133 #define a_close(f) checkfclose (f)
136 /* See bibtex.ch for why these are necessary. */
137 extern FILE *standardinput;
138 extern FILE *standardoutput;
141 #endif /* not PASCAL_H */