2005-02-08 22:02:44 -05:00
|
|
|
! Copyright (C) 2004, 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2005-06-19 17:50:35 -04:00
|
|
|
IN: io
|
2005-09-27 14:12:17 -04:00
|
|
|
USING: hashtables kernel lists math namespaces sequences strings
|
|
|
|
styles ;
|
2004-08-28 16:43:43 -04:00
|
|
|
|
2005-03-18 21:41:13 -05:00
|
|
|
! Words for accessing filesystem meta-data.
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2005-06-19 18:31:02 -04:00
|
|
|
: path+ ( path path -- path ) "/" swap append3 ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
2005-03-18 21:41:13 -05:00
|
|
|
: exists? ( file -- ? ) stat >boolean ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
2005-03-19 00:30:49 -05:00
|
|
|
: directory? ( file -- ? ) stat car ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
|
|
|
: directory ( dir -- list )
|
2005-09-16 23:33:20 -04:00
|
|
|
(directory)
|
2005-10-29 23:25:38 -04:00
|
|
|
H{ [[ "." "." ]] [[ ".." ".." ]] }
|
2005-09-16 23:33:20 -04:00
|
|
|
swap remove-all string-sort ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
2005-05-28 20:52:23 -04:00
|
|
|
: file-length ( file -- length ) stat third ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
2005-03-18 21:41:13 -05:00
|
|
|
: file-extension ( filename -- extension )
|
2005-09-24 15:21:17 -04:00
|
|
|
"." split dup length 1 <= [ drop f ] [ peek ] if ;
|
2005-06-19 18:53:58 -04:00
|
|
|
|
2005-09-14 00:37:50 -04:00
|
|
|
: resource-path ( path -- path )
|
|
|
|
"resource-path" get [ "." ] unless* swap path+ ;
|
2005-06-19 18:53:58 -04:00
|
|
|
|
|
|
|
: <resource-stream> ( path -- stream )
|
|
|
|
#! Open a file path relative to the Factor source code root.
|
2005-09-14 00:37:50 -04:00
|
|
|
resource-path <file-reader> ;
|
2005-09-27 14:12:17 -04:00
|
|
|
|
|
|
|
DEFER: directory.
|
|
|
|
|
|
|
|
: file-style ( text path -- text style )
|
|
|
|
dup directory? [
|
|
|
|
>r "/" append r>
|
|
|
|
dup [ directory. ] curry outline swons unit
|
|
|
|
] [
|
|
|
|
f
|
|
|
|
] if swap file swons swons ;
|
|
|
|
|
|
|
|
: file. ( dir name -- )
|
|
|
|
tuck path+ file-style format ;
|
|
|
|
|
|
|
|
: directory. ( dir -- )
|
|
|
|
dup directory [ file. terpri ] each-with ;
|