summaryrefslogtreecommitdiff
path: root/Master/bin/win32/tl-w32-wrapper.cmd
blob: ce0d0d24346438f7b756f54c70ed4cf7b0c01198 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
@echo off
rem Universal script launcher
rem
rem Originally written 2009 by Tomasz M. Trzeciak
rem Public Domain

rem Make environment changes local
setlocal enableextensions
rem Get program/script name
if not defined TL_PROGNAME set TL_PROGNAME=%~n0
rem Check if this is 'sys' version of program
set TEX_SYS_PROG=
if /i "%TL_PROGNAME:~-4%"=="-sys" (
  set TL_PROGNAME=%TL_PROGNAME:~0,-4%
  set TEX_SYS_PROG=true
)

rem Default command to execute
set CMDLINE=call :noscript "%~0" "%TL_PROGNAME%"
rem Make sure our dir is on the search path; avoid trailing backslash
set TL_ROOT=%~dp0?
set TL_ROOT=%TL_ROOT:\bin\win32\?=%
path %TL_ROOT%\bin\win32;%path%
rem Check for kpsewhich availability
if not exist "%TL_ROOT%\bin\win32\kpsewhich.exe" goto :nokpsewhich
rem Ask kpsewhich about root and texmfsys trees (the first line of output)
rem and location of the script (the second line of output)
rem (4NT shell acts wierd with 'if' statements in a 'for' loop,
rem so better process this output further in a subroutine)
for /f "tokens=1-2 delims=;" %%I in (
  '%~sdp0kpsewhich.exe --expand-var "$TEXMFSYSCONFIG/?;$TEXMFSYSVAR/?" --format texmfscripts ^
  "%TL_PROGNAME%.pl" "%TL_PROGNAME%.tlu" "%TL_PROGNAME%.rb" "%TL_PROGNAME%.py"'
) do (
  call :setcmdenv "%%~I" "%%~J"
)

rem By now we should have the command to execute (whatever it is)
rem Unset program name variable and execute the command
set TL_PROGNAME=
%CMDLINE% %*
rem Finish with goto :eof (it will preserve the last errorlevel)
goto :eof

REM SUBROUTINES

:setcmdenv selfautoparent texmfsysconfig texmfsysvar
rem If there is only one argument it must be a script name
if "%~2"=="" goto :setcmd
rem Otherwise, it is the first line from kpsewhich, so to set up the environment
set PERL5LIB=%TL_ROOT%\tlpkg\tlperl\lib
set GS_LIB=%TL_ROOT%\tlpkg\tlgs\lib;%TL_ROOT%\tlpkg\tlgs\fonts
path %TL_ROOT%\tlpkg\tlgs\bin;%TL_ROOT%\tlpkg\tlperl\bin;%TL_ROOT%\tlpkg\installer;%TL_ROOT%\tlpkg\installer\wget;%path%
if not defined TEX_SYS_PROG goto :eof
rem Extra stuff for sys version
set TEXMFCONFIG=%~1
set TEXMFCONFIG=%TEXMFCONFIG:/?=%
set TEXMFVAR=%~2
set TEXMFVAR=%TEXMFVAR:/?=%
rem For sys version we might have an executable in the bin dir, so check for it
if exist "%TL_ROOT%\bin\win32\%TL_PROGNAME%.exe" set CMDLINE="%TL_ROOT%\bin\win32\%TL_PROGNAME%.exe"
goto :eof

:setcmd script
rem Set command based on the script extension
if /i %~x1==.pl  set CMDLINE="%TL_ROOT%\tlpkg\tlperl\bin\perl.exe" "%~f1"
if /i %~x1==.tlu set CMDLINE="%TL_ROOT%\bin\win32\texlua.exe" "%~f1"
rem For Ruby and Python we additionally check if their interpreter is available
if /i %~x1==.rb  call :chkcmd Ruby.exe "%~f1"
if /i %~x1==.py  call :chkcmd Python.exe "%~f1"
goto :eof

:chkcmd program script
set CMDLINE=%*
rem If there is no interpreter Ruby or Python, suggest getting one
if "%~$PATH:1"=="" set CMDLINE=call :notinstalled %*
goto :eof

:notinstalled program
echo %1 not found on search path>&2
echo %~n1 is not distributed with TeX Live and has to be installed separately
exit /b 1

:noscript this_file program_name
echo %~nx1: no appropriate script or program found: "%~2">&2
exit /b 1

:nokpsewhich
echo %~nx0: kpsewhich not found: "%~dp0kpsewhich.exe">&2
exit /b 1