1 /* ptexlib.h 2 3 Copyright 1996-2006 Han The Thanh <thanh@pdftex.org> 4 Copyright 2006-2013 Taco Hoekwater <taco@luatex.org> 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 # define pdftex_version_string "-2.00.0" 57 /* current \pdfTeX\ version */ 58 # define pdftex_version 200 /* \.{\\pdftexversion} */ 59 # define pdftex_revision "0" /* \.{\\pdftexrevision} */ 60 61 #define LUA_COMPAT_MODULE 1 62 # include "lua.h" 63 64 65 /* pdftexlib macros from ptexmac.h */ 66 67 # ifdef WIN32 68 # define inline __inline 69 # endif 70 71 /**********************************************************************/ 72 /* Pascal WEB macros */ 73 74 # define max_integer 0x7FFFFFFF 75 # define max_dimen 0x3FFFFFFF 76 77 /**********************************************************************/ 78 79 # define PRINTF_BUF_SIZE 1024 80 # define MAX_CSTRING_LEN 1024 * 1024 81 # define MAX_PSTRING_LEN 1024 82 # define SMALL_BUF_SIZE 256 83 # define SMALL_ARRAY_SIZE 256 84 85 # define check_buf(size, buf_size) \ 86 if ((unsigned)(size) > (unsigned)(buf_size)) \ 87 luatex_fail("buffer overflow: %d > %d at file %s, line %d", \ 88 (int)(size), (int)(buf_size), __FILE__, __LINE__ ) 89 90 # define append_char_to_buf(c, p, buf, buf_size) do { \ 91 if (c == 9) \ 92 c = 32; \ 93 if (c == 13 || c == EOF) \ 94 c = 10; \ 95 if (c != ' ' || (p > buf && p[-1] != 32)) { \ 96 check_buf(p - buf + 1, (buf_size)); \ 97 *p++ = c; \ 98 } \ 99 } while (0) 100 101 # define append_eol(p, buf, buf_size) do { \ 102 check_buf(p - buf + 2, (buf_size)); \ 103 if (p - buf > 1 && p[-1] != 10) \ 104 *p++ = 10; \ 105 if (p - buf > 2 && p[-2] == 32) { \ 106 p[-2] = 10; \ 107 p--; \ 108 } \ 109 *p = 0; \ 110 } while (0) 111 112 # define remove_eol(p, buf) do { \ 113 p = strend(buf) - 1; \ 114 if (*p == 10) \ 115 *p = 0; \ 116 } while (0) 117 118 # define skip(p, c) if (*p == c) p++ 119 120 # define alloc_array(T, n, s) do { \ 121 if (T##_array == NULL) { \ 122 T##_limit = (size_t)(s); \ 123 if ((unsigned)(n) > (unsigned)T##_limit) \ 124 T##_limit = (size_t)(n); \ 125 T##_array = xtalloc((unsigned)T##_limit, T##_entry); \ 126 T##_ptr = T##_array; \ 127 } \ 128 else if ((unsigned)(T##_ptr - T##_array + (unsigned)(n)) > (unsigned)(T##_limit)) { \ 129 size_t last_ptr_index = (size_t)(T##_ptr - T##_array); \ 130 T##_limit *= 2; \ 131 if ((unsigned)(T##_ptr - T##_array + (unsigned)(n)) > (unsigned)(T##_limit)) \ 132 T##_limit = (size_t)(T##_ptr - T##_array + (unsigned)(n)); \ 133 xretalloc(T##_array, (unsigned)T##_limit, T##_entry); \ 134 T##_ptr = T##_array + last_ptr_index; \ 135 } \ 136 } while (0) 137 138 # define define_array(T) \ 139 T##_entry *T##_ptr, *T##_array = NULL; \ 140 size_t T##_limit 141 142 # define xfree(a) do { free(a); a = NULL; } while (0) 143 # define dxfree(a,b) do { free(a); a = b; } while (0) 144 # define strend(s) strchr(s, 0) 145 # define xtalloc XTALLOC 146 # define xretalloc XRETALLOC 147 148 # define cmp_return(a, b) \ 149 if ((a) > (b)) \ 150 return 1; \ 151 if ((a) < (b)) \ 152 return -1 153 154 # define str_prefix(s1, s2) (strncmp((s1), (s2), strlen(s2)) == 0) 155 156 /* that was ptexmac.h */ 157 158 # include "tex/mainbody.h" 159 # include "tex/expand.h" 160 # include "tex/conditional.h" 161 # include "pdf/pdftypes.h" 162 163 /* synctex */ 164 # include "synctex.h" 165 166 # include "utils/avlstuff.h" 167 # include "utils/managed-sa.h" 168 # include "image/writeimg.h" 169 # include "dvi/dvigen.h" 170 # include "pdf/pdfpagetree.h" 171 # include "pdf/pdfgen.h" 172 # include "pdf/pdfpage.h" 173 # include "pdf/pdftables.h" 174 175 # include "pdf/pdfaction.h" 176 # include "pdf/pdfannot.h" 177 # include "pdf/pdfcolorstack.h" 178 # include "pdf/pdfdest.h" 179 # include "pdf/pdffont.h" 180 # include "pdf/pdfglyph.h" 181 # include "pdf/pdfimage.h" 182 # include "pdf/pdflink.h" 183 # include "pdf/pdflistout.h" 184 # include "pdf/pdfliteral.h" 185 # include "pdf/pdfluaapi.h" 186 # include "pdf/pdfobj.h" 187 # include "pdf/pdfoutline.h" 188 # include "pdf/pdfrule.h" 189 # include "pdf/pdfsaverestore.h" 190 # include "pdf/pdfsetmatrix.h" 191 # include "pdf/pdfshipout.h" 192 # include "pdf/pdfthread.h" 193 # include "pdf/pdfxform.h" 194 195 # include "lua/luagen.h" 196 197 # include "luascripts/pdflua.h" 198 199 # include "font/luatexfont.h" 200 # include "font/mapfile.h" 201 # include "utils/utils.h" 202 # include "utils/unistring.h" 203 # include "image/writejbig2.h" 204 # include "image/pdftoepdf.h" 205 206 # include "lang/texlang.h" 207 208 # include "tex/textcodes.h" 209 # include "tex/mathcodes.h" 210 211 # include "tex/align.h" 212 # include "tex/directions.h" 213 # include "tex/errors.h" 214 # include "tex/inputstack.h" 215 # include "tex/stringpool.h" 216 # include "tex/textoken.h" 217 # include "tex/printing.h" 218 # include "tex/texfileio.h" 219 # include "tex/arithmetic.h" 220 # include "tex/nesting.h" 221 # include "tex/packaging.h" 222 # include "tex/linebreak.h" 223 # include "tex/postlinebreak.h" 224 # include "tex/scanning.h" 225 # include "tex/buildpage.h" 226 # include "tex/maincontrol.h" 227 # include "tex/dumpdata.h" 228 # include "tex/mainbody.h" 229 # include "tex/extensions.h" 230 # include "tex/texnodes.h" 231 232 # include "tex/texmath.h" 233 # include "tex/mlist.h" 234 # include "tex/primitive.h" 235 # include "tex/commands.h" 236 # include "tex/equivalents.h" 237 238 /**********************************************************************/ 239 240 # include "tex/filename.h" 241 242 /* lua/luainit.c */ 243 extern void write_svnversion(char *a); 244 245 /**********************************************************************/ 246 247 extern halfword new_ligkern(halfword head, halfword tail); 248 extern halfword handle_ligaturing(halfword head, halfword tail); 249 extern halfword handle_kerning(halfword head, halfword tail); 250 251 halfword lua_hpack_filter(halfword head_node, scaled size, int pack_type, 252 int extrainfo, int d); 253 void lua_node_filter(int filterid, int extrainfo, halfword head_node, 254 halfword * tail_node); 255 halfword lua_vpack_filter(halfword head_node, scaled size, int pack_type, 256 scaled maxd, int extrainfo, int d); 257 void lua_node_filter_s(int filterid, int extrainfo); 258 int lua_linebreak_callback(int is_broken, halfword head_node, 259 halfword * new_head); 260 261 void lua_pdf_literal(PDF pdf, int i); 262 void copy_pdf_literal(pointer r, pointer p); 263 void free_pdf_literal(pointer p); 264 void show_pdf_literal(pointer p); 265 266 void copy_late_lua(pointer r, pointer p); 267 void copy_user_lua(pointer r, pointer p); 268 void free_late_lua(pointer p); 269 void free_user_lua(pointer p); 270 void show_late_lua(pointer p); 271 272 void load_tex_patterns(int curlang, halfword head); 273 void load_tex_hyphenation(int curlang, halfword head); 274 275 /* lua/llualib.c */ 276 277 void dump_luac_registers(void); 278 void undump_luac_registers(void); 279 280 /* lua/ltexlib.c */ 281 void luacstring_start(int n); 282 void luacstring_close(int n); 283 int luacstring_cattable(void); 284 int luacstring_input(void); 285 int luacstring_partial(void); 286 int luacstring_final_line(void); 287 288 /* lua/luatoken.c */ 289 void do_get_token_lua(int callback_id); 290 291 /* lua/luanode.c */ 292 int visible_last_node_type(int n); 293 void print_node_mem_stats(void); 294 295 /* lua/limglib.c */ 296 void vf_out_image(PDF pdf, unsigned i); 297 298 /* lua/ltexiolib.c */ 299 void flush_loggable_info(void); 300 301 /* lua/luastuff.w and lua/luajitstuff.w */ 302 void luafunctioncall(int slot); 303 304 /* lua/luastuff.c */ 305 void luatokencall(int p, int nameptr); 306 extern void late_lua(PDF pdf, halfword p); 307 308 extern void check_texconfig_init(void); 309 310 scaled divide_scaled(scaled s, scaled m, int dd); 311 scaled divide_scaled_n(double s, double m, double d); 312 313 # include "tex/texdeffont.h" 314 # include "luatexcallbackids.h" 315 316 extern boolean get_callback(lua_State * L, int i); 317 318 /* Additions to texmfmp.h for pdfTeX */ 319 320 /* mark a char in font */ 321 # define pdf_mark_char(f,c) set_char_used(f,c,true) 322 323 /* test whether a char in font is marked */ 324 # define pdf_char_marked char_used 325 326 # define pdfassert assert 327 # define voidcast(a) (void *)(a) 328 # define fixmemcast(a) (smemory_word *)(a) 329 330 extern void do_vf(internal_font_number tmp_f); 331 332 /* This routine has to return four values. */ 333 # define dateandtime(i,j,k,l) get_date_and_time (&(i), &(j), &(k), &(l)) 334 extern void get_date_and_time(int *, int *, int *, int *); 335 336 /* Get high-res time info. */ 337 # define seconds_and_micros(i,j) get_seconds_and_micros (&(i), &(j)) 338 extern void get_seconds_and_micros(int *, int *); 339 340 /* This routine has to return a scaled value. */ 341 extern int getrandomseed(void); 342 343 /* Copy command-line arguments into the buffer, despite the name. */ 344 extern void topenin(void); 345 346 /* Can't prototype this since it uses poolpointer and ASCIIcode, which 347 are defined later in mfd.h, and mfd.h uses stuff from here. */ 348 /* Therefore the department of ugly hacks decided to move this declaration 349 to the *coerce.h files. */ 350 /* extern void calledit (); */ 351 352 /* Set an array size from texmf.cnf. */ 353 /*extern void setupboundvariable(integer *, const_string, integer);*/ 354 355 /* here are a few functions that used to be in coerce.h */ 356 357 extern str_number getjobname(str_number); 358 extern str_number makefullnamestring(void); 359 360 # include <kpathsea/version.h> 361 362 extern PDF static_pdf; 363 364 extern string normalize_quotes(const_string name, const_string mesg); 365 extern string dump_name; 366 extern const_string c_job_name; 367 368 extern halfword *check_isnode(lua_State * L, int ud); 369 extern void lua_nodelib_push_fast(lua_State * L, halfword n); 370 371 extern void lua_nodelib_push_fast(lua_State * L, halfword n); 372 373 extern halfword list_node_mem_usage(void); 374 375 extern halfword *check_isnode(lua_State * L, int ud); 376 377 extern extinfo *get_charinfo_vert_variants(charinfo * ci); 378 extern extinfo *get_charinfo_hor_variants(charinfo * ci); 379 extern void set_charinfo_hor_variants(charinfo * ci, extinfo * ext); 380 extern void set_charinfo_vert_variants(charinfo * ci, extinfo * ext); 381 382 extern extinfo *copy_variants(extinfo * o); 383 384 extern int program_name_set; /* in lkpselib.c */ 385 386 387 388 #endif /* PTEXLIB_H */ 389