Merge branch 'master' of git://factorcode.org/git/factor
commit
52fbbc7287
|
@ -269,7 +269,7 @@ $nl
|
||||||
{ $heading "Example: ls" }
|
{ $heading "Example: ls" }
|
||||||
"Here is an example implementing a simplified version of the Unix " { $snippet "ls" } " command in Factor:"
|
"Here is an example implementing a simplified version of the Unix " { $snippet "ls" } " command in Factor:"
|
||||||
{ $code
|
{ $code
|
||||||
<" USING: command-line namespaces io io.files io.files.listing
|
<" USING: command-line namespaces io io.files tools.files
|
||||||
sequences kernel ;
|
sequences kernel ;
|
||||||
|
|
||||||
command-line get [
|
command-line get [
|
||||||
|
|
|
@ -80,7 +80,7 @@ TUPLE: unix-file-system-info < file-system-info
|
||||||
block-size preferred-block-size
|
block-size preferred-block-size
|
||||||
blocks blocks-free blocks-available
|
blocks blocks-free blocks-available
|
||||||
files files-free files-available
|
files files-free files-available
|
||||||
name-max flags id ;
|
name-max flags id id0 id1 ;
|
||||||
|
|
||||||
HOOK: new-file-system-info os ( -- file-system-info )
|
HOOK: new-file-system-info os ( -- file-system-info )
|
||||||
|
|
||||||
|
@ -108,6 +108,8 @@ M: unix statvfs>file-system-info drop ;
|
||||||
[ dup [ blocks-free>> ] [ block-size>> ] bi * >>free-space drop ]
|
[ dup [ blocks-free>> ] [ block-size>> ] bi * >>free-space drop ]
|
||||||
[ dup [ blocks>> ] [ block-size>> ] bi * >>total-space drop ]
|
[ dup [ blocks>> ] [ block-size>> ] bi * >>total-space drop ]
|
||||||
[ dup [ total-space>> ] [ free-space>> ] bi - >>used-space drop ]
|
[ dup [ total-space>> ] [ free-space>> ] bi - >>used-space drop ]
|
||||||
|
[ dup id>> 2 c-uint-array> first2 [ >>id0 ] [ >>id1 ] bi* drop ]
|
||||||
|
[ f >>id drop ]
|
||||||
[ ]
|
[ ]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
|
|
|
@ -2,23 +2,53 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien.c-types alien.syntax combinators
|
USING: accessors alien.c-types alien.syntax combinators
|
||||||
io.backend io.files io.unix.files kernel math system unix
|
io.backend io.files io.unix.files kernel math system unix
|
||||||
unix.statvfs.freebsd ;
|
unix.statfs.freebsd unix.statvfs.freebsd unix.getfsstat.freebsd
|
||||||
|
sequences grouping alien.strings io.encodings.utf8 ;
|
||||||
IN: io.unix.files.freebsd
|
IN: io.unix.files.freebsd
|
||||||
|
|
||||||
|
TUPLE: freebsd-file-system-info < unix-file-system-info
|
||||||
|
version io-size owner syncreads syncwrites asyncreads asyncwrites ;
|
||||||
|
|
||||||
|
M: freebsd new-file-system-info freebsd-file-system-info new ;
|
||||||
|
|
||||||
|
M: freebsd file-system-statfs ( path -- byte-array )
|
||||||
|
"statfs" <c-object> tuck statfs io-error ;
|
||||||
|
|
||||||
|
M: freebsd statfs>file-system-info ( file-system-info statvfs -- file-system-info )
|
||||||
|
{
|
||||||
|
[ statfs-f_version >>version ]
|
||||||
|
[ statfs-f_type >>type ]
|
||||||
|
[ statfs-f_flags >>flags ]
|
||||||
|
[ statfs-f_bsize >>block-size ]
|
||||||
|
[ statfs-f_iosize >>io-size ]
|
||||||
|
[ statfs-f_blocks >>blocks ]
|
||||||
|
[ statfs-f_bfree >>blocks-free ]
|
||||||
|
[ statfs-f_bavail >>blocks-available ]
|
||||||
|
[ statfs-f_files >>files ]
|
||||||
|
[ statfs-f_ffree >>files-free ]
|
||||||
|
[ statfs-f_syncwrites >>syncwrites ]
|
||||||
|
[ statfs-f_asyncwrites >>asyncwrites ]
|
||||||
|
[ statfs-f_syncreads >>syncreads ]
|
||||||
|
[ statfs-f_asyncreads >>asyncreads ]
|
||||||
|
[ statfs-f_namemax >>name-max ]
|
||||||
|
[ statfs-f_owner >>owner ]
|
||||||
|
[ statfs-f_fsid >>id ]
|
||||||
|
[ statfs-f_fstypename utf8 alien>string >>type ]
|
||||||
|
[ statfs-f_mntfromname utf8 alien>string >>device-name ]
|
||||||
|
[ statfs-f_mntonname utf8 alien>string >>mount-point ]
|
||||||
|
} cleave ;
|
||||||
|
|
||||||
M: freebsd file-system-statvfs ( path -- byte-array )
|
M: freebsd file-system-statvfs ( path -- byte-array )
|
||||||
"statvfs" <c-object> tuck statvfs io-error ;
|
"statvfs" <c-object> tuck statvfs io-error ;
|
||||||
|
|
||||||
M: freebsd statvfs>file-system-info ( file-system-info statvfs -- file-system-info )
|
M: freebsd statvfs>file-system-info ( file-system-info statvfs -- file-system-info )
|
||||||
{
|
{
|
||||||
[ statvfs-f_bavail >>blocks-available ]
|
|
||||||
[ statvfs-f_bfree >>blocks-free ]
|
|
||||||
[ statvfs-f_blocks >>blocks ]
|
|
||||||
[ statvfs-f_favail >>files-available ]
|
[ statvfs-f_favail >>files-available ]
|
||||||
[ statvfs-f_ffree >>files-free ]
|
|
||||||
[ statvfs-f_files >>files ]
|
|
||||||
[ statvfs-f_bsize >>block-size ]
|
|
||||||
[ statvfs-f_flag >>flags ]
|
|
||||||
[ statvfs-f_frsize >>preferred-block-size ]
|
[ statvfs-f_frsize >>preferred-block-size ]
|
||||||
[ statvfs-f_fsid >>id ]
|
|
||||||
[ statvfs-f_namemax >>name-max ]
|
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
|
M: freebsd file-systems ( -- array )
|
||||||
|
f 0 0 getfsstat dup io-error
|
||||||
|
"statfs" <c-array> dup dup length 0 getfsstat io-error
|
||||||
|
"statfs" heap-size group
|
||||||
|
[ statfs-f_mntonname alien>native-string file-system-info ] map ;
|
||||||
|
|
|
@ -10,10 +10,10 @@ TUPLE: macosx-file-system-info < unix-file-system-info
|
||||||
io-size owner type-id filesystem-subtype ;
|
io-size owner type-id filesystem-subtype ;
|
||||||
|
|
||||||
M: macosx file-systems ( -- array )
|
M: macosx file-systems ( -- array )
|
||||||
f 0 0 getfsstat64 dup io-error
|
f <void*> dup 0 getmntinfo64 dup io-error
|
||||||
"statfs" <c-array> dup dup length 0 getfsstat64 io-error
|
[ *void* ] dip
|
||||||
"statfs" heap-size group
|
"statfs64" heap-size [ * memory>byte-array ] keep group
|
||||||
[ statfs64-f_mntonname alien>native-string file-system-info ] map ;
|
[ [ new-file-system-info ] dip statfs>file-system-info ] map ;
|
||||||
|
|
||||||
M: macosx new-file-system-info macosx-file-system-info new ;
|
M: macosx new-file-system-info macosx-file-system-info new ;
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,14 @@
|
||||||
USING: alien.syntax kernel unix.stat math unix
|
USING: alien.syntax kernel unix.stat math unix
|
||||||
combinators system io.backend accessors alien.c-types
|
combinators system io.backend accessors alien.c-types
|
||||||
io.encodings.utf8 alien.strings unix.types io.unix.files
|
io.encodings.utf8 alien.strings unix.types io.unix.files
|
||||||
io.files unix.statvfs.netbsd ;
|
io.files unix.statvfs.netbsd unix.getfsstat.netbsd
|
||||||
|
grouping sequences ;
|
||||||
IN: io.unix.files.netbsd
|
IN: io.unix.files.netbsd
|
||||||
|
|
||||||
TUPLE: netbsd-file-system-info < unix-file-system-info
|
TUPLE: netbsd-file-system-info < unix-file-system-info
|
||||||
blocks-reserved files-reserved
|
blocks-reserved files-reserved
|
||||||
owner io-size
|
owner io-size sync-reads sync-writes async-reads async-writes
|
||||||
sync-reads sync-writes
|
idx mount-from ;
|
||||||
async-reads async-writes
|
|
||||||
idx mount-from spare ;
|
|
||||||
|
|
||||||
M: netbsd new-file-system-info netbsd-file-system-info new ;
|
M: netbsd new-file-system-info netbsd-file-system-info new ;
|
||||||
|
|
||||||
|
@ -40,10 +39,14 @@ M: netbsd statvfs>file-system-info ( file-system-info statvfs -- file-system-inf
|
||||||
[ statvfs-f_fsid >>id ]
|
[ statvfs-f_fsid >>id ]
|
||||||
[ statvfs-f_namemax >>name-max ]
|
[ statvfs-f_namemax >>name-max ]
|
||||||
[ statvfs-f_owner >>owner ]
|
[ statvfs-f_owner >>owner ]
|
||||||
[ statvfs-f_spare >>spare ]
|
! [ statvfs-f_spare >>spare ]
|
||||||
[ statvfs-f_fstypename alien>native-string >>type ]
|
[ statvfs-f_fstypename alien>native-string >>type ]
|
||||||
[ statvfs-f_mntonname alien>native-string >>mount-point ]
|
[ statvfs-f_mntonname alien>native-string >>mount-point ]
|
||||||
[ statvfs-f_mntfromname alien>native-string >>device-name ]
|
[ statvfs-f_mntfromname alien>native-string >>device-name ]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
FUNCTION: int statvfs ( char* path, statvfs* buf ) ;
|
M: netbsd file-systems ( -- array )
|
||||||
|
f 0 0 getvfsstat dup io-error
|
||||||
|
"statvfs" <c-array> dup dup length 0 getvfsstat io-error
|
||||||
|
"statvfs" heap-size group
|
||||||
|
[ statvfs-f_mntonname alien>native-string file-system-info ] map ;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! 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: help.markup help.syntax io.streams.string strings ;
|
USING: help.markup help.syntax io.streams.string strings ;
|
||||||
IN: io.files.listing
|
IN: tools.files
|
||||||
|
|
||||||
HELP: directory.
|
HELP: directory.
|
||||||
{ $values
|
{ $values
|
||||||
|
@ -9,9 +9,9 @@ HELP: directory.
|
||||||
}
|
}
|
||||||
{ $description "Prints information about all files in a directory to the output stream in a cross-platform way similar to the Unix " { $snippet "ls" } " command." } ;
|
{ $description "Prints information about all files in a directory to the output stream in a cross-platform way similar to the Unix " { $snippet "ls" } " command." } ;
|
||||||
|
|
||||||
ARTICLE: "io.files.listing" "Listing files"
|
ARTICLE: "tools.files" "Files tools"
|
||||||
"The " { $vocab-link "io.files.listing" } " vocabulary implements directory file listing in a cross-platform way." $nl
|
"The " { $vocab-link "tools.files" } " vocabulary implements directory files and file-systems listing in a cross-platform way." $nl
|
||||||
"Listing a directory:"
|
"Listing a directory:"
|
||||||
{ $subsection directory. } ;
|
{ $subsection directory. } ;
|
||||||
|
|
||||||
ABOUT: "io.files.listing"
|
ABOUT: "tools.files"
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2008 Your name.
|
! Copyright (C) 2008 Your name.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: tools.test io.files.listing strings kernel ;
|
USING: tools.test tools.files strings kernel ;
|
||||||
IN: io.files.listing.tests
|
IN: tools.files.tests
|
||||||
|
|
||||||
\ directory. must-infer
|
\ directory. must-infer
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays combinators io io.files kernel
|
USING: accessors arrays combinators io io.files kernel
|
||||||
math.parser sequences system vocabs.loader calendar ;
|
math.parser sequences system vocabs.loader calendar ;
|
||||||
|
IN: tools.files
|
||||||
IN: io.files.listing
|
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
@ -34,6 +33,6 @@ PRIVATE>
|
||||||
[ (directory.) ] with-directory-files [ print ] each ;
|
[ (directory.) ] with-directory-files [ print ] each ;
|
||||||
|
|
||||||
{
|
{
|
||||||
{ [ os unix? ] [ "io.files.listing.unix" ] }
|
{ [ os unix? ] [ "tools.files.unix" ] }
|
||||||
{ [ os windows? ] [ "io.files.listing.windows" ] }
|
{ [ os windows? ] [ "tools.files.windows" ] }
|
||||||
} cond require
|
} cond require
|
|
@ -1,10 +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 combinators kernel system unicode.case
|
USING: accessors combinators kernel system unicode.case
|
||||||
io.unix.files io.files.listing generalizations strings
|
io.unix.files tools.files generalizations strings
|
||||||
arrays sequences io.files math.parser unix.groups unix.users
|
arrays sequences io.files math.parser unix.groups unix.users
|
||||||
io.files.listing.private unix.stat math ;
|
tools.files.private unix.stat math ;
|
||||||
IN: io.files.listing.unix
|
IN: tools.files.unix
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
! 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 calendar.format combinators io.files
|
USING: accessors calendar.format combinators io.files
|
||||||
kernel math.parser sequences splitting system io.files.listing
|
kernel math.parser sequences splitting system tools.files
|
||||||
generalizations io.files.listing.private ;
|
generalizations tools.files.private ;
|
||||||
IN: io.files.listing.windows
|
IN: tools.files.windows
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Doug Coleman
|
|
@ -0,0 +1,11 @@
|
||||||
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: alien.syntax ;
|
||||||
|
IN: unix.getfsstat.freebsd
|
||||||
|
|
||||||
|
: MNT_WAIT 1 ; inline ! synchronously wait for I/O to complete
|
||||||
|
: MNT_NOWAIT 2 ; inline ! start all I/O, but do not wait for it
|
||||||
|
: MNT_LAZY 3 ; inline ! push data not written by filesystem syncer
|
||||||
|
: MNT_SUSPEND 4 ; inline ! Suspend file system after sync
|
||||||
|
|
||||||
|
FUNCTION: int getfsstat ( statfs* buf, int bufsize, int flags ) ;
|
|
@ -0,0 +1 @@
|
||||||
|
unportable
|
|
@ -0,0 +1 @@
|
||||||
|
Doug Coleman
|
|
@ -0,0 +1,10 @@
|
||||||
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: alien.syntax ;
|
||||||
|
IN: unix.getfsstat.netbsd
|
||||||
|
|
||||||
|
: MNT_WAIT 1 ; inline ! synchronously wait for I/O to complete
|
||||||
|
: MNT_NOWAIT 2 ; inline ! start all I/O, but do not wait for it
|
||||||
|
: MNT_LAZY 3 ; inline ! push data not written by filesystem syncer
|
||||||
|
|
||||||
|
FUNCTION: int getvfsstat ( statfs* buf, int bufsize, int flags ) ;
|
|
@ -0,0 +1 @@
|
||||||
|
unportable
|
|
@ -2,3 +2,33 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.syntax ;
|
USING: alien.syntax ;
|
||||||
IN: unix.statfs.freebsd
|
IN: unix.statfs.freebsd
|
||||||
|
|
||||||
|
: MFSNAMELEN 16 ; inline ! length of type name including null */
|
||||||
|
: MNAMELEN 88 ; inline ! size of on/from name bufs
|
||||||
|
: STATFS_VERSION HEX: 20030518 ; inline ! current version number
|
||||||
|
|
||||||
|
C-STRUCT: statfs
|
||||||
|
{ "uint32_t" "f_version" }
|
||||||
|
{ "uint32_t" "f_type" }
|
||||||
|
{ "uint64_t" "f_flags" }
|
||||||
|
{ "uint64_t" "f_bsize" }
|
||||||
|
{ "uint64_t" "f_iosize" }
|
||||||
|
{ "uint64_t" "f_blocks" }
|
||||||
|
{ "uint64_t" "f_bfree" }
|
||||||
|
{ "int64_t" "f_bavail" }
|
||||||
|
{ "uint64_t" "f_files" }
|
||||||
|
{ "int64_t" "f_ffree" }
|
||||||
|
{ "uint64_t" "f_syncwrites" }
|
||||||
|
{ "uint64_t" "f_asyncwrites" }
|
||||||
|
{ "uint64_t" "f_syncreads" }
|
||||||
|
{ "uint64_t" "f_asyncreads" }
|
||||||
|
{ { "uint64_t" 10 } "f_spare" }
|
||||||
|
{ "uint32_t" "f_namemax" }
|
||||||
|
{ "uid_t" "f_owner" }
|
||||||
|
{ "fsid_t" "f_fsid" }
|
||||||
|
{ { "char" 80 } "f_charspare" }
|
||||||
|
{ { "char" MFSNAMELEN } "f_fstypename" }
|
||||||
|
{ { "char" MNAMELEN } "f_mntfromname" }
|
||||||
|
{ { "char" MNAMELEN } "f_mntonname" } ;
|
||||||
|
|
||||||
|
FUNCTION: int statfs ( char* path, statvfs* buf ) ;
|
||||||
|
|
|
@ -115,3 +115,4 @@ C-STRUCT: statfs64
|
||||||
{ { "uint32_t" 8 } "f_reserved" } ;
|
{ { "uint32_t" 8 } "f_reserved" } ;
|
||||||
|
|
||||||
FUNCTION: int statfs64 ( char* path, statfs64* buf ) ;
|
FUNCTION: int statfs64 ( char* path, statfs64* buf ) ;
|
||||||
|
FUNCTION: int getmntinfo64 ( statfs64** mntbufp, int flags ) ;
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespaces make sequences ftp io.unix.launcher.parser
|
||||||
unicode.case splitting assocs classes io.servers.connection
|
unicode.case splitting assocs classes io.servers.connection
|
||||||
destructors calendar io.timeouts io.streams.duplex threads
|
destructors calendar io.timeouts io.streams.duplex threads
|
||||||
continuations math concurrency.promises byte-arrays
|
continuations math concurrency.promises byte-arrays
|
||||||
io.backend sequences.lib tools.hexdump io.files.listing
|
io.backend sequences.lib tools.hexdump tools.files
|
||||||
io.streams.string ;
|
io.streams.string ;
|
||||||
IN: ftp.server
|
IN: ftp.server
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue