split list vocabulary into unix and windows sides

db4
Doug Coleman 2008-11-14 00:05:12 -06:00
parent 5f6421af5d
commit ba2d9bcd93
7 changed files with 82 additions and 40 deletions

57
extra/ls/ls.factor Normal file → Executable file
View File

@ -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 ]
} <arr> 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 ]
} <arr> 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

1
extra/ls/unix/authors.txt Executable file
View File

@ -0,0 +1 @@
Doug Coleman

1
extra/ls/unix/tags.txt Normal file
View File

@ -0,0 +1 @@
unportable

41
extra/ls/unix/unix.factor Executable file
View File

@ -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 ]
} <arr> 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 ]
} <arr> swap suffix " " join
] map
] with-group-cache ] with-user-cache ;

1
extra/ls/windows/authors.txt Executable file
View File

@ -0,0 +1 @@
Doug Coleman

View File

@ -0,0 +1 @@
unportable

20
extra/ls/windows/windows.factor Executable file
View File

@ -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 "<DIR>" 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 ]
} <arr> swap suffix " " join
] map ;