split list vocabulary into unix and windows sides
parent
5f6421af5d
commit
ba2d9bcd93
|
@ -1,12 +1,10 @@
|
||||||
! 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: accessors arrays assocs combinators generalizations
|
USING: accessors arrays combinators io io.files kernel
|
||||||
io.files io.unix.files math.parser sequences.lib calendar math
|
math.parser sequences system vocabs.loader calendar
|
||||||
kernel sequences unix.groups unix.users combinators.cleave
|
sequences.lib ;
|
||||||
strings combinators.short-circuit unicode.case ;
|
|
||||||
IN: ls
|
|
||||||
|
|
||||||
TUPLE: ls-info path user group size ;
|
IN: ls
|
||||||
|
|
||||||
: ls-time ( timestamp -- string )
|
: ls-time ( timestamp -- string )
|
||||||
[ hour>> ] [ minute>> ] bi
|
[ hour>> ] [ minute>> ] bi
|
||||||
|
@ -25,39 +23,18 @@ TUPLE: ls-info path user group size ;
|
||||||
|
|
||||||
: write>string ( ? -- string ) "w" "-" ? ; inline
|
: write>string ( ? -- string ) "w" "-" ? ; inline
|
||||||
|
|
||||||
: execute-string ( str bools -- str' )
|
HOOK: execute>string os ( ? -- string )
|
||||||
swap {
|
|
||||||
{ { t t } [ >lower ] }
|
|
||||||
{ { t f } [ >upper ] }
|
|
||||||
{ { f t } [ drop "x" ] }
|
|
||||||
[ 2drop "-" ]
|
|
||||||
} case ;
|
|
||||||
|
|
||||||
: permissions-string ( permissions -- str )
|
M: object execute>string ( ? -- string ) "x" "-" ? ; inline
|
||||||
{
|
|
||||||
[ type>> file-type>ch 1string ]
|
HOOK: permissions-string os ( -- str )
|
||||||
[ user-read? read>string ]
|
|
||||||
[ user-write? write>string ]
|
HOOK: (directory.) os ( path -- lines )
|
||||||
[ [ uid? ] [ user-execute? ] bi 2array "s" execute-string ]
|
|
||||||
[ group-read? read>string ]
|
: directory. ( path -- )
|
||||||
[ group-write? write>string ]
|
[ (directory.) ] with-directory-files [ print ] each ;
|
||||||
[ [ 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 ;
|
|
||||||
|
|
||||||
: ls ( path -- lines )
|
|
||||||
[ [ [
|
|
||||||
"" directory-files [
|
|
||||||
dup file-info
|
|
||||||
{
|
{
|
||||||
[ permissions-string ]
|
{ [ os unix? ] [ "ls.unix" ] }
|
||||||
[ nlink>> number>string 3 CHAR: \s pad-left ]
|
{ [ os windows? ] [ "ls.windows" ] }
|
||||||
! [ uid>> ]
|
} cond require
|
||||||
! [ 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 ;
|
|
|
@ -0,0 +1 @@
|
||||||
|
Doug Coleman
|
|
@ -0,0 +1 @@
|
||||||
|
unportable
|
|
@ -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 ;
|
|
@ -0,0 +1 @@
|
||||||
|
Doug Coleman
|
|
@ -0,0 +1 @@
|
||||||
|
unportable
|
|
@ -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 ;
|
Loading…
Reference in New Issue