Debian Codegraph @

texk/web2c/luatexdir/ptexlib.h

raw
1 /* ptexlib.h
2
3 Copyright 1996-2006 Han The Thanh <[email protected]>
4 Copyright 2006-2013 Taco Hoekwater <[email protected]>
5
6 This file is part of LuaTeX.
7
8 LuaTeX is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your
11 option) any later version.
12
13 LuaTeX is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
20
21
22 #ifndef PTEXLIB_H
23 # define PTEXLIB_H
24
25 /* Try to detect if a system header has already been included. */
26 #if (defined(__linux__) && defined(_FEATURES_H)) || \
27 (defined(_MSC_VER) && (defined(_INC_CRTDEFS) || defined(_OFF_T_DEFINED))) || \
28 (defined(__MINGW32__) && defined(__MINGW_H))
29 ptexlib.h must be included first!!!
30 #endif
31
32 #ifdef HAVE_CONFIG_H
33 #include <w2c/config.h>
34 #endif
35
36 /* WEB2C macros and prototypes */
37 # include "luatex.h"
38
39 # include "lib/lib.h"
40
41 # ifdef _MSC_VER
42 extern double rint(double x);
43 # endif
44
45 # if defined(WIN32) || defined(__MINGW32__) || defined(__CYGWIN__)
46 extern char **suffixlist; /* in luainit.w */
47 # endif
48
49 /* Replicate these here. They are hardcoded anyway */
50
51 # define eTeX_version_string "2.2" /* current \eTeX\ version */
52 # define eTeX_version 2 /* \.{\\eTeXversion} */
53 # define eTeX_minor_version 2 /* \.{\\eTeXminorversion} */
54 # define eTeX_revision ".2" /* \.{\\eTeXrevision} */
55
56
57 #define LUA_COMPAT_MODULE 1
58 # include "lua.h"
59
60
61 /* pdftexlib macros from ptexmac.h */
62
63 # ifdef WIN32
64 # define inline __inline
65 # endif
66
67 /**********************************************************************/
68 /* Pascal WEB macros */
69
70 # define max_integer 0x7FFFFFFF
71 # define max_dimen 0x3FFFFFFF
72
73 /**********************************************************************/
74
75 # define PRINTF_BUF_SIZE 1024
76 # define MAX_CSTRING_LEN 1024 * 1024
77 # define MAX_PSTRING_LEN 1024
78 # define SMALL_BUF_SIZE 256
79 # define SMALL_ARRAY_SIZE 256
80
81 # define check_buf(size, buf_size) \
82 if ((unsigned)(size) > (unsigned)(buf_size)) \
83 formatted_error("internal","buffer overflow: %d > %d at file %s, line %d", \
84 (int)(size), (int)(buf_size), __FILE__, __LINE__ )
85
86 # define append_char_to_buf(c, p, buf, buf_size) do { \
87 if (c == 9) \
88 c = 32; \
89 if (c == 13 || c == EOF) \
90 c = 10; \
91 if (c != ' ' || (p > buf && p[-1] != 32)) { \
92 check_buf(p - buf + 1, (buf_size)); \
93 *p++ = c; \
94 } \
95 } while (0)
96
97 # define append_eol(p, buf, buf_size) do { \
98 check_buf(p - buf + 2, (buf_size)); \
99 if (p - buf > 1 && p[-1] != 10) \
100 *p++ = 10; \
101 if (p - buf > 2 && p[-2] == 32) { \
102 p[-2] = 10; \
103 p--; \
104 } \
105 *p = 0; \
106 } while (0)
107
108 # define remove_eol(p, buf) do { \
109 p = strend(buf) - 1; \
110 if (*p == 10) \
111 *p = 0; \
112 } while (0)
113
114 # define skip_char(p, c) if (*p == c) p++
115
116 # define alloc_array(T, n, s) do { \
117 if (T##_array == NULL) { \
118 T##_limit = (size_t)(s); \
119 if ((unsigned)(n) > (unsigned)T##_limit) \
120 T##_limit = (size_t)(n); \
121 T##_array = xtalloc((unsigned)T##_limit, T##_entry); \
122 T##_ptr = T##_array; \
123 } \
124 else if ((unsigned)(T##_ptr - T##_array + (unsigned)(n)) > (unsigned)(T##_limit)) { \
125 size_t last_ptr_index = (size_t)(T##_ptr - T##_array); \
126 T##_limit *= 2; \
127 if ((unsigned)(T##_ptr - T##_array + (unsigned)(n)) > (unsigned)(T##_limit)) \
128 T##_limit = (size_t)(T##_ptr - T##_array + (unsigned)(n)); \
129 xretalloc(T##_array, (unsigned)T##_limit, T##_entry); \
130 T##_ptr = T##_array + last_ptr_index; \
131 } \
132 } while (0)
133
134 # define define_array(T) \
135 T##_entry *T##_ptr, *T##_array = NULL; \
136 size_t T##_limit
137
138 # define xfree(a) do { free(a); a = NULL; } while (0)
139 # define dxfree(a,b) do { free(a); a = b; } while (0)
140 # define strend(s) strchr(s, 0)
141 # define xtalloc XTALLOC
142 # define xretalloc XRETALLOC
143
144 # define cmp_return(a, b) \
145 if ((a) > (b)) \
146 return 1; \
147 if ((a) < (b)) \
148 return -1
149
150 # define str_prefix(s1, s2) (strncmp((s1), (s2), strlen(s2)) == 0)
151
152 # include "tex/mainbody.h"
153 # include "tex/expand.h"
154 # include "tex/conditional.h"
155
156 # include "pdf/pdftypes.h" /* the backend data structure, shared between dvi and pdf (might move to |tex/backend| */
157 # include "tex/backend.h" /* more backend data */
158
159 # include "synctex.h"
160
161 # include "utils/avlstuff.h"
162 # include "utils/managed-sa.h"
163
164 # include "image/writeimg.h"
165
166 # include "dvi/dvigen.h"
167
168 # include "pdf/pdftables.h"
169 # include "pdf/pdfpagetree.h"
170 # include "pdf/pdfgen.h"
171 # include "pdf/pdfpage.h"
172 # include "pdf/pdfaction.h"
173 # include "pdf/pdfannot.h"
174 # include "pdf/pdfcolorstack.h"
175 # include "pdf/pdfdest.h"
176 # include "pdf/pdffont.h"
177 # include "pdf/pdfglyph.h"
178 # include "pdf/pdfimage.h"
179 # include "pdf/pdflink.h"
180 # include "pdf/pdflistout.h"
181 # include "pdf/pdfliteral.h"
182 # include "pdf/pdfobj.h"
183 # include "pdf/pdfoutline.h"
184 # include "pdf/pdfrule.h"
185 # include "pdf/pdfsaverestore.h"
186 # include "pdf/pdfsetmatrix.h"
187 # include "pdf/pdfshipout.h"
188 # include "pdf/pdfthread.h"
189 # include "pdf/pdfxform.h"
190
191
192 # include "font/luatexfont.h"
193 # include "font/mapfile.h"
194
195 # include "utils/utils.h"
196 # include "utils/unistring.h"
197
198 # include "image/writejbig2.h"
199 # include "image/pdftoepdf.h"
200
201 # include "lang/texlang.h"
202
203 # include "tex/textcodes.h"
204 # include "tex/mathcodes.h"
205
206 # include "tex/align.h"
207 # include "tex/directions.h"
208 # include "tex/errors.h"
209 # include "tex/inputstack.h"
210 # include "tex/stringpool.h"
211 # include "tex/textoken.h"
212 # include "tex/printing.h"
213 # include "tex/texfileio.h"
214 # include "tex/arithmetic.h"
215 # include "tex/nesting.h"
216 # include "tex/packaging.h"
217 # include "tex/linebreak.h"
218 # include "tex/postlinebreak.h"
219 # include "tex/scanning.h"
220 # include "tex/buildpage.h"
221 # include "tex/maincontrol.h"
222 # include "tex/dumpdata.h"
223 # include "tex/mainbody.h"
224 # include "tex/extensions.h"
225 # include "tex/texnodes.h"
226
227 # include "tex/texmath.h"
228 # include "tex/mlist.h"
229 # include "tex/primitive.h"
230 # include "tex/commands.h"
231 # include "tex/equivalents.h"
232
233 /**********************************************************************/
234
235 # include "tex/filename.h"
236
237 /**********************************************************************/
238
239 extern halfword new_ligkern(halfword head, halfword tail);
240 extern halfword handle_ligaturing(halfword head, halfword tail);
241 extern halfword handle_kerning(halfword head, halfword tail);
242
243 halfword lua_hpack_filter(
244 halfword head_node, scaled size, int pack_type, int extrainfo, int d, halfword a);
245 void lua_node_filter(
246 int filterid, int extrainfo, halfword head_node,
247 halfword * tail_node);
248 halfword lua_vpack_filter(
249 halfword head_node, scaled size, int pack_type, scaled maxd, int extrainfo, int d, halfword a);
250 void lua_node_filter_s(
251 int filterid, int extrainfo);
252 int lua_linebreak_callback(
253 int is_broken, halfword head_node, halfword * new_head);
254 int lua_appendtovlist_callback(
255 halfword box, int location, halfword prev_depth, boolean is_mirrored,
256 halfword * result, int * next_depth, boolean * prev_set);
257
258 void lua_pdf_literal(PDF pdf, int i, int noline);
259 void copy_pdf_literal(pointer r, pointer p);
260 void free_pdf_literal(pointer p);
261 void show_pdf_literal(pointer p);
262
263 void copy_late_lua(pointer r, pointer p);
264 void copy_user_lua(pointer r, pointer p);
265 void free_late_lua(pointer p);
266 void free_user_lua(pointer p);
267 void show_late_lua(pointer p);
268
269 void load_tex_patterns(int curlang, halfword head);
270 void load_tex_hyphenation(int curlang, halfword head);
271
272 /* lua/llualib.c */
273
274 void dump_luac_registers(void);
275 void undump_luac_registers(void);
276
277 /* lua/ltexlib.c */
278 void luacstring_start(int n);
279 void luacstring_close(int n);
280 int luacstring_cattable(void);
281 int luacstring_input(halfword *n);
282 int luacstring_partial(void);
283 int luacstring_final_line(void);
284
285 /* lua/luanode.c */
286 int visible_last_node_type(int n);
287 void print_node_mem_stats(void);
288
289 /* lua/limglib.c */
290 void vf_out_image(PDF pdf, unsigned i);
291
292 /* lua/ltexiolib.c */
293 void flush_loggable_info(void);
294
295 /* lua/luastuff.w */
296 void luafunctioncall(int slot);
297 void luabytecodecall(int slot);
298
299 /* lua/luastuff.c */
300 void luatokencall(int p, int nameptr);
301 extern void late_lua(PDF pdf, halfword p);
302
303 extern void check_texconfig_init(void);
304
305 scaled divide_scaled(scaled s, scaled m, int dd);
306 scaled divide_scaled_n(double s, double m, double d);
307
308 # include "tex/texdeffont.h"
309 # include "luatexcallbackids.h"
310
311 extern boolean get_callback(lua_State * L, int i);
312
313 /* Additions to texmfmp.h for pdfTeX */
314
315 /* mark a char in font */
316 # define pdf_mark_char(f,c) set_char_used(f,c,true)
317
318 /* test whether a char in font is marked */
319 # define pdf_char_marked char_used
320
321 # define voidcast(a) (void *)(a)
322 # define fixmemcast(a) (smemory_word *)(a)
323
324 extern void do_vf(internal_font_number tmp_f);
325
326 /* This routine has to return four values. */
327 # define dateandtime(i,j,k,l) get_date_and_time (&(i), &(j), &(k), &(l))
328 extern void get_date_and_time(int *, int *, int *, int *);
329
330 /* Get high-res time info. */
331 # define seconds_and_micros(i,j) get_seconds_and_micros (&(i), &(j))
332 extern void get_seconds_and_micros(int *, int *);
333
334 /* This routine has to return a scaled value. */
335 extern int getrandomseed(void);
336
337 /* Copy command-line arguments into the buffer, despite the name. */
338 extern void topenin(void);
339
340 /* Can't prototype this since it uses poolpointer and ASCIIcode, which
341 are defined later in mfd.h, and mfd.h uses stuff from here. */
342 /* Therefore the department of ugly hacks decided to move this declaration
343 to the *coerce.h files. */
344 /* extern void calledit (); */
345
346 /* Set an array size from texmf.cnf. */
347 /*extern void setupboundvariable(integer *, const_string, integer);*/
348
349 /* here are a few functions that used to be in coerce.h */
350
351 extern str_number getjobname(str_number);
352 extern str_number makefullnamestring(void);
353
354 # include <kpathsea/version.h>
355
356 extern PDF static_pdf;
357
358 extern string normalize_quotes(const_string name, const_string mesg);
359 extern string dump_name;
360 extern const_string c_job_name;
361
362 extern halfword *check_isnode(lua_State * L, int i);
363 extern void lua_nodelib_push_fast(lua_State * L, halfword n);
364
365 extern halfword list_node_mem_usage(void);
366
367 extern halfword *check_isnode(lua_State * L, int ud);
368
369 extern extinfo *get_charinfo_vert_variants(charinfo * ci);
370 extern extinfo *get_charinfo_hor_variants(charinfo * ci);
371 extern void set_charinfo_hor_variants(charinfo * ci, extinfo * ext);
372 extern void set_charinfo_vert_variants(charinfo * ci, extinfo * ext);
373
374 extern extinfo *copy_variants(extinfo * o);
375
376 extern int program_name_set; /* in lkpselib.c */
377
378 extern int kpse_init; /* in luainit.w */
379 extern int kpse_available(const char * m); /* in texfileio.w */
380
381 #endif /* PTEXLIB_H */