fix relative path in Windows `indepedent' launchers

svn: r2836
This commit is contained in:
Matthew Flatt 2006-04-28 16:07:03 +00:00
parent 7c45b22d9d
commit f11bdc9925
2 changed files with 47 additions and 17 deletions

View File

@ -236,6 +236,15 @@
(let ([s (if (path? s) (path->string s) s)]) (let ([s (if (path? s) (path->string s) s)])
(regexp-replace* #rx"[\"$`]" 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) (define (make-relative-path-header dest bindir)
;; rely only on binaries in /usr/bin:/bin ;; rely only on binaries in /usr/bin:/bin
(define (has-exe? exe) (define (has-exe? exe)
@ -281,13 +290,11 @@
"cd \"$saveD\"\n" "cd \"$saveD\"\n"
"\n" "\n"
"bindir=\"$D" "bindir=\"$D"
(let loop ([b bindir-explode] [d dest-explode]) (let ([s (relativize bindir-explode dest-explode)])
(if (and (pair? b) (equal? (car b) (car d))) (if s
(loop (cdr b) (cdr d)) (string-append "/"
(let ([p (append (map (lambda (x) 'up) (cdr d)) b)]) (protect-shell-string s))
(if (null? p) "" ""))
(string-append
"/" (protect-shell-string (apply build-path p)))))))
"\"\n" "\"\n"
"PATH=\"$saveP\"\n" "PATH=\"$saveP\"\n"
"\n") "\n")
@ -376,7 +383,12 @@
[x #rx#"<Executable Directory: Replace This[^>]*>"] [x #rx#"<Executable Directory: Replace This[^>]*>"]
[v #rx#"<Executable Variant: Replace This>"]) [v #rx#"<Executable Variant: Replace This>"])
(let* ([exedir (bytes-append (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 ;; null character marks end of executable directory
#"\0")] #"\0")]
[find-it ; Find the magic start [find-it ; Find the magic start

View File

@ -229,7 +229,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
int main(int argc_in, char **argv_in) int main(int argc_in, char **argv_in)
#endif #endif
{ {
char *p;
char go[MAXCOMMANDLEN * 2]; char go[MAXCOMMANDLEN * 2];
char *args[MAX_ARGS + 1]; char *args[MAX_ARGS + 1];
char *command_line; char *command_line;
@ -252,7 +251,33 @@ int main(int argc_in, char **argv_in)
count = 1; count = 1;
count = parse_command_line(count, args, input, MAX_ARGS); 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); strcpy(go, exedir);
strcat(go, GOSUBDIR); strcat(go, GOSUBDIR);
strcat(go, (variant[0] != '<') ? GOEXE3M : GOEXE); 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); */ /* 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++) for (i = 0; i < sizeof(si); i++)
((char *)&si)[i] = 0; ((char *)&si)[i] = 0;
si.cb = sizeof(si); si.cb = sizeof(si);