OSDN Git Service

binding with libharu.
[putex/putex.git] / src / texsourc / texmf.h
1 /* Main include file for TeX in C.  Originally by Tim Morgan,
2    December 23, 1987.  These routines are also used by Metafont (with
3    some name changes).
4
5    Copyright 1992 Karl Berry
6    Copyright 2007 TeX Users Group
7    Copyright 2014 Clerk Ma
8
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.
13
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.
18
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
22    02110-1301 USA.  */
23
24 #include "config.h"
25 #include <stdarg.h>
26 #ifdef _MSC_VER
27   #define INLINE __inline
28 #else
29   #define INLINE inline
30 #endif
31
32 /* need io.h for write() - bkph */
33
34 #ifdef MSDOS
35 /* #include <io.h> */ /* conflict with read() in pascal.h ??? */
36 //int __cdecl write(int, const void *, unsigned int);
37 #endif
38
39 #ifdef TeX
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
45 #else /* not TeX */
46   #define dump_file basefile
47   #define dump_path MFBASEPATH
48   #define write_out writegf
49   #define out_file gffile
50   #define out_buf gfbuf
51 #endif /* not TeX */
52
53
54 \f
55 /* File types.  */
56 typedef FILE *byte_file, *word_file;
57 \f
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(); */
62
63
64 /* We need to read an integer from stdin if we're debugging.  */
65 #ifdef DEBUG
66 #define getint()  inputint (stdin)
67 #else
68 #define getint()
69 #endif
70
71
72 \f
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'.  */
76    
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
83
84 /* This routine has to return four values.  */
85 #define dateandtime(i, j, k, l) get_date_and_time (&(i), &(j), &(k), &(l))
86
87
88 \f
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. */ 
91 #ifndef unix
92   #define       dumpcore()      exit (1)
93 #else /* unix */
94   #define       dumpcore        abort
95 #endif
96
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 */
100
101 /* This was horseshit, since for MSDOS it did no errors checking! - bkph */
102 #ifdef TeX
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")
110 #else
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")
117 #endif /* not TeX */
118
119 #else /* unix */
120
121 /* #error WE APPEAR TO BE USING SYSTEM CALLS WITH ERROR CHECKING! */
122 /* USE fwrite(...) instead of write(fileno (...)) ! */
123
124 #ifdef TeX
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")
130 #else
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")
136 #endif /* not TeX */
137 #endif /* unix */
138
139
140 /* Reading and writing the dump files.  `(un)dumpthings' is called from
141    the change file.*/
142 #define dumpthings(base, len)                                           \
143   do_dump ((char *) &(base), sizeof (base), (int) (len), dump_file)
144
145 #define undumpthings(base, len)                                         \
146   do_undump ((char *) &(base), sizeof (base), (int) (len), dump_file)
147
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(); */
155
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)
159
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
166
167 /* `dump_int' is called with constant integers, so we put them into a
168    variable first.  */
169 #define dump_int(x)                                                     \
170   do                                                                    \
171     {                                                                   \
172       integer x_val = (x);                                              \
173       generic_dump (x_val);                                             \
174     }                                                                   \
175   while (0)
176
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.  */
180 #ifdef REGFIX
181 #define undump_int(x)                                                   \
182   do                                                                    \
183     {                                                                   \
184       integer x_val;                                                    \
185       generic_undump (x_val);                                           \
186       x = x_val;                                                        \
187     }                                                                   \
188   while (0)
189 #else
190 #define undump_int      generic_undump
191 #endif
192
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.  */
197
198 #define bwritebyte(f, b)    putc ((char) (b), f)
199 #define bwrite2bytes(f, h)                                              \
200   do                                                                    \
201     {                                                                   \
202       integer v = (integer) (h);                                        \
203       putc (v >> 8, f);  putc (v & 0xff, f);                            \
204     }                                                                   \
205   while (0)
206 #define bwrite4bytes(f, w)                                              \
207   do                                                                    \
208     {                                                                   \
209       integer v = (integer) (w);                                        \
210       putc (v >> 24, f); putc (v >> 16, f);                             \
211       putc (v >> 8, f);  putc (v & 0xff, f);                            \
212     }                                                                   \
213   while (0)
214
215
216 \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] */
221 /* #else */
222 /* #define      Xchr(x)         ((char) (x)) */
223 /* #endif */
224
225 /* Following used in tex0.c - make possible to use non ASCII */
226
227 #define Xchr(x) xchr[x]
228
229 /* following added from new texmf.c file 1996/Jan/12 */
230 /* these, of course are useless definitions since parameters not given */
231
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();
241
242 #ifdef TeX
243 extern bool maketextex();
244 extern bool maketextfm();
245 #else
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();
252 #endif /* not TeX */