Merge branch 'master' of git://factorcode.org/git/factor

db4
Slava Pestov 2008-12-03 00:08:10 -06:00
commit 52fbbc7287
25 changed files with 130 additions and 40 deletions

View File

@ -269,7 +269,7 @@ $nl
{ $heading "Example: ls" }
"Here is an example implementing a simplified version of the Unix " { $snippet "ls" } " command in Factor:"
{ $code
<" USING: command-line namespaces io io.files io.files.listing
<" USING: command-line namespaces io io.files tools.files
sequences kernel ;
command-line get [

View File

@ -80,7 +80,7 @@ TUPLE: unix-file-system-info < file-system-info
block-size preferred-block-size
blocks blocks-free blocks-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 )
@ -108,6 +108,8 @@ M: unix statvfs>file-system-info drop ;
[ dup [ blocks-free>> ] [ block-size>> ] bi * >>free-space drop ]
[ dup [ blocks>> ] [ block-size>> ] bi * >>total-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 ;

View File

@ -2,23 +2,53 @@
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.syntax combinators
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
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 )
"statvfs" <c-object> tuck statvfs io-error ;
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_ffree >>files-free ]
[ statvfs-f_files >>files ]
[ statvfs-f_bsize >>block-size ]
[ statvfs-f_flag >>flags ]
[ statvfs-f_frsize >>preferred-block-size ]
[ statvfs-f_fsid >>id ]
[ statvfs-f_namemax >>name-max ]
} 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 ;

View File

@ -10,10 +10,10 @@ TUPLE: macosx-file-system-info < unix-file-system-info
io-size owner type-id filesystem-subtype ;
M: macosx file-systems ( -- array )
f 0 0 getfsstat64 dup io-error
"statfs" <c-array> dup dup length 0 getfsstat64 io-error
"statfs" heap-size group
[ statfs64-f_mntonname alien>native-string file-system-info ] map ;
f <void*> dup 0 getmntinfo64 dup io-error
[ *void* ] dip
"statfs64" heap-size [ * memory>byte-array ] keep group
[ [ new-file-system-info ] dip statfs>file-system-info ] map ;
M: macosx new-file-system-info macosx-file-system-info new ;

View File

@ -3,15 +3,14 @@
USING: alien.syntax kernel unix.stat math unix
combinators system io.backend accessors alien.c-types
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
TUPLE: netbsd-file-system-info < unix-file-system-info
blocks-reserved files-reserved
owner io-size
sync-reads sync-writes
async-reads async-writes
idx mount-from spare ;
owner io-size sync-reads sync-writes async-reads async-writes
idx mount-from ;
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_namemax >>name-max ]
[ statvfs-f_owner >>owner ]
[ statvfs-f_spare >>spare ]
! [ statvfs-f_spare >>spare ]
[ statvfs-f_fstypename alien>native-string >>type ]
[ statvfs-f_mntonname alien>native-string >>mount-point ]
[ statvfs-f_mntfromname alien>native-string >>device-name ]
} 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 ;

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax io.streams.string strings ;
IN: io.files.listing
IN: tools.files
HELP: directory.
{ $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." } ;
ARTICLE: "io.files.listing" "Listing files"
"The " { $vocab-link "io.files.listing" } " vocabulary implements directory file listing in a cross-platform way." $nl
ARTICLE: "tools.files" "Files tools"
"The " { $vocab-link "tools.files" } " vocabulary implements directory files and file-systems listing in a cross-platform way." $nl
"Listing a directory:"
{ $subsection directory. } ;
ABOUT: "io.files.listing"
ABOUT: "tools.files"

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 Your name.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test io.files.listing strings kernel ;
IN: io.files.listing.tests
USING: tools.test tools.files strings kernel ;
IN: tools.files.tests
\ directory. must-infer

View File

@ -2,8 +2,7 @@
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays combinators io io.files kernel
math.parser sequences system vocabs.loader calendar ;
IN: io.files.listing
IN: tools.files
<PRIVATE
@ -34,6 +33,6 @@ PRIVATE>
[ (directory.) ] with-directory-files [ print ] each ;
{
{ [ os unix? ] [ "io.files.listing.unix" ] }
{ [ os windows? ] [ "io.files.listing.windows" ] }
{ [ os unix? ] [ "tools.files.unix" ] }
{ [ os windows? ] [ "tools.files.windows" ] }
} cond require

View File

@ -1,10 +1,10 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
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
io.files.listing.private unix.stat math ;
IN: io.files.listing.unix
tools.files.private unix.stat math ;
IN: tools.files.unix
<PRIVATE

View File

@ -1,9 +1,9 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors calendar.format combinators io.files
kernel math.parser sequences splitting system io.files.listing
generalizations io.files.listing.private ;
IN: io.files.listing.windows
kernel math.parser sequences splitting system tools.files
generalizations tools.files.private ;
IN: tools.files.windows
<PRIVATE

View File

@ -0,0 +1 @@
Doug Coleman

View File

@ -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 ) ;

View File

@ -0,0 +1 @@
unportable

View File

@ -0,0 +1 @@
Doug Coleman

View File

@ -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 ) ;

View File

@ -0,0 +1 @@
unportable

View File

@ -2,3 +2,33 @@
! See http://factorcode.org/license.txt for BSD license.
USING: alien.syntax ;
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 ) ;

View File

@ -115,3 +115,4 @@ C-STRUCT: statfs64
{ { "uint32_t" 8 } "f_reserved" } ;
FUNCTION: int statfs64 ( char* path, statfs64* buf ) ;
FUNCTION: int getmntinfo64 ( statfs64** mntbufp, int flags ) ;

View File

@ -7,7 +7,7 @@ namespaces make sequences ftp io.unix.launcher.parser
unicode.case splitting assocs classes io.servers.connection
destructors calendar io.timeouts io.streams.duplex threads
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 ;
IN: ftp.server