]> gitweb.factorcode.org Git - factor.git/commitdiff
io.standard-paths: adding support for PATHEXT.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 1 Jun 2015 21:57:47 +0000 (14:57 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 1 Jun 2015 21:57:47 +0000 (14:57 -0700)
basis/io/standard-paths/windows/windows.factor

index d82bcdbd6a6ec9808af87e7a4e5e7bbc571fef73..4911bb3b36aca577dc71061bd54a35d2f3590a4e 100644 (file)
@@ -1,14 +1,25 @@
 ! Copyright (C) 2011 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: environment fry io.directories.search.windows io.files
-io.pathnames io.standard-paths kernel sequences splitting
-system unicode.case ;
+USING: arrays assocs environment fry
+io.directories.search.windows io.files io.pathnames
+io.standard-paths kernel sequences splitting system
+unicode.case ;
 IN: io.standard-paths.windows
 
 M: windows find-in-applications
     '[ [ >lower _ tail? ] find-in-program-files ] map-find drop ;
 
-M: windows find-in-path*
-    [ "PATH" os-env ";" split ] dip
-    '[ _ append-path exists? ] find nip ;
+: path ( -- path )
+    "PATH" os-env ";" split "." prefix ;
+
+: path-extensions ( command -- commands )
+    "PATHEXT" os-env [
+        ";" split 2dup [ [ >lower ] bi@ tail? ] with any?
+        [ drop 1array ] [ [ append ] with map ] if
+    ] [ 1array ] if* ;
 
+M: windows find-in-path*
+    path-extensions path
+    cartesian-product flip concat
+    [ prepend-path ] { } assoc>map
+    [ exists? ] find nip ;