fix bug in io.paths, add io.paths.windows
parent
65c54b7220
commit
7f93d335a6
|
@ -1,11 +1,13 @@
|
||||||
! Copyright (C) 2008 Doug Coleman.
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: io.files kernel sequences accessors
|
USING: accessors arrays deques dlists io.files io.paths.private
|
||||||
dlists deques arrays ;
|
kernel sequences system vocabs.loader fry continuations ;
|
||||||
IN: io.paths
|
IN: io.paths
|
||||||
|
|
||||||
TUPLE: directory-iterator path bfs queue ;
|
TUPLE: directory-iterator path bfs queue ;
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
: qualified-directory ( path -- seq )
|
: qualified-directory ( path -- seq )
|
||||||
dup directory-files [ append-path ] with map ;
|
dup directory-files [ append-path ] with map ;
|
||||||
|
|
||||||
|
@ -25,25 +27,32 @@ TUPLE: directory-iterator path bfs queue ;
|
||||||
[ over push-directory next-file ] [ nip ] if
|
[ over push-directory next-file ] [ nip ] if
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: iterate-directory ( iter quot -- obj )
|
: iterate-directory ( iter quot: ( obj -- ? ) -- obj )
|
||||||
over next-file [
|
over next-file [
|
||||||
over call
|
over call
|
||||||
[ 2drop ] [ iterate-directory ] if
|
[ 2nip ] [ iterate-directory ] if*
|
||||||
] [
|
] [
|
||||||
2drop f
|
2drop f
|
||||||
] if* ; inline recursive
|
] if* ; inline recursive
|
||||||
|
|
||||||
: find-file ( path bfs? quot -- path/f )
|
PRIVATE>
|
||||||
|
|
||||||
|
: find-file ( path bfs? quot: ( obj -- ? ) -- path/f )
|
||||||
[ <directory-iterator> ] dip
|
[ <directory-iterator> ] dip
|
||||||
[ keep and ] curry iterate-directory ; inline
|
[ keep and ] curry iterate-directory ; inline
|
||||||
|
|
||||||
: each-file ( path bfs? quot -- )
|
: each-file ( path bfs? quot: ( obj -- ? ) -- )
|
||||||
[ <directory-iterator> ] dip
|
[ <directory-iterator> ] dip
|
||||||
[ f ] compose iterate-directory drop ; inline
|
[ f ] compose iterate-directory drop ; inline
|
||||||
|
|
||||||
: find-all-files ( path bfs? quot -- paths )
|
: find-all-files ( path bfs? quot: ( obj -- ? ) -- paths )
|
||||||
[ <directory-iterator> ] dip
|
[ <directory-iterator> ] dip
|
||||||
pusher [ [ f ] compose iterate-directory drop ] dip ; inline
|
pusher [ [ f ] compose iterate-directory drop ] dip ; inline
|
||||||
|
|
||||||
: recursive-directory ( path bfs? -- paths )
|
: recursive-directory ( path bfs? -- paths )
|
||||||
[ ] accumulator [ each-file ] dip ;
|
[ ] accumulator [ each-file ] dip ;
|
||||||
|
|
||||||
|
: find-in-directories ( directories bfs? quot -- path' )
|
||||||
|
'[ _ _ find-file ] attempt-all ; inline
|
||||||
|
|
||||||
|
os windows? [ "io.paths.windows" require ] when
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Doug Coleman
|
|
@ -0,0 +1 @@
|
||||||
|
unportable
|
|
@ -0,0 +1,13 @@
|
||||||
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: arrays continuations fry io.files io.paths
|
||||||
|
kernel windows.shell32 sequences ;
|
||||||
|
IN: io.paths.windows
|
||||||
|
|
||||||
|
: program-files-directories ( -- array )
|
||||||
|
program-files program-files-x86 2array ; inline
|
||||||
|
|
||||||
|
: find-in-program-files ( base-directory bfs? quot -- path )
|
||||||
|
[
|
||||||
|
[ program-files-directories ] dip '[ _ append-path ] map
|
||||||
|
] 2dip find-in-directories ; inline
|
Loading…
Reference in New Issue