3
local svnrevision = string.match("$Revision: 46031 $", "%d+") or "0"
4
local svndate = string.match("$Date: 2017-12-10 14:35:30 +0100 (Sun, 10 Dec 2017) $", "[-%d]+") or "2009-12-04"
3
local svnrevision = string.match("$Revision: 48059 $", "%d+") or "0"
4
local svndate = string.match("$Date: 2018-06-20 05:55:23 +0200 (Wed, 20 Jun 2018) $", "[-%d]+") or "2009-12-04"
5
5
local bannerstr = "runscript wrapper utility (rev. " ..
6
6
svnrevision .. ", " .. svndate .. ")\n" ..
7
7
"usage: runscript script-name [arguments]\n" ..
263
263
- introduce sys_user_progs, make checks for updmap/fmtutil
264
264
use sys_user_progs instead, add kanji-config-updmap
266
- introduce a new function gettexmfdist() for security.
268
- introduce a new function is_64bit_windows_os() to
271
- support also scripts in trees other than TEXMFDIST:
272
https://tug.org/pipermail/tex-live/2018-June/041922.html
267
275
-- HELPER SUBROUTINES --
398
-- return the TEXMFDIST directory in TeX Live
400
local function gettexmfdist()
401
local ffi = require("ffi")
403
typedef void* HANDLE;
404
typedef char* LPCSTR;
405
int GetModuleFileNameA(HANDLE h, LPCSTR l, int i);
406
HANDLE GetModuleHandleA(const char *a);
408
local buffer = ffi.new("char[?]", 512)
409
local runscripthandle = ffi.C.GetModuleHandleA("runscript.dll")
410
if runscripthandle == nil then
413
local err = ffi.C.GetModuleFileNameA(runscripthandle, buffer, 256)
417
local str = ffi.string(buffer)
418
str = string.gsub(str, "\\","/")
419
str = string.reverse(str)
421
-- remove /runscript.dll
422
a, b = string.find(str, '/', 1, true)
423
str = string.sub(str,a+1)
425
a, b = string.find(str, '/', 1, true)
426
str = string.sub(str,a+1)
428
a, b = string.find(str, '/', 1, true)
429
str = string.sub(str,a+1)
430
str = string.reverse(str)
431
str = str .. '/texmf-dist'
436
-- Is the Windows OS 64bit?
438
local function is_64bit_windows_os()
439
local return_val = false
440
-- 32 bit binaries always work, thus the default is false
441
local architecture = os.getenv('PROCESSOR_ARCHITECTURE')
442
if architecture ~= nil then
443
if architecture == 'x86' then
444
local is_wow64 = os.getenv('PROCESSOR_ARCHITEW6432')
445
if is_wow64 == nil then
389
457
-- MAIN_CHUNK -- encapsulated in a function for more robust execution with pcall
391
459
local function MAIN_CHUNK()
461
-- set the system-default value for LC_CTYPE
462
-- http://tug.org/pipermail/tex-live/2018-May/041628.html
463
os.setlocale("", "ctype")
393
465
-- preprocess arguments
395
467
local guimode = false
473
545
-- various dir-vars
474
546
local TEXDIR = kpse.var_value('SELFAUTOPARENT')
475
local TEXMFDIST = kpse.var_value('TEXMFDIST')
547
-- local TEXMFDIST = kpse.var_value('TEXMFDIST')
548
-- use a new function to obtain TEXMFDIST
549
local TEXMFDIST = gettexmfdist()
550
if TEXMFDIST == nil then
551
TEXMFDIST = kpse.var_value('TEXMFDIST')
476
553
local BINDIR = kpse.var_value('SELFAUTOLOC')
477
554
local PATH = os.getenv('PATH') or ''
623
700
elseif userprog then
624
701
argline = ' --user ' .. argline
703
-- do not guess input encoding in format creation for ptex
704
-- and friends since guessing is not complete
705
os.setenv('GUESS_INPUT_KANJI_ENCODING', '0')
626
706
elseif progname == 'asy' then
627
707
os.setenv('ASYMPTOTE_GS', GSEXE)
628
708
os.setenv('CYGWIN', 'nodosfilewarning')
629
ARGV = {[0]=TEXDIR..'/tlpkg/asymptote/asy.exe', 'asy'}
709
if is_64bit_windows_os() then
710
ARGV = {[0]=TEXDIR..'/tlpkg/asymptote64/asy.exe', 'asy'}
712
ARGV = {[0]=TEXDIR..'/tlpkg/asymptote/asy.exe', 'asy'}
630
714
elseif progname == 'dviout' then
631
715
local fontsdir = kpse.var_value('TEXMFVAR') .. '/fonts'
632
716
if (lfs.attributes(fontsdir, 'mode') ~= 'directory') then
686
local extlist = '.tlu;.texlua;.lua;.pl;.rb;.py;.tcl;.jar;.vbs;.js;.bat;.cmd;\0'
770
os.setenv('TEXMF', TEXMFDIST)
771
local extlist = '.tlu;.texlua;.pl;.lua;.rb;.py;.tcl;.jar;.vbs;.js;.bat;.cmd;\0'
687
772
local progfullname = search_path(progname, BINDIR, '.tlu;.bat;.cmd') or
688
assert(find_texmfscript(progname, extlist))
773
find_texmfscript(progname, extlist)
774
os.setenv('TEXMF', nil)
775
if progfullname == nil then
776
-- scripts in $TEXMFLOCAL etc. can't be found without the following
778
kpse.set_program_name('runscript')
779
progfullname = assert(find_texmfscript(progname, extlist))
689
781
local ext = string.match(string.lower(progfullname), '%.[^\\/.]*$') or ''
690
782
if (ext == '.lua') or (ext == '.tlu') or (ext == '.texlua') then -- lua script
691
783
arg[0] = progfullname