From 4e4a86c4a17cc80136fb26405aeddcc216150712 Mon Sep 17 00:00:00 2001 From: Piotr Strzelczyk Date: Thu, 3 Dec 2009 20:17:18 +0000 Subject: move wrapper sources to a separate directory git-svn-id: svn://tug.org/texlive/trunk@16280 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/texlive/Makefile.am | 7 +- Build/source/texk/texlive/runscript.dll | Bin 5120 -> 0 bytes Build/source/texk/texlive/runscript.exe | Bin 1536 -> 0 bytes Build/source/texk/texlive/runscript_dll.c | 198 --------------------- Build/source/texk/texlive/runscript_exe.c | 7 - Build/source/texk/texlive/tl-w32-wrapper.cmd | 90 ---------- .../source/texk/texlive/w32_wrapper/runscript.dll | Bin 0 -> 5120 bytes .../source/texk/texlive/w32_wrapper/runscript.exe | Bin 0 -> 1536 bytes .../texk/texlive/w32_wrapper/runscript_dll.c | 198 +++++++++++++++++++++ .../texk/texlive/w32_wrapper/runscript_exe.c | 7 + .../texk/texlive/w32_wrapper/tl-w32-wrapper.cmd | 90 ++++++++++ 11 files changed, 296 insertions(+), 301 deletions(-) delete mode 100755 Build/source/texk/texlive/runscript.dll delete mode 100755 Build/source/texk/texlive/runscript.exe delete mode 100644 Build/source/texk/texlive/runscript_dll.c delete mode 100644 Build/source/texk/texlive/runscript_exe.c delete mode 100644 Build/source/texk/texlive/tl-w32-wrapper.cmd create mode 100755 Build/source/texk/texlive/w32_wrapper/runscript.dll create mode 100755 Build/source/texk/texlive/w32_wrapper/runscript.exe create mode 100644 Build/source/texk/texlive/w32_wrapper/runscript_dll.c create mode 100644 Build/source/texk/texlive/w32_wrapper/runscript_exe.c create mode 100644 Build/source/texk/texlive/w32_wrapper/tl-w32-wrapper.cmd (limited to 'Build/source') diff --git a/Build/source/texk/texlive/Makefile.am b/Build/source/texk/texlive/Makefile.am index 064ed4341a2..8168d34b7b5 100644 --- a/Build/source/texk/texlive/Makefile.am +++ b/Build/source/texk/texlive/Makefile.am @@ -9,12 +9,7 @@ SUBDIRS = linked_scripts ## Win32 wrapper ## -EXTRA_DIST = \ - runscript_dll.c \ - runscript_exe.c \ - runscript.dll \ - runscript.exe \ - tl-w32-wrapper.cmd +EXTRA_DIST = w32_wrapper ## Not used ## diff --git a/Build/source/texk/texlive/runscript.dll b/Build/source/texk/texlive/runscript.dll deleted file mode 100755 index 9262bd27cff..00000000000 Binary files a/Build/source/texk/texlive/runscript.dll and /dev/null differ diff --git a/Build/source/texk/texlive/runscript.exe b/Build/source/texk/texlive/runscript.exe deleted file mode 100755 index 5777d90a17a..00000000000 Binary files a/Build/source/texk/texlive/runscript.exe and /dev/null differ diff --git a/Build/source/texk/texlive/runscript_dll.c b/Build/source/texk/texlive/runscript_dll.c deleted file mode 100644 index ed399a9e0b2..00000000000 --- a/Build/source/texk/texlive/runscript_dll.c +++ /dev/null @@ -1,198 +0,0 @@ -/* - -Public Domain -Originally written 2009 by T.M.Trzeciak - -Batch script launcher: - -Runs a batch file of the same name in the same location or sets -TL_PROGNAME environment variable to its own name and calls -the default batch script. - -Rationale: - -Batch scripts are not as universal as binary executables, there -are some odd cases where they are not interchangeable with them. - -Usage: - -Simply copy and rename the compiled program. The executable part -is just a proxy the runscript function in runscript.dll. This arrangement -is for maintenance reasons - upgrades can be done by replacement of -a single .dll rather than all .exe stubs - -Compilation: - -with gcc (size optimized): -gcc -Os -s -shared -o runscript.dll runscript_dll.c -gcc -Os -s -o runscript.exe runscript_exe.c -L./ -lrunscript - -with tcc (ver. 0.9.24), extra small size -tcc -shared -o runscript.dll runscript_dll.c -tcc -o runscript.exe runscript_exe.c runscript.def - -*/ - -#include -#include -#define IS_WHITESPACE(c) ((c == ' ') || (c == '\t')) -#define DEFAULT_SCRIPT "tl-w32-wrapper.cmd" -#define MAX_CMD 32768 -//#define DRYRUN - -static char dirname[MAX_PATH]; -static char basename[MAX_PATH]; -static char progname[MAX_PATH]; -static char cmdline[MAX_CMD]; -char *envpath; - -__declspec(dllexport) int dllrunscript( int argc, char *argv[] ) { - int i; - static char path[MAX_PATH]; - - // get file name of this executable and split it into parts - DWORD nchars = GetModuleFileNameA(NULL, path, MAX_PATH); - if ( !nchars || (nchars == MAX_PATH) ) { - fprintf(stderr, "runscript: cannot get own name or path too long\n"); - return -1; - } - // file extension part - i = strlen(path); - while ( i && (path[i] != '.') && (path[i] != '\\') ) i--; - strcpy(basename, path); - if ( basename[i] == '.' ) basename[i] = '\0'; //remove file extension - // file name part - while ( i && (path[i] != '\\') ) i--; - if ( path[i] != '\\' ) { - fprintf(stderr, "runcmd: no directory part in own name: %s\n", path); - return -1; - } - strcpy(dirname, path); - dirname[i+1] = '\0'; //remove file name, leave trailing backslash - strcpy(progname, &basename[i+1]); - - // find program to execute - if ( (strlen(basename)+4 >= MAX_PATH) || (strlen(dirname)+strlen(DEFAULT_SCRIPT) >= MAX_PATH) ) { - fprintf(stderr, "runscript: path too long: %s\n", path); - return -1; - } - // try .bat first - strcpy(path, basename); - strcat(path, ".bat"); - if ( GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES ) goto PROGRAM_FOUND; - // try .cmd next - strcpy(path, basename); - strcat(path, ".cmd"); - if ( GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES ) goto PROGRAM_FOUND; - // pass the program name through environment (generic launcher case) - if ( !SetEnvironmentVariableA("TL_PROGNAME", progname) ) { - fprintf(stderr, "runscript: cannot set evironment variable\n", path); - return -1; - } - // check environment for default command - /*if ( GetEnvironmentVariableA("TL_W32_WRAPPER", cmd, MAX_CMD) ) goto PROGRAM_FOUND;*/ - // use default script - strcpy(path, dirname); - strcat(path, DEFAULT_SCRIPT); - if ( GetFileAttributesA(path) == INVALID_FILE_ATTRIBUTES ) { - fprintf(stderr, "runscript: missing default script: %s\n", path); - return -1; - } - -PROGRAM_FOUND: - - if ( !cmdline[0] ) { - // batch file has to be executed through the call command in order to propagate its exit code - // cmd.exe is searched for only on PATH to prevent attacks through writing ./cmd.exe - envpath = (char *) getenv("PATH"); - if ( !envpath ) { - fprintf(stderr, "runscript: failed to read PATH variable\n"); - return -1; - } - cmdline[0] = '"'; - if ( !SearchPathA( envpath, /* Address of search path */ - "cmd.exe", /* Address of filename */ - NULL, /* Address of extension */ - MAX_PATH, /* Size of destination buffer */ - &cmdline[1], /* Address of destination buffer */ - NULL) /* File part of the full path */ - ) { - fprintf(stderr, "runscript: cmd.exe not found on PATH\n"); - return -1; - } - strcat(cmdline, "\" /c call \""); - strcat(cmdline, path); - strcat(cmdline, "\" "); - } - - // get the command line for this process - char *argstr; - argstr = GetCommandLineA(); - if ( argstr == NULL ) { - fprintf(stderr, "runscript: cannot get command line string\n"); - return -1; - } - // skip over argv[0] (it can contain embedded double quotes if launched from cmd.exe!) - int argstrlen = strlen(argstr); - int quoted = 0; - for ( i = 0; ( i < argstrlen) && ( !IS_WHITESPACE(argstr[i]) || quoted ); i++ ) - if (argstr[i] == '"') quoted = !quoted; - // while ( IS_WHITESPACE(argstr[i]) ) i++; // arguments leading whitespace - argstr = &argstr[i]; - if ( strlen(cmdline) + strlen(argstr) >= MAX_CMD ) { - fprintf(stderr, "runscript: command line string too long:\n%s%s\n", cmdline, argstr); - return -1; - } - // pass through all the arguments - strcat(cmdline, argstr); - -#ifdef DRYRUN - printf("progname: %s\n", progname); - printf("dirname: %s\n", dirname); - printf("args: %s\n", &argstr[-i]); - for (i = 0; i < argc; i++) printf("argv[%d]: %s\n", i, argv[i]); - printf("cmdl: %s\n", cmdline); - return; -#endif - - // create child process - STARTUPINFOA si; // ANSI variant - PROCESS_INFORMATION pi; - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - si.dwFlags = STARTF_USESTDHANDLES;// | STARTF_USESHOWWINDOW; - //si.dwFlags = STARTF_USESHOWWINDOW; - //si.wShowWindow = SW_HIDE ; // can be used to hide console window (requires STARTF_USESHOWWINDOW flag) - si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); - si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); - si.hStdError = GetStdHandle(STD_ERROR_HANDLE); - ZeroMemory( &pi, sizeof(pi) ); - if( !CreateProcessA( - NULL, // module name (uses command line if NULL) - cmdline, // command line - NULL, // process security atrributes - NULL, // thread security atrributes - TRUE, // handle inheritance - 0, // creation flags, e.g. CREATE_NEW_CONSOLE, CREATE_NO_WINDOW, DETACHED_PROCESS - NULL, // pointer to environment block (uses parent if NULL) - NULL, // starting directory (uses parent if NULL) - &si, // STARTUPINFO structure - &pi ) // PROCESS_INFORMATION structure - ) { - fprintf(stderr, "runscript: cannot create process: %s\n", cmdline); - return -1; - } - CloseHandle( pi.hThread ); // thread handle is not needed - DWORD ret = 0; - if ( WaitForSingleObject( pi.hProcess, INFINITE ) == WAIT_OBJECT_0 ) { - if ( !GetExitCodeProcess( pi.hProcess, &ret) ) { - fprintf(stderr, "runscript: cannot get process exit code: %s\n", cmdline); - return -1; - } - } else { - fprintf(stderr, "runscript: failed to wait for process termination: %s\n", cmdline); - return -1; - } - CloseHandle( pi.hProcess ); - return ret; -} diff --git a/Build/source/texk/texlive/runscript_exe.c b/Build/source/texk/texlive/runscript_exe.c deleted file mode 100644 index eb28592b37c..00000000000 --- a/Build/source/texk/texlive/runscript_exe.c +++ /dev/null @@ -1,7 +0,0 @@ -// an .exe part of runscript program -// see runscript_dll.c for more details -#include -__declspec(dllimport) int dllrunscript( int ac, char *av[] ); -int main( int argc, char *argv[] ) { - return dllrunscript( argc, argv ); -} diff --git a/Build/source/texk/texlive/tl-w32-wrapper.cmd b/Build/source/texk/texlive/tl-w32-wrapper.cmd deleted file mode 100644 index abf2bf1578e..00000000000 --- a/Build/source/texk/texlive/tl-w32-wrapper.cmd +++ /dev/null @@ -1,90 +0,0 @@ -@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 ( - 'call "%~dp0kpsewhich.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 - diff --git a/Build/source/texk/texlive/w32_wrapper/runscript.dll b/Build/source/texk/texlive/w32_wrapper/runscript.dll new file mode 100755 index 00000000000..9262bd27cff Binary files /dev/null and b/Build/source/texk/texlive/w32_wrapper/runscript.dll differ diff --git a/Build/source/texk/texlive/w32_wrapper/runscript.exe b/Build/source/texk/texlive/w32_wrapper/runscript.exe new file mode 100755 index 00000000000..5777d90a17a Binary files /dev/null and b/Build/source/texk/texlive/w32_wrapper/runscript.exe differ diff --git a/Build/source/texk/texlive/w32_wrapper/runscript_dll.c b/Build/source/texk/texlive/w32_wrapper/runscript_dll.c new file mode 100644 index 00000000000..ed399a9e0b2 --- /dev/null +++ b/Build/source/texk/texlive/w32_wrapper/runscript_dll.c @@ -0,0 +1,198 @@ +/* + +Public Domain +Originally written 2009 by T.M.Trzeciak + +Batch script launcher: + +Runs a batch file of the same name in the same location or sets +TL_PROGNAME environment variable to its own name and calls +the default batch script. + +Rationale: + +Batch scripts are not as universal as binary executables, there +are some odd cases where they are not interchangeable with them. + +Usage: + +Simply copy and rename the compiled program. The executable part +is just a proxy the runscript function in runscript.dll. This arrangement +is for maintenance reasons - upgrades can be done by replacement of +a single .dll rather than all .exe stubs + +Compilation: + +with gcc (size optimized): +gcc -Os -s -shared -o runscript.dll runscript_dll.c +gcc -Os -s -o runscript.exe runscript_exe.c -L./ -lrunscript + +with tcc (ver. 0.9.24), extra small size +tcc -shared -o runscript.dll runscript_dll.c +tcc -o runscript.exe runscript_exe.c runscript.def + +*/ + +#include +#include +#define IS_WHITESPACE(c) ((c == ' ') || (c == '\t')) +#define DEFAULT_SCRIPT "tl-w32-wrapper.cmd" +#define MAX_CMD 32768 +//#define DRYRUN + +static char dirname[MAX_PATH]; +static char basename[MAX_PATH]; +static char progname[MAX_PATH]; +static char cmdline[MAX_CMD]; +char *envpath; + +__declspec(dllexport) int dllrunscript( int argc, char *argv[] ) { + int i; + static char path[MAX_PATH]; + + // get file name of this executable and split it into parts + DWORD nchars = GetModuleFileNameA(NULL, path, MAX_PATH); + if ( !nchars || (nchars == MAX_PATH) ) { + fprintf(stderr, "runscript: cannot get own name or path too long\n"); + return -1; + } + // file extension part + i = strlen(path); + while ( i && (path[i] != '.') && (path[i] != '\\') ) i--; + strcpy(basename, path); + if ( basename[i] == '.' ) basename[i] = '\0'; //remove file extension + // file name part + while ( i && (path[i] != '\\') ) i--; + if ( path[i] != '\\' ) { + fprintf(stderr, "runcmd: no directory part in own name: %s\n", path); + return -1; + } + strcpy(dirname, path); + dirname[i+1] = '\0'; //remove file name, leave trailing backslash + strcpy(progname, &basename[i+1]); + + // find program to execute + if ( (strlen(basename)+4 >= MAX_PATH) || (strlen(dirname)+strlen(DEFAULT_SCRIPT) >= MAX_PATH) ) { + fprintf(stderr, "runscript: path too long: %s\n", path); + return -1; + } + // try .bat first + strcpy(path, basename); + strcat(path, ".bat"); + if ( GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES ) goto PROGRAM_FOUND; + // try .cmd next + strcpy(path, basename); + strcat(path, ".cmd"); + if ( GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES ) goto PROGRAM_FOUND; + // pass the program name through environment (generic launcher case) + if ( !SetEnvironmentVariableA("TL_PROGNAME", progname) ) { + fprintf(stderr, "runscript: cannot set evironment variable\n", path); + return -1; + } + // check environment for default command + /*if ( GetEnvironmentVariableA("TL_W32_WRAPPER", cmd, MAX_CMD) ) goto PROGRAM_FOUND;*/ + // use default script + strcpy(path, dirname); + strcat(path, DEFAULT_SCRIPT); + if ( GetFileAttributesA(path) == INVALID_FILE_ATTRIBUTES ) { + fprintf(stderr, "runscript: missing default script: %s\n", path); + return -1; + } + +PROGRAM_FOUND: + + if ( !cmdline[0] ) { + // batch file has to be executed through the call command in order to propagate its exit code + // cmd.exe is searched for only on PATH to prevent attacks through writing ./cmd.exe + envpath = (char *) getenv("PATH"); + if ( !envpath ) { + fprintf(stderr, "runscript: failed to read PATH variable\n"); + return -1; + } + cmdline[0] = '"'; + if ( !SearchPathA( envpath, /* Address of search path */ + "cmd.exe", /* Address of filename */ + NULL, /* Address of extension */ + MAX_PATH, /* Size of destination buffer */ + &cmdline[1], /* Address of destination buffer */ + NULL) /* File part of the full path */ + ) { + fprintf(stderr, "runscript: cmd.exe not found on PATH\n"); + return -1; + } + strcat(cmdline, "\" /c call \""); + strcat(cmdline, path); + strcat(cmdline, "\" "); + } + + // get the command line for this process + char *argstr; + argstr = GetCommandLineA(); + if ( argstr == NULL ) { + fprintf(stderr, "runscript: cannot get command line string\n"); + return -1; + } + // skip over argv[0] (it can contain embedded double quotes if launched from cmd.exe!) + int argstrlen = strlen(argstr); + int quoted = 0; + for ( i = 0; ( i < argstrlen) && ( !IS_WHITESPACE(argstr[i]) || quoted ); i++ ) + if (argstr[i] == '"') quoted = !quoted; + // while ( IS_WHITESPACE(argstr[i]) ) i++; // arguments leading whitespace + argstr = &argstr[i]; + if ( strlen(cmdline) + strlen(argstr) >= MAX_CMD ) { + fprintf(stderr, "runscript: command line string too long:\n%s%s\n", cmdline, argstr); + return -1; + } + // pass through all the arguments + strcat(cmdline, argstr); + +#ifdef DRYRUN + printf("progname: %s\n", progname); + printf("dirname: %s\n", dirname); + printf("args: %s\n", &argstr[-i]); + for (i = 0; i < argc; i++) printf("argv[%d]: %s\n", i, argv[i]); + printf("cmdl: %s\n", cmdline); + return; +#endif + + // create child process + STARTUPINFOA si; // ANSI variant + PROCESS_INFORMATION pi; + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + si.dwFlags = STARTF_USESTDHANDLES;// | STARTF_USESHOWWINDOW; + //si.dwFlags = STARTF_USESHOWWINDOW; + //si.wShowWindow = SW_HIDE ; // can be used to hide console window (requires STARTF_USESHOWWINDOW flag) + si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); + si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); + si.hStdError = GetStdHandle(STD_ERROR_HANDLE); + ZeroMemory( &pi, sizeof(pi) ); + if( !CreateProcessA( + NULL, // module name (uses command line if NULL) + cmdline, // command line + NULL, // process security atrributes + NULL, // thread security atrributes + TRUE, // handle inheritance + 0, // creation flags, e.g. CREATE_NEW_CONSOLE, CREATE_NO_WINDOW, DETACHED_PROCESS + NULL, // pointer to environment block (uses parent if NULL) + NULL, // starting directory (uses parent if NULL) + &si, // STARTUPINFO structure + &pi ) // PROCESS_INFORMATION structure + ) { + fprintf(stderr, "runscript: cannot create process: %s\n", cmdline); + return -1; + } + CloseHandle( pi.hThread ); // thread handle is not needed + DWORD ret = 0; + if ( WaitForSingleObject( pi.hProcess, INFINITE ) == WAIT_OBJECT_0 ) { + if ( !GetExitCodeProcess( pi.hProcess, &ret) ) { + fprintf(stderr, "runscript: cannot get process exit code: %s\n", cmdline); + return -1; + } + } else { + fprintf(stderr, "runscript: failed to wait for process termination: %s\n", cmdline); + return -1; + } + CloseHandle( pi.hProcess ); + return ret; +} diff --git a/Build/source/texk/texlive/w32_wrapper/runscript_exe.c b/Build/source/texk/texlive/w32_wrapper/runscript_exe.c new file mode 100644 index 00000000000..eb28592b37c --- /dev/null +++ b/Build/source/texk/texlive/w32_wrapper/runscript_exe.c @@ -0,0 +1,7 @@ +// an .exe part of runscript program +// see runscript_dll.c for more details +#include +__declspec(dllimport) int dllrunscript( int ac, char *av[] ); +int main( int argc, char *argv[] ) { + return dllrunscript( argc, argv ); +} diff --git a/Build/source/texk/texlive/w32_wrapper/tl-w32-wrapper.cmd b/Build/source/texk/texlive/w32_wrapper/tl-w32-wrapper.cmd new file mode 100644 index 00000000000..abf2bf1578e --- /dev/null +++ b/Build/source/texk/texlive/w32_wrapper/tl-w32-wrapper.cmd @@ -0,0 +1,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 ( + 'call "%~dp0kpsewhich.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 + -- cgit v1.2.3