~reviczky/luatex/metapost

« back to all changes in this revision

Viewing changes to trunk/source/texk/texlive/w32_wrapper/runscript.tlu

  • Committer: luigi.scarso at gmail
  • Date: 2018-08-29 13:19:26 UTC
  • Revision ID: svn-v4:b8f95e4b-c8ec-496e-911b-43368900ac28::2145
sync with luatex rev.6912 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
 
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" ..
262
262
    2017/05/06
263
263
        - introduce sys_user_progs, make checks for updmap/fmtutil
264
264
          use sys_user_progs instead, add kanji-config-updmap
 
265
    2018/03/12
 
266
        - introduce a new function gettexmfdist() for security.
 
267
    2018/04/06
 
268
        - introduce a new function is_64bit_windows_os() to
 
269
          check Windows OS.
 
270
    2018/06/20
 
271
        - support also scripts in trees other than TEXMFDIST:
 
272
          https://tug.org/pipermail/tex-live/2018-June/041922.html
265
273
]]
266
274
 
267
275
-- HELPER SUBROUTINES --
386
394
  end
387
395
end
388
396
 
 
397
--
 
398
-- return the TEXMFDIST directory in TeX Live
 
399
--
 
400
local function gettexmfdist()
 
401
  local ffi = require("ffi")
 
402
  ffi.cdef[[
 
403
  typedef void*  HANDLE;
 
404
  typedef char*  LPCSTR;
 
405
  int GetModuleFileNameA(HANDLE h, LPCSTR l, int i);
 
406
  HANDLE GetModuleHandleA(const char *a);
 
407
  ]]
 
408
  local buffer = ffi.new("char[?]", 512)
 
409
  local runscripthandle = ffi.C.GetModuleHandleA("runscript.dll")
 
410
  if runscripthandle == nil then
 
411
    return nil
 
412
  end
 
413
  local err = ffi.C.GetModuleFileNameA(runscripthandle, buffer, 256)
 
414
  if err == 0 then
 
415
    return nil
 
416
  end
 
417
  local str = ffi.string(buffer)
 
418
  str = string.gsub(str, "\\","/")
 
419
  str = string.reverse(str)
 
420
  local a, b
 
421
-- remove /runscript.dll
 
422
  a, b = string.find(str, '/', 1, true)
 
423
  str = string.sub(str,a+1)
 
424
-- remove /win32
 
425
  a, b = string.find(str, '/', 1, true)
 
426
  str = string.sub(str,a+1)
 
427
-- remove /bin
 
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'
 
432
  return str
 
433
end
 
434
 
 
435
--
 
436
-- Is the Windows OS 64bit?
 
437
--
 
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
 
446
        return_val = false
 
447
      else
 
448
        return_val = true
 
449
      end
 
450
    else
 
451
      return_val = true
 
452
    end
 
453
  end
 
454
  return return_val
 
455
end
 
456
 
389
457
-- MAIN_CHUNK -- encapsulated in a function for more robust execution with pcall
390
458
 
391
459
local function MAIN_CHUNK()
392
460
 
 
461
-- set the system-default value for LC_CTYPE
 
462
-- http://tug.org/pipermail/tex-live/2018-May/041628.html
 
463
os.setlocale("", "ctype")
 
464
 
393
465
-- preprocess arguments
394
466
 
395
467
local guimode = false
472
544
 
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')
 
552
end
476
553
local BINDIR = kpse.var_value('SELFAUTOLOC')
477
554
local PATH = os.getenv('PATH') or ''
478
555
 
623
700
  elseif userprog then
624
701
    argline = ' --user ' .. argline
625
702
  end
 
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'}
 
711
  else
 
712
    ARGV = {[0]=TEXDIR..'/tlpkg/asymptote/asy.exe', 'asy'}
 
713
  end
630
714
elseif progname == 'dviout' then
631
715
  local fontsdir = kpse.var_value('TEXMFVAR') .. '/fonts'
632
716
  if (lfs.attributes(fontsdir, 'mode') ~= 'directory') then 
683
767
-- general case
684
768
 
685
769
if not ARGV 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
 
777
-- line !!
 
778
    kpse.set_program_name('runscript')
 
779
    progfullname = assert(find_texmfscript(progname, extlist))
 
780
  end
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