3
% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
5
% This file is part of LuaTeX.
7
% LuaTeX is free software; you can redistribute it and/or modify it under
8
% the terms of the GNU General Public License as published by the Free
9
% Software Foundation; either version 2 of the License, or (at your
10
% option) any later version.
12
% LuaTeX is distributed in the hope that it will be useful, but WITHOUT
13
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
% FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15
% License for more details.
17
% You should have received a copy of the GNU General Public License along
18
% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
21
#include "openbsd-compat.h"
22
#ifdef HAVE_ASPRINTF /* asprintf is not defined in openbsd-compat.h, but in stdio.h */
25
#include <kpathsea/c-stat.h>
27
#include "lua/luatex-api.h"
30
static const char _svn_version[] =
31
"$Id: luainit.w 3621 2010-04-15 16:08:22Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.1/source/texk/web2c/luatexdir/lua/luainit.w $";
36
This file is getting a bit messy, but it is not simple to fix unilaterally.
38
Better to wait until Karl has some time (after texlive 2008) so we can
39
synchronize with kpathsea. One problem, for instance, is that I would
40
like to resolve the full executable path. |kpse_set_program_name()| does
41
that, indirectly (by setting SELFAUTOLOC in the environment), but it
42
does much more, making it hard to use for our purpose.
44
In fact, it sets three C variables:
46
|program_invocation_name| |program_invocation_short_name| |kpse->program_name|
48
and four environment variables:
50
SELFAUTOLOC SELFAUTODIR SELFAUTOPARENT progname
53
const_string LUATEX_IHELP[] = {
54
"Usage: luatex --lua=FILE [OPTION]... [TEXNAME[.tex]] [COMMANDS]",
55
" or: luatex --lua=FILE [OPTION]... \\FIRST-LINE",
56
" or: luatex --lua=FILE [OPTION]... &FMT ARGS",
57
" Run LuaTeX on TEXNAME, usually creating TEXNAME.pdf.",
58
" Any remaining COMMANDS are processed as luatex input, after TEXNAME is read.",
60
" Alternatively, if the first non-option argument begins with a backslash,",
61
" luatex interprets all non-option arguments as an input line.",
63
" Alternatively, if the first non-option argument begins with a &, the",
64
" next word is taken as the FMT to read, overriding all else. Any",
65
" remaining arguments are processed as above.",
67
" If no arguments or options are specified, prompt for input.",
69
" The following regular options are understood: ",
71
" --8bit ignored, input is assumed to be in UTF-8 encoding",
72
" --credits display credits and exit",
73
" --debug-format enable format debugging",
74
" --default-translate-file= ignored, input is assumed to be in UTF-8 encoding",
75
" --disable-write18 disable \\write18{SHELL COMMAND}",
76
" --draftmode switch on draft mode (generates no output PDF)",
77
" --enable-write18 enable \\write18{SHELL COMMAND}",
78
" --etex ignored, the etex extensions are always active",
79
" --[no-]file-line-error disable/enable file:line:error style messages",
80
" --[no-]file-line-error-style aliases of --[no-]file-line-error",
81
" --fmt=FORMAT load the format file FORMAT",
82
" --halt-on-error stop processing at the first error",
83
" --help display help and exit",
84
" --ini be iniluatex, for dumping formats",
85
" --interaction=STRING set interaction mode (STRING=batchmode/nonstopmode/scrollmode/errorstopmode)",
86
" --jobname=STRING set the job name to STRING",
87
" --kpathsea-debug=NUMBER set path searching debugging flags according to the bits of NUMBER",
88
" --lua=s load and execute a lua initialization script",
89
" --[no-]mktex=FMT disable/enable mktexFMT generation (FMT=tex/tfm)",
90
" --nosocket disable the lua socket library",
91
" --output-comment=STRING use STRING for DVI file comment instead of date (no effect for PDF)",
92
" --output-directory=DIR use DIR as the directory to write files to",
93
" --output-format=FORMAT use FORMAT for job output; FORMAT is 'dvi' or 'pdf'",
94
" --[no-]parse-first-line disable/enable parsing of the first line of the input file",
95
" --progname=STRING set the program name to STRING",
96
" --recorder enable filename recorder",
97
" --safer disable easily exploitable lua commands",
98
" --[no-]shell-escape disable/enable \\write18{SHELL COMMAND}",
99
" --shell-restricted restrict \\write18 to a list of commands given in texmf.cnf",
100
" --synctex=NUMBER enable synctex",
101
" --translate-file= ignored, input is assumed to be in UTF-8 encoding",
102
" --version display version and exit",
104
"Alternate behaviour models can be obtained by special switches",
106
" --luaonly run a lua file, then exit",
107
" --luaconly byte-compile a lua file, then exit",
109
"See the reference manual for more information about the startup process.",
113
@ The return value will be the directory of the executable, e.g.: \.{c:/TeX/bin}
115
static char *ex_selfdir(char *argv0)
118
char path[PATH_MAX], *fp;
120
/* SearchPath() always gives back an absolute directory */
121
if (SearchPath(NULL, argv0, ".exe", PATH_MAX, path, NULL) == 0)
122
FATAL1("Can't determine where the executable %s is.\n", argv0);
123
/* slashify the dirname */
124
for (fp = path; fp && *fp; fp++)
127
return xdirname(path);
129
return kpse_selfdir(argv0);
135
prepare_cmdline(lua_State * L, char **argv, int argc, int zero_offset)
139
luaL_checkstack(L, argc + 3, "too many arguments to script");
140
lua_createtable(L, 0, 0);
141
for (i = 0; i < argc; i++) {
142
lua_pushstring(L, argv[i]);
143
lua_rawseti(L, -2, (i - zero_offset));
145
lua_setglobal(L, "arg");
146
lua_getglobal(L, "os");
147
s = ex_selfdir(argv[0]);
148
lua_pushstring(L, s);
150
lua_setfield(L, -2, "selfdir");
155
string input_name = NULL;
157
static string user_progname = NULL;
159
char *startup_filename = NULL;
163
int safer_option = 0;
164
int nosocket_option = 0;
166
@ Reading the options.
168
@ Test whether getopt found an option ``A''.
169
Assumes the option index is in the variable |option_index|, and the
170
option table in a variable |long_options|.
173
#define ARGUMENT_IS(a) STREQ (long_options[option_index].name, a)
175
/* SunOS cc can't initialize automatic structs, so make this static. */
176
static struct option long_options[]
177
= { {"fmt", 1, 0, 0},
179
{"luaonly", 0, 0, 0},
180
{"safer", 0, &safer_option, 1},
181
{"nosocket", 0, &nosocket_option, 1},
183
{"ini", 0, &ini_version, 1},
184
{"interaction", 1, 0, 0},
185
{"halt-on-error", 0, &haltonerrorp, 1},
186
{"kpathsea-debug", 1, 0, 0},
187
{"progname", 1, 0, 0},
188
{"version", 0, 0, 0},
189
{"credits", 0, 0, 0},
190
{"recorder", 0, &recorder_enabled, 1},
192
{"output-comment", 1, 0, 0},
193
{"output-directory", 1, 0, 0},
194
{"draftmode", 0, 0, 0},
195
{"output-format", 1, 0, 0},
196
{"shell-escape", 0, &shellenabledp, 1},
197
{"no-shell-escape", 0, &shellenabledp, -1},
198
{"enable-write18", 0, &shellenabledp, 1},
199
{"disable-write18", 0, &shellenabledp, -1},
200
{"shell-restricted", 0, 0, 0},
201
{"debug-format", 0, &debug_format_file, 1},
202
{"file-line-error-style", 0, &filelineerrorstylep, 1},
203
{"no-file-line-error-style", 0, &filelineerrorstylep, -1},
204
/* Shorter option names for the above. */
205
{"file-line-error", 0, &filelineerrorstylep, 1},
206
{"no-file-line-error", 0, &filelineerrorstylep, -1},
207
{"jobname", 1, 0, 0},
208
{"parse-first-line", 0, &parsefirstlinep, 1},
209
{"no-parse-first-line", 0, &parsefirstlinep, -1},
210
{"translate-file", 1, 0, 0},
211
{"default-translate-file", 1, 0, 0},
214
{"no-mktex", 1, 0, 0},
215
/* Synchronization: just like "interaction" above */
216
{"synctex", 1, 0, 0},
221
static void parse_options(int argc, char **argv)
223
int g; /* `getopt' return code. */
225
char *firstfile = NULL;
226
opterr = 0; /* dont whine */
227
if ((strstr(argv[0], "luatexlua") != NULL) ||
228
(strstr(argv[0], "texlua") != NULL)) {
233
g = getopt_long_only(argc, argv, "+", long_options, &option_index);
235
if (g == -1) /* End of arguments, exit the loop. */
237
if (g == '?') /* Unknown option. */
240
assert(g == 0); /* We have no short option names. */
242
if (ARGUMENT_IS("luaonly")) {
246
} else if (ARGUMENT_IS("lua")) {
247
startup_filename = optarg;
248
lua_offset = (optind - 1);
251
} else if (ARGUMENT_IS("kpathsea-debug")) {
252
kpathsea_debug |= atoi(optarg);
254
} else if (ARGUMENT_IS("progname")) {
255
user_progname = optarg;
257
} else if (ARGUMENT_IS("jobname")) {
260
} else if (ARGUMENT_IS("fmt")) {
263
} else if (ARGUMENT_IS("output-directory")) {
264
output_directory = optarg;
266
} else if (ARGUMENT_IS("output-comment")) {
267
size_t len = strlen(optarg);
269
output_comment = optarg;
271
WARNING2("Comment truncated to 255 characters from %d. (%s)",
273
output_comment = (string) xmalloc(256);
274
strncpy(output_comment, optarg, 255);
275
output_comment[255] = 0;
278
} else if (ARGUMENT_IS("shell-restricted")) {
282
} else if (ARGUMENT_IS("output-format")) {
283
pdf_output_option = 1;
284
if (strcmp(optarg, "dvi") == 0) {
285
pdf_output_value = 0;
286
} else if (strcmp(optarg, "pdf") == 0) {
287
pdf_output_value = 2;
289
WARNING1("Ignoring unknown value `%s' for --output-format",
291
pdf_output_option = 0;
294
} else if (ARGUMENT_IS("draftmode")) {
295
pdf_draftmode_option = 1;
296
pdf_draftmode_value = 1;
298
} else if (ARGUMENT_IS("mktex")) {
299
kpse_maketex_option(optarg, true);
301
} else if (ARGUMENT_IS("no-mktex")) {
302
kpse_maketex_option(optarg, false);
304
} else if (ARGUMENT_IS("interaction")) {
305
/* These numbers match CPP defines */
306
if (STREQ(optarg, "batchmode")) {
307
interactionoption = 0;
308
} else if (STREQ(optarg, "nonstopmode")) {
309
interactionoption = 1;
310
} else if (STREQ(optarg, "scrollmode")) {
311
interactionoption = 2;
312
} else if (STREQ(optarg, "errorstopmode")) {
313
interactionoption = 3;
315
WARNING1("Ignoring unknown argument `%s' to --interaction",
319
} else if (ARGUMENT_IS("synctex")) {
320
/* Synchronize TeXnology: catching the command line option as a long */
321
synctexoption = (int) strtol(optarg, NULL, 0);
323
} else if (ARGUMENT_IS("help")) {
324
usagehelp(LUATEX_IHELP, BUG_ADDRESS);
326
} else if (ARGUMENT_IS("version")) {
327
print_version_banner();
329
puts("\n\nExecute 'luatex --credits' for credits and version details.\n\n"
330
"There is NO warranty. Redistribution of this software is covered by\n"
331
"the terms of the GNU General Public License, version 2. For more\n"
332
"information about these matters, see the file named COPYING and\n"
333
"the LuaTeX source.\n\n"
334
"Copyright 2009 Taco Hoekwater, the LuaTeX Team.\n");
337
} else if (ARGUMENT_IS("credits")) {
339
initversionstring(&versions);
340
print_version_banner();
342
puts("\n\nThe LuaTeX team is Hans Hagen, Hartmut Henkel, Taco Hoekwater.\n"
343
"LuaTeX merges and builds upon (parts of) the code from these projects:\n\n"
344
"tex by Donald Knuth\n"
345
"etex by Peter Breitenlohner, Phil Taylor and friends\n"
346
"omega by John Plaice and Yannis Haralambous\n"
347
"aleph by Giuseppe Bilotta\n"
348
"pdftex by Han The Thanh and friends\n"
349
"kpathsea by Karl Berry, Olaf Weber and others\n"
350
"lua by Roberto Ierusalimschy, Waldemar Celes,\n"
351
" Luiz Henrique de Figueiredo\n"
352
"metapost by John Hobby, Taco Hoekwater and friends.\n"
353
"xpdf by Derek Noonburg (partial)\n"
354
"fontforge by George Williams (partial)\n\n"
355
"Some extensions to lua and additional lua libraries are used, as well as\n"
356
"libraries for graphic inclusion. More details can be found in the source.\n"
357
"Code development was sponsored by a grant from Colorado State University\n"
358
"via the 'oriental tex' project, the TeX User Groups, and donations.\n");
364
/* attempt to find |input_name| / |dump_name| */
367
startup_filename = strdup(argv[optind]);
370
} else if (argv[optind] && argv[optind][0] == '&') {
371
dump_name = strdup(argv[optind] + 1);
372
} else if (argv[optind] && argv[optind][0] != '\\') {
373
if (argv[optind][0] == '*') {
374
input_name = strdup(argv[optind] + 1);
376
firstfile = strdup(argv[optind]);
377
if ((strstr(firstfile, ".lua") ==
378
firstfile + strlen(firstfile) - 4)
379
|| (strstr(firstfile, ".luc") ==
380
firstfile + strlen(firstfile) - 4)
381
|| (strstr(firstfile, ".LUA") ==
382
firstfile + strlen(firstfile) - 4)
383
|| (strstr(firstfile, ".LUC") ==
384
firstfile + strlen(firstfile) - 4)) {
385
if (startup_filename == NULL) {
386
startup_filename = firstfile;
392
input_name = firstfile;
396
if (safer_option) /* --safer implies --nosocket */
399
/* Finalize the input filename. */
400
if (input_name != NULL) {
401
argv[optind] = normalize_quotes(input_name, "argument");
405
@ test for readability
407
#define is_readable(a) (stat(a,&finfo)==0) && S_ISREG(finfo.st_mode) && \
408
(f=fopen(a,"r")) != NULL && !fclose(f)
411
static char *find_filename(char *name, const char *envkey)
414
char *dirname = NULL;
415
char *filename = NULL;
417
if (is_readable(name)) {
420
dirname = getenv(envkey);
421
if ((dirname != NULL) && strlen(dirname)) {
422
dirname = strdup(getenv(envkey));
423
if (*(dirname + strlen(dirname) - 1) == '/') {
424
*(dirname + strlen(dirname) - 1) = 0;
426
filename = xmalloc((unsigned) (strlen(dirname) + strlen(name) + 2));
427
filename = concat3(dirname, "/", name);
428
if (is_readable(filename)) {
440
static char *cleaned_invocation_name(char *arg)
443
const char *start = xbasename(arg);
444
ret = xstrdup(start);
445
dot = index(ret, '.');
453
static void init_kpse(void)
456
if (!user_progname) {
457
user_progname = dump_name;
458
} else if (!dump_name) {
459
dump_name = user_progname;
461
if (!user_progname) {
463
user_progname = input_name;
464
if (!user_progname) {
465
user_progname = cleaned_invocation_name(argv[0]);
469
dump_name = cleaned_invocation_name(argv[0]);
471
user_progname = dump_name;
474
kpse_set_program_enabled(kpse_fmt_format, MAKE_TEX_FMT_BY_DEFAULT,
477
kpse_set_program_name(argv[0], user_progname);
478
init_shell_escape(); /* set up 'restrictedshell' */
479
program_name_set = 1;
483
static void fix_dumpname(void)
487
/* adjust array for Pascal and provide extension, if needed */
488
dist = (int) (strlen(dump_name) - strlen(DUMP_EXT));
489
if (strstr(dump_name, DUMP_EXT) == dump_name + dist)
490
TEX_format_default = dump_name;
492
TEX_format_default = concat(dump_name, DUMP_EXT);
494
/* For |dump_name| to be NULL is a bug. */
502
@ Auxiliary function for kpse search
505
static const char *luatex_kpse_find_aux(lua_State *L, const char *name,
506
kpse_file_format_type format, const char *errname)
508
const char *filename;
510
altname = luaL_gsub(L, name, ".", "/"); /* Lua convention */
511
filename = kpse_find_file(altname, format, false);
512
if (filename == NULL) {
513
filename = kpse_find_file(name, format, false);
515
if (filename == NULL) {
516
lua_pushfstring(L, "\n\t[kpse %s searcher] file not found: " LUA_QS,
522
@ The lua search function.
524
When kpathsea is not initialized, then it runs the
525
normal lua function that is saved in the registry, otherwise
528
two registry ref variables are needed: one for the actual lua
529
function, the other for its environment .
532
static int lua_loader_function = 0;
533
static int lua_loader_env = 0;
535
static int luatex_kpse_lua_find(lua_State * L)
537
const char *filename;
539
name = luaL_checkstring(L, 1);
540
if (program_name_set == 0) {
541
lua_CFunction orig_func;
542
lua_rawgeti(L, LUA_REGISTRYINDEX, lua_loader_function);
543
lua_rawgeti(L, LUA_REGISTRYINDEX, lua_loader_env);
544
lua_replace(L, LUA_ENVIRONINDEX);
545
orig_func = lua_tocfunction(L, -1);
547
return (orig_func) (L);
549
filename = luatex_kpse_find_aux(L, name, kpse_lua_format, "lua");
550
if (filename == NULL)
551
return 1; /* library not found in this path */
552
if (luaL_loadfile(L, filename) != 0) {
553
luaL_error(L, "error loading module %s from file %s:\n\t%s",
554
lua_tostring(L, 1), filename, lua_tostring(L, -1));
556
return 1; /* library loaded successfully */
560
static int clua_loader_function = 0;
561
static int clua_loader_env = 0;
563
static int luatex_kpse_clua_find(lua_State * L)
565
const char *filename;
568
lua_pushliteral(L, "\n\t[C searcher disabled in safer mode]");
569
return 1; /* library not found in this path */
571
name = luaL_checkstring(L, 1);
572
if (program_name_set == 0) {
573
lua_CFunction orig_func;
574
lua_rawgeti(L, LUA_REGISTRYINDEX, clua_loader_function);
575
lua_rawgeti(L, LUA_REGISTRYINDEX, clua_loader_env);
576
lua_replace(L, LUA_ENVIRONINDEX);
577
orig_func = lua_tocfunction(L, -1);
579
return (orig_func) (L);
581
filename = luatex_kpse_find_aux(L, name, kpse_clua_format, "C");
582
if (filename == NULL)
583
return 1; /* library not found in this path */
584
return loader_C_luatex(L, name, filename);
588
static int clua_loadall_function = 0;
589
static int clua_loadall_env = 0;
591
static int luatex_kpse_cluaall_find(lua_State * L)
593
const char *filename;
596
const char *p = NULL;
598
lua_pushliteral(L, "\n\t[All-in-one searcher disabled in safer mode]");
599
return 1; /* library not found in this path */
601
name = luaL_checkstring(L, 1);
602
p = strchr(name, '.');
603
if (program_name_set == 0) {
604
lua_CFunction orig_func;
605
lua_rawgeti(L, LUA_REGISTRYINDEX, clua_loadall_function);
606
lua_rawgeti(L, LUA_REGISTRYINDEX, clua_loadall_env);
607
lua_replace(L, LUA_ENVIRONINDEX);
608
orig_func = lua_tocfunction(L, -1);
610
return (orig_func) (L);
612
if (p == NULL) return 0; /* is root */
613
fixedname = xmalloc((size_t)(p - name)+1);
614
memcpy(fixedname,name,(size_t)(p - name));
615
fixedname[(p - name)] = '\0';
616
filename = luatex_kpse_find_aux(L, fixedname, kpse_clua_format, "All-in-one");
618
if (filename == NULL)
619
return 1; /* library not found in this path */
620
return loader_Call_luatex(L, name, filename);
623
@ Setting up the new search functions.
625
This replaces package.loaders[2] with the function defined above.
628
static void setup_lua_path(lua_State * L)
630
lua_getglobal(L, "package");
631
lua_getfield(L, -1, "loaders");
632
lua_rawgeti(L, -1, 2); /* package.loaders[2] */
634
lua_loader_env = luaL_ref(L, LUA_REGISTRYINDEX);
635
lua_loader_function = luaL_ref(L, LUA_REGISTRYINDEX);
636
lua_pushcfunction(L, luatex_kpse_lua_find);
637
lua_rawseti(L, -2, 2); /* replace the normal lua loader */
639
lua_rawgeti(L, -1, 3); /* package.loaders[3] */
641
clua_loader_env = luaL_ref(L, LUA_REGISTRYINDEX);
642
clua_loader_function = luaL_ref(L, LUA_REGISTRYINDEX);
643
lua_pushcfunction(L, luatex_kpse_clua_find);
644
lua_rawseti(L, -2, 3); /* replace the normal lua lib loader */
646
lua_rawgeti(L, -1, 4); /* package.loaders[4] */
648
clua_loadall_env = luaL_ref(L, LUA_REGISTRYINDEX);
649
clua_loadall_function = luaL_ref(L, LUA_REGISTRYINDEX);
650
lua_pushcfunction(L, luatex_kpse_cluaall_find);
651
lua_rawseti(L, -2, 4); /* replace the normal lua lib loader */
653
lua_pop(L, 2); /* pop the array and table */
656
@ helper variables for the safe keeping of table ids
665
#if defined(WIN32) || defined(__MINGW32__) || defined(__CYGWIN__)
668
# define EXE_SUFFIXES ".com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.ws;.tcl;.py;.pyw"
671
static void mk_suffixlist(void)
677
# if defined(__CYGWIN__)
678
v = xstrdup(EXE_SUFFIXES);
680
v = (char *) getenv("PATHEXT");
681
if (v) /* strlwr() exists also in MingW */
682
v = (char *) strlwr(xstrdup(v));
684
v = xstrdup(EXE_SUFFIXES);
690
while ((r = strchr(q, ';')) != NULL) {
697
suffixlist = (char **) xmalloc((n + 2) * sizeof(char *));
699
*p = xstrdup(".dll");
702
while ((r = strchr(q, ';')) != NULL) {
719
void lua_initialize(int ac, char **av)
722
char *given_file = NULL;
725
static char LC_CTYPE_C[] = "LC_CTYPE=C";
726
static char LC_COLLATE_C[] = "LC_COLLATE=C";
727
static char LC_NUMERIC_C[] = "LC_NUMERIC=C";
728
static char engine_luatex[] = "engine=luatex";
729
/* Save to pass along to topenin. */
733
if (luatex_svn < 0) {
734
if (asprintf(&banner, "This is LuaTeX, Version %s-%d",
735
luatex_version_string, luatex_date_info) < 0) {
739
if (asprintf(&banner, "This is LuaTeX, Version %s-%d (rev %d)",
740
luatex_version_string, luatex_date_info, luatex_svn) < 0) {
746
program_invocation_name = cleaned_invocation_name(argv[0]);
750
(STREQ(program_invocation_name, "texluac") ||
751
STREQ(argv[1], "--luaconly") || STREQ(argv[1], "--luac"))) {
752
exit(luac_main(ac, av));
754
#if defined(WIN32) || defined(__MINGW32__) || defined(__CYGWIN__)
758
/* Must be initialized before options are parsed. */
759
interactionoption = 4;
762
/* 0 means "disable Synchronize TeXnology".
763
synctexoption is a *.web variable.
764
We initialize it to a weird value to catch the -synctex command line flag
765
At runtime, if synctexoption is not |INT_MAX|, then it contains the command line option provided,
766
otherwise no such option was given by the user. */
767
#define SYNCTEX_NO_OPTION INT_MAX
768
synctexoption = SYNCTEX_NO_OPTION;
770
/* parse commandline */
771
parse_options(ac, av);
773
shellenabledp = true;
775
/* make sure that the locale is 'sane' (for lua) */
778
putenv(LC_COLLATE_C);
779
putenv(LC_NUMERIC_C);
781
/* this is sometimes needed */
782
putenv(engine_luatex);
786
prepare_cmdline(Luas, argv, argc, lua_offset); /* collect arguments */
787
setup_lua_path(Luas);
789
if (startup_filename != NULL) {
790
given_file = xstrdup(startup_filename);
791
startup_filename = find_filename(startup_filename, "LUATEXDIR");
793
/* now run the file */
794
if (startup_filename != NULL) {
796
/* hide the 'tex' and 'pdf' table */
797
tex_table_id = hide_lua_table(Luas, "tex");
798
token_table_id = hide_lua_table(Luas, "token");
799
node_table_id = hide_lua_table(Luas, "node");
800
pdf_table_id = hide_lua_table(Luas, "pdf");
802
if (luaL_loadfile(Luas, startup_filename)) {
803
fprintf(stdout, "%s\n", lua_tostring(Luas, -1));
807
init_tex_table(Luas);
808
if (lua_pcall(Luas, 0, 0, 0)) {
809
fprintf(stdout, "%s\n", lua_tostring(Luas, -1));
812
/* no filename? quit now! */
814
get_lua_string("texconfig", "jobname", &input_name);
817
get_lua_string("texconfig", "formatname", &dump_name);
819
if ((lua_only) || ((!input_name) && (!dump_name))) {
822
/* this is not strictly needed but it pleases valgrind */
826
/* unhide the 'tex' and 'pdf' table */
827
unhide_lua_table(Luas, "tex", tex_table_id);
828
unhide_lua_table(Luas, "pdf", pdf_table_id);
829
unhide_lua_table(Luas, "token", token_table_id);
830
unhide_lua_table(Luas, "node", node_table_id);
834
get_lua_boolean("texconfig", "kpse_init", &kpse_init);
836
if (kpse_init != 0) {
837
luainit = 0; /* re-enable loading of texmf.cnf values, see luatex.ch */
840
/* |prohibit_file_trace| (boolean) */
842
get_lua_boolean("texconfig", "trace_file_names", &tracefilenames);
844
/* |file_line_error| */
845
filelineerrorstylep = false;
846
get_lua_boolean("texconfig", "file_line_error", &filelineerrorstylep);
848
/* |halt_on_error| */
849
haltonerrorp = false;
850
get_lua_boolean("texconfig", "halt_on_error", &haltonerrorp);
852
/* |restrictedshell| */
854
get_lua_string("texconfig", "shell_escape", &v1);
856
if (*v1 == 't' || *v1 == 'y' || *v1 == '1') {
858
} else if (*v1 == 'p') {
863
/* If shell escapes are restricted, get allowed cmds from cnf. */
864
if (shellenabledp && restrictedshell == 1) {
866
get_lua_string("texconfig", "shell_escape_commands", &v1);
877
fprintf(stdout, "%s file %s not found\n",
878
(lua_only ? "Script" : "Configuration"), given_file);
881
fprintf(stdout, "No %s file given\n",
882
(lua_only ? "script" : "configuration"));
894
void check_texconfig_init(void)
897
lua_getglobal(Luas, "texconfig");
898
if (lua_istable(Luas, -1)) {
899
lua_getfield(Luas, -1, "init");
900
if (lua_isfunction(Luas, -1)) {
901
int i = lua_pcall(Luas, 0, 0, 0);
903
/* Can't be more precise here, called before TeX initialization */
904
fprintf(stderr, "This went wrong: %s\n",
905
lua_tostring(Luas, -1));
914
void write_svnversion(char *v)
918
size_t l = strlen("$Id: luatex.web ");
924
while (*n != '\0' && *n != ' ')
927
fprintf(stdout, " luatex.web >= v%s", a);