]> gitweb.factorcode.org Git - factor.git/commitdiff
Fix Windows launcher issue
authorSlava Pestov <slava@factorcode.org>
Sun, 6 Apr 2008 05:53:50 +0000 (00:53 -0500)
committerSlava Pestov <slava@factorcode.org>
Sun, 6 Apr 2008 05:53:50 +0000 (00:53 -0500)
extra/io/windows/launcher/launcher-tests.factor [new file with mode: 0755]
extra/io/windows/launcher/launcher.factor

diff --git a/extra/io/windows/launcher/launcher-tests.factor b/extra/io/windows/launcher/launcher-tests.factor
new file mode 100755 (executable)
index 0000000..1dba8bd
--- /dev/null
@@ -0,0 +1,10 @@
+IN: io.windows.launcher.tests\r
+USING: tools.test io.windows.launcher ;\r
+\r
+[ "hello world" ] [ { "hello" "world" } join-arguments ] unit-test\r
+\r
+[ "bob \"mac arthur\"" ] [ { "bob" "mac arthur" } join-arguments ] unit-test\r
+\r
+[ "bob mac\\\\arthur" ] [ { "bob" "mac\\\\arthur" } join-arguments ] unit-test\r
+\r
+[ "bob \"mac arthur\\\\\"" ] [ { "bob" "mac arthur\\" } join-arguments ] unit-test\r
index 410e13d2668c6de87770cbad543279ac4f42b3f1..04e149d26124c8a2c58facaefb42af85c10aaca1 100755 (executable)
@@ -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 ;