summaryrefslogtreecommitdiff
path: root/scripts/context/stubs/source/mtxrun_dll.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/context/stubs/source/mtxrun_dll.c')
-rw-r--r--scripts/context/stubs/source/mtxrun_dll.c142
1 files changed, 105 insertions, 37 deletions
diff --git a/scripts/context/stubs/source/mtxrun_dll.c b/scripts/context/stubs/source/mtxrun_dll.c
index 400ed6778..fc2e260f5 100644
--- a/scripts/context/stubs/source/mtxrun_dll.c
+++ b/scripts/context/stubs/source/mtxrun_dll.c
@@ -55,7 +55,6 @@
return 1; \
}
-char texlua_name[] = "texlua"; // just a bare name, luatex strips the rest anyway
static char cmdline[MAX_CMD];
static char dirpath[MAX_PATH];
static char progname[MAX_PATH];
@@ -70,12 +69,12 @@ int main( int argc, char *argv[] )
__declspec(dllexport) int dllrunscript( int argc, char *argv[] )
#endif
{
- char *s, *luatexfname, *argstr, **lua_argv;
+ char *binary, *s, *luatexfname, *argstr, **lua_argv;
int k, quoted, lua_argc;
int passprogname = 0;
+ unsigned char is_jit=0;
// directory of this module/executable
-
HMODULE module_handle = GetModuleHandle( "mtxrun.dll" );
// if ( module_handle == NULL ) exe path will be used, which is OK too
k = (int) GetModuleFileName( module_handle, dirpath, MAX_PATH );
@@ -86,13 +85,20 @@ __declspec(dllexport) int dllrunscript( int argc, char *argv[] )
*(++s) = '\0'; //remove file name, leave trailing backslash
// program name
-
k = strlen(argv[0]);
while ( k && (argv[0][k-1] != '/') && (argv[0][k-1] != '\\') ) k--;
strcpy(progname, &argv[0][k]);
s = progname;
if ( s = strrchr(s, '.') ) *s = '\0'; // remove file extension part
+ /* check "jit" : strlen("jit") = 3 */
+ if (strncmp(progname + strlen(progname) - 3, "jit", 3) == 0) {
+ is_jit = 1;
+ progname[strlen(progname) - 3]='\0';
+ }
+ else
+ is_jit = 0;
+
// script path
strcpy( scriptpath, dirpath );
@@ -114,44 +120,110 @@ __declspec(dllexport) int dllrunscript( int argc, char *argv[] )
strcat( scriptpath, "mtxrun.lua" );
passprogname = 1;
}
-
if ( GetFileAttributes(scriptpath) == INVALID_FILE_ATTRIBUTES )
DIE( "file not found: %s\n", scriptpath );
- // find texlua.exe
-
- if ( !SearchPath(
- getenv( "PATH" ), // path to search (optional)
- "texlua.exe", // file name to search
- NULL, // file extension to add (optional)
- MAX_PATH, // output buffer size
- luatexpath, // output buffer pointer
- &luatexfname ) // pointer to a file part in the output buffer (optional)
- )
- if ( !SearchPath(
- dirpath, // path to search (optional)
- "texlua.exe", // file name to search
- NULL, // file extension to add (optional)
- MAX_PATH, // output buffer size
- luatexpath, // output buffer pointer
- &luatexfname ) // pointer to a file part in the output buffer (optional)
- )
- DIE( "unable to locate texlua.exe on the search path" );
+ // find luatex.exe /luajittex.exe
+ if ( SearchPath(
+ dirpath, // was getenv( "PATH" ), // path to search (optional)
+ (is_jit ? "luajittex.exe":"luatex.exe"), // file name to search
+ NULL, // file extension to add (optional)
+ MAX_PATH, // output buffer size
+ luatexpath, // output buffer pointer
+ &luatexfname ) // pointer to a file part in the output buffer (optional)
+ ) {
+ binary = (is_jit ? "luajittex.exe":"luatex.exe");
+ } else if ( SearchPath(
+ dirpath, // was getenv( "PATH" ), // path to search (optional)
+ (is_jit ? "texluajit.exe":"texlua.exe"), // file name to search
+ NULL, // file extension to add (optional)
+ MAX_PATH, // output buffer size
+ luatexpath, // output buffer pointer
+ &luatexfname ) // pointer to a file part in the output buffer (optional)
+ ) {
+ binary = (is_jit ? "texluajit.exe":"texlua.exe");
+ } else if ( SearchPath(
+ getenv("PATH"), // was dirpath, // path to search (optional)
+ (is_jit ? "luajittex.exe":"luatex.exe"), // file name to search
+ NULL, // file extension to add (optional)
+ MAX_PATH, // output buffer size
+ luatexpath, // output buffer pointer
+ &luatexfname ) // pointer to a file part in the output buffer (optional)
+ ) {
+ binary = (is_jit ? "luajittex.exe":"luatex.exe");
+ } else if ( SearchPath(
+ getenv("PATH") , // was dirpath, // path to search (optional)
+ (is_jit ? "texluajit.exe":"texlua.exe"), // file name to search
+ NULL, // file extension to add (optional)
+ MAX_PATH, // output buffer size
+ luatexpath, // output buffer pointer
+ &luatexfname ) // pointer to a file part in the output buffer (optional)
+ ) {
+ binary = (is_jit ? "texluajit.exe":"texlua.exe");
+ }else {
+ DIE( "unable to locate texlua.exe on the search path" );
+ }
+
+ /* if ( SearchPath( */
+ /* dirpath, // was getenv( "PATH" ), // path to search (optional) */
+ /* (is_jit ? "luajittex.exe":"luatex.exe"), // file name to search */
+ /* NULL, // file extension to add (optional) */
+ /* MAX_PATH, // output buffer size */
+ /* luatexpath, // output buffer pointer */
+ /* &luatexfname ) // pointer to a file part in the output buffer (optional) */
+ /* ) { */
+ /* binary = (is_jit ? "luajittex.exe":"luatex.exe"); */
+ /* }else if ( SearchPath( */
+ /* getenv("PATH"), // was dirpath, // path to search (optional) */
+ /* (is_jit ? "luajittex.exe":"luatex.exe"), // file name to search */
+ /* NULL, // file extension to add (optional) */
+ /* MAX_PATH, // output buffer size */
+ /* luatexpath, // output buffer pointer */
+ /* &luatexfname ) // pointer to a file part in the output buffer (optional) */
+ /* ) { */
+ /* binary = (is_jit ? "luajittex.exe":"luatex.exe"); */
+ /* }else if ( SearchPath( */
+ /* dirpath, // was getenv( "PATH" ), // path to search (optional) */
+ /* (is_jit ? "texluajit.exe":"texlua.exe"), // file name to search */
+ /* NULL, // file extension to add (optional) */
+ /* MAX_PATH, // output buffer size */
+ /* luatexpath, // output buffer pointer */
+ /* &luatexfname ) // pointer to a file part in the output buffer (optional) */
+ /* ) { */
+ /* binary = (is_jit ? "texluajit.exe":"texlua.exe"); */
+ /* }else if ( SearchPath( */
+ /* getenv("PATH") , // was dirpath, // path to search (optional) */
+ /* (is_jit ? "texluajit.exe":"texlua.exe"), // file name to search */
+ /* NULL, // file extension to add (optional) */
+ /* MAX_PATH, // output buffer size */
+ /* luatexpath, // output buffer pointer */
+ /* &luatexfname ) // pointer to a file part in the output buffer (optional) */
+ /* ) { */
+ /* binary = (is_jit ? "texluajit.exe":"texlua.exe"); */
+ /* }else { */
+ /* DIE( "unable to locate texlua.exe on the search path" ); */
+ /* } */
+
- // link directly with luatex.dll if available in texlua's dir
- strcpy( luatexfname, "luatex.dll" );
+
+ // link directly with luatex.dll if available in texlua's dir
+ strcpy( luatexfname, (is_jit ? "luajittex.dll":"luatex.dll") );
if ( dllluatex = LoadLibrary(luatexpath) )
{
- mainlikeproc dllluatexmain = (mainlikeproc) GetProcAddress( dllluatex, "dllluatexmain" );
+ mainlikeproc dllluatexmain = (mainlikeproc) GetProcAddress( dllluatex, (is_jit ? "dllluajittexmain": "dllluatexmain" ));
if ( dllluatexmain == NULL )
- DIE( "unable to locate dllluatexmain procedure in luatex.dll" );
+ if (is_jit)
+ DIE( "unable to locate dllluatexmain procedure in luajittex.dll" )
+ else
+ DIE( "unable to locate dllluatexmain procedure in luatex.dll" );
// set up argument list for texlua script
- lua_argv = (char **)malloc( (argc + 4) * sizeof(char *) );
+ lua_argv = (char **)malloc( (argc + 5) * sizeof(char *) );
if ( lua_argv == NULL ) DIE( "out of memory\n" );
- lua_argv[lua_argc=0] = texlua_name;
+ lua_argv[lua_argc=0] = luatexfname;
+ lua_argv[++lua_argc] = "--luaonly";
lua_argv[++lua_argc] = scriptpath; // script to execute
if (passprogname) {
lua_argv[++lua_argc] = "--script";
@@ -162,15 +234,15 @@ __declspec(dllexport) int dllrunscript( int argc, char *argv[] )
// call texlua interpreter
// dllluatexmain never returns, but we pretend that it does
-
+
k = dllluatexmain( lua_argc, lua_argv );
if (lua_argv) free( lua_argv );
return k;
}
-
// we are still here, so no luatex.dll; spawn texlua.exe instead
- strcpy( luatexfname, "texlua.exe" );
+ strcpy( luatexfname,binary);
+ strcpy( cmdline, " --luaonly " );
strcpy( cmdline, "\"" );
strcat( cmdline, luatexpath );
strcat( cmdline, "\" \"" );
@@ -180,7 +252,6 @@ __declspec(dllexport) int dllrunscript( int argc, char *argv[] )
strcat( cmdline, " --script " );
strcat( cmdline, progname );
}
-
argstr = GetCommandLine(); // get the command line of this process
if ( argstr == NULL ) DIE( "unable to retrieve the command line string\n" );
@@ -209,7 +280,6 @@ __declspec(dllexport) int dllrunscript( int argc, char *argv[] )
si.hStdOutput = GetStdHandle( STD_OUTPUT_HANDLE );
si.hStdError = GetStdHandle( STD_ERROR_HANDLE );
ZeroMemory( &pi, sizeof(pi) );
-
if( !CreateProcess(
NULL, // module name (uses command line if NULL)
cmdline, // command line
@@ -222,7 +292,6 @@ __declspec(dllexport) int dllrunscript( int argc, char *argv[] )
&si, // STARTUPINFO structure
&pi ) // PROCESS_INFORMATION structure
) DIE( "command execution failed: %s\n", cmdline );
-
DWORD ret = 0;
CloseHandle( pi.hThread ); // thread handle is not needed
if ( WaitForSingleObject( pi.hProcess, INFINITE ) == WAIT_OBJECT_0 ) {
@@ -232,7 +301,6 @@ __declspec(dllexport) int dllrunscript( int argc, char *argv[] )
CloseHandle( pi.hProcess );
// propagate exit code from the child process
-
return ret;
}