2008-11-14 01:25:00 -05:00
|
|
|
! Copyright (C) 2008 Doug Coleman.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-12-15 02:13:35 -05:00
|
|
|
USING: accessors combinators kernel system unicode.case io.files
|
|
|
|
io.files.info io.files.info.unix tools.files generalizations
|
|
|
|
strings arrays sequences math.parser unix.groups unix.users
|
2009-01-07 15:53:43 -05:00
|
|
|
tools.files.private unix.stat math fry macros ;
|
2008-12-02 22:49:59 -05:00
|
|
|
IN: tools.files.unix
|
2008-11-14 01:25:00 -05:00
|
|
|
|
2009-01-07 15:53:43 -05:00
|
|
|
MACRO: cleave>array ( array -- quot )
|
|
|
|
dup length '[ _ cleave _ narray ] ;
|
|
|
|
|
2008-11-14 01:51:14 -05:00
|
|
|
<PRIVATE
|
|
|
|
|
2008-11-14 01:44:01 -05:00
|
|
|
: unix-execute>string ( str bools -- str' )
|
2008-11-14 01:25:00 -05:00
|
|
|
swap {
|
|
|
|
{ { t t } [ >lower ] }
|
|
|
|
{ { t f } [ >upper ] }
|
|
|
|
{ { f t } [ drop "x" ] }
|
|
|
|
[ 2drop "-" ]
|
|
|
|
} case ;
|
|
|
|
|
2008-11-14 01:44:01 -05:00
|
|
|
: permissions-string ( permissions -- str )
|
2008-11-14 01:25:00 -05:00
|
|
|
{
|
|
|
|
[ type>> file-type>ch 1string ]
|
|
|
|
[ user-read? read>string ]
|
|
|
|
[ user-write? write>string ]
|
2008-11-14 01:44:01 -05:00
|
|
|
[ [ uid? ] [ user-execute? ] bi 2array "s" unix-execute>string ]
|
2008-11-14 01:25:00 -05:00
|
|
|
[ group-read? read>string ]
|
|
|
|
[ group-write? write>string ]
|
2008-11-14 01:44:01 -05:00
|
|
|
[ [ gid? ] [ group-execute? ] bi 2array "s" unix-execute>string ]
|
2008-11-14 01:25:00 -05:00
|
|
|
[ other-read? read>string ]
|
|
|
|
[ other-write? write>string ]
|
2008-11-14 01:44:01 -05:00
|
|
|
[ [ sticky? ] [ other-execute? ] bi 2array "t" unix-execute>string ]
|
2009-01-07 15:53:43 -05:00
|
|
|
} cleave>array concat ;
|
2008-11-14 01:25:00 -05:00
|
|
|
|
2008-11-19 22:15:27 -05:00
|
|
|
: mode>symbol ( mode -- ch )
|
|
|
|
S_IFMT bitand
|
|
|
|
{
|
|
|
|
{ [ dup S_IFDIR = ] [ drop "/" ] }
|
|
|
|
{ [ dup S_IFIFO = ] [ drop "|" ] }
|
|
|
|
{ [ dup any-execute? ] [ drop "*" ] }
|
|
|
|
{ [ dup S_IFLNK = ] [ drop "@" ] }
|
|
|
|
{ [ dup S_IFWHT = ] [ drop "%" ] }
|
|
|
|
{ [ dup S_IFSOCK = ] [ drop "=" ] }
|
|
|
|
{ [ t ] [ drop "" ] }
|
|
|
|
} cond ;
|
|
|
|
|
2008-11-14 01:44:01 -05:00
|
|
|
M: unix (directory.) ( path -- lines )
|
|
|
|
[ [
|
|
|
|
[
|
2008-11-14 01:25:00 -05:00
|
|
|
dup file-info
|
|
|
|
{
|
|
|
|
[ permissions-string ]
|
|
|
|
[ nlink>> number>string 3 CHAR: \s pad-left ]
|
2009-01-07 15:53:43 -05:00
|
|
|
[ uid>> user-name ]
|
|
|
|
[ gid>> group-name ]
|
2008-11-14 01:25:00 -05:00
|
|
|
[ size>> number>string 15 CHAR: \s pad-left ]
|
|
|
|
[ modified>> ls-timestamp ]
|
2009-01-07 15:53:43 -05:00
|
|
|
} cleave>array swap suffix " " join
|
2008-11-14 01:25:00 -05:00
|
|
|
] map
|
|
|
|
] with-group-cache ] with-user-cache ;
|
2008-11-14 01:51:14 -05:00
|
|
|
|
|
|
|
PRIVATE>
|