Debian Codegraph @

texk/web2c/texmfmp.h

raw
1 /* texmfmp.h: Main include file for TeX and MF in C. This file is
2 included by {tex,mf}d.h, which is the first include in the C files
3 output by web2c. */
4
5 #include "cpascal.h"
6 #include <kpathsea/c-pathch.h> /* for IS_DIR_SEP, used in the change files */
7 #include <kpathsea/tex-make.h> /* for kpse_make_tex_discard_errors */
8
9 #ifdef XeTeX
10 #ifdef XETEX_MAC
11 /* include this here to avoid conflict between clang's emmintrin.h and
12 * texmfmem.h. Should be removed once a fixed clang is widely available
13 * http://llvm.org/bugs/show_bug.cgi?id=14964 */
14 #include <ApplicationServices/ApplicationServices.h>
15 #endif
16 /* added typedefs for unicodefile and voidpointer */
17 #define XETEX_UNICODE_FILE_DEFINED 1
18 typedef struct {
19 FILE *f;
20 long savedChar;
21 short skipNextLF;
22 short encodingMode;
23 void *conversionData;
24 } UFILE;
25 typedef UFILE* unicodefile;
26
27 typedef void* voidpointer;
28 #endif
29
30 /* If we have these macros, use them, as they provide a better guide to
31 the endianess when cross-compiling. */
32 #if defined (BYTE_ORDER) && defined (BIG_ENDIAN) && defined (LITTLE_ENDIAN)
33 #ifdef WORDS_BIGENDIAN
34 #undef WORDS_BIGENDIAN
35 #endif
36 #if BYTE_ORDER == BIG_ENDIAN
37 #define WORDS_BIGENDIAN
38 #endif
39 #endif
40 /* More of the same, but now NeXT-specific. */
41 #ifdef NeXT
42 #ifdef WORDS_BIGENDIAN
43 #undef WORDS_BIGENDIAN
44 #endif
45 #ifdef __BIG_ENDIAN__
46 #define WORDS_BIGENDIAN
47 #endif
48 #endif
49
50 /* Some things are the same except for the name. */
51 #ifdef TeX
52 #if defined (pdfTeX)
53 #define TEXMFPOOLNAME "pdftex.pool"
54 #define TEXMFENGINENAME "pdftex"
55 #elif defined (eTeX)
56 #define TEXMFPOOLNAME "etex.pool"
57 #define TEXMFENGINENAME "etex"
58 #elif defined (XeTeX)
59 #define TEXMFPOOLNAME "xetex.pool"
60 #define TEXMFENGINENAME "xetex"
61 #elif defined (Aleph)
62 #define TEXMFPOOLNAME "aleph.pool"
63 #define TEXMFENGINENAME "aleph"
64 #elif defined (pTeX)
65 #define TEXMFPOOLNAME "ptex.pool"
66 #define TEXMFENGINENAME "ptex"
67 #include "ptexdir/kanji.h"
68 #elif defined (epTeX)
69 #define TEXMFPOOLNAME "eptex.pool"
70 #define TEXMFENGINENAME "eptex"
71 #include "ptexdir/kanji.h"
72 #elif defined (upTeX)
73 #define TEXMFPOOLNAME "uptex.pool"
74 #define TEXMFENGINENAME "uptex"
75 #include "uptexdir/kanji.h"
76 #elif defined (eupTeX)
77 #define TEXMFPOOLNAME "euptex.pool"
78 #define TEXMFENGINENAME "euptex"
79 #include "uptexdir/kanji.h"
80 #else
81 #define TEXMFPOOLNAME "tex.pool"
82 #define TEXMFENGINENAME "tex"
83 #endif
84 #define DUMP_FILE fmtfile
85 #define DUMP_FORMAT kpse_fmt_format
86 #define writedvi WRITE_OUT
87 #define flushdvi flush_out
88 #define OUT_FILE dvifile
89 #define OUT_BUF dvibuf
90 #endif /* TeX */
91 #ifdef MF
92 #if defined(MFLua)
93 #define TEXMFPOOLNAME "mflua.pool"
94 #define TEXMFENGINENAME "mflua"
95 #elif defined(MFLuaJIT)
96 #define TEXMFPOOLNAME "mfluajit.pool"
97 #define TEXMFENGINENAME "mfluajit"
98 #else
99 #define TEXMFPOOLNAME "mf.pool"
100 #define TEXMFENGINENAME "metafont"
101 #endif
102 #define DUMP_FILE basefile
103 #define DUMP_FORMAT kpse_base_format
104 #define writegf WRITE_OUT
105 #define OUT_FILE gffile
106 #define OUT_BUF gfbuf
107 #endif /* MF */
108
109 /* Restore underscores. */
110 #define dumpname dump_name
111 #define kpsedvipsconfigformat kpse_dvips_config_format
112 #define kpsefontmapformat kpse_fontmap_format
113 #define kpsemfpoolformat kpse_mfpool_format
114 #define kpsempformat kpse_mp_format
115 #define kpsemppoolformat kpse_mppool_format
116 #define kpsetexpoolformat kpse_texpool_format
117 #define kpsetexformat kpse_tex_format
118
119 /* Hacks for TeX that are better not to #ifdef, see lib/openclose.c. */
120 extern int tfmtemp, texinputtype;
121
122 /* pdfTeX routines also used for e-pTeX, e-upTeX, and XeTeX */
123 #if defined (pdfTeX) || defined (epTeX) || defined (eupTeX) || defined(XeTeX)
124 #if !defined (pdfTeX)
125 extern void pdftex_fail(const char *fmt, ...);
126 #endif
127 extern char start_time_str[];
128 extern void initstarttime(void);
129 extern string find_input_file(integer s);
130 #if !defined(XeTeX)
131 extern char *makecstring(integer s);
132 extern char *makecfilename(integer s);
133 #endif /* !XeTeX */
134 extern void getcreationdate(void);
135 extern void getfilemoddate(integer s);
136 extern void getfilesize(integer s);
137 extern void getfiledump(integer s, int offset, int length);
138 extern void convertStringToHexString(const char *in, char *out, int lin);
139 extern void getmd5sum(integer s, int file);
140 #endif
141
142 /* pdftex etc. except for tex use these for pipe support */
143 #if defined(TeX) && !defined(onlyTeX)
144 extern boolean open_in_or_pipe (FILE **, int, const_string fopen_mode);
145 extern boolean open_out_or_pipe (FILE **, const_string fopen_mode);
146 extern void close_file_or_pipe (FILE *);
147 #define ENABLE_PIPES 1
148 #else
149 #define ENABLE_PIPES 0
150 #endif
151
152 /* Executing shell commands. */
153 extern int runsystem (const char *cmd);
154
155 /* The entry point. */
156 extern void maininit (int ac, string *av);
157 #if defined(WIN32) && !defined(__MINGW32__) && defined(DLLPROC)
158 extern __declspec(dllexport) int DLLPROC (int ac, string *av);
159 #else
160 #undef DLLPROC
161 #endif
162
163 /* All but the Omega family use this. */
164 #if !defined(Aleph)
165 extern void readtcxfile (void);
166 extern string translate_filename;
167 #define translatefilename translate_filename
168 #endif
169
170 #ifdef TeX
171 /* The type `glueratio' should be a floating point type which won't
172 unnecessarily increase the size of the memoryword structure. This is
173 the basic requirement. On most machines, if you're building a
174 normal-sized TeX, then glueratio must probably meet the following
175 restriction: sizeof(glueratio) <= sizeof(integer). Usually, then,
176 glueratio must be `float'. But if you build a big TeX, you can (on
177 most machines) and should make it `double' to avoid loss of precision
178 and conversions to and from double during calculations. (All this
179 also goes for Metafont.) Furthermore, if you have enough memory, it
180 won't hurt to have this defined to be `double' for running the
181 trip/trap tests.
182
183 This type is set automatically to `float' by configure if a small TeX
184 is built. */
185 #ifndef GLUERATIO_TYPE
186 #define GLUERATIO_TYPE double
187 #endif
188 typedef GLUERATIO_TYPE glueratio;
189
190 #if defined(__DJGPP__) && defined (IPC)
191 #undef IPC
192 #endif
193
194 #ifdef IPC
195 extern void ipcpage (int);
196 #endif /* IPC */
197 #endif /* TeX */
198
199 /* How to flush the DVI file. */
200 #define flush_out() fflush (OUT_FILE)
201
202 /* Used to write to a TFM file. */
203 #define put2bytes(f, h) do { \
204 integer v = (integer) (h); putbyte (v >> 8, f); putbyte (v & 0xff, f); \
205 } while (0)
206 #define put4bytes(f, w) do { \
207 integer v = (integer) (w); \
208 putbyte (v >> 24, f); putbyte (v >> 16, f); \
209 putbyte (v >> 8, f); putbyte (v & 0xff, f); \
210 } while (0)
211
212 /* Read a line of input as quickly as possible. */
213 #define inputln(stream, flag) input_line (stream)
214 #ifdef XeTeX
215 extern boolean input_line (UFILE *);
216 #else
217 extern boolean input_line (FILE *);
218 #endif
219
220 /* This routine has to return four values. */
221 #define dateandtime(i,j,k,l) get_date_and_time (&(i), &(j), &(k), &(l))
222 extern void get_date_and_time (integer *, integer *, integer *, integer *);
223
224 #if defined(pdfTeX) || defined(epTeX) || defined(eupTeX) || defined(XeTeX)
225 /* Get high-res time info. */
226 #define secondsandmicros(i,j) get_seconds_and_micros (&(i), &(j))
227 extern void get_seconds_and_micros (integer *, integer *);
228 #endif
229
230 /* Copy command-line arguments into the buffer, despite the name. */
231 extern void topenin (void);
232
233 /* Can't prototype this since it uses poolpointer and ASCIIcode, which
234 are defined later in mfd.h, and mfd.h uses stuff from here. */
235 /* Therefore the department of ugly hacks decided to move this declaration
236 to the *coerce.h files. */
237 /* extern void calledit (); */
238
239 /* These defines reroute the file i/o calls to the new pipe-enabled
240 functions in texmfmp.c*/
241
242 #if ENABLE_PIPES
243 #undef aopenin
244 #undef aopenout
245 #undef aclose
246 #define aopenin(f,p) open_in_or_pipe(&(f),p,FOPEN_RBIN_MODE)
247 #define aopenout(f) open_out_or_pipe(&(f),FOPEN_W_MODE)
248 #define aclose(f) close_file_or_pipe(f)
249 #endif
250
251 /* define FMT_COMPRESS for engines which compress formats */
252 #if defined(pTeX) || defined(epTeX) || defined(upTeX) || defined(eupTeX)
253 #define FMT_COMPRESS 1
254 #endif
255 #if defined(eTeX) || defined(pdfTeX) || defined(XeTeX)
256 #define FMT_COMPRESS 1
257 #endif
258
259 /* `bopenin' (and out) is used only for reading (and writing) .tfm
260 files; `wopenin' (and out) only for dump files. The filenames are
261 passed in as a global variable, `nameoffile'. */
262 #define bopenin(f) open_input (&(f), kpse_tfm_format, FOPEN_RBIN_MODE)
263 #define ocpopenin(f) open_input (&(f), kpse_ocp_format, FOPEN_RBIN_MODE)
264 #define ofmopenin(f) open_input (&(f), kpse_ofm_format, FOPEN_RBIN_MODE)
265
266 #define bopenout(f) open_output (&(f), FOPEN_WBIN_MODE)
267 #define bclose aclose
268 #ifdef FMT_COMPRESS
269 /* f is declared as gzFile, but we temporarily use it for a FILE *
270 so that we can use the standard open calls */
271 #define wopenin(f) (open_input ((FILE**)&(f), DUMP_FORMAT, FOPEN_RBIN_MODE) \
272 && (f = gzdopen(fileno((FILE*)f), FOPEN_RBIN_MODE)))
273 #define wopenout(f) (open_output ((FILE**)&(f), FOPEN_WBIN_MODE) \
274 && (f = gzdopen(fileno((FILE*)f), FOPEN_WBIN_MODE)) \
275 && (gzsetparams(f, 1, Z_DEFAULT_STRATEGY) == Z_OK))
276 #define wclose(f) gzclose(f)
277 #else
278 #define wopenin(f) open_input (&(f), DUMP_FORMAT, FOPEN_RBIN_MODE)
279 #define wopenout bopenout
280 #define wclose aclose
281 #endif
282
283 #ifdef XeTeX
284 #if ENABLE_PIPES
285 extern boolean u_open_in_or_pipe(unicodefile* f, integer filefmt, const_string fopen_mode, integer mode, integer encodingData);
286 extern void u_close_file_or_pipe(unicodefile* f);
287 #define uopenin(f,p,m,d) u_open_in_or_pipe(&(f), p, FOPEN_RBIN_MODE, m, d)
288 #define uclose(f) u_close_file_or_pipe(&(f))
289 #else
290 #define uopenin(f,p,m,d) u_open_in(&(f), p, FOPEN_RBIN_MODE, m, d)
291 #define uclose(f) u_close_inout(&(f))
292 #endif
293 #endif
294
295 /* Used in tex.ch (section 1338) to get a core dump in debugging mode. */
296 #ifdef unix
297 #define dumpcore abort
298 #else
299 #define dumpcore uexit (1)
300 #endif
301
302 #ifdef MF
303 extern boolean initscreen (void);
304 extern void updatescreen (void);
305 /* Can't prototype these for same reason as `calledit' above. */
306 #if 0 /* Therefore the real declaration is found in the coerce.h files. */
307 extern void blankrectangle (/*screencol, screencol, screenrow, screenrow*/);
308 extern void paintrow (/*screenrow, pixelcolor, transspec, screencol*/);
309 #endif
310 #endif /* MF */
311
312
313 /* (Un)dumping. These are called from the change file. */
314 #define dumpthings(base, len) \
315 do_dump ((char *) &(base), sizeof (base), (int) (len), DUMP_FILE)
316 #define undumpthings(base, len) \
317 do_undump ((char *) &(base), sizeof (base), (int) (len), DUMP_FILE)
318
319 #ifndef PRIdPTR
320 #define PRIdPTR "ld"
321 #endif
322 #ifndef PRIxPTR
323 #define PRIxPTR "lx"
324 #endif
325
326 /* Like do_undump, but check each value against LOW and HIGH. The
327 slowdown isn't significant, and this improves the chances of
328 detecting incompatible format files. In fact, Knuth himself noted
329 this problem with Web2c some years ago, so it seems worth fixing. We
330 can't make this a subroutine because then we lose the type of BASE. */
331 #define undumpcheckedthings(low, high, base, len) \
332 do { \
333 unsigned i; \
334 undumpthings (base, len); \
335 for (i = 0; i < (len); i++) { \
336 if ((&(base))[i] < (low) || (&(base))[i] > (high)) { \
337 FATAL5 ("Item %u (=%" PRIdPTR ") of .fmt array at %" PRIxPTR \
338 " <%" PRIdPTR " or >%" PRIdPTR, \
339 i, (uintptr_t) (&(base))[i], (uintptr_t) &(base), \
340 (uintptr_t) low, (uintptr_t) high); \
341 } \
342 } \
343 } while (0)
344
345 /* Like undump_checked_things, but only check the upper value. We use
346 this when the base type is unsigned, and thus all the values will be
347 greater than zero by definition. */
348 #define undumpuppercheckthings(high, base, len) \
349 do { \
350 unsigned i; \
351 undumpthings (base, len); \
352 for (i = 0; i < (len); i++) { \
353 if ((&(base))[i] > (high)) { \
354 FATAL4 ("Item %u (=%" PRIdPTR ") of .fmt array at %" PRIxPTR \
355 " >%" PRIdPTR, \
356 i, (uintptr_t) (&(base))[i], (uintptr_t) &(base), \
357 (uintptr_t) high); \
358 } \
359 } \
360 } while (0)
361
362 /* We define the routines to do the actual work in texmfmp.c. */
363 #ifdef FMT_COMPRESS
364 #include <zlib.h>
365 extern void do_dump (char *, int, int, gzFile);
366 extern void do_undump (char *, int, int, gzFile);
367 #else
368 extern void do_dump (char *, int, int, FILE *);
369 extern void do_undump (char *, int, int, FILE *);
370 #endif
371
372 /* Use the above for all the other dumping and undumping. */
373 #define generic_dump(x) dumpthings (x, 1)
374 #define generic_undump(x) undumpthings (x, 1)
375
376 #define dumpwd generic_dump
377 #define dumphh generic_dump
378 #define dumpqqqq generic_dump
379 #define undumpwd generic_undump
380 #define undumphh generic_undump
381 #define undumpqqqq generic_undump
382
383 /* `dump_int' is called with constant integers, so we put them into a
384 variable first. */
385 #define dumpint(x) \
386 do \
387 { \
388 integer x_val = (x); \
389 generic_dump (x_val); \
390 } \
391 while (0)
392
393 /* web2c/regfix puts variables in the format file loading into
394 registers. Some compilers aren't willing to take addresses of such
395 variables. So we must kludge. */
396 #if defined(REGFIX) || defined(WIN32)
397 #define undumpint(x) \
398 do \
399 { \
400 integer x_val; \
401 generic_undump (x_val); \
402 x = x_val; \
403 } \
404 while (0)
405 #else
406 #define undumpint generic_undump
407 #endif
408
409 /* Handle SyncTeX, if requested */
410 #if defined(TeX)
411 # if defined(__SyncTeX__)
412 # include "synctexdir/synctex-common.h"
413 extern char *generic_synctex_get_current_name(void);
414 # endif
415 #endif
416