diff --git a/extra/ls/ls.factor b/extra/ls/ls.factor old mode 100644 new mode 100755 index 3e21873fec..92aff714e6 --- a/extra/ls/ls.factor +++ b/extra/ls/ls.factor @@ -1,12 +1,10 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays assocs combinators generalizations -io.files io.unix.files math.parser sequences.lib calendar math -kernel sequences unix.groups unix.users combinators.cleave -strings combinators.short-circuit unicode.case ; -IN: ls +USING: accessors arrays combinators io io.files kernel +math.parser sequences system vocabs.loader calendar +sequences.lib ; -TUPLE: ls-info path user group size ; +IN: ls : ls-time ( timestamp -- string ) [ hour>> ] [ minute>> ] bi @@ -25,39 +23,18 @@ TUPLE: ls-info path user group size ; : write>string ( ? -- string ) "w" "-" ? ; inline -: execute-string ( str bools -- str' ) - swap { - { { t t } [ >lower ] } - { { t f } [ >upper ] } - { { f t } [ drop "x" ] } - [ 2drop "-" ] - } case ; +HOOK: execute>string os ( ? -- string ) -: permissions-string ( permissions -- str ) - { - [ type>> file-type>ch 1string ] - [ user-read? read>string ] - [ user-write? write>string ] - [ [ uid? ] [ user-execute? ] bi 2array "s" execute-string ] - [ group-read? read>string ] - [ group-write? write>string ] - [ [ gid? ] [ group-execute? ] bi 2array "s" execute-string ] - [ other-read? read>string ] - [ other-write? write>string ] - [ [ sticky? ] [ other-execute? ] bi 2array "t" execute-string ] - } concat ; +M: object execute>string ( ? -- string ) "x" "-" ? ; inline -: ls ( path -- lines ) - [ [ [ - "" directory-files [ - dup file-info - { - [ permissions-string ] - [ nlink>> number>string 3 CHAR: \s pad-left ] - ! [ uid>> ] - ! [ gid>> ] - [ size>> number>string 15 CHAR: \s pad-left ] - [ modified>> ls-timestamp ] - } swap suffix " " join - ] map - ] with-group-cache ] with-user-cache ] with-directory ; +HOOK: permissions-string os ( -- str ) + +HOOK: (directory.) os ( path -- lines ) + +: directory. ( path -- ) + [ (directory.) ] with-directory-files [ print ] each ; + +{ + { [ os unix? ] [ "ls.unix" ] } + { [ os windows? ] [ "ls.windows" ] } +} cond require \ No newline at end of file diff --git a/extra/ls/unix/authors.txt b/extra/ls/unix/authors.txt new file mode 100755 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/ls/unix/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/ls/unix/tags.txt b/extra/ls/unix/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/extra/ls/unix/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/extra/ls/unix/unix.factor b/extra/ls/unix/unix.factor new file mode 100755 index 0000000000..9a3f832961 --- /dev/null +++ b/extra/ls/unix/unix.factor @@ -0,0 +1,41 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors combinators combinators.cleave kernel system unicode.case +io.unix.files ls ; +IN: ls.unix + +M: unix execute-string ( str bools -- str' ) + swap { + { { t t } [ >lower ] } + { { t f } [ >upper ] } + { { f t } [ drop "x" ] } + [ 2drop "-" ] + } case ; + +M: unix permissions-string ( permissions -- str ) + { + [ type>> file-type>ch 1string ] + [ user-read? read>string ] + [ user-write? write>string ] + [ [ uid? ] [ user-execute? ] bi 2array "s" execute-string ] + [ group-read? read>string ] + [ group-write? write>string ] + [ [ gid? ] [ group-execute? ] bi 2array "s" execute-string ] + [ other-read? read>string ] + [ other-write? write>string ] + [ [ sticky? ] [ other-execute? ] bi 2array "t" execute-string ] + } concat ; + +M: unix ls ( path -- lines ) + [ [ + dup file-info + { + [ permissions-string ] + [ nlink>> number>string 3 CHAR: \s pad-left ] + ! [ uid>> ] + ! [ gid>> ] + [ size>> number>string 15 CHAR: \s pad-left ] + [ modified>> ls-timestamp ] + } swap suffix " " join + ] map + ] with-group-cache ] with-user-cache ; \ No newline at end of file diff --git a/extra/ls/windows/authors.txt b/extra/ls/windows/authors.txt new file mode 100755 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/ls/windows/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/ls/windows/tags.txt b/extra/ls/windows/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/extra/ls/windows/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/extra/ls/windows/windows.factor b/extra/ls/windows/windows.factor new file mode 100755 index 0000000000..b7d7eeeb0b --- /dev/null +++ b/extra/ls/windows/windows.factor @@ -0,0 +1,20 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors calendar.format combinators combinators.cleave +io.files kernel math.parser sequences splitting system ls sequences.lib ; +IN: ls.windows + +: directory-or-size ( file-info -- str ) + dup directory? [ + drop "" 20 CHAR: \s pad-right + ] [ + size>> number>string 20 CHAR: \s pad-left + ] if ; + +M: windows (directory.) ( entries -- lines ) + [ + dup file-info { + [ modified>> timestamp>ymdhms " " split1 " " splice ] + [ directory-or-size ] + } swap suffix " " join + ] map ; \ No newline at end of file