3 Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
4 Copyright 2006-2013 Taco Hoekwater <taco@luatex.org>
6 This file is part of LuaTeX.
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.
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.
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/>. */
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
!!!
33 #include <w2c/config.h>
36 /* WEB2C macros and prototypes */
42 extern double rint(double x
);
45 # if defined(WIN32) || defined(__MINGW32__) || defined(__CYGWIN__)
46 extern char **suffixlist
; /* in luainit.w */
49 /* Replicate these here. They are hardcoded anyway */
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} */
57 #define LUA_COMPAT_MODULE 1
61 /* pdftexlib macros from ptexmac.h */
64 # define inline __inline
67 /**********************************************************************/
68 /* Pascal WEB macros */
70 # define max_integer 0x7FFFFFFF
71 # define max_dimen 0x3FFFFFFF
73 /**********************************************************************/
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
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__ )
86 # define append_char_to_buf(c, p, buf, buf_size) do { \
89 if (c == 13 || c == EOF) \
91 if (c != ' ' || (p > buf && p[-1] != 32)) { \
92 check_buf(p - buf + 1, (buf_size)); \
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) \
101 if (p - buf > 2 && p[-2] == 32) { \
108 # define remove_eol(p, buf) do { \
109 p = strend(buf) - 1; \
114 # define skip_char(p, c) if (*p == c) p++
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; \
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); \
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; \
134 # define define_array(T) \
135 T##_entry *T##_ptr, *T##_array = NULL; \
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
144 # define cmp_return(a, b) \
150 # define str_prefix(s1, s2) (strncmp((s1), (s2), strlen(s2)) == 0)
152 # include "tex/mainbody.h"
153 # include "tex/expand.h"
154 # include "tex/conditional.h"
156 # include "pdf/pdftypes.h" /* the backend data structure, shared between dvi and pdf */
158 # include "synctex.h"
160 # include "utils/avlstuff.h"
161 # include "utils/managed-sa.h"
163 # include "image/writeimg.h"
165 # include "dvi/dvigen.h"
167 # include "pdf/pdftables.h"
168 # include "pdf/pdfpagetree.h"
169 # include "pdf/pdfgen.h"
170 # include "pdf/pdfpage.h"
171 # include "pdf/pdfaction.h"
172 # include "pdf/pdfannot.h"
173 # include "pdf/pdfcolorstack.h"
174 # include "pdf/pdfdest.h"
175 # include "pdf/pdffont.h"
176 # include "pdf/pdfglyph.h"
177 # include "pdf/pdfimage.h"
178 # include "pdf/pdflink.h"
179 # include "pdf/pdflistout.h"
180 # include "pdf/pdfliteral.h"
181 # include "pdf/pdfobj.h"
182 # include "pdf/pdfoutline.h"
183 # include "pdf/pdfrule.h"
184 # include "pdf/pdfsaverestore.h"
185 # include "pdf/pdfsetmatrix.h"
186 # include "pdf/pdfshipout.h"
187 # include "pdf/pdfthread.h"
188 # include "pdf/pdfxform.h"
191 # include "font/luatexfont.h"
192 # include "font/mapfile.h"
194 # include "utils/utils.h"
195 # include "utils/unistring.h"
197 # include "image/writejbig2.h"
198 # include "image/pdftoepdf.h"
200 # include "lang/texlang.h"
202 # include "tex/textcodes.h"
203 # include "tex/mathcodes.h"
205 # include "tex/align.h"
206 # include "tex/directions.h"
207 # include "tex/errors.h"
208 # include "tex/inputstack.h"
209 # include "tex/stringpool.h"
210 # include "tex/textoken.h"
211 # include "tex/printing.h"
212 # include "tex/texfileio.h"
213 # include "tex/arithmetic.h"
214 # include "tex/nesting.h"
215 # include "tex/packaging.h"
216 # include "tex/linebreak.h"
217 # include "tex/postlinebreak.h"
218 # include "tex/scanning.h"
219 # include "tex/buildpage.h"
220 # include "tex/maincontrol.h"
221 # include "tex/dumpdata.h"
222 # include "tex/mainbody.h"
223 # include "tex/extensions.h"
224 # include "tex/texnodes.h"
226 # include "tex/texmath.h"
227 # include "tex/mlist.h"
228 # include "tex/primitive.h"
229 # include "tex/commands.h"
230 # include "tex/equivalents.h"
232 /**********************************************************************/
234 # include "tex/filename.h"
236 /**********************************************************************/
238 extern halfword
new_ligkern(halfword head
, halfword tail
);
239 extern halfword
handle_ligaturing(halfword head
, halfword tail
);
240 extern halfword
handle_kerning(halfword head
, halfword tail
);
242 halfword
lua_hpack_filter(
243 halfword head_node
, scaled size
, int pack_type
, int extrainfo
, int d
, halfword a
);
244 void lua_node_filter(
245 int filterid
, int extrainfo
, halfword head_node
,
246 halfword
* tail_node
);
247 halfword
lua_vpack_filter(
248 halfword head_node
, scaled size
, int pack_type
, scaled maxd
, int extrainfo
, int d
, halfword a
);
249 void lua_node_filter_s(
250 int filterid
, int extrainfo
);
251 int lua_linebreak_callback(
252 int is_broken
, halfword head_node
, halfword
* new_head
);
253 int lua_appendtovlist_callback(
254 halfword box
, int location
, halfword prev_depth
, boolean is_mirrored
,
255 halfword
* result
, int * next_depth
, boolean
* prev_set
);
257 void lua_pdf_literal(PDF pdf
, int i
);
258 void copy_pdf_literal(pointer r
, pointer p
);
259 void free_pdf_literal(pointer p
);
260 void show_pdf_literal(pointer p
);
262 void copy_late_lua(pointer r
, pointer p
);
263 void copy_user_lua(pointer r
, pointer p
);
264 void free_late_lua(pointer p
);
265 void free_user_lua(pointer p
);
266 void show_late_lua(pointer p
);
268 void load_tex_patterns(int curlang
, halfword head
);
269 void load_tex_hyphenation(int curlang
, halfword head
);
273 void dump_luac_registers(void);
274 void undump_luac_registers(void);
277 void luacstring_start(int n
);
278 void luacstring_close(int n
);
279 int luacstring_cattable(void);
280 int luacstring_input(void);
281 int luacstring_partial(void);
282 int luacstring_final_line(void);
285 int visible_last_node_type(int n
);
286 void print_node_mem_stats(void);
289 void vf_out_image(PDF pdf
, unsigned i
);
291 /* lua/ltexiolib.c */
292 void flush_loggable_info(void);
294 /* lua/luastuff.w and lua/luajitstuff.w */
295 void luafunctioncall(int slot
);
298 void luatokencall(int p
, int nameptr
);
299 extern void late_lua(PDF pdf
, halfword p
);
301 extern void check_texconfig_init(void);
303 scaled
divide_scaled(scaled s
, scaled m
, int dd
);
304 scaled
divide_scaled_n(double s
, double m
, double d
);
306 # include "tex/texdeffont.h"
307 # include "luatexcallbackids.h"
309 extern boolean
get_callback(lua_State
* L
, int i
);
311 /* Additions to texmfmp.h for pdfTeX */
313 /* mark a char in font */
314 # define pdf_mark_char(f,c) set_char_used(f,c,true)
316 /* test whether a char in font is marked */
317 # define pdf_char_marked char_used
319 # define voidcast(a) (void *)(a)
320 # define fixmemcast(a) (smemory_word *)(a)
322 extern void do_vf(internal_font_number tmp_f
);
324 /* This routine has to return four values. */
325 # define dateandtime(i,j,k,l) get_date_and_time (&(i), &(j), &(k), &(l))
326 extern void get_date_and_time(int *, int *, int *, int *);
328 /* Get high-res time info. */
329 # define seconds_and_micros(i,j) get_seconds_and_micros (&(i), &(j))
330 extern void get_seconds_and_micros(int *, int *);
332 /* This routine has to return a scaled value. */
333 extern int getrandomseed(void);
335 /* Copy command-line arguments into the buffer, despite the name. */
336 extern void topenin(void);
338 /* Can't prototype this since it uses poolpointer and ASCIIcode, which
339 are defined later in mfd.h, and mfd.h uses stuff from here. */
340 /* Therefore the department of ugly hacks decided to move this declaration
341 to the *coerce.h files. */
342 /* extern void calledit (); */
344 /* Set an array size from texmf.cnf. */
345 /*extern void setupboundvariable(integer *, const_string, integer);*/
347 /* here are a few functions that used to be in coerce.h */
349 extern str_number
getjobname(str_number
);
350 extern str_number
makefullnamestring(void);
352 # include <kpathsea/version.h>
354 extern PDF static_pdf
;
356 extern string
normalize_quotes(const_string name
, const_string mesg
);
357 extern string dump_name
;
358 extern const_string c_job_name
;
360 extern halfword
*check_isnode(lua_State
* L
, int i
);
361 extern void lua_nodelib_push_fast(lua_State
* L
, halfword n
);
363 extern halfword
list_node_mem_usage(void);
365 extern halfword
*check_isnode(lua_State
* L
, int ud
);
367 extern extinfo
*get_charinfo_vert_variants(charinfo
* ci
);
368 extern extinfo
*get_charinfo_hor_variants(charinfo
* ci
);
369 extern void set_charinfo_hor_variants(charinfo
* ci
, extinfo
* ext
);
370 extern void set_charinfo_vert_variants(charinfo
* ci
, extinfo
* ext
);
372 extern extinfo
*copy_variants(extinfo
* o
);
374 extern int program_name_set
; /* in lkpselib.c */
376 extern int kpse_init
; /* in luainit.w */
377 extern int kpse_available(const char * m
); /* in texfileio.w */
379 #endif /* PTEXLIB_H */