PRIVATE>
-SYMBOLS: file-name file-name/type permissions file-type nlinks file-size
-file-date file-time file-datetime uid gid user group link-target unix-datetime
-directory-or-size ;
+SYMBOLS: +file-name+ +file-name/type+ +permissions+ +file-type+
++nlinks+ +file-size+ +file-date+ +file-time+ +file-datetime+
++uid+ +gid+ +user+ +group+ +link-target+ +unix-datetime+
++directory-or-size+ ;
TUPLE: listing-tool path specs sort ;
: <listing-tool> ( path -- listing-tool )
listing-tool new
swap >>path
- { file-name } >>specs ;
+ { +file-name+ } >>specs ;
: list-slow? ( listing-tool -- ? )
- specs>> { file-name } sequence= not ;
+ specs>> { +file-name+ } sequence= not ;
ERROR: unknown-file-spec symbol ;
M: object file-spec>string ( file-listing spec -- string )
{
- { file-name [ directory-entry>> name>> ] }
- { directory-or-size [ file-info>> dir-or-size ] }
- { file-size [ file-info>> size>> number>string ] }
- { file-date [ file-info>> modified>> listing-date ] }
- { file-time [ file-info>> modified>> listing-time ] }
- { file-datetime [ file-info>> modified>> timestamp>ymdhms ] }
+ { +file-name+ [ directory-entry>> name>> ] }
+ { +directory-or-size+ [ file-info>> dir-or-size ] }
+ { +file-size+ [ file-info>> size>> number>string ] }
+ { +file-date+ [ file-info>> modified>> listing-date ] }
+ { +file-time+ [ file-info>> modified>> listing-time ] }
+ { +file-datetime+ [ file-info>> modified>> timestamp>ymdhms ] }
[ unknown-file-spec ]
} case ;
: directory. ( path -- ) (directory.) simple-table. ;
-SYMBOLS: device-name mount-point type
-available-space free-space used-space total-space
-percent-used percent-free ;
+SYMBOLS: +device-name+ +mount-point+ +type+
++available-space+ +free-space+ +used-space+ +total-space+
++percent-used+ +percent-free+ ;
: percent ( real -- integer ) 100 * >integer ; inline
: file-system-spec ( file-system-info obj -- str )
{
- { device-name [ device-name>> "" or ] }
- { mount-point [ mount-point>> "" or ] }
- { type [ type>> "" or ] }
- { available-space [ available-space>> 0 or ] }
- { free-space [ free-space>> 0 or ] }
- { used-space [ used-space>> 0 or ] }
- { total-space [ total-space>> 0 or ] }
- { percent-used [
+ { +device-name+ [ device-name>> "" or ] }
+ { +mount-point+ [ mount-point>> "" or ] }
+ { +type+ [ type>> "" or ] }
+ { +available-space+ [ available-space>> 0 or ] }
+ { +free-space+ [ free-space>> 0 or ] }
+ { +used-space+ [ used-space>> 0 or ] }
+ { +total-space+ [ total-space>> 0 or ] }
+ { +percent-used+ [
[ used-space>> ] [ total-space>> ] bi
[ 0 or ] bi@ dup 0 =
[ 2drop 0 ] [ / percent ] if
: file-systems. ( -- )
{
- device-name available-space free-space used-space
- total-space percent-used mount-point
+ +device-name+ +available-space+ +free-space+ +used-space+
+ +total-space+ +percent-used+ +mount-point+
} print-file-systems ;
{
M: unix (directory.) ( path -- lines )
<listing-tool>
- { permissions nlinks user group file-size file-date file-name } >>specs
+ {
+ +permissions+ +nlinks+ +user+ +group+
+ +file-size+ +file-date+ +file-name+
+ } >>specs
{ { directory-entry>> name>> <=> } } >>sort
[ [ list-files ] with-group-cache ] with-user-cache ;
M: unix file-spec>string ( file-listing spec -- string )
{
- { file-name/type [
+ { +file-name/type+ [
directory-entry>> [ name>> ] [ file-type>trailing ] bi append
] }
- { permissions [ file-info>> permissions-string ] }
- { nlinks [ file-info>> nlink>> number>string ] }
- { user [ file-info>> uid>> user-name ] }
- { group [ file-info>> gid>> group-name ] }
- { uid [ file-info>> uid>> number>string ] }
- { gid [ file-info>> gid>> number>string ] }
+ { +permissions+ [ file-info>> permissions-string ] }
+ { +nlinks+ [ file-info>> nlink>> number>string ] }
+ { +user+ [ file-info>> uid>> user-name ] }
+ { +group+ [ file-info>> gid>> group-name ] }
+ { +uid+ [ file-info>> uid>> number>string ] }
+ { +gid+ [ file-info>> gid>> number>string ] }
[ call-next-method ]
} case ;