1 /* Main include file for TeX in C. Originally by Tim Morgan,
2 December 23, 1987. These routines are also used by Metafont (with
5 Copyright 1992 Karl Berry
6 Copyright 2007 TeX Users Group
7 Copyright 2014 Clerk Ma
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 #define INLINE __inline
32 /* need io.h for write() - bkph */
35 /* #include <io.h> */ /* conflict with read() in pascal.h ??? */
36 //int __cdecl write(int, const void *, unsigned int);
40 #define dump_file fmt_file
41 #define dump_path TEXFORMATPATH
42 #define mwrite_out writedvi
43 #define out_file dvi_file
44 #define out_buf dvi_buf
46 #define dump_file basefile
47 #define dump_path MFBASEPATH
48 #define write_out writegf
49 #define out_file gffile
56 typedef FILE *byte_file, *word_file;
58 /* Read a line of input as quickly as possible. */
59 #define input_ln(stream, flag) input_line (stream)
60 extern bool input_line (FILE *);
61 /* was extern bool input_line(); */
64 /* We need to read an integer from stdin if we're debugging. */
66 #define getint() inputint (stdin)
73 /* `b_open_in' (and out) is used only for reading (and writing) .tfm
74 files; `w_open_in' (and out) only for dump files. The filenames are
75 passed in as a global variable, `name_of_file'. */
77 #define b_open_in(f) open_input (&(f), TFMFILEPATH, FOPEN_RBIN_MODE)
78 #define w_open_in(f) open_input (&(f), dump_path, FOPEN_RBIN_MODE)
79 #define b_open_out(f) open_output (&(f), FOPEN_WBIN_MODE)
80 #define w_open_out b_open_out
81 #define b_close a_close
82 #define w_close a_close
84 /* This routine has to return four values. */
85 #define dateandtime(i, j, k, l) get_date_and_time (&(i), &(j), &(k), &(l))
89 /* If we're running under Unix, use system calls instead of standard I/O
90 to read and write the output files; also, be able to make a core dump. */
92 #define dumpcore() exit (1)
94 #define dumpcore abort
97 /* #ifndef unix */ /* change bkph 93/Nov/26 */
98 /* #if ! defined unix && ! defined MSDOS */
99 #ifndef unix /* changed back bkph 93/Dec/28 fixed macro */
101 /* This was horseshit, since for MSDOS it did no errors checking! - bkph */
103 /* #define writedvi(a, b) \
104 (void) fwrite ((char *) &dvi_buf[a], sizeof (dvi_buf[a]), \
105 (int) ((b) - (a) + 1), dvi_file) */
106 #define writedvi(a, b) \
107 if (fwrite ((char *) &dvi_buf[a], sizeof (dvi_buf[a]), \
108 (int) ((b) - (a) + 1), dvi_file) != (size_t) ((b) - (a) + 1)) \
109 FATAL_PERROR ("\n! dvi file")
111 #define writegf(a, b) \
112 /* (void) fwrite ((char *) &gfbuf[a], sizeof (gfbuf[a]), \
113 (int) ((b) - (a) + 1), gffile) */
114 if (fwrite ((char *) &gfbuf[a], sizeof (gfbuf[a]), \
115 (int) ((b) - (a) + 1), gffile) != (size_t) ((end) - (start) + 1)) \
116 FATAL_PERROR ("\n! gf file")
121 /* #error WE APPEAR TO BE USING SYSTEM CALLS WITH ERROR CHECKING! */
122 /* USE fwrite(...) instead of write(fileno (...)) ! */
125 #define writedvi(start, end) \
126 if (write (fileno (dvi_file), (char *) &dvi_buf[start], \
127 (int) ((end) - (start) + 1)) \
128 != (int) ((end) - (start) + 1)) \
129 FATAL_PERROR ("\n! dvi file")
131 #define writegf(start, end) \
132 if (write (fileno (gffile), (char *) &gfbuf[start], \
133 (int) ((end) - (start) + 1)) \
134 != (int) ((end) - (start) + 1)) \
135 FATAL_PERROR ("\n! gf file")
140 /* Reading and writing the dump files. `(un)dumpthings' is called from
142 #define dumpthings(base, len) \
143 do_dump ((char *) &(base), sizeof (base), (int) (len), dump_file)
145 #define undumpthings(base, len) \
146 do_undump ((char *) &(base), sizeof (base), (int) (len), dump_file)
148 /* We define the routines to do the actual work in texmf.c. */
149 // extern void do_dump (char *, int, int, FILE *);
150 extern int do_dump (char *, int, int, FILE *);
151 /* extern void do_dump(); */
152 // extern void do_undump (char *, int, int, FILE *);
153 extern int do_undump (char *, int, int, FILE *);
154 /* extern void do_undump(); */
156 /* Use the above for all the other dumping and undumping. */
157 #define generic_dump(x) dumpthings (x, 1)
158 #define generic_undump(x) undumpthings (x, 1)
160 #define dump_wd generic_dump
161 #define undump_wd generic_undump
162 #define dump_hh generic_dump
163 #define undump_hh generic_undump
164 #define dump_qqqq generic_dump
165 #define undump_qqqq generic_undump
167 /* `dump_int' is called with constant integers, so we put them into a
169 #define dump_int(x) \
172 integer x_val = (x); \
173 generic_dump (x_val); \
177 /* web2c/regfix puts variables in the format file loading into
178 registers. Some compilers aren't willing to take addresses of such
179 variables. So we must kludge. */
181 #define undump_int(x) \
185 generic_undump (x_val); \
190 #define undump_int generic_undump
193 /* Metafont wants to write bytes to the TFM file. The casts in these
194 routines are important, since otherwise memory is clobbered in some
195 strange way, which causes ``13 font metric dimensions to be
196 decreased'' in the trap test, instead of 4. */
198 #define bwritebyte(f, b) putc ((char) (b), f)
199 #define bwrite2bytes(f, h) \
202 integer v = (integer) (h); \
203 putc (v >> 8, f); putc (v & 0xff, f); \
206 #define bwrite4bytes(f, w) \
209 integer v = (integer) (w); \
210 putc (v >> 24, f); putc (v >> 16, f); \
211 putc (v >> 8, f); putc (v & 0xff, f); \
217 /* If we're running on an ASCII system, there is no need to use the
218 `xchr' array to convert characters to the external encoding. */
219 /* #ifdef NONASCII */
220 /* #define Xchr(x) xchr[x] */
222 /* #define Xchr(x) ((char) (x)) */
225 /* Following used in tex0.c - make possible to use non ASCII */
227 #define Xchr(x) xchr[x]
229 /* following added from new texmf.c file 1996/Jan/12 */
230 /* these, of course are useless definitions since parameters not given */
232 /* Declare routines in texmf.c. */
233 extern void get_date_and_time();
234 extern void t_open_in();
235 // extern void call_edit();
236 // extern int call_edit();
237 extern bool extensionirrelevantp();
238 extern bool input_line();
239 // extern void do_dump();
240 // extern void do_undump();
243 extern bool maketextex();
244 extern bool maketextfm();
246 extern void main_body();
247 extern bool initscreen();
248 extern bool maketexmf();
249 extern void updatescreen();
250 extern void blankrectangle();
251 extern void paintrow();