Fix Windows launcher issue

db4
Slava Pestov 2008-04-06 00:53:50 -05:00
parent f1bacc2110
commit 562ccb24f3
2 changed files with 24 additions and 1 deletions

View File

@ -0,0 +1,10 @@
IN: io.windows.launcher.tests
USING: tools.test io.windows.launcher ;
[ "hello world" ] [ { "hello" "world" } join-arguments ] unit-test
[ "bob \"mac arthur\"" ] [ { "bob" "mac arthur" } join-arguments ] unit-test
[ "bob mac\\\\arthur" ] [ { "bob" "mac\\\\arthur" } join-arguments ] unit-test
[ "bob \"mac arthur\\\\\"" ] [ { "bob" "mac arthur\\" } join-arguments ] unit-test

View File

@ -44,8 +44,21 @@ TUPLE: CreateProcess-args
lpProcessInformation>>
} get-slots CreateProcess win32-error=0/f ;
: count-trailing-backslashes ( str n -- str n )
>r "\\" ?tail [
r> 1+ count-trailing-backslashes
] [
r>
] if ;
: fix-trailing-backslashes ( str -- str' )
0 count-trailing-backslashes
2 * CHAR: \\ <repetition> append ;
: escape-argument ( str -- newstr )
CHAR: \s over member? [ "\"" swap "\"" 3append ] when ;
CHAR: \s over member? [
"\"" swap fix-trailing-backslashes "\"" 3append
] when ;
: join-arguments ( args -- cmd-line )
[ escape-argument ] map " " join ;