From f11bdc9925d4e73b543699dec3164adcc462e53e Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 28 Apr 2006 16:07:03 +0000 Subject: [PATCH] fix relative path in Windows `indepedent' launchers svn: r2836 --- collects/launcher/launcher-unit.ss | 28 ++++++++++++++++------- src/mzscheme/dynsrc/start.c | 36 ++++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/collects/launcher/launcher-unit.ss b/collects/launcher/launcher-unit.ss index 59a97eeea2..0afd588c69 100644 --- a/collects/launcher/launcher-unit.ss +++ b/collects/launcher/launcher-unit.ss @@ -236,6 +236,15 @@ (let ([s (if (path? s) (path->string s) s)]) (regexp-replace* #rx"[\"$`]" s "\\\\&"))) + (define (relativize bindir-explode dest-explode) + (let loop ([b bindir-explode] [d dest-explode]) + (if (and (pair? b) (equal? (car b) (car d))) + (loop (cdr b) (cdr d)) + (let ([p (append (map (lambda (x) 'up) (cdr d)) b)]) + (if (null? p) + #f + (apply build-path p)))))) + (define (make-relative-path-header dest bindir) ;; rely only on binaries in /usr/bin:/bin (define (has-exe? exe) @@ -281,13 +290,11 @@ "cd \"$saveD\"\n" "\n" "bindir=\"$D" - (let loop ([b bindir-explode] [d dest-explode]) - (if (and (pair? b) (equal? (car b) (car d))) - (loop (cdr b) (cdr d)) - (let ([p (append (map (lambda (x) 'up) (cdr d)) b)]) - (if (null? p) "" - (string-append - "/" (protect-shell-string (apply build-path p))))))) + (let ([s (relativize bindir-explode dest-explode)]) + (if s + (string-append "/" + (protect-shell-string s)) + "")) "\"\n" "PATH=\"$saveP\"\n" "\n") @@ -376,7 +383,12 @@ [x #rx#"]*>"] [v #rx#""]) (let* ([exedir (bytes-append - (path->bytes plthome) + (path->bytes (if (let ([m (assq 'relative? aux)]) + (and m (cdr m))) + (or (relativize (explode-path plthome) + (explode-path dest)) + (build-path 'same)) + plthome)) ;; null character marks end of executable directory #"\0")] [find-it ; Find the magic start diff --git a/src/mzscheme/dynsrc/start.c b/src/mzscheme/dynsrc/start.c index 1377aed149..3eca91acd8 100644 --- a/src/mzscheme/dynsrc/start.c +++ b/src/mzscheme/dynsrc/start.c @@ -229,7 +229,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, int main(int argc_in, char **argv_in) #endif { - char *p; char go[MAXCOMMANDLEN * 2]; char *args[MAX_ARGS + 1]; char *command_line; @@ -252,7 +251,33 @@ int main(int argc_in, char **argv_in) count = 1; count = parse_command_line(count, args, input, MAX_ARGS); - /* exedir should be PLTHOME path */ + /* exedir can be relative to the current executable */ + if ((exedir[0] == '\\') + || ((((exedir[0] >= 'a') && (exedir[0] <= 'z')) + || ((exedir[0] >= 'A') && (exedir[0] <= 'Z'))) + && (exedir[1] == ':'))) { + /* Absolute path */ + } else { + /* Make it absolute, relative to this executable */ + int plen; + int mlen; + char *s2, *path; + + path = (char *)malloc(1024); + GetModuleFileName(NULL, path, 1024); + + plen = strlen(exedir); + mlen = strlen(path); + + while (mlen && (path[mlen - 1] != '\\')) { + mlen--; + } + s2 = (char *)malloc(mlen + plen + 1); + memcpy(s2, path, mlen); + memcpy(s2 + mlen, exedir, plen + 1); + exedir = s2; + } + strcpy(go, exedir); strcat(go, GOSUBDIR); strcat(go, (variant[0] != '<') ? GOEXE3M : GOEXE); @@ -294,13 +319,6 @@ int main(int argc_in, char **argv_in) /* MessageBox(NULL, args[i], "Argument", MB_OK); */ } - /* make the exedir PLTHOME if it's not currently */ - - p = getenv("PLTHOME"); - if (p == NULL || strcmp(p,exedir)) { - SetEnvironmentVariable("PLTHOME", exedir); - } - for (i = 0; i < sizeof(si); i++) ((char *)&si)[i] = 0; si.cb = sizeof(si);