| 1 |
/* cpascal.h: implement various bits of standard and other Pascal that |
| 2 |
we use in the change files. Public domain. |
| 3 |
|
| 4 |
This is the top-level include file for all the web2c-generated C |
| 5 |
programs except TeX and Metafont themselves, which use texmf.h. |
| 6 |
It's not included by the web2c programs themselves. */ |
| 7 |
|
| 8 |
#ifndef CPASCAL_H |
| 9 |
#define CPASCAL_H |
| 10 |
|
| 11 |
#ifdef WIN32 |
| 12 |
#pragma warning( disable : 4018 4244 ) |
| 13 |
#endif |
| 14 |
|
| 15 |
/* We must include this first, to resolve many C issues. */ |
| 16 |
#include <w2c/config.h> |
| 17 |
|
| 18 |
/* We only use getopt in the applications, not in web2c itself. */ |
| 19 |
#include <kpathsea/getopt.h> |
| 20 |
|
| 21 |
/* Almost everybody needs path searching. May as well always include |
| 22 |
them and simplify the change files. */ |
| 23 |
#include <kpathsea/progname.h> |
| 24 |
#include <kpathsea/proginit.h> |
| 25 |
#include <kpathsea/tex-file.h> |
| 26 |
#include <kpathsea/variable.h> |
| 27 |
|
| 28 |
/* Help messages. */ |
| 29 |
#include "help.h" |
| 30 |
|
| 31 |
/* Allow translation files. */ |
| 32 |
#define Xchr(x) xchr[x] |
| 33 |
|
| 34 |
/* Pieces of predefined Pascal web2c doesn't convert. */ |
| 35 |
|
| 36 |
/* Absolute value. Without the casts to integer here, the Ultrix and |
| 37 |
AIX compilers (at least) produce bad code (or maybe it's that I don't |
| 38 |
understand all the casting rules in C) for tests on memory fields. |
| 39 |
Specifically, a test in diag_round (in Metafont) on a quarterword |
| 40 |
comes out differently without the cast, thus causing the trap test to |
| 41 |
fail. (A path at line 86 is constructed slightly differently). */ |
| 42 |
/* If the system had an abs #define already, get rid of it. */ |
| 43 |
#undef abs |
| 44 |
#define abs(x) ((integer)(x) >= 0 ? (integer)(x) : (integer)-(x)) |
| 45 |
|
| 46 |
#define chr(x) (x) |
| 47 |
#define ord(x) (x) |
| 48 |
#define odd(x) ((x) & 1) |
| 49 |
#define round(x) zround ((double) (x)) |
| 50 |
#define trunc(x) ((integer) (x)) |
| 51 |
#undef floor /* MacOSX */ |
| 52 |
#define floor(x) ((integer)floor((double)(x))) |
| 53 |
#define input stdin |
| 54 |
#define output stdout |
| 55 |
#define maxint INTEGER_MAX |
| 56 |
#define nil NULL |
| 57 |
|
| 58 |
#define floorunscaled(i) ((i)>>16) |
| 59 |
#define floorscaled(i) ((i)&(-65536)) |
| 60 |
#define roundunscaled(i) ((((i)>>15)+1)>>1) |
| 61 |
#define roundfraction(i) ((((i)>>11)+1)>>1) |
| 62 |
#ifndef TeX |
| 63 |
/* In TeX, the half routine is always applied to positive integers. |
| 64 |
In MF and MP, it isn't; therefore, we can't portably use the C shift |
| 65 |
operator -- whether zeros or the sign bit will be shifted in on |
| 66 |
negative left operands is implementation-defined. |
| 67 |
|
| 68 |
It might be worth going through MF and using halfp where possible, as |
| 69 |
in MP. */ |
| 70 |
#define half(i) ( ((i)<0) ? (((i)+1)>>1) : ((i)>>1) ) |
| 71 |
#endif |
| 72 |
#define halfp(i) ((i) >> 1) |
| 73 |
|
| 74 |
/* Standard Pascal file routines. These are used for both binary and |
| 75 |
text files, but binary is more common. If you want it 100% right, |
| 76 |
fix the change files to pass the fopen mode to reset in all cases and |
| 77 |
send me the changes; it doesn't matter for Unix, so I'm not going to |
| 78 |
spend any more time on it. */ |
| 79 |
#define reset(f,n) f = xfopen (n, FOPEN_R_MODE) |
| 80 |
#define rewrite(f,n) f = xfopen (n, FOPEN_W_MODE) |
| 81 |
#define resetbin(f,n) f = xfopen (n, FOPEN_RBIN_MODE) |
| 82 |
#define rewritebin(f,n) f = xfopen (n, FOPEN_WBIN_MODE) |
| 83 |
|
| 84 |
#if defined(read) |
| 85 |
#undef read |
| 86 |
#endif |
| 87 |
#define read(f,b) ((b) = getc (f)) |
| 88 |
|
| 89 |
/* We hope this will be efficient than the `x = x - 1' that decr would |
| 90 |
otherwise be translated to. Likewise for incr. */ |
| 91 |
#define decr(x) --(x) |
| 92 |
#define incr(x) ++(x) |
| 93 |
|
| 94 |
/* `real' is used for noncritical floating-point stuff. */ |
| 95 |
typedef double real; |
| 96 |
|
| 97 |
/* C doesn't need to distinguish between text files and other files. */ |
| 98 |
typedef FILE *text; |
| 99 |
|
| 100 |
/* Extra stuff used in various change files for various reasons. */ |
| 101 |
|
| 102 |
/* Pascal has no address-of operator, and we need pointers to integers |
| 103 |
to set up the option table. */ |
| 104 |
#define addressof(x) (&(x)) |
| 105 |
|
| 106 |
/* So dvicopy can use stdin/stdout. */ |
| 107 |
#if defined (__DJGPP__) || defined (WIN32) |
| 108 |
#include <io.h> |
| 109 |
/* Don't set console device to binary. */ |
| 110 |
#define makebinaryfile(arg) ((void)(!isatty(fileno(arg)) && setmode(fileno(arg), O_BINARY)), arg) |
| 111 |
#else |
| 112 |
#define makebinaryfile(arg) (arg) |
| 113 |
#endif |
| 114 |
|
| 115 |
/* It's not worth fixing fixwrites to handle Pascal-style n:m write |
| 116 |
specifiers for reals, so the change files call print_real instead. */ |
| 117 |
#define printreal(r,n,m) fprintreal (stdout, r, n, m) |
| 118 |
|
| 119 |
/* Write the byte X to the file F. */ |
| 120 |
#define putbyte(x,f) \ |
| 121 |
do { if (putc ((char) (x) & 255, f) == EOF) \ |
| 122 |
FATAL1 ("putbyte(%ld) failed", (long) x); } while (0) |
| 123 |
|
| 124 |
/* To work around casting problems. */ |
| 125 |
#define ucharcast(x) ((unsigned char) (x)) |
| 126 |
#define int64cast(x) ((integer64) (x)) |
| 127 |
#define stringcast(x) ((string) (x)) |
| 128 |
#define conststringcast(x) ((const_string) (x)) |
| 129 |
#define ustringcast(x) ((unsigned char *) (x)) |
| 130 |
|
| 131 |
/* For throwing away input from the file F. */ |
| 132 |
#define vgetc(f) (void) getc (f) |
| 133 |
|
| 134 |
/* The fixwrites program outputs this, for diagnostics and such, that |
| 135 |
aren't worth checking the return value on. */ |
| 136 |
#define Fputs(f,s) (void) fputs (s, f) |
| 137 |
|
| 138 |
/* `aopenin' is used for all kinds of input text files, so it |
| 139 |
needs to know what path to use. Used by BibTeX, MF, TeX. */ |
| 140 |
#define aopenin(f,p) open_input (&(f), p, FOPEN_RBIN_MODE) |
| 141 |
#define aopenout(f) open_output (&(f), FOPEN_W_MODE) |
| 142 |
#define aclose close_file |
| 143 |
|
| 144 |
/* Used in BibTeX for subsidiary aux files. */ |
| 145 |
#define aopeninwithdirname(f,p,s) open_input_with_dirname (&(f), p, s) |
| 146 |
|
| 147 |
/* How to output to the GF or DVI file. */ |
| 148 |
#define WRITE_OUT(a, b) \ |
| 149 |
if ((size_t) fwrite ((char *) &OUT_BUF[a], sizeof (OUT_BUF[a]), \ |
| 150 |
(size_t) ((size_t)(b) - (size_t)(a) + 1), OUT_FILE) \ |
| 151 |
!= (size_t) ((size_t) (b) - (size_t) (a) + 1)) \ |
| 152 |
FATAL_PERROR ("fwrite"); |
| 153 |
|
| 154 |
#ifdef GFTODVI |
| 155 |
#define writedvi WRITE_OUT |
| 156 |
#define OUT_FILE dvifile |
| 157 |
#define OUT_BUF dvibuf |
| 158 |
#endif |
| 159 |
|
| 160 |
/* PatGen 2 uses this. */ |
| 161 |
#define input2ints(a,b) zinput2ints (&a, &b) |
| 162 |
|
| 163 |
/* We need this only if TeX is being debugged. */ |
| 164 |
#define input3ints(a,b,c) zinput3ints (&a, &b, &c) |
| 165 |
|
| 166 |
/* Allocate an array of a given type. Add 1 to size to account for the |
| 167 |
fact that Pascal arrays are used from [1..size], unlike C arrays which |
| 168 |
use [0..size). */ |
| 169 |
#define xmallocarray(type,size) ((type*)xmalloc((size+1)*sizeof(type))) |
| 170 |
/* Same for reallocating an array. */ |
| 171 |
#define xreallocarray(ptr,type,size) ((type*)xrealloc(ptr,(size+1)*sizeof(type))) |
| 172 |
/* Allocate and clear an array of a given type. Add 1 to nmemb and size. */ |
| 173 |
#define xcallocarray(type,nmemb,size) ((type*)xcalloc(nmemb+1,(size+1)*sizeof(type))) |
| 174 |
|
| 175 |
/* BibTeX needs this to dynamically reallocate arrays. Too bad we can't |
| 176 |
rely on stringification, or we could avoid the ARRAY_NAME arg. |
| 177 |
Actually allocate one more than requests, so we can index the last |
| 178 |
entry, as Pascal wants to do. */ |
| 179 |
#define BIBXRETALLOCNOSET(array_name, array_var, type, size_var, new_size) \ |
| 180 |
fprintf (logfile, "Reallocated %s (elt_size=%ld) to %ld items from %ld.\n", \ |
| 181 |
array_name, (long) sizeof (type), (long) new_size, (long) size_var); \ |
| 182 |
XRETALLOC (array_var, new_size + 1, type) |
| 183 |
/* Same as above, but also increase SIZE_VAR when no more arrays |
| 184 |
with the same size parameter will be resized. */ |
| 185 |
#define BIBXRETALLOC(array_name, array_var, type, size_var, new_size) do { \ |
| 186 |
BIBXRETALLOCNOSET(array_name, array_var, type, size_var, new_size); \ |
| 187 |
size_var = new_size; \ |
| 188 |
} while (0) |
| 189 |
/* Same as above, but for the pseudo-TYPE ASCII_code[LENGTH+1]. */ |
| 190 |
#define BIBXRETALLOCSTRING(array_name, array_var, length, size_var, new_size) \ |
| 191 |
fprintf (logfile, "Reallocated %s (elt_size=%ld) to %ld items from %ld.\n", \ |
| 192 |
array_name, (long) (length + 1), (long) new_size, (long) size_var); \ |
| 193 |
XRETALLOC (array_var, (new_size) * (length + 1), ASCIIcode) |
| 194 |
|
| 195 |
/* Need precisely int for getopt, etc. */ |
| 196 |
#define cinttype int |
| 197 |
|
| 198 |
/* Need this because web2c doesn't translate `var1,var2:^char' correctly |
| 199 |
-- var2 lacks the *. */ |
| 200 |
#define cstring string |
| 201 |
|
| 202 |
#define constcstring const_string |
| 203 |
|
| 204 |
/* For strings of unsigned chars, used as array indices. */ |
| 205 |
#define constw2custring const_w2custring |
| 206 |
typedef unsigned char *w2custring; |
| 207 |
typedef const unsigned char *const_w2custring; |
| 208 |
|
| 209 |
/* Not all C libraries have fabs, so we'll roll our own. */ |
| 210 |
#undef fabs |
| 211 |
#define fabs(x) ((x) >= 0.0 ? (x) : -(x)) |
| 212 |
|
| 213 |
/* TeX et al. have a variable free, but we also need the C routine. */ |
| 214 |
#define libcfree free |
| 215 |
|
| 216 |
/* We have a system-dependent prompt in tex.ch. We don't want it in the |
| 217 |
string pool, since (now that the pools are compiled into the |
| 218 |
binaries), that would make the .fmt unsharable. So go through this |
| 219 |
circumlotion to print a C string. The lack of the closing ) is |
| 220 |
intentional, since the code adds more text sometimes. Although the |
| 221 |
eof character can be changed with stty or whatever, we're certainly |
| 222 |
not going to try to extract the actual value from a terminal struct. |
| 223 |
Anyone who is savvy enough to change it will not be confused. */ |
| 224 |
#ifdef WIN32 |
| 225 |
#define promptfilenamehelpmsg "(Press Enter to retry, or Control-Z to exit" |
| 226 |
#else |
| 227 |
#define promptfilenamehelpmsg "(Press Enter to retry, or Control-D to exit" |
| 228 |
#endif |
| 229 |
|
| 230 |
/* We use this rather than a simple fputs so that the string will end up |
| 231 |
in the .log file, too. */ |
| 232 |
#define printcstring(STR) \ |
| 233 |
do { \ |
| 234 |
const_string ch_ptr = (STR); \ |
| 235 |
while (*ch_ptr) \ |
| 236 |
printchar(*(ch_ptr++)); \ |
| 237 |
} while (0) |
| 238 |
|
| 239 |
|
| 240 |
/* Tangle removes underscores from names. Put them back for things that |
| 241 |
are defined in C with _'s. */ |
| 242 |
#define extendfilename extend_filename |
| 243 |
#define findsuffix find_suffix |
| 244 |
#define makesuffix make_suffix |
| 245 |
#define FOPENRBINMODE FOPEN_RBIN_MODE |
| 246 |
#define FOPENRMODE FOPEN_R_MODE |
| 247 |
#define getoptlongonly getopt_long_only |
| 248 |
#define hasarg has_arg |
| 249 |
#define ISDIRSEP IS_DIR_SEP |
| 250 |
#define kpsebibformat kpse_bib_format |
| 251 |
#define kpsebstformat kpse_bst_format |
| 252 |
#define kpsefindfile kpse_find_file |
| 253 |
#define kpsefindmf kpse_find_mf |
| 254 |
#define kpsefindmft kpse_find_mft |
| 255 |
#define kpsefindofm kpse_find_ofm |
| 256 |
#define kpsefindovf kpse_find_ovf |
| 257 |
#define kpsefindtex kpse_find_tex |
| 258 |
#define kpsefindtfm kpse_find_tfm |
| 259 |
#define kpsefindvf kpse_find_vf |
| 260 |
#define kpseinnameok kpse_in_name_ok |
| 261 |
#define kpseinitprog kpse_init_prog |
| 262 |
#define kpsesetprogramname kpse_set_program_name |
| 263 |
#define kpseresetprogramname kpse_reset_program_name |
| 264 |
#define kpsegfformat kpse_gf_format |
| 265 |
#define kpselastformat kpse_last_format |
| 266 |
#define kpsemaketexdiscarderrors kpse_make_tex_discard_errors |
| 267 |
#define kpsemfformat kpse_mf_format |
| 268 |
#define kpsemftformat kpse_mft_format |
| 269 |
#define kpsempformat kpse_mp_format |
| 270 |
#define kpseocpformat kpse_ocp_format |
| 271 |
#define kpseofmformat kpse_ofm_format |
| 272 |
#define kpseoplformat kpse_opl_format |
| 273 |
#define kpseotpformat kpse_otp_format |
| 274 |
#define kpseoutnameok kpse_out_name_ok |
| 275 |
#define kpseovpformat kpse_ovp_format |
| 276 |
#define kpseovfformat kpse_ovf_format |
| 277 |
#define kpseopenfile kpse_open_file |
| 278 |
#define kpsepkformat kpse_pk_format |
| 279 |
#define kpsetfmformat kpse_tfm_format |
| 280 |
#define kpsevfformat kpse_vf_format |
| 281 |
#define kpsewebformat kpse_web_format |
| 282 |
#define kpsevarvalue kpse_var_value |
| 283 |
#define kpsesetprogramenabled kpse_set_program_enabled |
| 284 |
#define kpsesrccmdline kpse_src_cmdline |
| 285 |
#define kpsesrccompile kpse_src_compile |
| 286 |
#define recorderchangefilename recorder_change_filename |
| 287 |
#define recorderenabled recorder_enabled |
| 288 |
#define removesuffix remove_suffix |
| 289 |
#define texmfyesno texmf_yesno |
| 290 |
|
| 291 |
/* We need a new type for the argument parsing, too. */ |
| 292 |
typedef struct option getoptstruct; |
| 293 |
|
| 294 |
/* We never need the `link' system call, which may be declared in |
| 295 |
<unistd.h>, but we do have variables named `link' in the webs. */ |
| 296 |
#undef link |
| 297 |
#define link link_var |
| 298 |
|
| 299 |
/* Throw away VMS' library routine `getname', as WEB uses that name. */ |
| 300 |
#ifdef VMS |
| 301 |
#undef getname |
| 302 |
#define getname vms_getname |
| 303 |
#endif |
| 304 |
|
| 305 |
/* Apparently POSIX 2008 has getline and glibc 2.9.90 exports it. |
| 306 |
tangle, weave, et al. use that symbol; try to define it away to |
| 307 |
something that a standard won't usurp. */ |
| 308 |
#ifdef getline |
| 309 |
#undef getline |
| 310 |
#endif |
| 311 |
#define getline web2c_getline |
| 312 |
|
| 313 |
|
| 314 |
/* Declarations for the routines we provide ourselves in lib/. */ |
| 315 |
#include "lib/lib.h" |
| 316 |
|
| 317 |
extern int loadpoolstrings (integer); |
| 318 |
|
| 319 |
#endif /* not CPASCAL_H */ |