From 50e214c1529717183b9b8b609b29a6d09ee7d9d4 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 14 Dec 2008 20:03:00 -0600 Subject: [PATCH] io.files split up and general refactoring work in progress --- basis/bootstrap/io/io.factor | 7 +- basis/bootstrap/stage2.factor | 12 +- basis/command-line/command-line.factor | 4 +- basis/debugger/debugger.factor | 8 +- basis/editors/gvim/unix/unix.factor | 3 +- basis/editors/gvim/windows/windows.factor | 4 +- basis/ftp/server/server.factor | 2 +- basis/io/{ => backend}/unix/authors.txt | 0 .../backend => backend/unix/bsd}/authors.txt | 0 basis/io/{ => backend}/unix/bsd/bsd.factor | 6 +- .../backend => backend/unix/bsd}/tags.txt | 0 basis/io/backend/unix/freebsd/freebsd.factor | 3 + .../bsd => backend/unix/freebsd}/tags.txt | 0 .../bsd => backend/unix/linux}/authors.txt | 0 .../io/{ => backend}/unix/linux/linux.factor | 7 +- .../epoll => backend/unix/linux}/tags.txt | 0 .../{ => backend}/unix/macosx/macosx.factor | 6 +- .../bsd => backend/unix/macosx}/tags.txt | 0 .../unix/multiplexers}/epoll/authors.txt | 0 .../unix/multiplexers/epoll/epoll.factor | 6 +- .../unix/multiplexers/epoll}/tags.txt | 0 .../unix/multiplexers/kqueue}/authors.txt | 0 .../unix/multiplexers/kqueue/kqueue.factor | 6 +- .../unix/multiplexers/kqueue}/tags.txt | 0 .../unix/multiplexers/multiplexers.factor | 2 +- .../multiplexers/run-loop/run-loop.factor | 6 +- .../unix/multiplexers/run-loop}/tags.txt | 0 .../unix/multiplexers/select}/authors.txt | 0 .../unix/multiplexers/select/select.factor | 4 +- .../unix/multiplexers/select}/tags.txt | 0 basis/io/backend/unix/netbsd/netbsd.factor | 3 + .../openbsd => backend/unix/netbsd}/tags.txt | 0 basis/io/backend/unix/openbsd/openbsd.factor | 3 + .../files => backend/unix/openbsd}/tags.txt | 0 .../backend => backend/unix}/summary.txt | 0 .../files/unique => backend/unix}/tags.txt | 0 basis/io/{ => backend}/unix/unix-tests.factor | 2 +- .../unix/unix.factor} | 4 +- basis/io/{ => backend}/windows/authors.txt | 0 .../windows/nt}/authors.txt | 0 .../windows/nt/nt.factor} | 4 +- .../windows/nt/privileges/privileges.factor | 6 +- .../windows/nt/privileges}/tags.txt | 0 .../kqueue => backend/windows/nt}/tags.txt | 0 .../windows/privileges/privileges.factor | 6 +- .../windows/privileges}/tags.txt | 0 basis/io/{ => backend}/windows/summary.txt | 0 .../launcher => backend/windows}/tags.txt | 0 basis/io/{ => backend}/windows/windows.factor | 2 +- basis/io/directories/directories-docs.factor | 191 +++++++++ basis/io/directories/directories-tests.factor | 199 ++++++++++ basis/io/directories/directories.factor | 112 ++++++ .../mmap => directories/search}/authors.txt | 0 .../io/directories/search/search-tests.factor | 11 + basis/io/directories/search/search.factor | 58 +++ .../search/windows}/authors.txt | 0 .../search/windows}/tags.txt | 0 .../directories/search/windows/windows.factor | 13 + basis/io/directories/unix/unix.factor | 75 ++++ basis/io/encodings/binary/authors.txt | 1 + basis/io/encodings/binary/binary-docs.factor | 11 + basis/io/encodings/binary/binary.factor | 8 + basis/io/encodings/binary/summary.txt | 1 + basis/io/encodings/binary/tags.txt | 1 + basis/io/files/info/info-docs.factor | 76 ++++ basis/io/files/info/info-tests.factor | 16 + basis/io/files/info/info.factor | 38 ++ .../files => files/info/unix}/bsd/bsd.factor | 7 +- .../linux => files/info/unix/bsd}/tags.txt | 0 .../info/unix}/freebsd/freebsd.factor | 6 +- .../info/unix/freebsd}/tags.txt | 0 .../info/unix}/linux/linux.factor | 6 +- .../macosx => files/info/unix/linux}/tags.txt | 0 .../info/unix}/macosx/macosx.factor | 7 +- .../mmap => files/info/unix/macosx}/tags.txt | 0 .../info/unix}/netbsd/netbsd.factor | 7 +- .../epoll => files/info/unix/netbsd}/tags.txt | 0 .../info/unix}/openbsd/openbsd.factor | 6 +- .../info/unix/openbsd}/tags.txt | 0 .../info/unix/unix.factor} | 139 +------ basis/io/files/links/links-docs.factor | 26 ++ basis/io/files/links/links.factor | 10 + basis/io/files/links/unix/unix.factor | 10 + basis/io/files/unique/unique.factor | 4 +- .../run-loop => files/unique/unix}/tags.txt | 0 .../unique/unix/unix.factor} | 4 +- .../select => files/unique/windows}/tags.txt | 0 .../unique/windows/windows.factor} | 6 +- .../{unix/launcher => files/unix}/authors.txt | 0 .../io/{unix/files => files/unix}/summary.txt | 0 basis/io/{unix/netbsd => files/unix}/tags.txt | 0 .../unix/unix-docs.factor} | 12 +- .../unix/unix-tests.factor} | 4 +- basis/io/files/unix/unix.factor | 40 ++ .../files => files/windows}/files.factor | 4 +- .../nt/files => files/windows/nt}/authors.txt | 0 .../windows/nt}/files-tests.factor | 4 +- .../files => files/windows/nt}/files.factor | 6 +- .../openbsd => files/windows/nt}/tags.txt | 0 .../io/{unix/pipes => files/windows}/tags.txt | 0 basis/io/launcher/launcher.factor | 6 +- .../{unix/linux => launcher/unix}/authors.txt | 0 .../unix}/parser/parser-tests.factor | 4 +- .../unix}/parser/parser.factor | 2 +- .../select => launcher/unix/parser}/tags.txt | 0 .../sockets/secure => launcher/unix}/tags.txt | 0 .../unix/unix-tests.factor} | 2 +- .../unix/unix.factor} | 6 +- .../launcher => launcher/windows}/authors.txt | 0 .../windows/nt}/authors.txt | 0 .../windows/nt/nt-tests.factor} | 2 +- .../windows/nt/nt.factor} | 6 +- .../sockets => launcher/windows/nt}/tags.txt | 0 .../windows/nt}/test/append.factor | 0 .../windows/nt}/test/env.factor | 0 .../windows/nt}/test/stderr.factor | 0 basis/io/{unix => launcher/windows}/tags.txt | 0 .../windows/windows-tests.factor} | 4 +- .../windows/windows.factor} | 4 +- basis/io/mmap/mmap.factor | 4 +- basis/io/{unix/mmap => mmap/unix}/authors.txt | 0 .../io/{windows/files => mmap/unix}/tags.txt | 0 .../mmap.factor => mmap/unix/unix.factor} | 4 +- basis/io/mmap/windows/authors.txt | 1 + .../files/unique => mmap/windows}/tags.txt | 0 .../windows/windows.factor} | 4 +- .../linux/linux-tests.factor} | 2 +- .../linux/linux.factor} | 4 +- .../launcher => monitors/linux}/tags.txt | 0 .../macosx/macosx.factor} | 2 +- .../mmap => monitors/macosx}/tags.txt | 0 basis/io/monitors/monitors.factor | 6 +- basis/io/monitors/windows/nt/authors.txt | 1 + basis/io/monitors/windows/nt/nt-tests.factor | 4 + .../windows/nt/nt.factor} | 6 +- .../backend => monitors/windows/nt}/tags.txt | 0 basis/io/pipes/pipes.factor | 4 +- .../pipes => pipes/unix}/pipes-tests.factor | 4 +- .../{unix/pipes => pipes/unix}/pipes.factor | 4 +- .../{windows/nt/files => pipes/unix}/tags.txt | 0 .../epoll => pipes/windows/nt}/authors.txt | 0 .../pipes => pipes/windows/nt}/pipes.factor | 4 +- .../nt/launcher => pipes/windows/nt}/tags.txt | 0 basis/io/sockets/secure/secure.factor | 2 +- .../secure/unix}/debug/debug.factor | 2 +- .../monitors => sockets/secure/unix}/tags.txt | 0 .../secure/unix/unix-tests.factor} | 4 +- .../secure/unix/unix.factor} | 4 +- basis/io/sockets/sockets.factor | 5 +- .../kqueue => sockets/unix}/authors.txt | 0 .../sockets => sockets/unix}/summary.txt | 0 .../nt/pipes => sockets/unix}/tags.txt | 0 .../unix/unix.factor} | 6 +- .../windows/nt}/authors.txt | 0 .../windows/nt/nt.factor} | 6 +- .../windows/nt}/tags.txt | 0 .../nt/sockets => sockets/windows}/tags.txt | 0 .../windows/windows.factor} | 4 +- basis/io/unix/epoll/epoll.factor | 63 --- basis/io/unix/freebsd/freebsd.factor | 3 - basis/io/unix/kqueue/kqueue.factor | 74 ---- basis/io/unix/multiplexers/select/authors.txt | 1 - basis/io/unix/netbsd/netbsd.factor | 3 - basis/io/unix/openbsd/openbsd.factor | 3 - basis/io/unix/select/authors.txt | 1 - basis/io/unix/select/select.factor | 56 --- basis/io/unix/sockets/authors.txt | 1 - basis/io/unix/summary.txt | 1 - basis/io/unix/unix.factor | 4 - basis/io/windows/nt/authors.txt | 2 - .../windows/nt/monitors/monitors-tests.factor | 4 - basis/io/windows/nt/nt.factor | 7 - basis/io/windows/nt/pipes/authors.txt | 1 - basis/io/windows/nt/summary.txt | 1 - basis/io/windows/nt/tags.txt | 1 - basis/io/windows/privileges/tags.txt | 1 - basis/io/windows/sockets/tags.txt | 1 - basis/io/windows/tags.txt | 1 - basis/prettyprint/backend/backend.factor | 6 +- basis/prettyprint/prettyprint.factor | 2 +- basis/smtp/server/server.factor | 2 +- basis/tools/deploy/macosx/macosx.factor | 2 +- basis/tools/files/unix/unix.factor | 2 +- basis/unix/groups/groups.factor | 2 +- basis/unix/process/process.factor | 2 +- basis/unix/stat/stat.factor | 2 +- basis/unix/unix.factor | 15 +- basis/unix/users/users.factor | 2 +- core/checksums/checksums.factor | 7 +- core/io/files/files-docs.factor | 375 +----------------- core/io/files/files-tests.factor | 320 +++------------ core/io/files/files.factor | 296 +------------- core/io/io-tests.factor | 50 --- core/io/pathnames/pathnames-docs.factor | 78 ++++ core/io/pathnames/pathnames-tests.factor | 65 +++ core/io/pathnames/pathnames.factor | 143 +++++++ core/source-files/source-files.factor | 6 +- core/syntax/syntax-docs.factor | 2 +- core/syntax/syntax.factor | 2 +- core/vocabs/loader/loader.factor | 8 +- 200 files changed, 1441 insertions(+), 1535 deletions(-) rename basis/io/{ => backend}/unix/authors.txt (100%) rename basis/io/{unix/backend => backend/unix/bsd}/authors.txt (100%) mode change 100644 => 100755 rename basis/io/{ => backend}/unix/bsd/bsd.factor (72%) rename basis/io/{unix/backend => backend/unix/bsd}/tags.txt (100%) create mode 100644 basis/io/backend/unix/freebsd/freebsd.factor rename basis/io/{unix/bsd => backend/unix/freebsd}/tags.txt (100%) rename basis/io/{unix/bsd => backend/unix/linux}/authors.txt (100%) rename basis/io/{ => backend}/unix/linux/linux.factor (50%) rename basis/io/{unix/epoll => backend/unix/linux}/tags.txt (100%) rename basis/io/{ => backend}/unix/macosx/macosx.factor (54%) rename basis/io/{unix/files/bsd => backend/unix/macosx}/tags.txt (100%) rename basis/io/{unix => backend/unix/multiplexers}/epoll/authors.txt (100%) rename basis/io/{ => backend}/unix/multiplexers/epoll/epoll.factor (94%) rename basis/io/{unix/files/freebsd => backend/unix/multiplexers/epoll}/tags.txt (100%) rename basis/io/{unix/files => backend/unix/multiplexers/kqueue}/authors.txt (100%) mode change 100644 => 100755 rename basis/io/{ => backend}/unix/multiplexers/kqueue/kqueue.factor (92%) rename basis/io/{unix/files/linux => backend/unix/multiplexers/kqueue}/tags.txt (100%) rename basis/io/{ => backend}/unix/multiplexers/multiplexers.factor (96%) rename basis/io/{ => backend}/unix/multiplexers/run-loop/run-loop.factor (87%) rename basis/io/{unix/files/macosx => backend/unix/multiplexers/run-loop}/tags.txt (100%) rename basis/io/{unix/kqueue => backend/unix/multiplexers/select}/authors.txt (100%) rename basis/io/{ => backend}/unix/multiplexers/select/select.factor (94%) rename basis/io/{unix/files/netbsd => backend/unix/multiplexers/select}/tags.txt (100%) create mode 100644 basis/io/backend/unix/netbsd/netbsd.factor rename basis/io/{unix/files/openbsd => backend/unix/netbsd}/tags.txt (100%) create mode 100644 basis/io/backend/unix/openbsd/openbsd.factor rename basis/io/{unix/files => backend/unix/openbsd}/tags.txt (100%) rename basis/io/{unix/backend => backend/unix}/summary.txt (100%) rename basis/io/{unix/files/unique => backend/unix}/tags.txt (100%) rename basis/io/{ => backend}/unix/unix-tests.factor (99%) rename basis/io/{unix/backend/backend.factor => backend/unix/unix.factor} (98%) rename basis/io/{ => backend}/windows/authors.txt (100%) rename basis/io/{windows/nt/backend => backend/windows/nt}/authors.txt (100%) rename basis/io/{windows/nt/backend/backend.factor => backend/windows/nt/nt.factor} (97%) rename basis/io/{ => backend}/windows/nt/privileges/privileges.factor (88%) rename basis/io/{unix/freebsd => backend/windows/nt/privileges}/tags.txt (100%) rename basis/io/{unix/kqueue => backend/windows/nt}/tags.txt (100%) rename basis/io/{ => backend}/windows/privileges/privileges.factor (61%) rename basis/io/{unix/launcher/parser => backend/windows/privileges}/tags.txt (100%) rename basis/io/{ => backend}/windows/summary.txt (100%) rename basis/io/{unix/launcher => backend/windows}/tags.txt (100%) mode change 100644 => 100755 rename basis/io/{ => backend}/windows/windows.factor (98%) create mode 100644 basis/io/directories/directories-docs.factor create mode 100644 basis/io/directories/directories-tests.factor create mode 100644 basis/io/directories/directories.factor rename basis/io/{windows/mmap => directories/search}/authors.txt (100%) create mode 100644 basis/io/directories/search/search-tests.factor create mode 100755 basis/io/directories/search/search.factor rename basis/io/{windows/nt/monitors => directories/search/windows}/authors.txt (100%) mode change 100755 => 100644 rename basis/io/{unix/linux/monitors => directories/search/windows}/tags.txt (100%) create mode 100644 basis/io/directories/search/windows/windows.factor create mode 100644 basis/io/directories/unix/unix.factor create mode 100644 basis/io/encodings/binary/authors.txt create mode 100644 basis/io/encodings/binary/binary-docs.factor create mode 100644 basis/io/encodings/binary/binary.factor create mode 100644 basis/io/encodings/binary/summary.txt create mode 100644 basis/io/encodings/binary/tags.txt create mode 100644 basis/io/files/info/info-docs.factor create mode 100644 basis/io/files/info/info-tests.factor create mode 100644 basis/io/files/info/info.factor rename basis/io/{unix/files => files/info/unix}/bsd/bsd.factor (76%) rename basis/io/{unix/linux => files/info/unix/bsd}/tags.txt (100%) rename basis/io/{unix/files => files/info/unix}/freebsd/freebsd.factor (93%) rename basis/io/{unix/macosx/monitors => files/info/unix/freebsd}/tags.txt (100%) rename basis/io/{unix/files => files/info/unix}/linux/linux.factor (94%) rename basis/io/{unix/macosx => files/info/unix/linux}/tags.txt (100%) rename basis/io/{unix/files => files/info/unix}/macosx/macosx.factor (91%) rename basis/io/{unix/mmap => files/info/unix/macosx}/tags.txt (100%) rename basis/io/{unix/files => files/info/unix}/netbsd/netbsd.factor (91%) rename basis/io/{unix/multiplexers/epoll => files/info/unix/netbsd}/tags.txt (100%) rename basis/io/{unix/files => files/info/unix}/openbsd/openbsd.factor (93%) rename basis/io/{unix/multiplexers/kqueue => files/info/unix/openbsd}/tags.txt (100%) rename basis/io/{unix/files/files.factor => files/info/unix/unix.factor} (65%) create mode 100644 basis/io/files/links/links-docs.factor create mode 100644 basis/io/files/links/links.factor create mode 100644 basis/io/files/links/unix/unix.factor rename basis/io/{unix/multiplexers/run-loop => files/unique/unix}/tags.txt (100%) rename basis/io/{unix/files/unique/unique.factor => files/unique/unix/unix.factor} (81%) rename basis/io/{unix/multiplexers/select => files/unique/windows}/tags.txt (100%) rename basis/io/{windows/files/unique/unique.factor => files/unique/windows/windows.factor} (54%) rename basis/io/{unix/launcher => files/unix}/authors.txt (100%) mode change 100755 => 100644 rename basis/io/{unix/files => files/unix}/summary.txt (100%) rename basis/io/{unix/netbsd => files/unix}/tags.txt (100%) rename basis/io/{unix/files/files-docs.factor => files/unix/unix-docs.factor} (97%) rename basis/io/{unix/files/files-tests.factor => files/unix/unix-tests.factor} (98%) create mode 100644 basis/io/files/unix/unix.factor rename basis/io/{windows/files => files/windows}/files.factor (99%) rename basis/io/{windows/nt/files => files/windows/nt}/authors.txt (100%) rename basis/io/{windows/nt/files => files/windows/nt}/files-tests.factor (96%) rename basis/io/{windows/nt/files => files/windows/nt}/files.factor (92%) rename basis/io/{unix/openbsd => files/windows/nt}/tags.txt (100%) rename basis/io/{unix/pipes => files/windows}/tags.txt (100%) rename basis/io/{unix/linux => launcher/unix}/authors.txt (100%) rename basis/io/{unix/launcher => launcher/unix}/parser/parser-tests.factor (95%) rename basis/io/{unix/launcher => launcher/unix}/parser/parser.factor (96%) rename basis/io/{unix/select => launcher/unix/parser}/tags.txt (100%) rename basis/io/{unix/sockets/secure => launcher/unix}/tags.txt (100%) rename basis/io/{unix/launcher/launcher-tests.factor => launcher/unix/unix-tests.factor} (99%) rename basis/io/{unix/launcher/launcher.factor => launcher/unix/unix.factor} (97%) rename basis/io/{windows/launcher => launcher/windows}/authors.txt (100%) rename basis/io/{windows/nt/launcher => launcher/windows/nt}/authors.txt (100%) rename basis/io/{windows/nt/launcher/launcher-tests.factor => launcher/windows/nt/nt-tests.factor} (99%) rename basis/io/{windows/nt/launcher/launcher.factor => launcher/windows/nt/nt.factor} (95%) rename basis/io/{unix/sockets => launcher/windows/nt}/tags.txt (100%) rename basis/io/{windows/nt/launcher => launcher/windows/nt}/test/append.factor (100%) rename basis/io/{windows/nt/launcher => launcher/windows/nt}/test/env.factor (100%) rename basis/io/{windows/nt/launcher => launcher/windows/nt}/test/stderr.factor (100%) rename basis/io/{unix => launcher/windows}/tags.txt (100%) rename basis/io/{windows/launcher/launcher-tests.factor => launcher/windows/windows-tests.factor} (79%) rename basis/io/{windows/launcher/launcher.factor => launcher/windows/windows.factor} (98%) rename basis/io/{unix/mmap => mmap/unix}/authors.txt (100%) rename basis/io/{windows/files => mmap/unix}/tags.txt (100%) rename basis/io/{unix/mmap/mmap.factor => mmap/unix/unix.factor} (88%) create mode 100755 basis/io/mmap/windows/authors.txt rename basis/io/{windows/files/unique => mmap/windows}/tags.txt (100%) rename basis/io/{windows/mmap/mmap.factor => mmap/windows/windows.factor} (94%) rename basis/io/{unix/linux/monitors/monitors-tests.factor => monitors/linux/linux-tests.factor} (97%) rename basis/io/{unix/linux/monitors/monitors.factor => monitors/linux/linux.factor} (97%) rename basis/io/{windows/launcher => monitors/linux}/tags.txt (100%) rename basis/io/{unix/macosx/monitors/monitors.factor => monitors/macosx/macosx.factor} (96%) rename basis/io/{windows/mmap => monitors/macosx}/tags.txt (100%) create mode 100755 basis/io/monitors/windows/nt/authors.txt create mode 100644 basis/io/monitors/windows/nt/nt-tests.factor rename basis/io/{windows/nt/monitors/monitors.factor => monitors/windows/nt/nt.factor} (95%) rename basis/io/{windows/nt/backend => monitors/windows/nt}/tags.txt (100%) rename basis/io/{unix/pipes => pipes/unix}/pipes-tests.factor (81%) rename basis/io/{unix/pipes => pipes/unix}/pipes.factor (80%) rename basis/io/{windows/nt/files => pipes/unix}/tags.txt (100%) rename basis/io/{unix/multiplexers/epoll => pipes/windows/nt}/authors.txt (100%) rename basis/io/{windows/nt/pipes => pipes/windows/nt}/pipes.factor (92%) rename basis/io/{windows/nt/launcher => pipes/windows/nt}/tags.txt (100%) rename basis/io/{unix/sockets/secure => sockets/secure/unix}/debug/debug.factor (91%) rename basis/io/{windows/nt/monitors => sockets/secure/unix}/tags.txt (100%) rename basis/io/{unix/sockets/secure/secure-tests.factor => sockets/secure/unix/unix-tests.factor} (97%) rename basis/io/{unix/sockets/secure/secure.factor => sockets/secure/unix/unix.factor} (98%) rename basis/io/{unix/multiplexers/kqueue => sockets/unix}/authors.txt (100%) mode change 100755 => 100644 rename basis/io/{unix/sockets => sockets/unix}/summary.txt (100%) rename basis/io/{windows/nt/pipes => sockets/unix}/tags.txt (100%) rename basis/io/{unix/sockets/sockets.factor => sockets/unix/unix.factor} (96%) rename basis/io/{windows/nt/sockets => sockets/windows/nt}/authors.txt (100%) rename basis/io/{windows/nt/sockets/sockets.factor => sockets/windows/nt/nt.factor} (97%) rename basis/io/{windows/nt/privileges => sockets/windows/nt}/tags.txt (100%) rename basis/io/{windows/nt/sockets => sockets/windows}/tags.txt (100%) rename basis/io/{windows/sockets/sockets.factor => sockets/windows/windows.factor} (92%) delete mode 100644 basis/io/unix/epoll/epoll.factor delete mode 100644 basis/io/unix/freebsd/freebsd.factor delete mode 100644 basis/io/unix/kqueue/kqueue.factor delete mode 100755 basis/io/unix/multiplexers/select/authors.txt delete mode 100644 basis/io/unix/netbsd/netbsd.factor delete mode 100644 basis/io/unix/openbsd/openbsd.factor delete mode 100755 basis/io/unix/select/authors.txt delete mode 100644 basis/io/unix/select/select.factor delete mode 100644 basis/io/unix/sockets/authors.txt delete mode 100644 basis/io/unix/summary.txt delete mode 100644 basis/io/unix/unix.factor delete mode 100644 basis/io/windows/nt/authors.txt delete mode 100644 basis/io/windows/nt/monitors/monitors-tests.factor delete mode 100644 basis/io/windows/nt/nt.factor delete mode 100755 basis/io/windows/nt/pipes/authors.txt delete mode 100644 basis/io/windows/nt/summary.txt delete mode 100644 basis/io/windows/nt/tags.txt delete mode 100644 basis/io/windows/privileges/tags.txt delete mode 100644 basis/io/windows/sockets/tags.txt delete mode 100755 basis/io/windows/tags.txt create mode 100644 core/io/pathnames/pathnames-docs.factor create mode 100644 core/io/pathnames/pathnames-tests.factor create mode 100644 core/io/pathnames/pathnames.factor diff --git a/basis/bootstrap/io/io.factor b/basis/bootstrap/io/io.factor index a38107fbab..b9a49b48b8 100644 --- a/basis/bootstrap/io/io.factor +++ b/basis/bootstrap/io/io.factor @@ -1,12 +1,11 @@ USING: system vocabs vocabs.loader kernel combinators -namespaces sequences io.backend ; +namespaces sequences io.backend accessors ; IN: bootstrap.io "bootstrap.compiler" vocab [ - "io." { + "io.backend." { { [ "io-backend" get ] [ "io-backend" get ] } - { [ os unix? ] [ "unix" ] } + { [ os unix? ] [ "unix." os name>> append ] } { [ os winnt? ] [ "windows.nt" ] } - { [ os wince? ] [ "windows.ce" ] } } cond append require ] when diff --git a/basis/bootstrap/stage2.factor b/basis/bootstrap/stage2.factor index 45a6c354a6..d2b522581d 100644 --- a/basis/bootstrap/stage2.factor +++ b/basis/bootstrap/stage2.factor @@ -1,11 +1,11 @@ ! Copyright (C) 2004, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors init namespaces words io -kernel.private math memory continuations kernel io.files -io.backend system parser vocabs sequences -vocabs.loader combinators splitting source-files strings -definitions assocs compiler.errors compiler.units -math.parser generic sets command-line ; +USING: accessors init namespaces words io kernel.private math +memory continuations kernel io.files io.pathnames io.backend +system parser vocabs sequences vocabs.loader combinators +splitting source-files strings definitions assocs +compiler.errors compiler.units math.parser generic sets +command-line ; IN: bootstrap.stage2 SYMBOL: core-bootstrap-time diff --git a/basis/command-line/command-line.factor b/basis/command-line/command-line.factor index 7d5a041951..38d40d8482 100644 --- a/basis/command-line/command-line.factor +++ b/basis/command-line/command-line.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2003, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: init continuations hashtables io io.encodings.utf8 -io.files kernel kernel.private namespaces parser sequences -strings system splitting vocabs.loader ; +io.files io.pathnames kernel kernel.private namespaces parser +sequences strings system splitting vocabs.loader ; IN: command-line SYMBOL: script diff --git a/basis/debugger/debugger.factor b/basis/debugger/debugger.factor index 4e0c4e8840..885e2e303c 100644 --- a/basis/debugger/debugger.factor +++ b/basis/debugger/debugger.factor @@ -2,10 +2,10 @@ ! See http://factorcode.org/license.txt for BSD license. USING: slots arrays definitions generic hashtables summary io kernel math namespaces make prettyprint prettyprint.config -sequences assocs sequences.private strings io.styles io.files -vectors words system splitting math.parser classes.mixin -classes.tuple continuations continuations.private combinators -generic.math classes.builtin classes compiler.units +sequences assocs sequences.private strings io.styles +io.pathnames vectors words system splitting math.parser +classes.mixin classes.tuple continuations continuations.private +combinators generic.math classes.builtin classes compiler.units generic.standard vocabs init kernel.private io.encodings accessors math.order destructors source-files parser classes.tuple.parser effects.parser lexer compiler.errors diff --git a/basis/editors/gvim/unix/unix.factor b/basis/editors/gvim/unix/unix.factor index 82b6bf199d..3e2a42e6e5 100644 --- a/basis/editors/gvim/unix/unix.factor +++ b/basis/editors/gvim/unix/unix.factor @@ -1,5 +1,4 @@ -USING: io.unix.backend kernel namespaces editors.gvim -system ; +USING: kernel namespaces editors.gvim system ; IN: editors.gvim.unix M: unix gvim-path diff --git a/basis/editors/gvim/windows/windows.factor b/basis/editors/gvim/windows/windows.factor index 2f733f3c2f..1a6f8e902c 100644 --- a/basis/editors/gvim/windows/windows.factor +++ b/basis/editors/gvim/windows/windows.factor @@ -1,5 +1,5 @@ -USING: editors.gvim io.files io.windows kernel namespaces -sequences windows.shell32 io.paths.windows system ; +USING: editors.gvim io.files kernel namespaces sequences +windows.shell32 io.paths.windows system ; IN: editors.gvim.windows M: windows gvim-path diff --git a/basis/ftp/server/server.factor b/basis/ftp/server/server.factor index b0ec340202..ca27cbb784 100644 --- a/basis/ftp/server/server.factor +++ b/basis/ftp/server/server.factor @@ -3,7 +3,7 @@ USING: combinators.short-circuit accessors combinators io io.encodings.8-bit io.encodings io.encodings.binary io.encodings.utf8 io.files io.sockets kernel math.parser -namespaces make sequences ftp io.unix.launcher.parser +namespaces make sequences ftp io.launcher.unix.parser unicode.case splitting assocs classes io.servers.connection destructors calendar io.timeouts io.streams.duplex threads continuations math concurrency.promises byte-arrays diff --git a/basis/io/unix/authors.txt b/basis/io/backend/unix/authors.txt similarity index 100% rename from basis/io/unix/authors.txt rename to basis/io/backend/unix/authors.txt diff --git a/basis/io/unix/backend/authors.txt b/basis/io/backend/unix/bsd/authors.txt old mode 100644 new mode 100755 similarity index 100% rename from basis/io/unix/backend/authors.txt rename to basis/io/backend/unix/bsd/authors.txt diff --git a/basis/io/unix/bsd/bsd.factor b/basis/io/backend/unix/bsd/bsd.factor similarity index 72% rename from basis/io/unix/bsd/bsd.factor rename to basis/io/backend/unix/bsd/bsd.factor index 83f063d713..e0a675a8fc 100644 --- a/basis/io/unix/bsd/bsd.factor +++ b/basis/io/backend/unix/bsd/bsd.factor @@ -1,9 +1,9 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: namespaces system kernel accessors assocs continuations -unix io.backend io.unix.backend io.unix.multiplexers -io.unix.multiplexers.kqueue ; -IN: io.unix.bsd +unix io.backend io.backend.unix io.backend.unix.multiplexers +io.backend.unix.multiplexers.kqueue io.files.unix ; +IN: io.backend.unix.bsd M: bsd init-io ( -- ) mx set-global ; diff --git a/basis/io/unix/backend/tags.txt b/basis/io/backend/unix/bsd/tags.txt similarity index 100% rename from basis/io/unix/backend/tags.txt rename to basis/io/backend/unix/bsd/tags.txt diff --git a/basis/io/backend/unix/freebsd/freebsd.factor b/basis/io/backend/unix/freebsd/freebsd.factor new file mode 100644 index 0000000000..1c0471b330 --- /dev/null +++ b/basis/io/backend/unix/freebsd/freebsd.factor @@ -0,0 +1,3 @@ +USING: io.backend.unix.bsd io.backend system ; + +freebsd set-io-backend diff --git a/basis/io/unix/bsd/tags.txt b/basis/io/backend/unix/freebsd/tags.txt similarity index 100% rename from basis/io/unix/bsd/tags.txt rename to basis/io/backend/unix/freebsd/tags.txt diff --git a/basis/io/unix/bsd/authors.txt b/basis/io/backend/unix/linux/authors.txt similarity index 100% rename from basis/io/unix/bsd/authors.txt rename to basis/io/backend/unix/linux/authors.txt diff --git a/basis/io/unix/linux/linux.factor b/basis/io/backend/unix/linux/linux.factor similarity index 50% rename from basis/io/unix/linux/linux.factor rename to basis/io/backend/unix/linux/linux.factor index fd24e0ac02..54b20d1b44 100644 --- a/basis/io/unix/linux/linux.factor +++ b/basis/io/backend/unix/linux/linux.factor @@ -1,8 +1,9 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel system namespaces io.backend io.unix.backend -io.unix.multiplexers io.unix.multiplexers.epoll ; -IN: io.unix.linux +USING: kernel system namespaces io.files.unix io.backend +io.backend.unix io.backend.unix.multiplexers +io.backend.unix.multiplexers.epoll ; +IN: io.backend.unix.linux M: linux init-io ( -- ) mx set-global ; diff --git a/basis/io/unix/epoll/tags.txt b/basis/io/backend/unix/linux/tags.txt similarity index 100% rename from basis/io/unix/epoll/tags.txt rename to basis/io/backend/unix/linux/tags.txt diff --git a/basis/io/unix/macosx/macosx.factor b/basis/io/backend/unix/macosx/macosx.factor similarity index 54% rename from basis/io/unix/macosx/macosx.factor rename to basis/io/backend/unix/macosx/macosx.factor index 75f42b7394..e669875448 100644 --- a/basis/io/unix/macosx/macosx.factor +++ b/basis/io/backend/unix/macosx/macosx.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: io.backend system namespaces io.unix.multiplexers -io.unix.multiplexers.run-loop ; -IN: io.unix.macosx +USING: io.backend system namespaces io.backend.unix.bsd +io.backend.unix.multiplexers io.backend.unix.multiplexers.run-loop ; +IN: io.backend.macosx M: macosx init-io ( -- ) mx set-global ; diff --git a/basis/io/unix/files/bsd/tags.txt b/basis/io/backend/unix/macosx/tags.txt similarity index 100% rename from basis/io/unix/files/bsd/tags.txt rename to basis/io/backend/unix/macosx/tags.txt diff --git a/basis/io/unix/epoll/authors.txt b/basis/io/backend/unix/multiplexers/epoll/authors.txt similarity index 100% rename from basis/io/unix/epoll/authors.txt rename to basis/io/backend/unix/multiplexers/epoll/authors.txt diff --git a/basis/io/unix/multiplexers/epoll/epoll.factor b/basis/io/backend/unix/multiplexers/epoll/epoll.factor similarity index 94% rename from basis/io/unix/multiplexers/epoll/epoll.factor rename to basis/io/backend/unix/multiplexers/epoll/epoll.factor index 08e20d4b95..a91f62f1df 100644 --- a/basis/io/unix/multiplexers/epoll/epoll.factor +++ b/basis/io/backend/unix/multiplexers/epoll/epoll.factor @@ -2,9 +2,9 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types kernel destructors bit-arrays sequences assocs struct-arrays math namespaces locals fry unix -unix.linux.epoll unix.time io.ports io.unix.backend -io.unix.multiplexers ; -IN: io.unix.multiplexers.epoll +unix.linux.epoll unix.time io.ports io.backend.unix +io.backend.unix.multiplexers ; +IN: io.backend.unix.multiplexers.epoll TUPLE: epoll-mx < mx events ; diff --git a/basis/io/unix/files/freebsd/tags.txt b/basis/io/backend/unix/multiplexers/epoll/tags.txt similarity index 100% rename from basis/io/unix/files/freebsd/tags.txt rename to basis/io/backend/unix/multiplexers/epoll/tags.txt diff --git a/basis/io/unix/files/authors.txt b/basis/io/backend/unix/multiplexers/kqueue/authors.txt old mode 100644 new mode 100755 similarity index 100% rename from basis/io/unix/files/authors.txt rename to basis/io/backend/unix/multiplexers/kqueue/authors.txt diff --git a/basis/io/unix/multiplexers/kqueue/kqueue.factor b/basis/io/backend/unix/multiplexers/kqueue/kqueue.factor similarity index 92% rename from basis/io/unix/multiplexers/kqueue/kqueue.factor rename to basis/io/backend/unix/multiplexers/kqueue/kqueue.factor index a66e86a6a7..2a6648981b 100644 --- a/basis/io/unix/multiplexers/kqueue/kqueue.factor +++ b/basis/io/backend/unix/multiplexers/kqueue/kqueue.factor @@ -1,9 +1,9 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types combinators destructors -io.unix.backend kernel math.bitwise sequences struct-arrays unix -unix.kqueue unix.time assocs io.unix.multiplexers ; -IN: io.unix.multiplexers.kqueue +io.backend.unix kernel math.bitwise sequences struct-arrays unix +unix.kqueue unix.time assocs io.backend.unix.multiplexers ; +IN: io.backend.unix.multiplexers.kqueue TUPLE: kqueue-mx < mx events ; diff --git a/basis/io/unix/files/linux/tags.txt b/basis/io/backend/unix/multiplexers/kqueue/tags.txt similarity index 100% rename from basis/io/unix/files/linux/tags.txt rename to basis/io/backend/unix/multiplexers/kqueue/tags.txt diff --git a/basis/io/unix/multiplexers/multiplexers.factor b/basis/io/backend/unix/multiplexers/multiplexers.factor similarity index 96% rename from basis/io/unix/multiplexers/multiplexers.factor rename to basis/io/backend/unix/multiplexers/multiplexers.factor index 1c9fb134e7..844670d635 100644 --- a/basis/io/unix/multiplexers/multiplexers.factor +++ b/basis/io/backend/unix/multiplexers/multiplexers.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel accessors assocs sequences threads ; -IN: io.unix.multiplexers +IN: io.backend.unix.multiplexers TUPLE: mx fd reads writes ; diff --git a/basis/io/unix/multiplexers/run-loop/run-loop.factor b/basis/io/backend/unix/multiplexers/run-loop/run-loop.factor similarity index 87% rename from basis/io/unix/multiplexers/run-loop/run-loop.factor rename to basis/io/backend/unix/multiplexers/run-loop/run-loop.factor index 4b2486d19f..84a609643a 100644 --- a/basis/io/unix/multiplexers/run-loop/run-loop.factor +++ b/basis/io/backend/unix/multiplexers/run-loop/run-loop.factor @@ -1,10 +1,10 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel arrays namespaces math accessors alien locals -destructors system threads io.unix.multiplexers -io.unix.multiplexers.kqueue core-foundation +destructors system threads io.backend.unix.multiplexers +io.backend.unix.multiplexers.kqueue core-foundation core-foundation.run-loop ; -IN: io.unix.multiplexers.run-loop +IN: io.backend.unix.multiplexers.run-loop TUPLE: run-loop-mx kqueue-mx ; diff --git a/basis/io/unix/files/macosx/tags.txt b/basis/io/backend/unix/multiplexers/run-loop/tags.txt similarity index 100% rename from basis/io/unix/files/macosx/tags.txt rename to basis/io/backend/unix/multiplexers/run-loop/tags.txt diff --git a/basis/io/unix/kqueue/authors.txt b/basis/io/backend/unix/multiplexers/select/authors.txt similarity index 100% rename from basis/io/unix/kqueue/authors.txt rename to basis/io/backend/unix/multiplexers/select/authors.txt diff --git a/basis/io/unix/multiplexers/select/select.factor b/basis/io/backend/unix/multiplexers/select/select.factor similarity index 94% rename from basis/io/unix/multiplexers/select/select.factor rename to basis/io/backend/unix/multiplexers/select/select.factor index 915daac2d3..c62101e478 100644 --- a/basis/io/unix/multiplexers/select/select.factor +++ b/basis/io/backend/unix/multiplexers/select/select.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien.c-types kernel bit-arrays sequences assocs unix math namespaces accessors math.order locals unix.time fry -io.ports io.unix.backend io.unix.multiplexers ; -IN: io.unix.multiplexers.select +io.ports io.backend.unix io.backend.unix.multiplexers ; +IN: io.backend.unix.multiplexers.select TUPLE: select-mx < mx read-fdset write-fdset ; diff --git a/basis/io/unix/files/netbsd/tags.txt b/basis/io/backend/unix/multiplexers/select/tags.txt similarity index 100% rename from basis/io/unix/files/netbsd/tags.txt rename to basis/io/backend/unix/multiplexers/select/tags.txt diff --git a/basis/io/backend/unix/netbsd/netbsd.factor b/basis/io/backend/unix/netbsd/netbsd.factor new file mode 100644 index 0000000000..a47be300f8 --- /dev/null +++ b/basis/io/backend/unix/netbsd/netbsd.factor @@ -0,0 +1,3 @@ +USING: io.backend.unix.bsd io.backend system ; + +netbsd set-io-backend diff --git a/basis/io/unix/files/openbsd/tags.txt b/basis/io/backend/unix/netbsd/tags.txt similarity index 100% rename from basis/io/unix/files/openbsd/tags.txt rename to basis/io/backend/unix/netbsd/tags.txt diff --git a/basis/io/backend/unix/openbsd/openbsd.factor b/basis/io/backend/unix/openbsd/openbsd.factor new file mode 100644 index 0000000000..a9e25134de --- /dev/null +++ b/basis/io/backend/unix/openbsd/openbsd.factor @@ -0,0 +1,3 @@ +USING: io.backend.unix.bsd io.backend system ; + +openbsd set-io-backend diff --git a/basis/io/unix/files/tags.txt b/basis/io/backend/unix/openbsd/tags.txt similarity index 100% rename from basis/io/unix/files/tags.txt rename to basis/io/backend/unix/openbsd/tags.txt diff --git a/basis/io/unix/backend/summary.txt b/basis/io/backend/unix/summary.txt similarity index 100% rename from basis/io/unix/backend/summary.txt rename to basis/io/backend/unix/summary.txt diff --git a/basis/io/unix/files/unique/tags.txt b/basis/io/backend/unix/tags.txt similarity index 100% rename from basis/io/unix/files/unique/tags.txt rename to basis/io/backend/unix/tags.txt diff --git a/basis/io/unix/unix-tests.factor b/basis/io/backend/unix/unix-tests.factor similarity index 99% rename from basis/io/unix/unix-tests.factor rename to basis/io/backend/unix/unix-tests.factor index df61420c77..5add7933a7 100644 --- a/basis/io/unix/unix-tests.factor +++ b/basis/io/backend/unix/unix-tests.factor @@ -2,7 +2,7 @@ USING: io.files io.sockets io kernel threads namespaces tools.test continuations strings byte-arrays sequences prettyprint system io.encodings.binary io.encodings.ascii io.streams.duplex destructors make ; -IN: io.unix.tests +IN: io.backend.unix.tests ! Unix domain stream sockets : socket-server "unix-domain-socket-test" temp-file ; diff --git a/basis/io/unix/backend/backend.factor b/basis/io/backend/unix/unix.factor similarity index 98% rename from basis/io/unix/backend/backend.factor rename to basis/io/backend/unix/unix.factor index 41bd03a58b..e8ace90d73 100644 --- a/basis/io/unix/backend/backend.factor +++ b/basis/io/backend/unix/unix.factor @@ -5,9 +5,9 @@ kernel.private math io.ports sequences strings sbufs threads unix vectors io.buffers io.backend io.encodings math.parser continuations system libc qualified namespaces make io.timeouts io.encodings.utf8 destructors accessors summary combinators -locals unix.time fry io.unix.multiplexers ; +locals unix.time fry io.backend.unix.multiplexers ; QUALIFIED: io -IN: io.unix.backend +IN: io.backend.unix GENERIC: handle-fd ( handle -- fd ) diff --git a/basis/io/windows/authors.txt b/basis/io/backend/windows/authors.txt similarity index 100% rename from basis/io/windows/authors.txt rename to basis/io/backend/windows/authors.txt diff --git a/basis/io/windows/nt/backend/authors.txt b/basis/io/backend/windows/nt/authors.txt similarity index 100% rename from basis/io/windows/nt/backend/authors.txt rename to basis/io/backend/windows/nt/authors.txt diff --git a/basis/io/windows/nt/backend/backend.factor b/basis/io/backend/windows/nt/nt.factor similarity index 97% rename from basis/io/windows/nt/backend/backend.factor rename to basis/io/backend/windows/nt/nt.factor index 8035bd66e9..d6c74ed098 100644 --- a/basis/io/windows/nt/backend/backend.factor +++ b/basis/io/backend/windows/nt/nt.factor @@ -1,11 +1,11 @@ USING: alien alien.c-types arrays assocs combinators continuations destructors io io.backend io.ports io.timeouts -io.windows io.windows.files io.files io.buffers io.streams.c +io.backend.windows io.files.windows io.files io.buffers io.streams.c libc kernel math namespaces sequences threads windows windows.errors windows.kernel32 strings splitting qualified ascii system accessors locals ; QUALIFIED: windows.winsock -IN: io.windows.nt.backend +IN: io.backend.windows.nt ! Global variable with assoc mapping overlapped to threads SYMBOL: pending-overlapped diff --git a/basis/io/windows/nt/privileges/privileges.factor b/basis/io/backend/windows/nt/privileges/privileges.factor similarity index 88% rename from basis/io/windows/nt/privileges/privileges.factor rename to basis/io/backend/windows/nt/privileges/privileges.factor index 264f337eaf..64218f75b0 100755 --- a/basis/io/windows/nt/privileges/privileges.factor +++ b/basis/io/backend/windows/nt/privileges/privileges.factor @@ -1,9 +1,9 @@ USING: alien alien.c-types alien.syntax arrays continuations -destructors generic io.mmap io.ports io.windows io.windows.files +destructors generic io.mmap io.ports io.backend.windows io.files.windows kernel libc math math.bitwise namespaces quotations sequences windows windows.advapi32 windows.kernel32 io.backend system accessors -io.windows.privileges ; -IN: io.windows.nt.privileges +io.backend.windows.privileges ; +IN: io.backend.windows.nt.privileges TYPEDEF: TOKEN_PRIVILEGES* PTOKEN_PRIVILEGES diff --git a/basis/io/unix/freebsd/tags.txt b/basis/io/backend/windows/nt/privileges/tags.txt similarity index 100% rename from basis/io/unix/freebsd/tags.txt rename to basis/io/backend/windows/nt/privileges/tags.txt diff --git a/basis/io/unix/kqueue/tags.txt b/basis/io/backend/windows/nt/tags.txt similarity index 100% rename from basis/io/unix/kqueue/tags.txt rename to basis/io/backend/windows/nt/tags.txt diff --git a/basis/io/windows/privileges/privileges.factor b/basis/io/backend/windows/privileges/privileges.factor similarity index 61% rename from basis/io/windows/privileges/privileges.factor rename to basis/io/backend/windows/privileges/privileges.factor index e169bdf12f..8661ba99d9 100644 --- a/basis/io/windows/privileges/privileges.factor +++ b/basis/io/backend/windows/privileges/privileges.factor @@ -1,6 +1,6 @@ USING: io.backend kernel continuations sequences system vocabs.loader combinators ; -IN: io.windows.privileges +IN: io.backend.windows.privileges HOOK: set-privilege io-backend ( name ? -- ) inline @@ -9,6 +9,6 @@ HOOK: set-privilege io-backend ( name ? -- ) inline swap [ [ f set-privilege ] each ] curry [ ] cleanup ; inline { - { [ os winnt? ] [ "io.windows.nt.privileges" require ] } - { [ os wince? ] [ "io.windows.ce.privileges" require ] } + { [ os winnt? ] [ "io.backend.windows.nt.privileges" require ] } + { [ os wince? ] [ "io.backend.windows.ce.privileges" require ] } } cond diff --git a/basis/io/unix/launcher/parser/tags.txt b/basis/io/backend/windows/privileges/tags.txt similarity index 100% rename from basis/io/unix/launcher/parser/tags.txt rename to basis/io/backend/windows/privileges/tags.txt diff --git a/basis/io/windows/summary.txt b/basis/io/backend/windows/summary.txt similarity index 100% rename from basis/io/windows/summary.txt rename to basis/io/backend/windows/summary.txt diff --git a/basis/io/unix/launcher/tags.txt b/basis/io/backend/windows/tags.txt old mode 100644 new mode 100755 similarity index 100% rename from basis/io/unix/launcher/tags.txt rename to basis/io/backend/windows/tags.txt diff --git a/basis/io/windows/windows.factor b/basis/io/backend/windows/windows.factor similarity index 98% rename from basis/io/windows/windows.factor rename to basis/io/backend/windows/windows.factor index 94304edc05..e7c72edfd0 100755 --- a/basis/io/windows/windows.factor +++ b/basis/io/backend/windows/windows.factor @@ -5,7 +5,7 @@ io.buffers io.files io.ports io.binary io.timeouts windows.errors strings kernel math namespaces sequences windows windows.kernel32 windows.shell32 windows.types windows.winsock splitting continuations math.bitwise system accessors ; -IN: io.windows +IN: io.backend.windows : set-inherit ( handle ? -- ) [ HANDLE_FLAG_INHERIT ] dip diff --git a/basis/io/directories/directories-docs.factor b/basis/io/directories/directories-docs.factor new file mode 100644 index 0000000000..1638958e02 --- /dev/null +++ b/basis/io/directories/directories-docs.factor @@ -0,0 +1,191 @@ +IN: io.directories + +HELP: cwd +{ $values { "path" "a pathname string" } } +{ $description "Outputs the current working directory of the Factor process." } +{ $errors "Windows CE has no concept of ``current directory'', so this word throws an error there." } +{ $notes "User code should use " { $link with-directory } " or " { $link set-current-directory } " instead." } ; + +HELP: cd +{ $values { "path" "a pathname string" } } +{ $description "Changes the current working directory of the Factor process." } +{ $errors "Windows CE has no concept of ``current directory'', so this word throws an error there." } +{ $notes "User code should use " { $link with-directory } " or " { $link set-current-directory } " instead." } ; + +{ cd cwd current-directory set-current-directory with-directory } related-words + +HELP: current-directory +{ $description "A variable holding the current directory as an absolute path. Words that use the filesystem do so in relation to this variable." +$nl +"This variable should never be set directly; instead, use " { $link set-current-directory } " or " { $link with-directory } ". This preserves the invariant that the value of this variable is an absolute path." } ; + +HELP: set-current-directory +{ $values { "path" "a pathname string" } } +{ $description "Changes the " { $link current-directory } " variable." +$nl +"If " { $snippet "path" } " is relative, it is first resolved relative to the current directory. If " { $snippet "path" } " is absolute, it becomes the new current directory." } ; + +HELP: with-directory +{ $values { "path" "a pathname string" } { "quot" quotation } } +{ $description "Calls the quotation in a new dynamic scope with the " { $link current-directory } " variable rebound." +$nl +"If " { $snippet "path" } " is relative, it is first resolved relative to the current directory. If " { $snippet "path" } " is absolute, it becomes the new current directory." } ; + +HELP: (directory-entries) +{ $values { "path" "a pathname string" } { "seq" "a sequence of " { $snippet "{ name dir? }" } " pairs" } } +{ $description "Outputs the contents of a directory named by " { $snippet "path" } "." } +{ $notes "This is a low-level word, and user code should call one of the related words instead." } ; + +HELP: directory-entries +{ $values { "path" "a pathname string" } { "seq" "a sequence of " { $link directory-entry } " objects" } } +{ $description "Outputs the contents of a directory named by " { $snippet "path" } "." } ; + +HELP: directory-files +{ $values { "path" "a pathname string" } { "seq" "a sequence of filenames" } } +{ $description "Outputs the contents of a directory named by " { $snippet "path" } "." } ; + +HELP: with-directory-files +{ $values { "path" "a pathname string" } { "quot" quotation } } +{ $description "Calls the quotation with the directory file names on the stack and with the directory set as the " { $link current-directory } ". Restores the current directory after the quotation is called." } ; + +HELP: delete-file +{ $values { "path" "a pathname string" } } +{ $description "Deletes a file." } +{ $errors "Throws an error if the file could not be deleted." } ; + +HELP: make-directory +{ $values { "path" "a pathname string" } } +{ $description "Creates a directory." } +{ $errors "Throws an error if the directory could not be created." } ; + +HELP: make-directories +{ $values { "path" "a pathname string" } } +{ $description "Creates a directory and any parent directories which do not yet exist." } +{ $errors "Throws an error if the directories could not be created." } ; + +HELP: delete-directory +{ $values { "path" "a pathname string" } } +{ $description "Deletes a directory. The directory must be empty." } +{ $errors "Throws an error if the directory could not be deleted." } ; + +HELP: touch-file +{ $values { "path" "a pathname string" } } +{ $description "Updates the modification time of a file or directory. If the file does not exist, creates a new, empty file." } +{ $errors "Throws an error if the file could not be touched." } ; + +HELP: delete-tree +{ $values { "path" "a pathname string" } } +{ $description "Deletes a file or directory, recursing into subdirectories." } +{ $errors "Throws an error if the deletion fails." } +{ $warning "Misuse of this word can lead to catastrophic data loss." } ; + +HELP: move-file +{ $values { "from" "a pathname string" } { "to" "a pathname string" } } +{ $description "Moves or renames a file." } +{ $errors "Throws an error if the file does not exist or if the move operation fails." } ; + +HELP: move-file-into +{ $values { "from" "a pathname string" } { "to" "a directory pathname string" } } +{ $description "Moves a file to another directory without renaming it." } +{ $errors "Throws an error if the file does not exist or if the move operation fails." } ; + +HELP: move-files-into +{ $values { "files" "a sequence of pathname strings" } { "to" "a directory pathname string" } } +{ $description "Moves a set of files to another directory." } +{ $errors "Throws an error if the file does not exist or if the move operation fails." } ; + +HELP: copy-file +{ $values { "from" "a pathname string" } { "to" "a pathname string" } } +{ $description "Copies a file." } +{ $notes "This operation attempts to preserve the original file's attributes, however not all attributes may be preserved." } +{ $errors "Throws an error if the file does not exist or if the copy operation fails." } ; + +HELP: copy-file-into +{ $values { "from" "a pathname string" } { "to" "a directory pathname string" } } +{ $description "Copies a file to another directory." } +{ $errors "Throws an error if the file does not exist or if the copy operation fails." } ; + +HELP: copy-files-into +{ $values { "files" "a sequence of pathname strings" } { "to" "a directory pathname string" } } +{ $description "Copies a set of files to another directory." } +{ $errors "Throws an error if the file does not exist or if the copy operation fails." } ; + +HELP: copy-tree +{ $values { "from" "a pathname string" } { "to" "a pathname string" } } +{ $description "Copies a directory tree recursively." } +{ $notes "This operation attempts to preserve original file attributes, however not all attributes may be preserved." } +{ $errors "Throws an error if the copy operation fails." } ; + +HELP: copy-tree-into +{ $values { "from" "a pathname string" } { "to" "a directory pathname string" } } +{ $description "Copies a directory tree to another directory, recursively." } +{ $errors "Throws an error if the copy operation fails." } ; + +HELP: copy-trees-into +{ $values { "files" "a sequence of pathname strings" } { "to" "a directory pathname string" } } +{ $description "Copies a set of directory trees to another directory, recursively." } +{ $errors "Throws an error if the copy operation fails." } ; + +ARTICLE: "current-directory" "Current working directory" +"File system I/O operations use the value of a variable to resolve relative pathnames:" +{ $subsection current-directory } +"This variable can be changed with a pair of words:" +{ $subsection set-current-directory } +{ $subsection with-directory } +"This variable is independent of the operating system notion of ``current working directory''. While all Factor I/O operations use the variable and not the operating system's value, care must be taken when making FFI calls which expect a pathname. The first option is to resolve relative paths:" +{ $subsection (normalize-path) } +"The second is to change the working directory of the current process:" +{ $subsection cd } +{ $subsection cwd } ; + +ARTICLE: "io.directories.listing" "Directory listing" +"Directory listing:" +{ $subsection directory-entries } +{ $subsection directory-files } +{ $subsection with-directory-files } ; + +ARTICLE: "io.directories.create" "Creating directories" +{ $subsection make-directory } +{ $subsection make-directories } ; + +ARTICLE: "delete-move-copy" "Deleting, moving, and copying files" +"Operations for deleting and copying files come in two forms:" +{ $list + { "Words named " { $snippet { $emphasis "operation" } "-file" } " which work on regular files only." } + { "Words named " { $snippet { $emphasis "operation" } "-tree" } " works on directory trees recursively, and also accepts regular files." } +} +"The operations for moving and copying files come in three flavors:" +{ $list + { "A word named " { $snippet { $emphasis "operation" } } " which takes a source and destination path." } + { "A word named " { $snippet { $emphasis "operation" } "-into" } " which takes a source path and destination directory. The destination file will be stored in the destination directory and will have the same file name as the source path." } + { "A word named " { $snippet { $emphasis "operation" } "s-into" } " which takes a sequence of source paths and destination directory." } +} +"Since both of the above lists apply to copying files, that this means that there are a total of six variations on copying a file." +$nl +"Deleting files:" +{ $subsection delete-file } +{ $subsection delete-directory } +{ $subsection delete-tree } +"Moving files:" +{ $subsection move-file } +{ $subsection move-file-into } +{ $subsection move-files-into } +"Copying files:" +{ $subsection copy-file } +{ $subsection copy-file-into } +{ $subsection copy-files-into } +"Copying directory trees recursively:" +{ $subsection copy-tree } +{ $subsection copy-tree-into } +{ $subsection copy-trees-into } +"On most operating systems, files can only be moved within the same file system. To move files between file systems, use " { $link copy-file } " followed by " { $link delete-file } " on the old name." ; + +ARTICLE: "io.directories" "Directory manipulation" +"The " { $vocab-link "io.directories" } " vocabulary defines words for inspecting and manipulating directory trees." +{ $subsection home } +{ $subsection "current-directory" } +{ $subsection "io.directories.listing" } +{ $subsection "io.directories.create" } +{ $subsection "delete-move-copy" } ; + +ABOUT: "io.directories" diff --git a/basis/io/directories/directories-tests.factor b/basis/io/directories/directories-tests.factor new file mode 100644 index 0000000000..266760f925 --- /dev/null +++ b/basis/io/directories/directories-tests.factor @@ -0,0 +1,199 @@ +IN: io.directories.tests + +[ { "kernel" } ] [ + "core" resource-path [ + "." directory-files [ "kernel" = ] filter + ] with-directory +] unit-test + +[ { "kernel" } ] [ + "resource:core" [ + "." directory-files [ "kernel" = ] filter + ] with-directory +] unit-test + +[ { "kernel" } ] [ + "resource:core" [ + [ "kernel" = ] filter + ] with-directory-files +] unit-test + +[ ] [ "blahblah" temp-file dup exists? [ delete-directory ] [ drop ] if ] unit-test +[ ] [ "blahblah" temp-file make-directory ] unit-test +[ t ] [ "blahblah" temp-file file-info directory? ] unit-test + +[ t ] [ + [ temp-directory "loldir" append-path delete-directory ] ignore-errors + temp-directory [ + "loldir" make-directory + ] with-directory + temp-directory "loldir" append-path exists? +] unit-test + +[ ] [ + [ temp-directory "loldir" append-path delete-directory ] ignore-errors + temp-directory [ + "loldir" make-directory + "loldir" delete-directory + ] with-directory +] unit-test + +[ "file1 contents" ] [ + [ temp-directory "loldir" append-path delete-directory ] ignore-errors + temp-directory [ + "file1 contents" "file1" utf8 set-file-contents + "file1" "file2" copy-file + "file2" utf8 file-contents + ] with-directory + "file1" temp-file delete-file + "file2" temp-file delete-file +] unit-test + +[ "file3 contents" ] [ + temp-directory [ + "file3 contents" "file3" utf8 set-file-contents + "file3" "file4" move-file + "file4" utf8 file-contents + ] with-directory + "file4" temp-file delete-file +] unit-test + +[ "file5" temp-file delete-file ] ignore-errors + +[ ] [ + temp-directory [ + "file5" touch-file + "file5" delete-file + ] with-directory +] unit-test + +[ "file6" temp-file delete-file ] ignore-errors + +[ ] [ + temp-directory [ + "file6" touch-file + "file6" link-info drop + ] with-directory +] unit-test + +[ ] [ + { "Hello world." } + "test-foo.txt" temp-file ascii set-file-lines +] unit-test + +[ ] [ + "test-foo.txt" temp-file ascii [ + "Hello appender." print + ] with-file-appender +] unit-test + +[ ] [ + "test-bar.txt" temp-file ascii [ + "Hello appender." print + ] with-file-appender +] unit-test + +[ "Hello world.\nHello appender.\n" ] [ + "test-foo.txt" temp-file ascii file-contents +] unit-test + +[ "Hello appender.\n" ] [ + "test-bar.txt" temp-file ascii file-contents +] unit-test + +[ ] [ "test-foo.txt" temp-file delete-file ] unit-test + +[ ] [ "test-bar.txt" temp-file delete-file ] unit-test + +[ f ] [ "test-foo.txt" temp-file exists? ] unit-test + +[ f ] [ "test-bar.txt" temp-file exists? ] unit-test + +[ "test-blah" temp-file delete-tree ] ignore-errors + +[ ] [ "test-blah" temp-file make-directory ] unit-test + +[ ] [ + "test-blah/fooz" temp-file ascii dispose +] unit-test + +[ t ] [ + "test-blah/fooz" temp-file exists? +] unit-test + +[ ] [ "test-blah/fooz" temp-file delete-file ] unit-test + +[ ] [ "test-blah" temp-file delete-directory ] unit-test + +[ f ] [ "test-blah" temp-file exists? ] unit-test + +USE: debugger.threads + +[ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test + +[ ] [ "test-quux.txt" temp-file delete-file ] unit-test + +[ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test + +[ ] [ "test-quux.txt" "quux-test.txt" [ temp-file ] bi@ move-file ] unit-test + +[ t ] [ "quux-test.txt" temp-file exists? ] unit-test + +[ ] [ "quux-test.txt" temp-file delete-file ] unit-test + +[ ] [ "delete-tree-test/a/b/c" temp-file make-directories ] unit-test + +[ ] [ + { "Hi" } + "delete-tree-test/a/b/c/d" temp-file ascii set-file-lines +] unit-test + +[ ] [ + "delete-tree-test" temp-file delete-tree +] unit-test + +[ ] [ + "copy-tree-test/a/b/c" temp-file make-directories +] unit-test + +[ ] [ + "Foobar" + "copy-tree-test/a/b/c/d" temp-file + ascii set-file-contents +] unit-test + +[ ] [ + "copy-tree-test" temp-file + "copy-destination" temp-file copy-tree +] unit-test + +[ "Foobar" ] [ + "copy-destination/a/b/c/d" temp-file ascii file-contents +] unit-test + +[ ] [ + "copy-destination" temp-file delete-tree +] unit-test + +[ ] [ + "copy-tree-test" temp-file + "copy-destination" temp-file copy-tree-into +] unit-test + +[ "Foobar" ] [ + "copy-destination/copy-tree-test/a/b/c/d" temp-file ascii file-contents +] unit-test + +[ ] [ + "copy-destination/copy-tree-test/a/b/c/d" temp-file "" temp-file copy-file-into +] unit-test + +[ "Foobar" ] [ + "d" temp-file ascii file-contents +] unit-test + +[ ] [ "d" temp-file delete-file ] unit-test + +[ ] [ "copy-destination" temp-file delete-tree ] unit-test + +[ ] [ "copy-tree-test" temp-file delete-tree ] unit-test diff --git a/basis/io/directories/directories.factor b/basis/io/directories/directories.factor new file mode 100644 index 0000000000..8d7a276959 --- /dev/null +++ b/basis/io/directories/directories.factor @@ -0,0 +1,112 @@ +! Copyright (C) 2004, 2008 Slava Pestov, Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: vocabs.loader combinators ; +IN: io.directories + +: set-current-directory ( path -- ) + (normalize-path) current-directory set ; + +: with-directory ( path quot -- ) + [ (normalize-path) current-directory ] dip with-variable ; inline + +! Creating directories +HOOK: make-directory io-backend ( path -- ) + +: make-directories ( path -- ) + normalize-path trim-right-separators { + { [ dup "." = ] [ ] } + { [ dup root-directory? ] [ ] } + { [ dup empty? ] [ ] } + { [ dup exists? ] [ ] } + [ + dup parent-directory make-directories + dup make-directory + ] + } cond drop ; + +! Listing directories +TUPLE: directory-entry name type ; + +HOOK: >directory-entry os ( byte-array -- directory-entry ) + +HOOK: (directory-entries) os ( path -- seq ) + +: directory-entries ( path -- seq ) + normalize-path + (directory-entries) + [ name>> { "." ".." } member? not ] filter ; + +: directory-files ( path -- seq ) + directory-entries [ name>> ] map ; + +: with-directory-files ( path quot -- ) + [ "" directory-files ] prepose with-directory ; inline + +! Touching files +HOOK: touch-file io-backend ( path -- ) + +! Deleting files +HOOK: delete-file io-backend ( path -- ) + +HOOK: delete-directory io-backend ( path -- ) + +: delete-tree ( path -- ) + dup link-info type>> +directory+ = [ + [ [ [ delete-tree ] each ] with-directory-files ] + [ delete-directory ] + bi + ] [ delete-file ] if ; + +: to-directory ( from to -- from to' ) + over file-name append-path ; + +! Moving and renaming files +HOOK: move-file io-backend ( from to -- ) + +: move-file-into ( from to -- ) + to-directory move-file ; + +: move-files-into ( files to -- ) + [ move-file-into ] curry each ; + +! Copying files +HOOK: copy-file io-backend ( from to -- ) + +M: object copy-file + dup parent-directory make-directories + binary [ + swap binary [ + swap stream-copy + ] with-disposal + ] with-disposal ; + +: copy-file-into ( from to -- ) + to-directory copy-file ; + +: copy-files-into ( files to -- ) + [ copy-file-into ] curry each ; + +DEFER: copy-tree-into + +: copy-tree ( from to -- ) + normalize-path + over link-info type>> + { + { +symbolic-link+ [ copy-link ] } + { +directory+ [ + swap [ + [ swap copy-tree-into ] with each + ] with-directory-files + ] } + [ drop copy-file ] + } case ; + +: copy-tree-into ( from to -- ) + to-directory copy-tree ; + +: copy-trees-into ( files to -- ) + [ copy-tree-into ] curry each ; + +{ + { [ os unix? ] [ "io.directories.unix" require ] } +} cond \ No newline at end of file diff --git a/basis/io/windows/mmap/authors.txt b/basis/io/directories/search/authors.txt similarity index 100% rename from basis/io/windows/mmap/authors.txt rename to basis/io/directories/search/authors.txt diff --git a/basis/io/directories/search/search-tests.factor b/basis/io/directories/search/search-tests.factor new file mode 100644 index 0000000000..01763ce5c0 --- /dev/null +++ b/basis/io/directories/search/search-tests.factor @@ -0,0 +1,11 @@ +USING: io.paths kernel tools.test io.files.unique sequences +io.files namespaces sorting ; +IN: io.paths.tests + +[ t ] [ + [ + 10 [ "io.paths.test" "gogogo" make-unique-file* ] replicate + current-directory get t [ ] find-all-files + ] with-unique-directory + [ natural-sort ] bi@ = +] unit-test diff --git a/basis/io/directories/search/search.factor b/basis/io/directories/search/search.factor new file mode 100755 index 0000000000..34f06f08f2 --- /dev/null +++ b/basis/io/directories/search/search.factor @@ -0,0 +1,58 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors arrays deques dlists io.files +kernel sequences system vocabs.loader fry continuations ; +IN: io.directories.search + +TUPLE: directory-iterator path bfs queue ; + +> swap bfs>> + [ push-front ] [ push-back ] if + ] curry each ; + +: ( path bfs? -- iterator ) + directory-iterator boa + dup path>> over push-directory ; + +: next-file ( iter -- file/f ) + dup queue>> deque-empty? [ drop f ] [ + dup queue>> pop-back dup link-info directory? + [ over push-directory next-file ] [ nip ] if + ] if ; + +: iterate-directory ( iter quot: ( obj -- ? ) -- obj ) + over next-file [ + over call + [ 2nip ] [ iterate-directory ] if* + ] [ + 2drop f + ] if* ; inline recursive + +PRIVATE> + +: find-file ( path bfs? quot: ( obj -- ? ) -- path/f ) + [ ] dip + [ keep and ] curry iterate-directory ; inline + +: each-file ( path bfs? quot: ( obj -- ? ) -- ) + [ ] dip + [ f ] compose iterate-directory drop ; inline + +: find-all-files ( path bfs? quot: ( obj -- ? ) -- paths ) + [ ] dip + pusher [ [ f ] compose iterate-directory drop ] dip ; inline + +: recursive-directory ( path bfs? -- paths ) + [ ] accumulator [ each-file ] dip ; + +: find-in-directories ( directories bfs? quot -- path' ) + '[ _ _ find-file ] attempt-all ; inline + +os windows? [ "io.paths.windows" require ] when diff --git a/basis/io/windows/nt/monitors/authors.txt b/basis/io/directories/search/windows/authors.txt old mode 100755 new mode 100644 similarity index 100% rename from basis/io/windows/nt/monitors/authors.txt rename to basis/io/directories/search/windows/authors.txt diff --git a/basis/io/unix/linux/monitors/tags.txt b/basis/io/directories/search/windows/tags.txt similarity index 100% rename from basis/io/unix/linux/monitors/tags.txt rename to basis/io/directories/search/windows/tags.txt diff --git a/basis/io/directories/search/windows/windows.factor b/basis/io/directories/search/windows/windows.factor new file mode 100644 index 0000000000..b4858aaef8 --- /dev/null +++ b/basis/io/directories/search/windows/windows.factor @@ -0,0 +1,13 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: arrays continuations fry io.files io.paths +kernel windows.shell32 sequences ; +IN: io.paths.windows + +: program-files-directories ( -- array ) + program-files program-files-x86 2array ; inline + +: find-in-program-files ( base-directory bfs? quot -- path ) + [ + [ program-files-directories ] dip '[ _ append-path ] map + ] 2dip find-in-directories ; inline diff --git a/basis/io/directories/unix/unix.factor b/basis/io/directories/unix/unix.factor new file mode 100644 index 0000000000..11712d8545 --- /dev/null +++ b/basis/io/directories/unix/unix.factor @@ -0,0 +1,75 @@ +! Copyright (C) 2008 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: math.bitwise io.backend kernel io.files unix +io.backend.unix io.encodings.binary io.directories io destructors +accessors io.files.info alien.c-types io.encodings.utf8 fry +sequences system continuations alien.strings ; +IN: io.directories.unix + +: touch-mode ( -- n ) + { O_WRONLY O_APPEND O_CREAT O_EXCL } flags ; foldable + +M: unix touch-file ( path -- ) + normalize-path + dup exists? [ touch ] [ + touch-mode file-mode open-file close-file + ] if ; + +M: unix move-file ( from to -- ) + [ normalize-path ] bi@ rename io-error ; + +M: unix delete-file ( path -- ) normalize-path unlink-file ; + +M: unix make-directory ( path -- ) + normalize-path OCT: 777 mkdir io-error ; + +M: unix delete-directory ( path -- ) + normalize-path rmdir io-error ; + +: (copy-file) ( from to -- ) + dup parent-directory make-directories + binary [ + swap binary [ + swap stream-copy + ] with-disposal + ] with-disposal ; + +M: unix copy-file ( from to -- ) + [ normalize-path ] bi@ + [ (copy-file) ] + [ swap file-info permissions>> chmod io-error ] + 2bi ; + +: with-unix-directory ( path quot -- ) + [ opendir dup [ (io-error) ] unless ] dip + dupd curry swap '[ _ closedir io-error ] [ ] cleanup ; inline + +: find-next-file ( DIR* -- byte-array ) + "dirent" + f + [ readdir_r 0 = [ (io-error) ] unless ] 2keep + *void* [ drop f ] unless ; + +: dirent-type>file-type ( ch -- type ) + { + { DT_BLK [ +block-device+ ] } + { DT_CHR [ +character-device+ ] } + { DT_DIR [ +directory+ ] } + { DT_LNK [ +symbolic-link+ ] } + { DT_SOCK [ +socket+ ] } + { DT_FIFO [ +fifo+ ] } + { DT_REG [ +regular-file+ ] } + { DT_WHT [ +whiteout+ ] } + [ drop +unknown+ ] + } case ; + +M: unix >directory-entry ( byte-array -- directory-entry ) + [ dirent-d_name utf8 alien>string ] + [ dirent-d_type dirent-type>file-type ] bi directory-entry boa ; + +M: unix (directory-entries) ( path -- seq ) + [ + '[ _ find-next-file dup ] + [ >directory-entry ] + [ drop ] produce + ] with-unix-directory ; diff --git a/basis/io/encodings/binary/authors.txt b/basis/io/encodings/binary/authors.txt new file mode 100644 index 0000000000..f990dd0ed2 --- /dev/null +++ b/basis/io/encodings/binary/authors.txt @@ -0,0 +1 @@ +Daniel Ehrenberg diff --git a/basis/io/encodings/binary/binary-docs.factor b/basis/io/encodings/binary/binary-docs.factor new file mode 100644 index 0000000000..4da1e0811f --- /dev/null +++ b/basis/io/encodings/binary/binary-docs.factor @@ -0,0 +1,11 @@ +USING: help.syntax help.markup ; +IN: io.encodings.binary + +HELP: binary +{ $class-description "Encoding descriptor for binary I/O." } ; + +ARTICLE: "io.encodings.binary" "Binary encoding" +"Making an encoded stream with the binary encoding is a no-op; streams with this encoding deal with byte-arrays, not strings." +{ $subsection binary } ; + +ABOUT: "io.encodings.binary" diff --git a/basis/io/encodings/binary/binary.factor b/basis/io/encodings/binary/binary.factor new file mode 100644 index 0000000000..e54163f632 --- /dev/null +++ b/basis/io/encodings/binary/binary.factor @@ -0,0 +1,8 @@ +! Copyright (C) 2008 Daniel Ehrenberg. +! See http://factorcode.org/license.txt for BSD license. +USING: io.encodings kernel ; +IN: io.encodings.binary + +SINGLETON: binary +M: binary drop ; +M: binary drop ; diff --git a/basis/io/encodings/binary/summary.txt b/basis/io/encodings/binary/summary.txt new file mode 100644 index 0000000000..a1eb4bc664 --- /dev/null +++ b/basis/io/encodings/binary/summary.txt @@ -0,0 +1 @@ +Dummy encoding for binary I/O diff --git a/basis/io/encodings/binary/tags.txt b/basis/io/encodings/binary/tags.txt new file mode 100644 index 0000000000..8e27be7d61 --- /dev/null +++ b/basis/io/encodings/binary/tags.txt @@ -0,0 +1 @@ +text diff --git a/basis/io/files/info/info-docs.factor b/basis/io/files/info/info-docs.factor new file mode 100644 index 0000000000..8bb79851ec --- /dev/null +++ b/basis/io/files/info/info-docs.factor @@ -0,0 +1,76 @@ +IN: io.files.info + +HELP: file-info +{ $values { "path" "a pathname string" } { "info" file-info } } +{ $description "Queries the file system for metadata. If " { $snippet "path" } " refers to a symbolic link, it is followed. See the article " { $link "file-types" } " for a list of metadata symbols." } +{ $errors "Throws an error if the file does not exist." } ; + +HELP: link-info +{ $values { "path" "a pathname string" } { "info" "a file-info tuple" } } +{ $description "Queries the file system for metadata. If path refers to a symbolic link, information about the symbolic link itself is returned. If the file does not exist, an exception is thrown." } ; + +{ file-info link-info } related-words + +HELP: +regular-file+ +{ $description "A regular file. This type exists on all platforms. See " { $link "file-streams" } " for words operating on files." } ; + +HELP: +directory+ +{ $description "A directory. This type exists on all platforms. See " { $link "directories" } " for words operating on directories." } ; + +HELP: +symbolic-link+ +{ $description "A symbolic link file. This type is currently implemented on Unix platforms only. See " { $link "symbolic-links" } " for words operating on symbolic links." } ; + +HELP: +character-device+ +{ $description "A Unix character device file. This type exists on Unix platforms only." } ; + +HELP: +block-device+ +{ $description "A Unix block device file. This type exists on Unix platforms only." } ; + +HELP: +fifo+ +{ $description "A Unix fifo file. This type exists on Unix platforms only." } ; + +HELP: +socket+ +{ $description "A Unix socket file. This type exists on Unix platforms only." } ; + +HELP: +unknown+ +{ $description "A unknown file type." } ; + +HELP: directory? +{ $values { "file-info" file-info } { "?" "a boolean" } } +{ $description "Tests if " { $snippet "file-info" } " is a directory." } ; + +HELP: file-systems +{ $values { "array" array } } +{ $description "Returns an array of " { $link file-system-info } " objects returned by iterating the mount points and calling " { $link file-system-info } " on each." } ; + +HELP: file-system-info +{ $values +{ "path" "a pathname string" } +{ "file-system-info" file-system-info } } +{ $description "Returns a platform-specific object describing the file-system that contains the path. The cross-platform slot is " { $slot "free-space" } "." } ; + +ARTICLE: "file-types" "File types" +"Platform-independent types:" +{ $subsection +regular-file+ } +{ $subsection +directory+ } +"Platform-specific types:" +{ $subsection +character-device+ } +{ $subsection +block-device+ } +{ $subsection +fifo+ } +{ $subsection +symbolic-link+ } +{ $subsection +socket+ } +{ $subsection +unknown+ } ; + +ARTICLE: "io.files.info" "File system meta-data" +"File meta-data:" +{ $subsection file-info } +{ $subsection link-info } +{ $subsection exists? } +{ $subsection directory? } +"File types:" +{ $subsection "file-types" } +"File system meta-data:" +{ $subsection file-system-info } +{ $subsection file-systems } ; + +ABOUT: "io.files.info" diff --git a/basis/io/files/info/info-tests.factor b/basis/io/files/info/info-tests.factor new file mode 100644 index 0000000000..9d6eca13ca --- /dev/null +++ b/basis/io/files/info/info-tests.factor @@ -0,0 +1,16 @@ +IN: io.files.info.tests + +\ file-info must-infer +\ link-info must-infer + +[ t ] [ + temp-directory [ "hi41" "test41" utf8 set-file-contents ] with-directory + temp-directory "test41" append-path utf8 file-contents "hi41" = +] unit-test + +[ t ] [ + temp-directory [ "test41" file-info size>> ] with-directory 4 = +] unit-test + +[ t ] [ "/" file-system-info file-system-info? ] unit-test +[ t ] [ file-systems [ file-system-info? ] all? ] unit-test diff --git a/basis/io/files/info/info.factor b/basis/io/files/info/info.factor new file mode 100644 index 0000000000..ae8d806417 --- /dev/null +++ b/basis/io/files/info/info.factor @@ -0,0 +1,38 @@ +! Copyright (C) 2008 Doug Coleman, Eduardo Cavazos. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors kernel system sequences combinators +vocabs.loader ; +IN: io.files.info + +! File info +TUPLE: file-info type size permissions created modified +accessed ; + +HOOK: file-info os ( path -- info ) + +HOOK: link-info os ( path -- info ) + +SYMBOL: +regular-file+ +SYMBOL: +directory+ +SYMBOL: +symbolic-link+ +SYMBOL: +character-device+ +SYMBOL: +block-device+ +SYMBOL: +fifo+ +SYMBOL: +socket+ +SYMBOL: +whiteout+ +SYMBOL: +unknown+ + +: directory? ( file-info -- ? ) type>> +directory+ = ; + +! File systems +HOOK: file-systems os ( -- array ) + +TUPLE: file-system-info device-name mount-point type +available-space free-space used-space total-space ; + +HOOK: file-system-info os ( path -- file-system-info ) + +{ + { [ os unix? ] [ "io.files.info.unix." os name>> append ] } + { [ os windows? ] [ "io.files.info.windows" ] } +} cond require \ No newline at end of file diff --git a/basis/io/unix/files/bsd/bsd.factor b/basis/io/files/info/unix/bsd/bsd.factor similarity index 76% rename from basis/io/unix/files/bsd/bsd.factor rename to basis/io/files/info/unix/bsd/bsd.factor index 3c94baa39a..6d0f3e7161 100644 --- a/basis/io/unix/files/bsd/bsd.factor +++ b/basis/io/files/info/unix/bsd/bsd.factor @@ -1,8 +1,9 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel alien.syntax math io.unix.files system -unix.stat accessors combinators calendar.unix ; -IN: io.unix.files.bsd +USING: kernel alien.syntax math io.files.unix system +unix.stat accessors combinators calendar.unix +io.files.info.unix ; +IN: io.files.info.unix.bsd TUPLE: bsd-file-info < unix-file-info birth-time flags gen ; diff --git a/basis/io/unix/linux/tags.txt b/basis/io/files/info/unix/bsd/tags.txt similarity index 100% rename from basis/io/unix/linux/tags.txt rename to basis/io/files/info/unix/bsd/tags.txt diff --git a/basis/io/unix/files/freebsd/freebsd.factor b/basis/io/files/info/unix/freebsd/freebsd.factor similarity index 93% rename from basis/io/unix/files/freebsd/freebsd.factor rename to basis/io/files/info/unix/freebsd/freebsd.factor index eaf217af62..c36a750997 100644 --- a/basis/io/unix/files/freebsd/freebsd.factor +++ b/basis/io/files/info/unix/freebsd/freebsd.factor @@ -1,11 +1,11 @@ ! Copyright (C) 2008 Doug Coleman. ! 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 +io.backend io.files io.files.unix kernel math system unix unix.statfs.freebsd unix.statvfs.freebsd unix.getfsstat.freebsd sequences grouping alien.strings io.encodings.utf8 -specialized-arrays.direct.uint arrays ; -IN: io.unix.files.freebsd +specialized-arrays.direct.uint arrays io.files.info.unix ; +IN: io.files.info.unix.freebsd TUPLE: freebsd-file-system-info < unix-file-system-info version io-size owner syncreads syncwrites asyncreads asyncwrites ; diff --git a/basis/io/unix/macosx/monitors/tags.txt b/basis/io/files/info/unix/freebsd/tags.txt similarity index 100% rename from basis/io/unix/macosx/monitors/tags.txt rename to basis/io/files/info/unix/freebsd/tags.txt diff --git a/basis/io/unix/files/linux/linux.factor b/basis/io/files/info/unix/linux/linux.factor similarity index 94% rename from basis/io/unix/files/linux/linux.factor rename to basis/io/files/info/unix/linux/linux.factor index c30855c3ee..9d611bdc5c 100644 --- a/basis/io/unix/files/linux/linux.factor +++ b/basis/io/files/info/unix/linux/linux.factor @@ -2,10 +2,10 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types alien.syntax combinators csv io.backend io.encodings.utf8 io.files io.streams.string -io.unix.files kernel math.order namespaces sequences sorting +io.files.unix kernel math.order namespaces sequences sorting system unix unix.statfs.linux unix.statvfs.linux -specialized-arrays.direct.uint arrays ; -IN: io.unix.files.linux +specialized-arrays.direct.uint arrays io.files.info.unix ; +IN: io.files.info.unix.linux TUPLE: linux-file-system-info < unix-file-system-info namelen ; diff --git a/basis/io/unix/macosx/tags.txt b/basis/io/files/info/unix/linux/tags.txt similarity index 100% rename from basis/io/unix/macosx/tags.txt rename to basis/io/files/info/unix/linux/tags.txt diff --git a/basis/io/unix/files/macosx/macosx.factor b/basis/io/files/info/unix/macosx/macosx.factor similarity index 91% rename from basis/io/unix/files/macosx/macosx.factor rename to basis/io/files/info/unix/macosx/macosx.factor index 397145c9ae..53992bcb95 100644 --- a/basis/io/unix/files/macosx/macosx.factor +++ b/basis/io/files/info/unix/macosx/macosx.factor @@ -2,9 +2,10 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types alien.strings combinators grouping io.encodings.utf8 io.files kernel math sequences -system unix io.unix.files specialized-arrays.direct.uint arrays -unix.statfs.macosx unix.statvfs.macosx unix.getfsstat.macosx ; -IN: io.unix.files.macosx +system unix io.files.unix specialized-arrays.direct.uint arrays +unix.statfs.macosx unix.statvfs.macosx unix.getfsstat.macosx +io.files.info.unix io.files.info ; +IN: io.files.info.unix.macosx TUPLE: macosx-file-system-info < unix-file-system-info io-size owner type-id filesystem-subtype ; diff --git a/basis/io/unix/mmap/tags.txt b/basis/io/files/info/unix/macosx/tags.txt similarity index 100% rename from basis/io/unix/mmap/tags.txt rename to basis/io/files/info/unix/macosx/tags.txt diff --git a/basis/io/unix/files/netbsd/netbsd.factor b/basis/io/files/info/unix/netbsd/netbsd.factor similarity index 91% rename from basis/io/unix/files/netbsd/netbsd.factor rename to basis/io/files/info/unix/netbsd/netbsd.factor index 82ac3dc70d..0c26a2a2c9 100644 --- a/basis/io/unix/files/netbsd/netbsd.factor +++ b/basis/io/files/info/unix/netbsd/netbsd.factor @@ -2,10 +2,11 @@ ! See http://factorcode.org/license.txt for BSD license. 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.encodings.utf8 alien.strings unix.types io.files.unix io.files unix.statvfs.netbsd unix.getfsstat.netbsd arrays -grouping sequences io.encodings.utf8 specialized-arrays.direct.uint ; -IN: io.unix.files.netbsd +grouping sequences io.encodings.utf8 +specialized-arrays.direct.uint io.files.info.unix ; +IN: io.files.info.unix.netbsd TUPLE: netbsd-file-system-info < unix-file-system-info blocks-reserved files-reserved diff --git a/basis/io/unix/multiplexers/epoll/tags.txt b/basis/io/files/info/unix/netbsd/tags.txt similarity index 100% rename from basis/io/unix/multiplexers/epoll/tags.txt rename to basis/io/files/info/unix/netbsd/tags.txt diff --git a/basis/io/unix/files/openbsd/openbsd.factor b/basis/io/files/info/unix/openbsd/openbsd.factor similarity index 93% rename from basis/io/unix/files/openbsd/openbsd.factor rename to basis/io/files/info/unix/openbsd/openbsd.factor index e5e18b29ea..7057e2e8c7 100644 --- a/basis/io/unix/files/openbsd/openbsd.factor +++ b/basis/io/files/info/unix/openbsd/openbsd.factor @@ -1,11 +1,11 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types alien.strings alien.syntax -combinators io.backend io.files io.unix.files kernel math +combinators io.backend io.files io.files.unix kernel math sequences system unix unix.getfsstat.openbsd grouping unix.statfs.openbsd unix.statvfs.openbsd unix.types -specialized-arrays.direct.uint arrays ; -IN: io.unix.files.openbsd +specialized-arrays.direct.uint arrays io.files.info.unix ; +IN: io.files.unix.openbsd TUPLE: freebsd-file-system-info < unix-file-system-info io-size sync-writes sync-reads async-writes async-reads diff --git a/basis/io/unix/multiplexers/kqueue/tags.txt b/basis/io/files/info/unix/openbsd/tags.txt similarity index 100% rename from basis/io/unix/multiplexers/kqueue/tags.txt rename to basis/io/files/info/unix/openbsd/tags.txt diff --git a/basis/io/unix/files/files.factor b/basis/io/files/info/unix/unix.factor similarity index 65% rename from basis/io/unix/files/files.factor rename to basis/io/files/info/unix/unix.factor index 1fc5fe9226..3d08534b71 100644 --- a/basis/io/unix/files/files.factor +++ b/basis/io/files/info/unix/unix.factor @@ -1,80 +1,10 @@ -! Copyright (C) 2005, 2008 Slava Pestov, Doug Coleman. +! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: io.backend io.ports io.unix.backend io.files io -unix unix.stat unix.time kernel math continuations -math.bitwise byte-arrays alien combinators calendar -io.encodings.binary accessors sequences strings system -io.files.private destructors vocabs.loader calendar.unix -unix.stat alien.c-types arrays unix.users unix.groups -environment fry io.encodings.utf8 alien.strings -combinators.short-circuit ; -IN: io.unix.files - -M: unix cwd ( -- path ) - MAXPATHLEN [ ] keep getcwd - [ (io-error) ] unless* ; - -M: unix cd ( path -- ) [ chdir ] unix-system-call drop ; - -: read-flags O_RDONLY ; inline - -: open-read ( path -- fd ) O_RDONLY file-mode open-file ; - -M: unix (file-reader) ( path -- stream ) - open-read init-fd ; - -: write-flags { O_WRONLY O_CREAT O_TRUNC } flags ; inline - -: open-write ( path -- fd ) - write-flags file-mode open-file ; - -M: unix (file-writer) ( path -- stream ) - open-write init-fd ; - -: append-flags { O_WRONLY O_APPEND O_CREAT } flags ; inline - -: open-append ( path -- fd ) - [ - append-flags file-mode open-file |dispose - dup 0 SEEK_END lseek io-error - ] with-destructors ; - -M: unix (file-appender) ( path -- stream ) - open-append init-fd ; - -: touch-mode ( -- n ) - { O_WRONLY O_APPEND O_CREAT O_EXCL } flags ; foldable - -M: unix touch-file ( path -- ) - normalize-path - dup exists? [ touch ] [ - touch-mode file-mode open-file close-file - ] if ; - -M: unix move-file ( from to -- ) - [ normalize-path ] bi@ rename io-error ; - -M: unix delete-file ( path -- ) normalize-path unlink-file ; - -M: unix make-directory ( path -- ) - normalize-path OCT: 777 mkdir io-error ; - -M: unix delete-directory ( path -- ) - normalize-path rmdir io-error ; - -: (copy-file) ( from to -- ) - dup parent-directory make-directories - binary [ - swap binary [ - swap stream-copy - ] with-disposal - ] with-disposal ; - -M: unix copy-file ( from to -- ) - [ normalize-path ] bi@ - [ (copy-file) ] - [ swap file-info permissions>> chmod io-error ] - 2bi ; +USING: accessors kernel system math math.bitwise strings arrays +sequences combinators combinators.short-circuit alien.c-types +vocabs.loader calendar calendar.unix io.files.info io.backend +unix unix.stat unix.time unix.users unix.groups ; +IN: io.files.info.unix TUPLE: unix-file-system-info < file-system-info block-size preferred-block-size @@ -103,13 +33,10 @@ HOOK: statvfs>file-system-info os ( file-system-info statvfs -- file-system-info M: unix statvfs>file-system-info drop ; : file-system-calculations ( file-system-info -- file-system-info' ) - { - [ dup [ blocks-available>> ] [ block-size>> ] bi * >>available-space 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 ] - [ ] - } cleave ; + dup [ blocks-available>> ] [ block-size>> ] bi * >>available-space + dup [ blocks-free>> ] [ block-size>> ] bi * >>free-space + dup [ blocks>> ] [ block-size>> ] bi * >>total-space + dup [ total-space>> ] [ free-space>> ] bi - >>used-space ; M: unix file-system-info normalize-path @@ -118,14 +45,6 @@ M: unix file-system-info [ file-system-statvfs statvfs>file-system-info ] bi file-system-calculations ; -os { - { linux [ "io.unix.files.linux" require ] } - { macosx [ "io.unix.files.macosx" require ] } - { freebsd [ "io.unix.files.freebsd" require ] } - { netbsd [ "io.unix.files.netbsd" require ] } - { openbsd [ "io.unix.files.openbsd" require ] } -} case - TUPLE: unix-file-info < file-info uid gid dev ino nlink rdev blocks blocksize ; @@ -141,12 +60,6 @@ M: unix file-info ( path -- info ) M: unix link-info ( path -- info ) normalize-path link-status stat>file-info ; -M: unix make-link ( path1 path2 -- ) - normalize-path symlink io-error ; - -M: unix read-link ( path -- path' ) - normalize-path read-symbolic-link ; - M: unix new-file-info ( -- class ) unix-file-info new ; M: unix stat>file-info ( stat -- file-info ) @@ -183,36 +96,6 @@ M: unix stat>file-info ( stat -- file-info ) M: unix stat>type ( stat -- type ) stat-st_mode n>file-type ; -! Linux has no extra fields in its stat struct -os { - { macosx [ "io.unix.files.bsd" require ] } - { netbsd [ "io.unix.files.bsd" require ] } - { openbsd [ "io.unix.files.bsd" require ] } - { freebsd [ "io.unix.files.bsd" require ] } - { linux [ ] } -} case - -: with-unix-directory ( path quot -- ) - [ opendir dup [ (io-error) ] unless ] dip - dupd curry swap '[ _ closedir io-error ] [ ] cleanup ; inline - -: find-next-file ( DIR* -- byte-array ) - "dirent" - f - [ readdir_r 0 = [ (io-error) ] unless ] 2keep - *void* [ drop f ] unless ; - -M: unix >directory-entry ( byte-array -- directory-entry ) - [ dirent-d_name utf8 alien>string ] - [ dirent-d_type dirent-type>file-type ] bi directory-entry boa ; - -M: unix (directory-entries) ( path -- seq ) - [ - '[ _ find-next-file dup ] - [ >directory-entry ] - [ drop ] produce - ] with-unix-directory ; - '[ _ with-directory ] [ delete-tree ] bi ; inline { - { [ os unix? ] [ "io.unix.files.unique" ] } - { [ os windows? ] [ "io.windows.files.unique" ] } + { [ os unix? ] [ "io.files.unique.unix" ] } + { [ os windows? ] [ "io.files.unique.windows" ] } } cond require diff --git a/basis/io/unix/multiplexers/run-loop/tags.txt b/basis/io/files/unique/unix/tags.txt similarity index 100% rename from basis/io/unix/multiplexers/run-loop/tags.txt rename to basis/io/files/unique/unix/tags.txt diff --git a/basis/io/unix/files/unique/unique.factor b/basis/io/files/unique/unix/unix.factor similarity index 81% rename from basis/io/unix/files/unique/unique.factor rename to basis/io/files/unique/unix/unix.factor index 24dcdcb65a..ed4e120b79 100644 --- a/basis/io/unix/files/unique/unique.factor +++ b/basis/io/files/unique/unix/unix.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel io.ports io.unix.backend math.bitwise +USING: kernel io.ports io.backend.unix math.bitwise unix system io.files.unique ; -IN: io.unix.files.unique +IN: io.files.unique.unix : open-unique-flags ( -- flags ) { O_RDWR O_CREAT O_EXCL } flags ; diff --git a/basis/io/unix/multiplexers/select/tags.txt b/basis/io/files/unique/windows/tags.txt similarity index 100% rename from basis/io/unix/multiplexers/select/tags.txt rename to basis/io/files/unique/windows/tags.txt diff --git a/basis/io/windows/files/unique/unique.factor b/basis/io/files/unique/windows/windows.factor similarity index 54% rename from basis/io/windows/files/unique/unique.factor rename to basis/io/files/unique/windows/windows.factor index ab99bf2cac..47f30999c3 100644 --- a/basis/io/windows/files/unique/unique.factor +++ b/basis/io/files/unique/windows/windows.factor @@ -1,7 +1,7 @@ -USING: kernel system windows.kernel32 io.windows -io.windows.files io.ports windows destructors environment +USING: kernel system windows.kernel32 io.backend.windows +io.files.windows io.ports windows destructors environment io.files.unique ; -IN: io.windows.files.unique +IN: io.files.unique.windows M: windows touch-unique-file ( path -- ) GENERIC_WRITE CREATE_NEW 0 open-file dispose ; diff --git a/basis/io/unix/launcher/authors.txt b/basis/io/files/unix/authors.txt old mode 100755 new mode 100644 similarity index 100% rename from basis/io/unix/launcher/authors.txt rename to basis/io/files/unix/authors.txt diff --git a/basis/io/unix/files/summary.txt b/basis/io/files/unix/summary.txt similarity index 100% rename from basis/io/unix/files/summary.txt rename to basis/io/files/unix/summary.txt diff --git a/basis/io/unix/netbsd/tags.txt b/basis/io/files/unix/tags.txt similarity index 100% rename from basis/io/unix/netbsd/tags.txt rename to basis/io/files/unix/tags.txt diff --git a/basis/io/unix/files/files-docs.factor b/basis/io/files/unix/unix-docs.factor similarity index 97% rename from basis/io/unix/files/files-docs.factor rename to basis/io/files/unix/unix-docs.factor index 3798380e0f..eeac3cea0f 100644 --- a/basis/io/unix/files/files-docs.factor +++ b/basis/io/files/unix/unix-docs.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: classes help.markup help.syntax io.streams.string strings math calendar io.files ; -IN: io.unix.files +IN: io.files.unix HELP: file-group-id { $values @@ -90,12 +90,12 @@ HELP: set-file-permissions { "path" "a pathname string" } { "n" "an integer, interepreted as a string of bits" } } { $description "Sets the file permissions for a given file with the supplied Unix permissions integer. Supplying an octal number with " { $link POSTPONE: OCT: } " is recommended." } { $examples "Using the tradidional octal value:" - { $unchecked-example "USING: io.unix.files kernel ;" + { $unchecked-example "USING: io.files.unix kernel ;" "\"resource:license.txt\" OCT: 755 set-file-permissions" "" } "Higher-level, setting named bits:" - { $unchecked-example "USING: io.unix.files kernel math.bitwise ;" + { $unchecked-example "USING: io.files.unix kernel math.bitwise ;" "\"resource:license.txt\"" "{ USER-ALL GROUP-READ GROUP-EXECUTE OTHER-READ OTHER-EXECUTE }" "flags set-file-permissions" @@ -268,10 +268,10 @@ ARTICLE: "unix-file-ids" "Unix file user and group ids" { $subsection set-file-group } ; -ARTICLE: "io.unix.files" "Unix file attributes" -"The " { $vocab-link "io.unix.files" } " vocabulary implements the Unix backend for opening files and provides a high-level way to set permissions, timestamps, and user and group ids for files." +ARTICLE: "io.files.unix" "Unix file attributes" +"The " { $vocab-link "io.files.unix" } " vocabulary implements the Unix backend for opening files and provides a high-level way to set permissions, timestamps, and user and group ids for files." { $subsection "unix-file-permissions" } { $subsection "unix-file-timestamps" } { $subsection "unix-file-ids" } ; -ABOUT: "io.unix.files" +ABOUT: "io.files.unix" diff --git a/basis/io/unix/files/files-tests.factor b/basis/io/files/unix/unix-tests.factor similarity index 98% rename from basis/io/unix/files/files-tests.factor rename to basis/io/files/unix/unix-tests.factor index 78a80ad969..a112da2876 100644 --- a/basis/io/unix/files/files-tests.factor +++ b/basis/io/files/unix/unix-tests.factor @@ -1,7 +1,7 @@ -USING: tools.test io.files continuations kernel io.unix.files +USING: tools.test io.files continuations kernel io.files.unix math.bitwise calendar accessors math.functions math unix.users unix.groups arrays sequences ; -IN: io.unix.files.tests +IN: io.files.unix.tests [ "/usr/libexec/" ] [ "/usr/libexec/awk/" parent-directory ] unit-test [ "/etc/" ] [ "/etc/passwd" parent-directory ] unit-test diff --git a/basis/io/files/unix/unix.factor b/basis/io/files/unix/unix.factor new file mode 100644 index 0000000000..ac78cdff0c --- /dev/null +++ b/basis/io/files/unix/unix.factor @@ -0,0 +1,40 @@ +! Copyright (C) 2005, 2008 Slava Pestov, Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: unix byte-arrays kernel io.backend.unix math.bitwise +io.ports io.files io.files.private io.pathnames environment +destructors system ; +IN: io.files.unix + +M: unix cwd ( -- path ) + MAXPATHLEN [ ] keep getcwd + [ (io-error) ] unless* ; + +M: unix cd ( path -- ) [ chdir ] unix-system-call drop ; + +: read-flags O_RDONLY ; inline + +: open-read ( path -- fd ) O_RDONLY file-mode open-file ; + +M: unix (file-reader) ( path -- stream ) + open-read init-fd ; + +: write-flags { O_WRONLY O_CREAT O_TRUNC } flags ; inline + +: open-write ( path -- fd ) + write-flags file-mode open-file ; + +M: unix (file-writer) ( path -- stream ) + open-write init-fd ; + +: append-flags { O_WRONLY O_APPEND O_CREAT } flags ; inline + +: open-append ( path -- fd ) + [ + append-flags file-mode open-file |dispose + dup 0 SEEK_END lseek io-error + ] with-destructors ; + +M: unix (file-appender) ( path -- stream ) + open-append init-fd ; + +M: unix home "HOME" os-env ; diff --git a/basis/io/windows/files/files.factor b/basis/io/files/windows/files.factor similarity index 99% rename from basis/io/windows/files/files.factor rename to basis/io/files/windows/files.factor index 664727dbdb..76105c5fe6 100755 --- a/basis/io/windows/files/files.factor +++ b/basis/io/files/windows/files.factor @@ -1,12 +1,12 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: alien.c-types io.binary io.backend io.files io.buffers -io.encodings.utf16n io.ports io.windows kernel math splitting +io.encodings.utf16n io.ports io.backend.windows kernel math splitting fry alien.strings windows windows.kernel32 windows.time calendar combinators math.functions sequences namespaces make words symbols system destructors accessors math.bitwise continuations windows.errors arrays byte-arrays generalizations ; -IN: io.windows.files +IN: io.files.windows : open-file ( path access-mode create-mode flags -- handle ) [ diff --git a/basis/io/windows/nt/files/authors.txt b/basis/io/files/windows/nt/authors.txt similarity index 100% rename from basis/io/windows/nt/files/authors.txt rename to basis/io/files/windows/nt/authors.txt diff --git a/basis/io/windows/nt/files/files-tests.factor b/basis/io/files/windows/nt/files-tests.factor similarity index 96% rename from basis/io/windows/nt/files/files-tests.factor rename to basis/io/files/windows/nt/files-tests.factor index 6620dd691e..727f72c808 100644 --- a/basis/io/windows/nt/files/files-tests.factor +++ b/basis/io/files/windows/nt/files-tests.factor @@ -1,6 +1,6 @@ USING: io.files kernel tools.test io.backend -io.windows.nt.files splitting sequences ; -IN: io.windows.nt.files.tests +io.files.windows.nt splitting sequences ; +IN: io.files.windows.nt.tests [ f ] [ "\\foo" absolute-path? ] unit-test [ t ] [ "\\\\?\\c:\\foo" absolute-path? ] unit-test diff --git a/basis/io/windows/nt/files/files.factor b/basis/io/files/windows/nt/files.factor similarity index 92% rename from basis/io/windows/nt/files/files.factor rename to basis/io/files/windows/nt/files.factor index 892a5c4d31..b50b4cfa3d 100755 --- a/basis/io/windows/nt/files/files.factor +++ b/basis/io/files/windows/nt/files.factor @@ -1,11 +1,11 @@ USING: continuations destructors io.buffers io.files io.backend -io.timeouts io.ports io.files.private io.windows -io.windows.files io.windows.nt.backend io.encodings.utf16n +io.timeouts io.ports io.files.private io.backend.windows +io.files.windows io.backend.windows.nt io.encodings.utf16n windows windows.kernel32 kernel libc math threads system environment alien.c-types alien.arrays alien.strings sequences combinators combinators.short-circuit ascii splitting alien strings assocs namespaces make accessors tr ; -IN: io.windows.nt.files +IN: io.files.windows.nt M: winnt cwd MAX_UNICODE_PATH dup "ushort" diff --git a/basis/io/unix/openbsd/tags.txt b/basis/io/files/windows/nt/tags.txt similarity index 100% rename from basis/io/unix/openbsd/tags.txt rename to basis/io/files/windows/nt/tags.txt diff --git a/basis/io/unix/pipes/tags.txt b/basis/io/files/windows/tags.txt similarity index 100% rename from basis/io/unix/pipes/tags.txt rename to basis/io/files/windows/tags.txt diff --git a/basis/io/launcher/launcher.factor b/basis/io/launcher/launcher.factor index 7bafb95376..ad2f7e44a9 100644 --- a/basis/io/launcher/launcher.factor +++ b/basis/io/launcher/launcher.factor @@ -261,8 +261,8 @@ M: object run-pipeline-element drop ; { - { [ os unix? ] [ "io.unix.launcher" require ] } - { [ os winnt? ] [ "io.windows.nt.launcher" require ] } - { [ os wince? ] [ "io.windows.launcher" require ] } + { [ os unix? ] [ "io.launcher.unix" require ] } + { [ os winnt? ] [ "io.backend.windows.nt.launcher" require ] } + { [ os wince? ] [ "io.launcher.windows" require ] } [ ] } cond diff --git a/basis/io/unix/linux/authors.txt b/basis/io/launcher/unix/authors.txt similarity index 100% rename from basis/io/unix/linux/authors.txt rename to basis/io/launcher/unix/authors.txt diff --git a/basis/io/unix/launcher/parser/parser-tests.factor b/basis/io/launcher/unix/parser/parser-tests.factor similarity index 95% rename from basis/io/unix/launcher/parser/parser-tests.factor rename to basis/io/launcher/unix/parser/parser-tests.factor index 63aadcabbe..07502e87a4 100644 --- a/basis/io/unix/launcher/parser/parser-tests.factor +++ b/basis/io/launcher/unix/parser/parser-tests.factor @@ -1,5 +1,5 @@ -IN: io.unix.launcher.parser.tests -USING: io.unix.launcher.parser tools.test ; +IN: io.launcher.unix.parser.tests +USING: io.launcher.unix.parser tools.test ; [ "" tokenize-command ] must-fail [ " " tokenize-command ] must-fail diff --git a/basis/io/unix/launcher/parser/parser.factor b/basis/io/launcher/unix/parser/parser.factor similarity index 96% rename from basis/io/unix/launcher/parser/parser.factor rename to basis/io/launcher/unix/parser/parser.factor index 276ed45f27..97e6dee95f 100644 --- a/basis/io/unix/launcher/parser/parser.factor +++ b/basis/io/launcher/unix/parser/parser.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. USING: peg peg.parsers kernel sequences strings words ; -IN: io.unix.launcher.parser +IN: io.launcher.unix.parser ! Our command line parser. Supported syntax: ! foo bar baz -- simple tokens diff --git a/basis/io/unix/select/tags.txt b/basis/io/launcher/unix/parser/tags.txt similarity index 100% rename from basis/io/unix/select/tags.txt rename to basis/io/launcher/unix/parser/tags.txt diff --git a/basis/io/unix/sockets/secure/tags.txt b/basis/io/launcher/unix/tags.txt similarity index 100% rename from basis/io/unix/sockets/secure/tags.txt rename to basis/io/launcher/unix/tags.txt diff --git a/basis/io/unix/launcher/launcher-tests.factor b/basis/io/launcher/unix/unix-tests.factor similarity index 99% rename from basis/io/unix/launcher/launcher-tests.factor rename to basis/io/launcher/unix/unix-tests.factor index 68ca821ed4..f741507011 100644 --- a/basis/io/unix/launcher/launcher-tests.factor +++ b/basis/io/launcher/unix/unix-tests.factor @@ -1,4 +1,4 @@ -IN: io.unix.launcher.tests +IN: io.launcher.unix.tests USING: io.files tools.test io.launcher arrays io namespaces continuations math io.encodings.binary io.encodings.ascii accessors kernel sequences io.encodings.utf8 destructors diff --git a/basis/io/unix/launcher/launcher.factor b/basis/io/launcher/unix/unix.factor similarity index 97% rename from basis/io/unix/launcher/launcher.factor rename to basis/io/launcher/unix/unix.factor index 729c1545d8..eabb0130af 100644 --- a/basis/io/unix/launcher/launcher.factor +++ b/basis/io/launcher/unix/unix.factor @@ -4,10 +4,10 @@ USING: kernel namespaces math system sequences continuations arrays assocs combinators alien.c-types strings threads accessors environment io io.backend io.launcher io.ports io.files -io.files.private io.unix.files io.unix.backend -io.unix.launcher.parser +io.files.private io.files.unix io.backend.unix +io.launcher.unix.parser unix unix.process ; -IN: io.unix.launcher +IN: io.launcher.unix ! Search unix first USE: unix diff --git a/basis/io/windows/launcher/authors.txt b/basis/io/launcher/windows/authors.txt similarity index 100% rename from basis/io/windows/launcher/authors.txt rename to basis/io/launcher/windows/authors.txt diff --git a/basis/io/windows/nt/launcher/authors.txt b/basis/io/launcher/windows/nt/authors.txt similarity index 100% rename from basis/io/windows/nt/launcher/authors.txt rename to basis/io/launcher/windows/nt/authors.txt diff --git a/basis/io/windows/nt/launcher/launcher-tests.factor b/basis/io/launcher/windows/nt/nt-tests.factor similarity index 99% rename from basis/io/windows/nt/launcher/launcher-tests.factor rename to basis/io/launcher/windows/nt/nt-tests.factor index cbae2f5eca..2cdb7d5f89 100644 --- a/basis/io/windows/nt/launcher/launcher-tests.factor +++ b/basis/io/launcher/windows/nt/nt-tests.factor @@ -1,7 +1,7 @@ USING: io.launcher tools.test calendar accessors environment namespaces kernel system arrays io io.files io.encodings.ascii sequences parser assocs hashtables math continuations eval ; -IN: io.windows.launcher.nt.tests +IN: io.launcher.windows.nt.tests [ ] [ diff --git a/basis/io/windows/nt/launcher/launcher.factor b/basis/io/launcher/windows/nt/nt.factor similarity index 95% rename from basis/io/windows/nt/launcher/launcher.factor rename to basis/io/launcher/windows/nt/nt.factor index de4fb99c64..d098456486 100644 --- a/basis/io/windows/nt/launcher/launcher.factor +++ b/basis/io/launcher/windows/nt/nt.factor @@ -1,12 +1,12 @@ ! Copyright (C) 2007, 2008 Doug Coleman, Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types arrays continuations destructors io -io.windows libc io.ports io.pipes windows.types math +io.backend.windows libc io.ports io.pipes windows.types math windows.kernel32 windows namespaces make io.launcher kernel sequences windows.errors assocs splitting system strings -io.windows.launcher io.windows.files io.backend io.files +io.launcher.windows io.files.windows io.backend io.files io.files.private combinators shuffle accessors locals ; -IN: io.windows.nt.launcher +IN: io.backend.windows.nt.launcher : duplicate-handle ( handle -- handle' ) GetCurrentProcess ! source process diff --git a/basis/io/unix/sockets/tags.txt b/basis/io/launcher/windows/nt/tags.txt similarity index 100% rename from basis/io/unix/sockets/tags.txt rename to basis/io/launcher/windows/nt/tags.txt diff --git a/basis/io/windows/nt/launcher/test/append.factor b/basis/io/launcher/windows/nt/test/append.factor similarity index 100% rename from basis/io/windows/nt/launcher/test/append.factor rename to basis/io/launcher/windows/nt/test/append.factor diff --git a/basis/io/windows/nt/launcher/test/env.factor b/basis/io/launcher/windows/nt/test/env.factor similarity index 100% rename from basis/io/windows/nt/launcher/test/env.factor rename to basis/io/launcher/windows/nt/test/env.factor diff --git a/basis/io/windows/nt/launcher/test/stderr.factor b/basis/io/launcher/windows/nt/test/stderr.factor similarity index 100% rename from basis/io/windows/nt/launcher/test/stderr.factor rename to basis/io/launcher/windows/nt/test/stderr.factor diff --git a/basis/io/unix/tags.txt b/basis/io/launcher/windows/tags.txt similarity index 100% rename from basis/io/unix/tags.txt rename to basis/io/launcher/windows/tags.txt diff --git a/basis/io/windows/launcher/launcher-tests.factor b/basis/io/launcher/windows/windows-tests.factor similarity index 79% rename from basis/io/windows/launcher/launcher-tests.factor rename to basis/io/launcher/windows/windows-tests.factor index 1dba8bd0ec..1a3fe823a5 100644 --- a/basis/io/windows/launcher/launcher-tests.factor +++ b/basis/io/launcher/windows/windows-tests.factor @@ -1,5 +1,5 @@ -IN: io.windows.launcher.tests -USING: tools.test io.windows.launcher ; +IN: io.launcher.windows.tests +USING: tools.test io.launcher.windows ; [ "hello world" ] [ { "hello" "world" } join-arguments ] unit-test diff --git a/basis/io/windows/launcher/launcher.factor b/basis/io/launcher/windows/windows.factor similarity index 98% rename from basis/io/windows/launcher/launcher.factor rename to basis/io/launcher/windows/windows.factor index fd31ca999f..1e6d1f1a6d 100644 --- a/basis/io/windows/launcher/launcher.factor +++ b/basis/io/launcher/windows/windows.factor @@ -1,14 +1,14 @@ ! Copyright (C) 2007, 2008 Doug Coleman, Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types arrays continuations io -io.windows io.windows.nt.pipes libc io.ports +io.backend.windows io.pipes.windows.nt libc io.ports windows.types math windows.kernel32 namespaces make io.launcher kernel sequences windows.errors splitting system threads init strings combinators io.backend accessors concurrency.flags io.files assocs io.files.private windows destructors specialized-arrays.ushort specialized-arrays.alien ; -IN: io.windows.launcher +IN: io.launcher.windows TUPLE: CreateProcess-args lpApplicationName diff --git a/basis/io/mmap/mmap.factor b/basis/io/mmap/mmap.factor index 3cf451bd03..5c867d9a45 100644 --- a/basis/io/mmap/mmap.factor +++ b/basis/io/mmap/mmap.factor @@ -21,6 +21,6 @@ M: mapped-file dispose* ( mmap -- ) close-mapped-file ; [ ] dip with-disposal ; inline { - { [ os unix? ] [ "io.unix.mmap" require ] } - { [ os winnt? ] [ "io.windows.mmap" require ] } + { [ os unix? ] [ "io.mmap.unix" require ] } + { [ os winnt? ] [ "io.mmap.windows" require ] } } cond diff --git a/basis/io/unix/mmap/authors.txt b/basis/io/mmap/unix/authors.txt similarity index 100% rename from basis/io/unix/mmap/authors.txt rename to basis/io/mmap/unix/authors.txt diff --git a/basis/io/windows/files/tags.txt b/basis/io/mmap/unix/tags.txt similarity index 100% rename from basis/io/windows/files/tags.txt rename to basis/io/mmap/unix/tags.txt diff --git a/basis/io/unix/mmap/mmap.factor b/basis/io/mmap/unix/unix.factor similarity index 88% rename from basis/io/unix/mmap/mmap.factor rename to basis/io/mmap/unix/unix.factor index d5dcda9436..9325dcd632 100644 --- a/basis/io/unix/mmap/mmap.factor +++ b/basis/io/mmap/unix/unix.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2007 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: alien io io.files kernel math math.bitwise system unix -io.unix.backend io.ports io.mmap destructors locals accessors ; -IN: io.unix.mmap +io.backend.unix io.ports io.mmap destructors locals accessors ; +IN: io.mmap.unix : open-r/w ( path -- fd ) O_RDWR file-mode open-file ; diff --git a/basis/io/mmap/windows/authors.txt b/basis/io/mmap/windows/authors.txt new file mode 100755 index 0000000000..7c1b2f2279 --- /dev/null +++ b/basis/io/mmap/windows/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/basis/io/windows/files/unique/tags.txt b/basis/io/mmap/windows/tags.txt similarity index 100% rename from basis/io/windows/files/unique/tags.txt rename to basis/io/mmap/windows/tags.txt diff --git a/basis/io/windows/mmap/mmap.factor b/basis/io/mmap/windows/windows.factor similarity index 94% rename from basis/io/windows/mmap/mmap.factor rename to basis/io/mmap/windows/windows.factor index e5b0d10f2f..fcdf416511 100644 --- a/basis/io/windows/mmap/mmap.factor +++ b/basis/io/mmap/windows/windows.factor @@ -1,9 +1,9 @@ USING: alien alien.c-types arrays destructors generic io.mmap -io.ports io.windows io.windows.files io.windows.privileges +io.ports io.backend.windows io.files.windows io.backend.windows.privileges kernel libc math math.bitwise namespaces quotations sequences windows windows.advapi32 windows.kernel32 io.backend system accessors locals ; -IN: io.windows.mmap +IN: io.mmap.windows : create-file-mapping ( hFile lpAttributes flProtect dwMaximumSizeHigh dwMaximumSizeLow lpName -- HANDLE ) CreateFileMapping [ win32-error=0/f ] keep ; diff --git a/basis/io/unix/linux/monitors/monitors-tests.factor b/basis/io/monitors/linux/linux-tests.factor similarity index 97% rename from basis/io/unix/linux/monitors/monitors-tests.factor rename to basis/io/monitors/linux/linux-tests.factor index 42c5009ccb..8e2cebc3a4 100644 --- a/basis/io/unix/linux/monitors/monitors-tests.factor +++ b/basis/io/monitors/linux/linux-tests.factor @@ -1,4 +1,4 @@ -IN: io.unix.linux.monitors.tests +IN: io.monitors.linux.tests USING: io.monitors tools.test io.files system sequences continuations namespaces concurrency.count-downs kernel io threads calendar prettyprint destructors io.timeouts ; diff --git a/basis/io/unix/linux/monitors/monitors.factor b/basis/io/monitors/linux/linux.factor similarity index 97% rename from basis/io/unix/linux/monitors/monitors.factor rename to basis/io/monitors/linux/linux.factor index 3964a25a04..12efd8112d 100644 --- a/basis/io/unix/linux/monitors/monitors.factor +++ b/basis/io/monitors/linux/linux.factor @@ -2,11 +2,11 @@ ! See http://factorcode.org/license.txt for BSD license. USING: kernel io.backend io.monitors io.monitors.recursive io.files io.buffers io.monitors io.ports io.timeouts -io.unix.backend io.encodings.utf8 unix.linux.inotify assocs +io.backend.unix io.encodings.utf8 unix.linux.inotify assocs namespaces make threads continuations init math math.bitwise sets alien alien.strings alien.c-types vocabs.loader accessors system hashtables destructors unix ; -IN: io.unix.linux.monitors +IN: io.monitors.linux SYMBOL: watches diff --git a/basis/io/windows/launcher/tags.txt b/basis/io/monitors/linux/tags.txt similarity index 100% rename from basis/io/windows/launcher/tags.txt rename to basis/io/monitors/linux/tags.txt diff --git a/basis/io/unix/macosx/monitors/monitors.factor b/basis/io/monitors/macosx/macosx.factor similarity index 96% rename from basis/io/unix/macosx/monitors/monitors.factor rename to basis/io/monitors/macosx/macosx.factor index cde1d6339a..be1dcc64b6 100644 --- a/basis/io/unix/macosx/monitors/monitors.factor +++ b/basis/io/monitors/macosx/macosx.factor @@ -3,7 +3,7 @@ USING: io.backend io.monitors core-foundation.fsevents continuations kernel sequences namespaces arrays system locals accessors destructors fry ; -IN: io.unix.macosx.monitors +IN: io.monitors.macosx TUPLE: macosx-monitor < monitor handle ; diff --git a/basis/io/windows/mmap/tags.txt b/basis/io/monitors/macosx/tags.txt similarity index 100% rename from basis/io/windows/mmap/tags.txt rename to basis/io/monitors/macosx/tags.txt diff --git a/basis/io/monitors/monitors.factor b/basis/io/monitors/monitors.factor index 72f2bc80c5..e225e45430 100644 --- a/basis/io/monitors/monitors.factor +++ b/basis/io/monitors/monitors.factor @@ -56,8 +56,8 @@ SYMBOL: +rename-file+ [ ] dip with-disposal ; inline { - { [ os macosx? ] [ "io.unix.macosx.monitors" require ] } - { [ os linux? ] [ "io.unix.linux.monitors" require ] } - { [ os winnt? ] [ "io.windows.nt.monitors" require ] } + { [ os macosx? ] [ "io.monitors.macosx" require ] } + { [ os linux? ] [ "io.monitors.linux" require ] } + { [ os winnt? ] [ "io.monitors.windows.nt" require ] } [ ] } cond diff --git a/basis/io/monitors/windows/nt/authors.txt b/basis/io/monitors/windows/nt/authors.txt new file mode 100755 index 0000000000..7c1b2f2279 --- /dev/null +++ b/basis/io/monitors/windows/nt/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/basis/io/monitors/windows/nt/nt-tests.factor b/basis/io/monitors/windows/nt/nt-tests.factor new file mode 100644 index 0000000000..79cd7e9e9f --- /dev/null +++ b/basis/io/monitors/windows/nt/nt-tests.factor @@ -0,0 +1,4 @@ +IN: io.monitors.windows.nt.tests +USING: io.monitors.windows.nt tools.test ; + +\ fill-queue-thread must-infer diff --git a/basis/io/windows/nt/monitors/monitors.factor b/basis/io/monitors/windows/nt/nt.factor similarity index 95% rename from basis/io/windows/nt/monitors/monitors.factor rename to basis/io/monitors/windows/nt/nt.factor index a2b7c4fa2d..57bd07ef24 100755 --- a/basis/io/windows/nt/monitors/monitors.factor +++ b/basis/io/monitors/windows/nt/nt.factor @@ -3,11 +3,11 @@ USING: alien alien.c-types alien.strings libc destructors locals kernel math assocs namespaces make continuations sequences hashtables sorting arrays combinators math.bitwise strings -system accessors threads splitting io.backend io.windows -io.windows.nt.backend io.windows.nt.files io.monitors io.ports +system accessors threads splitting io.backend io.backend.windows +io.backend.windows.nt io.files.windows.nt io.monitors io.ports io.buffers io.files io.timeouts io.encodings.string io.encodings.utf16n io windows windows.kernel32 windows.types ; -IN: io.windows.nt.monitors +IN: io.monitors.windows.nt : open-directory ( path -- handle ) normalize-path diff --git a/basis/io/windows/nt/backend/tags.txt b/basis/io/monitors/windows/nt/tags.txt similarity index 100% rename from basis/io/windows/nt/backend/tags.txt rename to basis/io/monitors/windows/nt/tags.txt diff --git a/basis/io/pipes/pipes.factor b/basis/io/pipes/pipes.factor index 3a7fa5a2e0..9cadb3f6cc 100644 --- a/basis/io/pipes/pipes.factor +++ b/basis/io/pipes/pipes.factor @@ -53,7 +53,7 @@ PRIVATE> ] 2parallel-map ; { - { [ os unix? ] [ "io.unix.pipes" require ] } - { [ os winnt? ] [ "io.windows.nt.pipes" require ] } + { [ os unix? ] [ "io.pipes.unix" require ] } + { [ os winnt? ] [ "io.pipes.windows.nt" require ] } [ ] } cond diff --git a/basis/io/unix/pipes/pipes-tests.factor b/basis/io/pipes/unix/pipes-tests.factor similarity index 81% rename from basis/io/unix/pipes/pipes-tests.factor rename to basis/io/pipes/unix/pipes-tests.factor index 6ea74043ca..ce3f1551b1 100644 --- a/basis/io/unix/pipes/pipes-tests.factor +++ b/basis/io/pipes/unix/pipes-tests.factor @@ -1,6 +1,6 @@ -USING: tools.test io.pipes io.unix.pipes io.encodings.utf8 +USING: tools.test io.pipes io.pipes.unix io.encodings.utf8 io.encodings io namespaces sequences ; -IN: io.unix.pipes.tests +IN: io.pipes.unix.tests [ { 0 0 } ] [ { "ls" "grep ." } run-pipeline ] unit-test diff --git a/basis/io/unix/pipes/pipes.factor b/basis/io/pipes/unix/pipes.factor similarity index 80% rename from basis/io/unix/pipes/pipes.factor rename to basis/io/pipes/unix/pipes.factor index a28738e147..acf8b787ed 100644 --- a/basis/io/unix/pipes/pipes.factor +++ b/basis/io/pipes/unix/pipes.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: system kernel unix math sequences qualified -io.unix.backend io.ports specialized-arrays.int accessors ; -IN: io.unix.pipes +io.backend.unix io.ports specialized-arrays.int accessors ; +IN: io.pipes.unix QUALIFIED: io.pipes M: unix io.pipes:(pipe) ( -- pair ) diff --git a/basis/io/windows/nt/files/tags.txt b/basis/io/pipes/unix/tags.txt similarity index 100% rename from basis/io/windows/nt/files/tags.txt rename to basis/io/pipes/unix/tags.txt diff --git a/basis/io/unix/multiplexers/epoll/authors.txt b/basis/io/pipes/windows/nt/authors.txt similarity index 100% rename from basis/io/unix/multiplexers/epoll/authors.txt rename to basis/io/pipes/windows/nt/authors.txt diff --git a/basis/io/windows/nt/pipes/pipes.factor b/basis/io/pipes/windows/nt/pipes.factor similarity index 92% rename from basis/io/windows/nt/pipes/pipes.factor rename to basis/io/pipes/windows/nt/pipes.factor index d498875c87..cec03cf6d3 100644 --- a/basis/io/windows/nt/pipes/pipes.factor +++ b/basis/io/pipes/windows/nt/pipes.factor @@ -1,10 +1,10 @@ ! Copyright (C) 2007, 2008 Doug Coleman, Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: alien alien.c-types arrays destructors io io.windows libc +USING: alien alien.c-types arrays destructors io io.backend.windows libc windows.types math.bitwise windows.kernel32 windows namespaces make kernel sequences windows.errors assocs math.parser system random combinators accessors io.pipes io.ports ; -IN: io.windows.nt.pipes +IN: io.pipes.windows.nt ! This code is based on ! http://twistedmatrix.com/trac/browser/trunk/twisted/internet/iocpreactor/process.py diff --git a/basis/io/windows/nt/launcher/tags.txt b/basis/io/pipes/windows/nt/tags.txt similarity index 100% rename from basis/io/windows/nt/launcher/tags.txt rename to basis/io/pipes/windows/nt/tags.txt diff --git a/basis/io/sockets/secure/secure.factor b/basis/io/sockets/secure/secure.factor index e752e7c328..c0d70fc047 100644 --- a/basis/io/sockets/secure/secure.factor +++ b/basis/io/sockets/secure/secure.factor @@ -97,6 +97,6 @@ HOOK: send-secure-handshake secure-socket-backend ( -- ) HOOK: accept-secure-handshake secure-socket-backend ( -- ) { - { [ os unix? ] [ "io.unix.sockets.secure" require ] } + { [ os unix? ] [ "io.sockets.secure.unix" require ] } { [ os windows? ] [ "openssl" require ] } } cond diff --git a/basis/io/unix/sockets/secure/debug/debug.factor b/basis/io/sockets/secure/unix/debug/debug.factor similarity index 91% rename from basis/io/unix/sockets/secure/debug/debug.factor rename to basis/io/sockets/secure/unix/debug/debug.factor index cd5353ea7b..d32cdee2ed 100644 --- a/basis/io/unix/sockets/secure/debug/debug.factor +++ b/basis/io/sockets/secure/unix/debug/debug.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors io.sockets.secure kernel ; -IN: io.unix.sockets.secure.debug +IN: io.sockets.secure.unix.debug : with-test-context ( quot -- ) diff --git a/basis/io/windows/nt/monitors/tags.txt b/basis/io/sockets/secure/unix/tags.txt similarity index 100% rename from basis/io/windows/nt/monitors/tags.txt rename to basis/io/sockets/secure/unix/tags.txt diff --git a/basis/io/unix/sockets/secure/secure-tests.factor b/basis/io/sockets/secure/unix/unix-tests.factor similarity index 97% rename from basis/io/unix/sockets/secure/secure-tests.factor rename to basis/io/sockets/secure/unix/unix-tests.factor index 0816dd270b..a3bfacc8a8 100644 --- a/basis/io/unix/sockets/secure/secure-tests.factor +++ b/basis/io/sockets/secure/unix/unix-tests.factor @@ -1,9 +1,9 @@ IN: io.sockets.secure.tests USING: accessors kernel namespaces io io.sockets io.sockets.secure io.encodings.ascii io.streams.duplex -io.unix.backend classes words destructors threads tools.test +io.backend.unix classes words destructors threads tools.test concurrency.promises byte-arrays locals calendar io.timeouts -io.unix.sockets.secure.debug ; +io.sockets.secure.unix.debug ; \ must-infer { 1 0 } [ [ ] with-secure-context ] must-infer-as diff --git a/basis/io/unix/sockets/secure/secure.factor b/basis/io/sockets/secure/unix/unix.factor similarity index 98% rename from basis/io/unix/sockets/secure/secure.factor rename to basis/io/sockets/secure/unix/unix.factor index 106b6569ed..8419246eb6 100644 --- a/basis/io/unix/sockets/secure/secure.factor +++ b/basis/io/sockets/secure/unix/unix.factor @@ -4,10 +4,10 @@ USING: accessors unix byte-arrays kernel sequences namespaces math math.order combinators init alien alien.c-types alien.strings libc continuations destructors openssl openssl.libcrypto openssl.libssl io io.files io.ports -io.unix.backend io.unix.sockets io.encodings.ascii io.buffers +io.backend.unix io.sockets.unix io.encodings.ascii io.buffers io.sockets io.sockets.secure io.sockets.secure.openssl io.timeouts system summary fry ; -IN: io.unix.sockets.secure +IN: io.sockets.secure.unix M: ssl-handle handle-fd file>> handle-fd ; diff --git a/basis/io/sockets/sockets.factor b/basis/io/sockets/sockets.factor index 597aa61138..8268030ace 100644 --- a/basis/io/sockets/sockets.factor +++ b/basis/io/sockets/sockets.factor @@ -318,7 +318,6 @@ M: inet (server) invalid-inet-server ; { - { [ os unix? ] [ "io.unix.sockets" require ] } - { [ os winnt? ] [ "io.windows.nt.sockets" require ] } - { [ os wince? ] [ "io.windows.ce.sockets" require ] } + { [ os unix? ] [ "io.sockets.unix" require ] } + { [ os winnt? ] [ "io.sockets.windows.nt" require ] } } cond diff --git a/basis/io/unix/multiplexers/kqueue/authors.txt b/basis/io/sockets/unix/authors.txt old mode 100755 new mode 100644 similarity index 100% rename from basis/io/unix/multiplexers/kqueue/authors.txt rename to basis/io/sockets/unix/authors.txt diff --git a/basis/io/unix/sockets/summary.txt b/basis/io/sockets/unix/summary.txt similarity index 100% rename from basis/io/unix/sockets/summary.txt rename to basis/io/sockets/unix/summary.txt diff --git a/basis/io/windows/nt/pipes/tags.txt b/basis/io/sockets/unix/tags.txt similarity index 100% rename from basis/io/windows/nt/pipes/tags.txt rename to basis/io/sockets/unix/tags.txt diff --git a/basis/io/unix/sockets/sockets.factor b/basis/io/sockets/unix/unix.factor similarity index 96% rename from basis/io/unix/sockets/sockets.factor rename to basis/io/sockets/unix/unix.factor index 5fba7badb0..90d034a338 100644 --- a/basis/io/unix/sockets/sockets.factor +++ b/basis/io/sockets/unix/unix.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types alien.strings generic kernel math namespaces threads sequences byte-arrays io.ports -io.binary io.unix.backend io.streams.duplex +io.binary io.backend.unix io.streams.duplex io.backend io.ports io.files io.files.private io.encodings.utf8 math.parser continuations libc combinators system accessors qualified destructors unix locals init ; @@ -10,7 +10,7 @@ system accessors qualified destructors unix locals init ; EXCLUDE: io => read write close ; EXCLUDE: io.sockets => accept ; -IN: io.unix.sockets +IN: io.sockets.unix : socket-fd ( domain type -- fd ) 0 socket dup io-error init-fd |dispose ; @@ -96,7 +96,7 @@ SYMBOL: receive-buffer : packet-size 65536 ; inline -[ packet-size malloc receive-buffer set-global ] "io.unix.sockets" add-init-hook +[ packet-size malloc receive-buffer set-global ] "io.sockets.unix" add-init-hook :: do-receive ( port -- packet sockaddr ) port addr>> empty-sockaddr/size [| sockaddr len | diff --git a/basis/io/windows/nt/sockets/authors.txt b/basis/io/sockets/windows/nt/authors.txt similarity index 100% rename from basis/io/windows/nt/sockets/authors.txt rename to basis/io/sockets/windows/nt/authors.txt diff --git a/basis/io/windows/nt/sockets/sockets.factor b/basis/io/sockets/windows/nt/nt.factor similarity index 97% rename from basis/io/windows/nt/sockets/sockets.factor rename to basis/io/sockets/windows/nt/nt.factor index ecd9ea9d9b..f6a1bcfcb0 100644 --- a/basis/io/windows/nt/sockets/sockets.factor +++ b/basis/io/sockets/windows/nt/nt.factor @@ -1,9 +1,9 @@ USING: alien alien.accessors alien.c-types byte-arrays continuations destructors io.ports io.timeouts io.sockets -io.sockets io namespaces io.streams.duplex io.windows -io.windows.sockets io.windows.nt.backend windows.winsock kernel +io.sockets io namespaces io.streams.duplex io.backend.windows +io.sockets.windows io.backend.windows.nt windows.winsock kernel libc math sequences threads system combinators accessors ; -IN: io.windows.nt.sockets +IN: io.sockets.windows.nt : malloc-int ( object -- object ) "int" heap-size malloc tuck 0 set-alien-signed-4 ; inline diff --git a/basis/io/windows/nt/privileges/tags.txt b/basis/io/sockets/windows/nt/tags.txt similarity index 100% rename from basis/io/windows/nt/privileges/tags.txt rename to basis/io/sockets/windows/nt/tags.txt diff --git a/basis/io/windows/nt/sockets/tags.txt b/basis/io/sockets/windows/tags.txt similarity index 100% rename from basis/io/windows/nt/sockets/tags.txt rename to basis/io/sockets/windows/tags.txt diff --git a/basis/io/windows/sockets/sockets.factor b/basis/io/sockets/windows/windows.factor similarity index 92% rename from basis/io/windows/sockets/sockets.factor rename to basis/io/sockets/windows/windows.factor index 809af605e0..29009403fc 100644 --- a/basis/io/windows/sockets/sockets.factor +++ b/basis/io/sockets/windows/windows.factor @@ -1,6 +1,6 @@ -USING: kernel accessors io.sockets io.windows io.backend +USING: kernel accessors io.sockets io.backend.windows io.backend windows.winsock system destructors alien.c-types ; -IN: io.windows.sockets +IN: io.sockets.windows HOOK: WSASocket-flags io-backend ( -- DWORD ) diff --git a/basis/io/unix/epoll/epoll.factor b/basis/io/unix/epoll/epoll.factor deleted file mode 100644 index 93d0b4aa99..0000000000 --- a/basis/io/unix/epoll/epoll.factor +++ /dev/null @@ -1,63 +0,0 @@ -! Copyright (C) 2008 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: accessors alien.c-types kernel io.ports io.unix.backend -bit-arrays sequences assocs struct-arrays math namespaces locals -fry unix unix.linux.epoll unix.time ; -IN: io.unix.epoll - -TUPLE: epoll-mx < mx events ; - -: max-events ( -- n ) - #! We read up to 256 events at a time. This is an arbitrary - #! constant... - 256 ; inline - -: ( -- mx ) - epoll-mx new-mx - max-events epoll_create dup io-error >>fd - max-events "epoll-event" >>events ; - -: make-event ( fd events -- event ) - "epoll-event" - [ set-epoll-event-events ] keep - [ set-epoll-event-fd ] keep ; - -:: do-epoll-ctl ( fd mx what events -- ) - mx fd>> what fd fd events make-event epoll_ctl io-error ; - -: do-epoll-add ( fd mx events -- ) - EPOLL_CTL_ADD swap EPOLLONESHOT bitor do-epoll-ctl ; - -: do-epoll-del ( fd mx events -- ) - EPOLL_CTL_DEL swap do-epoll-ctl ; - -M: epoll-mx add-input-callback ( thread fd mx -- ) - [ EPOLLIN do-epoll-add ] [ call-next-method ] 2bi ; - -M: epoll-mx add-output-callback ( thread fd mx -- ) - [ EPOLLOUT do-epoll-add ] [ call-next-method ] 2bi ; - -M: epoll-mx remove-input-callbacks ( fd mx -- seq ) - 2dup reads>> key? [ - [ call-next-method ] [ EPOLLIN do-epoll-del ] 2bi - ] [ 2drop f ] if ; - -M: epoll-mx remove-output-callbacks ( fd mx -- seq ) - 2dup writes>> key? [ - [ EPOLLOUT do-epoll-del ] [ call-next-method ] 2bi - ] [ 2drop f ] if ; - -: wait-event ( mx us -- n ) - [ [ fd>> ] [ events>> ] bi [ underlying>> ] [ length ] bi ] [ 1000 /i ] bi* - epoll_wait multiplexer-error ; - -: handle-event ( event mx -- ) - [ epoll-event-fd ] dip - [ EPOLLIN EPOLLOUT bitor do-epoll-del ] - [ input-available ] [ output-available ] 2tri ; - -: handle-events ( mx n -- ) - [ dup events>> ] dip head-slice swap '[ _ handle-event ] each ; - -M: epoll-mx wait-for-events ( us mx -- ) - swap 60000000 or dupd wait-event handle-events ; diff --git a/basis/io/unix/freebsd/freebsd.factor b/basis/io/unix/freebsd/freebsd.factor deleted file mode 100644 index 49fbc9af7e..0000000000 --- a/basis/io/unix/freebsd/freebsd.factor +++ /dev/null @@ -1,3 +0,0 @@ -USING: io.unix.bsd io.backend system ; - -freebsd set-io-backend diff --git a/basis/io/unix/kqueue/kqueue.factor b/basis/io/unix/kqueue/kqueue.factor deleted file mode 100644 index be99d17572..0000000000 --- a/basis/io/unix/kqueue/kqueue.factor +++ /dev/null @@ -1,74 +0,0 @@ -! Copyright (C) 2008 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: accessors alien.c-types combinators io.unix.backend -kernel math.bitwise sequences struct-arrays unix unix.kqueue -unix.time assocs ; -IN: io.unix.kqueue - -TUPLE: kqueue-mx < mx events ; - -: max-events ( -- n ) - #! We read up to 256 events at a time. This is an arbitrary - #! constant... - 256 ; inline - -: ( -- mx ) - kqueue-mx new-mx - kqueue dup io-error >>fd - max-events "kevent" >>events ; - -: make-kevent ( fd filter flags -- event ) - "kevent" - [ set-kevent-flags ] keep - [ set-kevent-filter ] keep - [ set-kevent-ident ] keep ; - -: register-kevent ( kevent mx -- ) - fd>> swap 1 f 0 f kevent io-error ; - -M: kqueue-mx add-input-callback ( thread fd mx -- ) - [ call-next-method ] [ - [ EVFILT_READ { EV_ADD EV_ONESHOT } flags make-kevent ] dip - register-kevent - ] 2bi ; - -M: kqueue-mx add-output-callback ( thread fd mx -- ) - [ call-next-method ] [ - [ EVFILT_WRITE { EV_ADD EV_ONESHOT } flags make-kevent ] dip - register-kevent - ] 2bi ; - -M: kqueue-mx remove-input-callbacks ( fd mx -- seq ) - 2dup reads>> key? [ - [ call-next-method ] [ - [ EVFILT_READ EV_DELETE make-kevent ] dip - register-kevent - ] 2bi - ] [ 2drop f ] if ; - -M: kqueue-mx remove-output-callbacks ( fd mx -- seq ) - 2dup writes>> key? [ - [ - [ EVFILT_WRITE EV_DELETE make-kevent ] dip - register-kevent - ] [ call-next-method ] 2bi - ] [ 2drop f ] if ; - -: wait-kevent ( mx timespec -- n ) - [ - [ fd>> f 0 ] - [ events>> [ underlying>> ] [ length ] bi ] bi - ] dip kevent multiplexer-error ; - -: handle-kevent ( mx kevent -- ) - [ kevent-ident swap ] [ kevent-filter ] bi { - { EVFILT_READ [ input-available ] } - { EVFILT_WRITE [ output-available ] } - } case ; - -: handle-kevents ( mx n -- ) - [ dup events>> ] dip head-slice [ handle-kevent ] with each ; - -M: kqueue-mx wait-for-events ( us mx -- ) - swap dup [ make-timespec ] when - dupd wait-kevent handle-kevents ; diff --git a/basis/io/unix/multiplexers/select/authors.txt b/basis/io/unix/multiplexers/select/authors.txt deleted file mode 100755 index 1901f27a24..0000000000 --- a/basis/io/unix/multiplexers/select/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Slava Pestov diff --git a/basis/io/unix/netbsd/netbsd.factor b/basis/io/unix/netbsd/netbsd.factor deleted file mode 100644 index ed134788b6..0000000000 --- a/basis/io/unix/netbsd/netbsd.factor +++ /dev/null @@ -1,3 +0,0 @@ -USING: io.unix.bsd io.backend system ; - -netbsd set-io-backend diff --git a/basis/io/unix/openbsd/openbsd.factor b/basis/io/unix/openbsd/openbsd.factor deleted file mode 100644 index dfc466f94b..0000000000 --- a/basis/io/unix/openbsd/openbsd.factor +++ /dev/null @@ -1,3 +0,0 @@ -USING: io.unix.bsd io.backend system ; - -openbsd set-io-backend diff --git a/basis/io/unix/select/authors.txt b/basis/io/unix/select/authors.txt deleted file mode 100755 index 1901f27a24..0000000000 --- a/basis/io/unix/select/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Slava Pestov diff --git a/basis/io/unix/select/select.factor b/basis/io/unix/select/select.factor deleted file mode 100644 index a6b61001a6..0000000000 --- a/basis/io/unix/select/select.factor +++ /dev/null @@ -1,56 +0,0 @@ -! Copyright (C) 2004, 2008 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: alien.c-types kernel io.ports io.unix.backend -bit-arrays sequences assocs unix math namespaces -accessors math.order locals unix.time fry ; -IN: io.unix.select - -TUPLE: select-mx < mx read-fdset write-fdset ; - -! Factor's bit-arrays are an array of bytes, OS X expects -! FD_SET to be an array of cells, so we have to account for -! byte order differences on big endian platforms -: munge ( i -- i' ) - little-endian? [ BIN: 11000 bitxor ] unless ; inline - -: ( -- mx ) - select-mx new-mx - FD_SETSIZE 8 * >>read-fdset - FD_SETSIZE 8 * >>write-fdset ; - -: clear-nth ( n seq -- ? ) - [ nth ] [ [ f ] 2dip set-nth ] 2bi ; - -:: check-fd ( fd fdset mx quot -- ) - fd munge fdset clear-nth [ fd mx quot call ] when ; inline - -: check-fdset ( fds fdset mx quot -- ) - [ check-fd ] 3curry each ; inline - -: init-fdset ( fds fdset -- ) - '[ t swap munge _ set-nth ] each ; - -: read-fdset/tasks ( mx -- seq fdset ) - [ reads>> keys ] [ read-fdset>> ] bi ; - -: write-fdset/tasks ( mx -- seq fdset ) - [ writes>> keys ] [ write-fdset>> ] bi ; - -: max-fd ( assoc -- n ) - dup assoc-empty? [ drop 0 ] [ keys supremum ] if ; - -: num-fds ( mx -- n ) - [ reads>> max-fd ] [ writes>> max-fd ] bi max 1+ ; - -: init-fdsets ( mx -- nfds read write except ) - [ num-fds ] - [ read-fdset/tasks [ init-fdset ] [ underlying>> ] bi ] - [ write-fdset/tasks [ init-fdset ] [ underlying>> ] bi ] tri - f ; - -M:: select-mx wait-for-events ( us mx -- ) - mx - [ init-fdsets us dup [ make-timeval ] when select multiplexer-error drop ] - [ [ read-fdset/tasks ] keep [ input-available ] check-fdset ] - [ [ write-fdset/tasks ] keep [ output-available ] check-fdset ] - tri ; diff --git a/basis/io/unix/sockets/authors.txt b/basis/io/unix/sockets/authors.txt deleted file mode 100644 index 1901f27a24..0000000000 --- a/basis/io/unix/sockets/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Slava Pestov diff --git a/basis/io/unix/summary.txt b/basis/io/unix/summary.txt deleted file mode 100644 index 8f66d889cc..0000000000 --- a/basis/io/unix/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Non-blocking I/O and sockets on Unix-like systems diff --git a/basis/io/unix/unix.factor b/basis/io/unix/unix.factor deleted file mode 100644 index 93b5fa620e..0000000000 --- a/basis/io/unix/unix.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: accessors system words sequences vocabs.loader -io.unix.backend io.unix.files ; - -"io.unix." os name>> append require diff --git a/basis/io/windows/nt/authors.txt b/basis/io/windows/nt/authors.txt deleted file mode 100644 index 781acc2b62..0000000000 --- a/basis/io/windows/nt/authors.txt +++ /dev/null @@ -1,2 +0,0 @@ -Doug Coleman -Mackenzie Straight diff --git a/basis/io/windows/nt/monitors/monitors-tests.factor b/basis/io/windows/nt/monitors/monitors-tests.factor deleted file mode 100644 index ef36baedc5..0000000000 --- a/basis/io/windows/nt/monitors/monitors-tests.factor +++ /dev/null @@ -1,4 +0,0 @@ -IN: io.windows.nt.monitors.tests -USING: io.windows.nt.monitors tools.test ; - -\ fill-queue-thread must-infer diff --git a/basis/io/windows/nt/nt.factor b/basis/io/windows/nt/nt.factor deleted file mode 100644 index efde4f4035..0000000000 --- a/basis/io/windows/nt/nt.factor +++ /dev/null @@ -1,7 +0,0 @@ -! Copyright (C) 2004, 2008 Mackenzie Straight, Doug Coleman, -! Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: vocabs.loader io.windows io.windows.nt.backend -io.windows.nt.files io.windows.files io.backend system ; - -winnt set-io-backend diff --git a/basis/io/windows/nt/pipes/authors.txt b/basis/io/windows/nt/pipes/authors.txt deleted file mode 100755 index 1901f27a24..0000000000 --- a/basis/io/windows/nt/pipes/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Slava Pestov diff --git a/basis/io/windows/nt/summary.txt b/basis/io/windows/nt/summary.txt deleted file mode 100644 index 0e1b3e244f..0000000000 --- a/basis/io/windows/nt/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Microsoft Windows XP/Vista native I/O implementation diff --git a/basis/io/windows/nt/tags.txt b/basis/io/windows/nt/tags.txt deleted file mode 100644 index 6bf68304bb..0000000000 --- a/basis/io/windows/nt/tags.txt +++ /dev/null @@ -1 +0,0 @@ -unportable diff --git a/basis/io/windows/privileges/tags.txt b/basis/io/windows/privileges/tags.txt deleted file mode 100644 index 6bf68304bb..0000000000 --- a/basis/io/windows/privileges/tags.txt +++ /dev/null @@ -1 +0,0 @@ -unportable diff --git a/basis/io/windows/sockets/tags.txt b/basis/io/windows/sockets/tags.txt deleted file mode 100644 index 6bf68304bb..0000000000 --- a/basis/io/windows/sockets/tags.txt +++ /dev/null @@ -1 +0,0 @@ -unportable diff --git a/basis/io/windows/tags.txt b/basis/io/windows/tags.txt deleted file mode 100755 index 6bf68304bb..0000000000 --- a/basis/io/windows/tags.txt +++ /dev/null @@ -1 +0,0 @@ -unportable diff --git a/basis/prettyprint/backend/backend.factor b/basis/prettyprint/backend/backend.factor index 92d039a15d..bcd91a4d94 100644 --- a/basis/prettyprint/backend/backend.factor +++ b/basis/prettyprint/backend/backend.factor @@ -1,9 +1,9 @@ ! Copyright (C) 2003, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays byte-arrays generic hashtables io assocs -kernel math namespaces make sequences strings sbufs io.styles -vectors words prettyprint.config prettyprint.custom -prettyprint.sections quotations io io.files math.parser effects +kernel math namespaces make sequences strings sbufs vectors +words prettyprint.config prettyprint.custom prettyprint.sections +quotations io io.pathnames io.styles math.parser effects classes.tuple math.order classes.tuple.private classes combinators colors ; IN: prettyprint.backend diff --git a/basis/prettyprint/prettyprint.factor b/basis/prettyprint/prettyprint.factor index 9d5af9e6a5..6b49c4a35a 100644 --- a/basis/prettyprint/prettyprint.factor +++ b/basis/prettyprint/prettyprint.factor @@ -5,7 +5,7 @@ namespaces make sequences strings io.styles io.streams.string vectors words prettyprint.backend prettyprint.custom prettyprint.sections prettyprint.config sorting splitting grouping math.parser vocabs definitions effects classes.builtin -classes.tuple io.files classes continuations hashtables +classes.tuple io.pathnames classes continuations hashtables classes.mixin classes.union classes.intersection classes.predicate classes.singleton combinators quotations sets accessors colors parser summary ; diff --git a/basis/smtp/server/server.factor b/basis/smtp/server/server.factor index 7de22e9af9..f986404404 100644 --- a/basis/smtp/server/server.factor +++ b/basis/smtp/server/server.factor @@ -4,7 +4,7 @@ USING: combinators kernel prettyprint io io.timeouts sequences namespaces io.sockets io.sockets.secure continuations calendar io.encodings.ascii io.streams.duplex destructors locals concurrency.promises threads accessors smtp.private -io.unix.sockets.secure.debug ; +io.sockets.secure.unix.debug ; IN: smtp.server ! Mock SMTP server for testing purposes. diff --git a/basis/tools/deploy/macosx/macosx.factor b/basis/tools/deploy/macosx/macosx.factor index 1f0e482441..94cab2bb9d 100644 --- a/basis/tools/deploy/macosx/macosx.factor +++ b/basis/tools/deploy/macosx/macosx.factor @@ -3,7 +3,7 @@ USING: io io.files kernel namespaces make sequences system tools.deploy.backend tools.deploy.config tools.deploy.config.editor assocs hashtables prettyprint -io.unix.backend cocoa io.encodings.utf8 io.backend +io.backend.unix cocoa io.encodings.utf8 io.backend cocoa.application cocoa.classes cocoa.plists qualified combinators ; IN: tools.deploy.macosx diff --git a/basis/tools/files/unix/unix.factor b/basis/tools/files/unix/unix.factor index 184f371b1c..3449968f70 100755 --- a/basis/tools/files/unix/unix.factor +++ b/basis/tools/files/unix/unix.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors combinators kernel system unicode.case -io.unix.files tools.files generalizations strings +io.files.unix tools.files generalizations strings arrays sequences io.files math.parser unix.groups unix.users tools.files.private unix.stat math ; IN: tools.files.unix diff --git a/basis/unix/groups/groups.factor b/basis/unix/groups/groups.factor index 177949aec9..f6aa7fa3e9 100644 --- a/basis/unix/groups/groups.factor +++ b/basis/unix/groups/groups.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types alien.strings io.encodings.utf8 -io.unix.backend kernel math sequences splitting unix strings +io.backend.unix kernel math sequences splitting unix strings combinators.short-circuit byte-arrays combinators qualified accessors math.parser fry assocs namespaces continuations unix.users unix.utilities ; diff --git a/basis/unix/process/process.factor b/basis/unix/process/process.factor index 7d5f9eb330..04ba4d3438 100644 --- a/basis/unix/process/process.factor +++ b/basis/unix/process/process.factor @@ -1,6 +1,6 @@ USING: kernel alien.c-types alien.strings sequences math alien.syntax unix vectors kernel namespaces continuations threads assocs vectors -io.unix.backend io.encodings.utf8 unix.utilities ; +io.backend.unix io.encodings.utf8 unix.utilities ; IN: unix.process ! Low-level Unix process launching utilities. These are used diff --git a/basis/unix/stat/stat.factor b/basis/unix/stat/stat.factor index a3b0ed11b7..a3f8a5ce82 100644 --- a/basis/unix/stat/stat.factor +++ b/basis/unix/stat/stat.factor @@ -1,5 +1,5 @@ USING: kernel system combinators alien.syntax alien.c-types -math io.unix.backend vocabs.loader unix ; +math io.backend.unix vocabs.loader unix ; IN: unix.stat ! File Types diff --git a/basis/unix/unix.factor b/basis/unix/unix.factor index 555f8e2c7d..2652a95d3e 100644 --- a/basis/unix/unix.factor +++ b/basis/unix/unix.factor @@ -4,7 +4,7 @@ USING: alien alien.c-types alien.syntax kernel libc sequences continuations byte-arrays strings math namespaces system combinators vocabs.loader qualified accessors stack-checker macros locals generalizations unix.types -io io.files vocabs vocabs.loader ; +io vocabs vocabs.loader ; IN: unix : PROT_NONE 0 ; inline @@ -30,19 +30,6 @@ IN: unix : DT_SOCK 12 ; inline : DT_WHT 14 ; inline -: dirent-type>file-type ( ch -- type ) - { - { DT_BLK [ +block-device+ ] } - { DT_CHR [ +character-device+ ] } - { DT_DIR [ +directory+ ] } - { DT_LNK [ +symbolic-link+ ] } - { DT_SOCK [ +socket+ ] } - { DT_FIFO [ +fifo+ ] } - { DT_REG [ +regular-file+ ] } - { DT_WHT [ +whiteout+ ] } - [ drop +unknown+ ] - } case ; - C-STRUCT: group { "char*" "gr_name" } { "char*" "gr_passwd" } diff --git a/basis/unix/users/users.factor b/basis/unix/users/users.factor index 8487d5adf2..78417c66bf 100644 --- a/basis/unix/users/users.factor +++ b/basis/unix/users/users.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types alien.strings io.encodings.utf8 -io.unix.backend kernel math sequences splitting unix strings +io.backend.unix kernel math sequences splitting unix strings combinators.short-circuit grouping byte-arrays combinators accessors math.parser fry assocs namespaces continuations vocabs.loader system ; diff --git a/core/checksums/checksums.factor b/core/checksums/checksums.factor index 699d93b8b4..a3662fcaa6 100644 --- a/core/checksums/checksums.factor +++ b/core/checksums/checksums.factor @@ -1,6 +1,6 @@ ! Copyright (c) 2008 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. -USING: sequences math.parser io io.encodings.binary io.files +USING: sequences math.parser io io.backend io.files kernel ; IN: checksums @@ -19,7 +19,10 @@ M: checksum checksum-lines [ B{ CHAR: \n } join ] dip checksum-bytes ; : checksum-file ( path checksum -- value ) - [ binary ] dip checksum-stream ; + #! normalize-path (file-reader) is equivalen to + #! binary . We use the lower-level form + #! so that we can move io.encodings.binary to basis/. + [ normalize-path (file-reader) ] dip checksum-stream ; : hex-string ( seq -- str ) [ >hex 2 CHAR: 0 pad-left ] { } map-as concat ; diff --git a/core/io/files/files-docs.factor b/core/io/files/files-docs.factor index 80b515b13f..7948a2e912 100644 --- a/core/io/files/files-docs.factor +++ b/core/io/files/files-docs.factor @@ -2,7 +2,7 @@ USING: help.markup help.syntax io strings arrays io.backend io.files.private quotations ; IN: io.files -ARTICLE: "file-streams" "Reading and writing files" +ARTICLE: "io.files" "Reading and writing files" "File streams:" { $subsection } { $subsection } @@ -17,182 +17,10 @@ ARTICLE: "file-streams" "Reading and writing files" { $subsection with-file-writer } { $subsection with-file-appender } ; -ARTICLE: "pathnames" "Pathname manipulation" -"Pathname manipulation:" -{ $subsection parent-directory } -{ $subsection file-name } -{ $subsection last-path-separator } -{ $subsection append-path } -"Pathnames relative to Factor's temporary files directory:" -{ $subsection temp-directory } -{ $subsection temp-file } -"Pathname presentations:" -{ $subsection pathname } -{ $subsection } ; - -ARTICLE: "symbolic-links" "Symbolic links" -"Reading and creating links:" -{ $subsection read-link } -{ $subsection make-link } -"Copying links:" -{ $subsection copy-link } -"Not all operating systems support symbolic links." -{ $see-also link-info } ; - -ARTICLE: "current-directory" "Current working directory" -"File system I/O operations use the value of a variable to resolve relative pathnames:" -{ $subsection current-directory } -"This variable can be changed with a pair of words:" -{ $subsection set-current-directory } -{ $subsection with-directory } -"This variable is independent of the operating system notion of ``current working directory''. While all Factor I/O operations use the variable and not the operating system's value, care must be taken when making FFI calls which expect a pathname. The first option is to resolve relative paths:" -{ $subsection (normalize-path) } -"The second is to change the working directory of the current process:" -{ $subsection cd } -{ $subsection cwd } ; - -ARTICLE: "directories" "Directories" -"Home directory:" -{ $subsection home } -"Directory listing:" -{ $subsection directory-entries } -{ $subsection directory-files } -{ $subsection with-directory-files } -"Creating directories:" -{ $subsection make-directory } -{ $subsection make-directories } -{ $subsection "current-directory" } ; - -ARTICLE: "file-types" "File Types" -"Platform-independent types:" -{ $subsection +regular-file+ } -{ $subsection +directory+ } -"Platform-specific types:" -{ $subsection +character-device+ } -{ $subsection +block-device+ } -{ $subsection +fifo+ } -{ $subsection +symbolic-link+ } -{ $subsection +socket+ } -{ $subsection +unknown+ } ; - -ARTICLE: "fs-meta" "File metadata" -"Querying file-system metadata:" -{ $subsection file-info } -{ $subsection link-info } -{ $subsection exists? } -{ $subsection directory? } - -"File types:" -{ $subsection "file-types" } ; - -ARTICLE: "delete-move-copy" "Deleting, moving, copying files" -"Operations for deleting and copying files come in two forms:" -{ $list - { "Words named " { $snippet { $emphasis "operation" } "-file" } " which work on regular files only." } - { "Words named " { $snippet { $emphasis "operation" } "-tree" } " works on directory trees recursively, and also accepts regular files." } -} -"The operations for moving and copying files come in three flavors:" -{ $list - { "A word named " { $snippet { $emphasis "operation" } } " which takes a source and destination path." } - { "A word named " { $snippet { $emphasis "operation" } "-into" } " which takes a source path and destination directory. The destination file will be stored in the destination directory and will have the same file name as the source path." } - { "A word named " { $snippet { $emphasis "operation" } "s-into" } " which takes a sequence of source paths and destination directory." } -} -"Since both of the above lists apply to copying files, that this means that there are a total of six variations on copying a file." -$nl -"Deleting files:" -{ $subsection delete-file } -{ $subsection delete-directory } -{ $subsection delete-tree } -"Moving files:" -{ $subsection move-file } -{ $subsection move-file-into } -{ $subsection move-files-into } -"Copying files:" -{ $subsection copy-file } -{ $subsection copy-file-into } -{ $subsection copy-files-into } -"Copying directory trees recursively:" -{ $subsection copy-tree } -{ $subsection copy-tree-into } -{ $subsection copy-trees-into } -"On most operating systems, files can only be moved within the same file system. To move files between file systems, use " { $link copy-file } " followed by " { $link delete-file } " on the old name." ; - -ARTICLE: "io.files" "Basic file operations" -"The " { $vocab-link "io.files" } " vocabulary provides basic support for working with files." -{ $subsection "pathnames" } -{ $subsection "file-streams" } -{ $subsection "fs-meta" } -{ $subsection "directories" } -{ $subsection "delete-move-copy" } -{ $subsection "symbolic-links" } ; - ABOUT: "io.files" -HELP: path-separator? -{ $values { "ch" "a code point" } { "?" "a boolean" } } -{ $description "Tests if the code point is a platform-specific path separator." } -{ $examples - "On Unix:" - { $example "USING: io.files prettyprint ;" "CHAR: / path-separator? ." "t" } -} ; - -HELP: parent-directory -{ $values { "path" "a pathname string" } { "parent" "a pathname string" } } -{ $description "Strips the last component off a pathname." } -{ $examples { $example "USING: io io.files ;" "\"/etc/passwd\" parent-directory print" "/etc/" } } ; - -HELP: file-name -{ $values { "path" "a pathname string" } { "string" string } } -{ $description "Outputs the last component of a pathname string." } -{ $examples - { $example "USING: io.files prettyprint ;" "\"/usr/bin/gcc\" file-name ." "\"gcc\"" } - { $example "USING: io.files prettyprint ;" "\"/usr/libexec/awk/\" file-name ." "\"awk\"" } -} ; - -! need a $class-description file-info - -HELP: file-info -{ $values { "path" "a pathname string" } { "info" file-info } } -{ $description "Queries the file system for metadata. If " { $snippet "path" } " refers to a symbolic link, it is followed. See the article " { $link "file-types" } " for a list of metadata symbols." } -{ $errors "Throws an error if the file does not exist." } ; - -HELP: link-info -{ $values { "path" "a pathname string" } { "info" "a file-info tuple" } } -{ $description "Queries the file system for metadata. If path refers to a symbolic link, information about the symbolic link itself is returned. If the file does not exist, an exception is thrown." } ; - -{ file-info link-info } related-words - -HELP: +regular-file+ -{ $description "A regular file. This type exists on all platforms. See " { $link "file-streams" } " for words operating on files." } ; - -HELP: +directory+ -{ $description "A directory. This type exists on all platforms. See " { $link "directories" } " for words operating on directories." } ; - -HELP: +symbolic-link+ -{ $description "A symbolic link file. This type is currently implemented on Unix platforms only. See " { $link "symbolic-links" } " for words operating on symbolic links." } ; - -HELP: +character-device+ -{ $description "A Unix character device file. This type exists on Unix platforms only." } ; - -HELP: +block-device+ -{ $description "A Unix block device file. This type exists on Unix platforms only." } ; - -HELP: +fifo+ -{ $description "A Unix fifo file. This type exists on Unix platforms only." } ; - -HELP: +socket+ -{ $description "A Unix socket file. This type exists on Unix platforms only." } ; - -HELP: +unknown+ -{ $description "A unknown file type." } ; - HELP: -{ - $values - { "path" "a pathname string" } - { "encoding" "an encoding descriptor" } - { "stream" "an input stream" } -} +{ $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "stream" "an input stream" } } { $description "Outputs an input stream for reading from the specified pathname using the given encoding." } { $errors "Throws an error if the file is unreadable." } ; @@ -243,205 +71,6 @@ HELP: file-contents { set-file-lines file-lines set-file-contents file-contents } related-words -HELP: cwd -{ $values { "path" "a pathname string" } } -{ $description "Outputs the current working directory of the Factor process." } -{ $errors "Windows CE has no concept of ``current directory'', so this word throws an error there." } -{ $notes "User code should use " { $link with-directory } " or " { $link set-current-directory } " instead." } ; - -HELP: cd -{ $values { "path" "a pathname string" } } -{ $description "Changes the current working directory of the Factor process." } -{ $errors "Windows CE has no concept of ``current directory'', so this word throws an error there." } -{ $notes "User code should use " { $link with-directory } " or " { $link set-current-directory } " instead." } ; - -{ cd cwd current-directory set-current-directory with-directory } related-words - -HELP: current-directory -{ $description "A variable holding the current directory as an absolute path. Words that use the filesystem do so in relation to this variable." -$nl -"This variable should never be set directly; instead, use " { $link set-current-directory } " or " { $link with-directory } ". This preserves the invariant that the value of this variable is an absolute path." } ; - -HELP: set-current-directory -{ $values { "path" "a pathname string" } } -{ $description "Changes the " { $link current-directory } " variable." -$nl -"If " { $snippet "path" } " is relative, it is first resolved relative to the current directory. If " { $snippet "path" } " is absolute, it becomes the new current directory." } ; - -HELP: with-directory -{ $values { "path" "a pathname string" } { "quot" quotation } } -{ $description "Calls the quotation in a new dynamic scope with the " { $link current-directory } " variable rebound." -$nl -"If " { $snippet "path" } " is relative, it is first resolved relative to the current directory. If " { $snippet "path" } " is absolute, it becomes the new current directory." } ; - -HELP: append-path -{ $values { "str1" "a string" } { "str2" "a string" } { "str" "a string" } } -{ $description "Appends " { $snippet "str1" } " and " { $snippet "str2" } " to form a pathname." } ; - -HELP: prepend-path -{ $values { "str1" "a string" } { "str2" "a string" } { "str" "a string" } } -{ $description "Appends " { $snippet "str2" } " and " { $snippet "str1" } " to form a pathname." } ; - -{ append-path prepend-path } related-words - -HELP: absolute-path? -{ $values { "path" "a pathname string" } { "?" "a boolean" } } -{ $description "Tests if a pathname is absolute. Examples of absolute pathnames are " { $snippet "/foo/bar" } " on Unix and " { $snippet "c:\\foo\\bar" } " on Windows." } ; - -HELP: windows-absolute-path? -{ $values { "path" "a pathname string" } { "?" "a boolean" } } -{ $description "Tests if a pathname is absolute on Windows. Examples of absolute pathnames on Windows are " { $snippet "c:\\foo\\bar" } " and " { $snippet "\\\\?\\c:\\foo\\bar" } " for absolute Unicode pathnames." } ; - -HELP: root-directory? -{ $values { "path" "a pathname string" } { "?" "a boolean" } } -{ $description "Tests if a pathname is a root directory. Examples of root directory pathnames are " { $snippet "/" } " on Unix and " { $snippet "c:\\" } " on Windows." } ; - -{ absolute-path? windows-absolute-path? root-directory? } related-words - HELP: exists? { $values { "path" "a pathname string" } { "?" "a boolean" } } { $description "Tests if the file named by " { $snippet "path" } " exists." } ; - -HELP: directory? -{ $values { "file-info" file-info } { "?" "a boolean" } } -{ $description "Tests if " { $snippet "file-info" } " is a directory." } ; - -HELP: (directory-entries) -{ $values { "path" "a pathname string" } { "seq" "a sequence of " { $snippet "{ name dir? }" } " pairs" } } -{ $description "Outputs the contents of a directory named by " { $snippet "path" } "." } -{ $notes "This is a low-level word, and user code should call one of the related words instead." } ; - -HELP: directory-entries -{ $values { "path" "a pathname string" } { "seq" "a sequence of " { $link directory-entry } " objects" } } -{ $description "Outputs the contents of a directory named by " { $snippet "path" } "." } ; - -HELP: directory-files -{ $values { "path" "a pathname string" } { "seq" "a sequence of filenames" } } -{ $description "Outputs the contents of a directory named by " { $snippet "path" } "." } ; - -HELP: with-directory-files -{ $values { "path" "a pathname string" } { "quot" quotation } } -{ $description "Calls the quotation with the directory file names on the stack and with the directory set as the " { $link current-directory } ". Restores the current directory after the quotation is called." } ; - -HELP: file-systems -{ $values { "array" array } } -{ $description "Returns an array of " { $link file-system-info } " objects returned by iterating the mount points and calling " { $link file-system-info } " on each." } ; - -HELP: file-system-info -{ $values -{ "path" "a pathname string" } -{ "file-system-info" file-system-info } } -{ $description "Returns a platform-specific object describing the file-system that contains the path. The cross-platform slot is " { $slot "free-space" } "." } ; - -HELP: resource-path -{ $values { "path" "a pathname string" } { "newpath" "a pathname string" } } -{ $description "Resolve a path relative to the Factor source code location." } ; - -HELP: pathname -{ $class-description "Class of path name objects. Path name objects can be created by calling " { $link } "." } ; - -HELP: normalize-path -{ $values { "str" "a pathname string" } { "newstr" "a new pathname string" } } -{ $description "Called by words such as " { $link } " and " { $link } " to prepare a pathname before passing it to underlying code." } ; - -HELP: ( str -- pathname ) -{ $values { "str" "a pathname string" } { "pathname" pathname } } -{ $description "Creates a new " { $link pathname } "." } ; - -HELP: make-link -{ $values { "target" "a path to the symbolic link's target" } { "symlink" "a path to new symbolic link" } } -{ $description "Creates a symbolic link." } ; - -HELP: read-link -{ $values { "symlink" "a path to an existing symbolic link" } { "path" "the path pointed to by the symbolic link" } } -{ $description "Reads the symbolic link and returns its target path." } ; - -HELP: copy-link -{ $values { "target" "a path to an existing symlink" } { "symlink" "a path to a new symbolic link" } } -{ $description "Copies a symbolic link without following the link." } ; - -{ make-link read-link copy-link } related-words - -HELP: home -{ $values { "dir" string } } -{ $description "Outputs the user's home directory." } ; - -HELP: delete-file -{ $values { "path" "a pathname string" } } -{ $description "Deletes a file." } -{ $errors "Throws an error if the file could not be deleted." } ; - -HELP: make-directory -{ $values { "path" "a pathname string" } } -{ $description "Creates a directory." } -{ $errors "Throws an error if the directory could not be created." } ; - -HELP: make-directories -{ $values { "path" "a pathname string" } } -{ $description "Creates a directory and any parent directories which do not yet exist." } -{ $errors "Throws an error if the directories could not be created." } ; - -HELP: delete-directory -{ $values { "path" "a pathname string" } } -{ $description "Deletes a directory. The directory must be empty." } -{ $errors "Throws an error if the directory could not be deleted." } ; - -HELP: touch-file -{ $values { "path" "a pathname string" } } -{ $description "Updates the modification time of a file or directory. If the file does not exist, creates a new, empty file." } -{ $errors "Throws an error if the file could not be touched." } ; - -HELP: delete-tree -{ $values { "path" "a pathname string" } } -{ $description "Deletes a file or directory, recursing into subdirectories." } -{ $errors "Throws an error if the deletion fails." } -{ $warning "Misuse of this word can lead to catastrophic data loss." } ; - -HELP: move-file -{ $values { "from" "a pathname string" } { "to" "a pathname string" } } -{ $description "Moves or renames a file." } -{ $errors "Throws an error if the file does not exist or if the move operation fails." } ; - -HELP: move-file-into -{ $values { "from" "a pathname string" } { "to" "a directory pathname string" } } -{ $description "Moves a file to another directory without renaming it." } -{ $errors "Throws an error if the file does not exist or if the move operation fails." } ; - -HELP: move-files-into -{ $values { "files" "a sequence of pathname strings" } { "to" "a directory pathname string" } } -{ $description "Moves a set of files to another directory." } -{ $errors "Throws an error if the file does not exist or if the move operation fails." } ; - -HELP: copy-file -{ $values { "from" "a pathname string" } { "to" "a pathname string" } } -{ $description "Copies a file." } -{ $notes "This operation attempts to preserve the original file's attributes, however not all attributes may be preserved." } -{ $errors "Throws an error if the file does not exist or if the copy operation fails." } ; - -HELP: copy-file-into -{ $values { "from" "a pathname string" } { "to" "a directory pathname string" } } -{ $description "Copies a file to another directory." } -{ $errors "Throws an error if the file does not exist or if the copy operation fails." } ; - -HELP: copy-files-into -{ $values { "files" "a sequence of pathname strings" } { "to" "a directory pathname string" } } -{ $description "Copies a set of files to another directory." } -{ $errors "Throws an error if the file does not exist or if the copy operation fails." } ; - -HELP: copy-tree -{ $values { "from" "a pathname string" } { "to" "a pathname string" } } -{ $description "Copies a directory tree recursively." } -{ $notes "This operation attempts to preserve original file attributes, however not all attributes may be preserved." } -{ $errors "Throws an error if the copy operation fails." } ; - -HELP: copy-tree-into -{ $values { "from" "a pathname string" } { "to" "a directory pathname string" } } -{ $description "Copies a directory tree to another directory, recursively." } -{ $errors "Throws an error if the copy operation fails." } ; - -HELP: copy-trees-into -{ $values { "files" "a sequence of pathname strings" } { "to" "a directory pathname string" } } -{ $description "Copies a set of directory trees to another directory, recursively." } -{ $errors "Throws an error if the copy operation fails." } ; - - diff --git a/core/io/files/files-tests.factor b/core/io/files/files-tests.factor index 4299634642..d3ce7f4909 100644 --- a/core/io/files/files-tests.factor +++ b/core/io/files/files-tests.factor @@ -6,283 +6,57 @@ namespaces ; \ exists? must-infer \ (exists?) must-infer -\ file-info must-infer -\ link-info must-infer - -[ ] [ "blahblah" temp-file dup exists? [ delete-directory ] [ drop ] if ] unit-test -[ ] [ "blahblah" temp-file make-directory ] unit-test -[ t ] [ "blahblah" temp-file file-info directory? ] unit-test - -[ t ] [ - [ temp-directory "loldir" append-path delete-directory ] ignore-errors - temp-directory [ - "loldir" make-directory - ] with-directory - temp-directory "loldir" append-path exists? -] unit-test - -[ ] [ - [ temp-directory "loldir" append-path delete-directory ] ignore-errors - temp-directory [ - "loldir" make-directory - "loldir" delete-directory - ] with-directory -] unit-test - -[ "file1 contents" ] [ - [ temp-directory "loldir" append-path delete-directory ] ignore-errors - temp-directory [ - "file1 contents" "file1" utf8 set-file-contents - "file1" "file2" copy-file - "file2" utf8 file-contents - ] with-directory - "file1" temp-file delete-file - "file2" temp-file delete-file -] unit-test - -[ "file3 contents" ] [ - temp-directory [ - "file3 contents" "file3" utf8 set-file-contents - "file3" "file4" move-file - "file4" utf8 file-contents - ] with-directory - "file4" temp-file delete-file -] unit-test - -[ "file5" temp-file delete-file ] ignore-errors - -[ ] [ - temp-directory [ - "file5" touch-file - "file5" delete-file - ] with-directory -] unit-test - -[ "file6" temp-file delete-file ] ignore-errors - -[ ] [ - temp-directory [ - "file6" touch-file - "file6" link-info drop - ] with-directory -] unit-test - -[ "passwd" ] [ "/etc/passwd" file-name ] unit-test -[ "awk" ] [ "/usr/libexec/awk/" file-name ] unit-test -[ "awk" ] [ "/usr/libexec/awk///" file-name ] unit-test -[ "" ] [ "" file-name ] unit-test - -[ "freetype6.dll" ] [ "resource:freetype6.dll" file-name ] unit-test -[ "freetype6.dll" ] [ "resource:/freetype6.dll" file-name ] unit-test - -[ ] [ - { "Hello world." } - "test-foo.txt" temp-file ascii set-file-lines -] unit-test - -[ ] [ - "test-foo.txt" temp-file ascii [ - "Hello appender." print - ] with-file-appender -] unit-test - -[ ] [ - "test-bar.txt" temp-file ascii [ - "Hello appender." print - ] with-file-appender -] unit-test - -[ "Hello world.\nHello appender.\n" ] [ - "test-foo.txt" temp-file ascii file-contents -] unit-test - -[ "Hello appender.\n" ] [ - "test-bar.txt" temp-file ascii file-contents -] unit-test - -[ ] [ "test-foo.txt" temp-file delete-file ] unit-test - -[ ] [ "test-bar.txt" temp-file delete-file ] unit-test - -[ f ] [ "test-foo.txt" temp-file exists? ] unit-test - -[ f ] [ "test-bar.txt" temp-file exists? ] unit-test - -[ "test-blah" temp-file delete-tree ] ignore-errors - -[ ] [ "test-blah" temp-file make-directory ] unit-test - -[ ] [ - "test-blah/fooz" temp-file ascii dispose -] unit-test - -[ t ] [ - "test-blah/fooz" temp-file exists? -] unit-test - -[ ] [ "test-blah/fooz" temp-file delete-file ] unit-test - -[ ] [ "test-blah" temp-file delete-directory ] unit-test - -[ f ] [ "test-blah" temp-file exists? ] unit-test - -USE: debugger.threads - -[ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test - -[ ] [ "test-quux.txt" temp-file delete-file ] unit-test - -[ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test - -[ ] [ "test-quux.txt" "quux-test.txt" [ temp-file ] bi@ move-file ] unit-test - -[ t ] [ "quux-test.txt" temp-file exists? ] unit-test - -[ ] [ "quux-test.txt" temp-file delete-file ] unit-test - -[ ] [ "delete-tree-test/a/b/c" temp-file make-directories ] unit-test - -[ ] [ - { "Hi" } - "delete-tree-test/a/b/c/d" temp-file ascii set-file-lines -] unit-test - -[ ] [ - "delete-tree-test" temp-file delete-tree -] unit-test - -[ { "kernel" } ] [ - "core" resource-path [ - "." directory-files [ "kernel" = ] filter - ] with-directory -] unit-test - -[ { "kernel" } ] [ - "resource:core" [ - "." directory-files [ "kernel" = ] filter - ] with-directory -] unit-test - -[ { "kernel" } ] [ - "resource:core" [ - [ "kernel" = ] filter - ] with-directory-files -] unit-test - -[ ] [ - "copy-tree-test/a/b/c" temp-file make-directories -] unit-test - -[ ] [ - "Foobar" - "copy-tree-test/a/b/c/d" temp-file - ascii set-file-contents -] unit-test - -[ ] [ - "copy-tree-test" temp-file - "copy-destination" temp-file copy-tree -] unit-test - -[ "Foobar" ] [ - "copy-destination/a/b/c/d" temp-file ascii file-contents -] unit-test - -[ ] [ - "copy-destination" temp-file delete-tree -] unit-test - -[ ] [ - "copy-tree-test" temp-file - "copy-destination" temp-file copy-tree-into -] unit-test - -[ "Foobar" ] [ - "copy-destination/copy-tree-test/a/b/c/d" temp-file ascii file-contents -] unit-test - -[ ] [ - "copy-destination/copy-tree-test/a/b/c/d" temp-file "" temp-file copy-file-into -] unit-test - -[ "Foobar" ] [ - "d" temp-file ascii file-contents -] unit-test - -[ ] [ "d" temp-file delete-file ] unit-test - -[ ] [ "copy-destination" temp-file delete-tree ] unit-test - -[ ] [ "copy-tree-test" temp-file delete-tree ] unit-test - -[ t ] [ cwd "misc" resource-path [ ] with-directory cwd = ] unit-test - -[ t ] [ - temp-directory [ "hi41" "test41" utf8 set-file-contents ] with-directory - temp-directory "test41" append-path utf8 file-contents "hi41" = -] unit-test - -[ t ] [ - temp-directory [ "test41" file-info size>> ] with-directory 4 = -] unit-test [ ] [ "append-test" temp-file dup exists? [ delete-file ] [ drop ] if ] unit-test [ ] [ "append-test" temp-file ascii dispose ] unit-test -[ "/usr/lib" ] [ "/usr" "lib" append-path ] unit-test -[ "/usr/lib" ] [ "/usr/" "lib" append-path ] unit-test -[ "/usr/lib" ] [ "/usr" "./lib" append-path ] unit-test -[ "/usr/lib/" ] [ "/usr" "./lib/" append-path ] unit-test -[ "/lib" ] [ "/usr" "../lib" append-path ] unit-test -[ "/lib/" ] [ "/usr" "../lib/" append-path ] unit-test - -[ "" ] [ "" "." append-path ] unit-test -[ "" ".." append-path ] must-fail - -[ "/" ] [ "/" "./." append-path ] unit-test -[ "/" ] [ "/" "././" append-path ] unit-test -[ "/a/b/lib" ] [ "/a/b/c/d/e/f/" "../../../../lib" append-path ] unit-test -[ "/a/b/lib/" ] [ "/a/b/c/d/e/f/" "../../../../lib/" append-path ] unit-test - -[ "" "../lib/" append-path ] must-fail -[ "lib" ] [ "" "lib" append-path ] unit-test -[ "lib" ] [ "" "./lib" append-path ] unit-test - -[ "foo/bar/." parent-directory ] must-fail -[ "foo/bar/./" parent-directory ] must-fail -[ "foo/bar/baz/.." parent-directory ] must-fail -[ "foo/bar/baz/../" parent-directory ] must-fail - -[ "." parent-directory ] must-fail -[ "./" parent-directory ] must-fail -[ ".." parent-directory ] must-fail -[ "../" parent-directory ] must-fail -[ "../../" parent-directory ] must-fail -[ "foo/.." parent-directory ] must-fail -[ "foo/../" parent-directory ] must-fail -[ "" parent-directory ] must-fail -[ "." ] [ "boot.x86.64.image" parent-directory ] unit-test - -[ "bar/foo" ] [ "bar/baz" "..///foo" append-path ] unit-test -[ "bar/baz/foo" ] [ "bar/baz" ".///foo" append-path ] unit-test -[ "bar/foo" ] [ "bar/baz" "./..//foo" append-path ] unit-test -[ "bar/foo" ] [ "bar/baz" "./../././././././///foo" append-path ] unit-test - -[ t ] [ "resource:core" absolute-path? ] unit-test -[ f ] [ "" absolute-path? ] unit-test - -[ "touch-twice-test" temp-file delete-file ] ignore-errors -[ ] [ 2 [ "touch-twice-test" temp-file touch-file ] times ] unit-test - -! aum's bug [ - "." current-directory set - ".." "resource-path" set - [ "../core/bootstrap/stage2.factor" ] - [ "resource:core/bootstrap/stage2.factor" (normalize-path) ] - unit-test -] with-scope + "This is a line.\rThis is another line.\r" +] [ + "resource:core/io/test/mac-os-eol.txt" latin1 + [ 500 read ] with-input-stream +] unit-test -[ t ] [ "/" file-system-info file-system-info? ] unit-test -[ t ] [ file-systems [ file-system-info? ] all? ] unit-test +[ + 255 +] [ + "resource:core/io/test/binary.txt" latin1 + [ read1 ] with-input-stream >fixnum +] unit-test + +[ ] [ + "It seems Jobs has lost his grasp on reality again.\n" + "separator-test.txt" temp-file latin1 set-file-contents +] unit-test + +[ + { + { "It seems " CHAR: J } + { "obs has lost h" CHAR: i } + { "s grasp on reality again.\n" f } + } +] [ + [ + "separator-test.txt" temp-file + latin1 [ + "J" read-until 2array , + "i" read-until 2array , + "X" read-until 2array , + ] with-input-stream + ] { } make +] unit-test + +[ ] [ + image binary [ + 10 [ 65536 read drop ] times + ] with-file-reader +] unit-test + +! Test EOF behavior +[ 10 ] [ + image binary [ + 0 read drop + 10 read length + ] with-file-reader +] unit-test diff --git a/core/io/files/files.factor b/core/io/files/files.factor index 77b37180c6..19659ee5bb 100644 --- a/core/io/files/files.factor +++ b/core/io/files/files.factor @@ -1,10 +1,7 @@ ! Copyright (C) 2004, 2008 Slava Pestov, Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. -USING: io.backend io.files.private io hashtables kernel -kernel.private math memory namespaces sequences strings assocs -arrays definitions system combinators splitting sbufs -continuations destructors io.encodings io.encodings.binary init -accessors math.order ; +USING: kernel kernel.private sequences init namespaces system io +io.backend io.pathnames io.encodings io.files.private ; IN: io.files HOOK: (file-reader) io-backend ( path -- stream ) @@ -43,155 +40,9 @@ HOOK: (file-appender) io-backend ( path -- stream ) : with-file-appender ( path encoding quot -- ) [ ] dip with-output-stream ; inline -! Pathnames -: path-separator? ( ch -- ? ) os windows? "/\\" "/" ? member? ; - -: path-separator ( -- string ) os windows? "\\" "/" ? ; - -: trim-right-separators ( str -- newstr ) - [ path-separator? ] trim-right ; - -: trim-left-separators ( str -- newstr ) - [ path-separator? ] trim-left ; - -: last-path-separator ( path -- n ? ) - [ length 1- ] keep [ path-separator? ] find-last-from ; - -HOOK: root-directory? io-backend ( path -- ? ) - -M: object root-directory? ( path -- ? ) - [ f ] [ [ path-separator? ] all? ] if-empty ; - -ERROR: no-parent-directory path ; - -: parent-directory ( path -- parent ) - dup root-directory? [ - trim-right-separators - dup last-path-separator [ - 1+ cut - ] [ - drop "." swap - ] if - { "" "." ".." } member? [ - no-parent-directory - ] when - ] unless ; - - - -: windows-absolute-path? ( path -- path ? ) - { - { [ dup "\\\\?\\" head? ] [ t ] } - { [ dup length 2 < ] [ f ] } - { [ dup second CHAR: : = ] [ t ] } - [ f ] - } cond ; - -: absolute-path? ( path -- ? ) - { - { [ dup empty? ] [ f ] } - { [ dup "resource:" head? ] [ t ] } - { [ os windows? ] [ windows-absolute-path? ] } - { [ dup first path-separator? ] [ t ] } - [ f ] - } cond nip ; - -: append-path ( str1 str2 -- str ) - { - { [ over empty? ] [ append-path-empty ] } - { [ dup empty? ] [ drop ] } - { [ over trim-right-separators "." = ] [ nip ] } - { [ dup absolute-path? ] [ nip ] } - { [ dup head.? ] [ rest trim-left-separators append-path ] } - { [ dup head..? ] [ - 2 tail trim-left-separators - [ parent-directory ] dip append-path - ] } - { [ over absolute-path? over first path-separator? and ] [ - [ 2 head ] dip append - ] } - [ - [ trim-right-separators "/" ] dip - trim-left-separators 3append - ] - } cond ; - -: prepend-path ( str1 str2 -- str ) - swap append-path ; inline - -: file-name ( path -- string ) - dup root-directory? [ - trim-right-separators - dup last-path-separator [ 1+ tail ] [ - drop "resource:" ?head [ file-name ] when - ] if - ] unless ; - -: file-extension ( filename -- extension ) - "." split1-last nip ; - -! File info -TUPLE: file-info type size permissions created modified -accessed ; - -HOOK: file-info io-backend ( path -- info ) - -! Symlinks -HOOK: link-info io-backend ( path -- info ) - -HOOK: make-link io-backend ( target symlink -- ) - -HOOK: read-link io-backend ( symlink -- path ) - -: copy-link ( target symlink -- ) - [ read-link ] dip make-link ; - -SYMBOL: +regular-file+ -SYMBOL: +directory+ -SYMBOL: +symbolic-link+ -SYMBOL: +character-device+ -SYMBOL: +block-device+ -SYMBOL: +fifo+ -SYMBOL: +socket+ -SYMBOL: +whiteout+ -SYMBOL: +unknown+ - -! File metadata : exists? ( path -- ? ) normalize-path (exists?) ; -: directory? ( file-info -- ? ) type>> +directory+ = ; - -! File-system - -HOOK: file-systems os ( -- array ) - -TUPLE: file-system-info device-name mount-point type -available-space free-space used-space total-space ; - -HOOK: file-system-info os ( path -- file-system-info ) - +! Current directory -SYMBOL: current-directory - [ cwd current-directory set-global 13 getenv cwd prepend-path \ image set-global 14 getenv cwd prepend-path \ vm set-global image parent-directory "resource-path" set-global -] "io.files" add-init-hook - -: resource-path ( path -- newpath ) - "resource-path" get prepend-path ; - -: (normalize-path) ( path -- path' ) - "resource:" ?head [ - trim-left-separators resource-path - (normalize-path) - ] [ - current-directory get prepend-path - ] if ; - -M: object normalize-path ( path -- path' ) - (normalize-path) ; - -: set-current-directory ( path -- ) - (normalize-path) current-directory set ; - -: with-directory ( path quot -- ) - [ (normalize-path) current-directory ] dip with-variable ; inline - -! Creating directories -HOOK: make-directory io-backend ( path -- ) - -: make-directories ( path -- ) - normalize-path trim-right-separators { - { [ dup "." = ] [ ] } - { [ dup root-directory? ] [ ] } - { [ dup empty? ] [ ] } - { [ dup exists? ] [ ] } - [ - dup parent-directory make-directories - dup make-directory - ] - } cond drop ; - -TUPLE: directory-entry name type ; - -HOOK: >directory-entry os ( byte-array -- directory-entry ) - -HOOK: (directory-entries) os ( path -- seq ) - -: directory-entries ( path -- seq ) - normalize-path - (directory-entries) - [ name>> { "." ".." } member? not ] filter ; - -: directory-files ( path -- seq ) - directory-entries [ name>> ] map ; - -: with-directory-files ( path quot -- ) - [ "" directory-files ] prepose with-directory ; inline - -! Touching files -HOOK: touch-file io-backend ( path -- ) - -! Deleting files -HOOK: delete-file io-backend ( path -- ) - -HOOK: delete-directory io-backend ( path -- ) - -: delete-tree ( path -- ) - dup link-info type>> +directory+ = [ - [ [ [ delete-tree ] each ] with-directory-files ] - [ delete-directory ] - bi - ] [ delete-file ] if ; - -: to-directory ( from to -- from to' ) - over file-name append-path ; - -! Moving and renaming files -HOOK: move-file io-backend ( from to -- ) - -: move-file-into ( from to -- ) - to-directory move-file ; - -: move-files-into ( files to -- ) - [ move-file-into ] curry each ; - -! Copying files -HOOK: copy-file io-backend ( from to -- ) - -M: object copy-file - dup parent-directory make-directories - binary [ - swap binary [ - swap stream-copy - ] with-disposal - ] with-disposal ; - -: copy-file-into ( from to -- ) - to-directory copy-file ; - -: copy-files-into ( files to -- ) - [ copy-file-into ] curry each ; - -DEFER: copy-tree-into - -: copy-tree ( from to -- ) - normalize-path - over link-info type>> - { - { +symbolic-link+ [ copy-link ] } - { +directory+ [ - swap [ - [ swap copy-tree-into ] with each - ] with-directory-files - ] } - [ drop copy-file ] - } case ; - -: copy-tree-into ( from to -- ) - to-directory copy-tree ; - -: copy-trees-into ( files to -- ) - [ copy-tree-into ] curry each ; - -! Special paths - -: temp-directory ( -- path ) - "temp" resource-path dup make-directories ; - -: temp-file ( name -- path ) - temp-directory prepend-path ; - -! Pathname presentations -TUPLE: pathname string ; - -C: pathname - -M: pathname <=> [ string>> ] compare ; - -! Home directory -HOOK: home io-backend ( -- dir ) - -M: object home "" resource-path ; +] "io.files" add-init-hook \ No newline at end of file diff --git a/core/io/io-tests.factor b/core/io/io-tests.factor index 18cde1a35c..009ba3a9e7 100644 --- a/core/io/io-tests.factor +++ b/core/io/io-tests.factor @@ -8,55 +8,5 @@ IN: io.tests "foo" "io.tests" lookup ] unit-test -[ - "This is a line.\rThis is another line.\r" -] [ - "resource:core/io/test/mac-os-eol.txt" latin1 - [ 500 read ] with-input-stream -] unit-test - -[ - 255 -] [ - "resource:core/io/test/binary.txt" latin1 - [ read1 ] with-input-stream >fixnum -] unit-test - ! Make sure we use correct to_c_string form when writing [ ] [ "\0" write ] unit-test - -[ ] [ - "It seems Jobs has lost his grasp on reality again.\n" - "separator-test.txt" temp-file latin1 set-file-contents -] unit-test - -[ - { - { "It seems " CHAR: J } - { "obs has lost h" CHAR: i } - { "s grasp on reality again.\n" f } - } -] [ - [ - "separator-test.txt" temp-file - latin1 [ - "J" read-until 2array , - "i" read-until 2array , - "X" read-until 2array , - ] with-input-stream - ] { } make -] unit-test - -[ ] [ - image binary [ - 10 [ 65536 read drop ] times - ] with-file-reader -] unit-test - -! Test EOF behavior -[ 10 ] [ - image binary [ - 0 read drop - 10 read length - ] with-file-reader -] unit-test diff --git a/core/io/pathnames/pathnames-docs.factor b/core/io/pathnames/pathnames-docs.factor new file mode 100644 index 0000000000..21fd5b4b36 --- /dev/null +++ b/core/io/pathnames/pathnames-docs.factor @@ -0,0 +1,78 @@ +USING: help.markup help.syntax io.backend io.files strings ; +IN: io.pathnames + +HELP: path-separator? +{ $values { "ch" "a code point" } { "?" "a boolean" } } +{ $description "Tests if the code point is a platform-specific path separator." } +{ $examples + "On Unix:" + { $example "USING: io.files prettyprint ;" "CHAR: / path-separator? ." "t" } +} ; + +HELP: parent-directory +{ $values { "path" "a pathname string" } { "parent" "a pathname string" } } +{ $description "Strips the last component off a pathname." } +{ $examples { $example "USING: io io.files ;" "\"/etc/passwd\" parent-directory print" "/etc/" } } ; + +HELP: file-name +{ $values { "path" "a pathname string" } { "string" string } } +{ $description "Outputs the last component of a pathname string." } +{ $examples + { $example "USING: io.files prettyprint ;" "\"/usr/bin/gcc\" file-name ." "\"gcc\"" } + { $example "USING: io.files prettyprint ;" "\"/usr/libexec/awk/\" file-name ." "\"awk\"" } +} ; + +HELP: append-path +{ $values { "str1" "a string" } { "str2" "a string" } { "str" "a string" } } +{ $description "Appends " { $snippet "str1" } " and " { $snippet "str2" } " to form a pathname." } ; + +HELP: prepend-path +{ $values { "str1" "a string" } { "str2" "a string" } { "str" "a string" } } +{ $description "Appends " { $snippet "str2" } " and " { $snippet "str1" } " to form a pathname." } ; + +{ append-path prepend-path } related-words + +HELP: absolute-path? +{ $values { "path" "a pathname string" } { "?" "a boolean" } } +{ $description "Tests if a pathname is absolute. Examples of absolute pathnames are " { $snippet "/foo/bar" } " on Unix and " { $snippet "c:\\foo\\bar" } " on Windows." } ; + +HELP: windows-absolute-path? +{ $values { "path" "a pathname string" } { "?" "a boolean" } } +{ $description "Tests if a pathname is absolute on Windows. Examples of absolute pathnames on Windows are " { $snippet "c:\\foo\\bar" } " and " { $snippet "\\\\?\\c:\\foo\\bar" } " for absolute Unicode pathnames." } ; + +HELP: root-directory? +{ $values { "path" "a pathname string" } { "?" "a boolean" } } +{ $description "Tests if a pathname is a root directory. Examples of root directory pathnames are " { $snippet "/" } " on Unix and " { $snippet "c:\\" } " on Windows." } ; + +{ absolute-path? windows-absolute-path? root-directory? } related-words + +HELP: resource-path +{ $values { "path" "a pathname string" } { "newpath" "a pathname string" } } +{ $description "Resolve a path relative to the Factor source code location." } ; + +HELP: pathname +{ $class-description "Class of path name objects. Path name objects can be created by calling " { $link } "." } ; + +HELP: normalize-path +{ $values { "str" "a pathname string" } { "newstr" "a new pathname string" } } +{ $description "Called by words such as " { $link } " and " { $link } " to prepare a pathname before passing it to underlying code." } ; + +HELP: ( str -- pathname ) +{ $values { "str" "a pathname string" } { "pathname" pathname } } +{ $description "Creates a new " { $link pathname } "." } ; + +HELP: home +{ $values { "dir" string } } +{ $description "Outputs the user's home directory." } ; + +ARTICLE: "pathnames" "Pathname manipulation" +"Pathname manipulation:" +{ $subsection parent-directory } +{ $subsection file-name } +{ $subsection last-path-separator } +{ $subsection append-path } +"Pathname presentations:" +{ $subsection pathname } +{ $subsection } ; + +ABOUT: "io.pathnames" diff --git a/core/io/pathnames/pathnames-tests.factor b/core/io/pathnames/pathnames-tests.factor new file mode 100644 index 0000000000..eaf3ed0ef7 --- /dev/null +++ b/core/io/pathnames/pathnames-tests.factor @@ -0,0 +1,65 @@ +IN: io.pathnames.tests + +[ "passwd" ] [ "/etc/passwd" file-name ] unit-test +[ "awk" ] [ "/usr/libexec/awk/" file-name ] unit-test +[ "awk" ] [ "/usr/libexec/awk///" file-name ] unit-test +[ "" ] [ "" file-name ] unit-test + +[ "freetype6.dll" ] [ "resource:freetype6.dll" file-name ] unit-test +[ "freetype6.dll" ] [ "resource:/freetype6.dll" file-name ] unit-test + +[ "/usr/lib" ] [ "/usr" "lib" append-path ] unit-test +[ "/usr/lib" ] [ "/usr/" "lib" append-path ] unit-test +[ "/usr/lib" ] [ "/usr" "./lib" append-path ] unit-test +[ "/usr/lib/" ] [ "/usr" "./lib/" append-path ] unit-test +[ "/lib" ] [ "/usr" "../lib" append-path ] unit-test +[ "/lib/" ] [ "/usr" "../lib/" append-path ] unit-test + +[ "" ] [ "" "." append-path ] unit-test +[ "" ".." append-path ] must-fail + +[ "/" ] [ "/" "./." append-path ] unit-test +[ "/" ] [ "/" "././" append-path ] unit-test +[ "/a/b/lib" ] [ "/a/b/c/d/e/f/" "../../../../lib" append-path ] unit-test +[ "/a/b/lib/" ] [ "/a/b/c/d/e/f/" "../../../../lib/" append-path ] unit-test + +[ "" "../lib/" append-path ] must-fail +[ "lib" ] [ "" "lib" append-path ] unit-test +[ "lib" ] [ "" "./lib" append-path ] unit-test + +[ "foo/bar/." parent-directory ] must-fail +[ "foo/bar/./" parent-directory ] must-fail +[ "foo/bar/baz/.." parent-directory ] must-fail +[ "foo/bar/baz/../" parent-directory ] must-fail + +[ "." parent-directory ] must-fail +[ "./" parent-directory ] must-fail +[ ".." parent-directory ] must-fail +[ "../" parent-directory ] must-fail +[ "../../" parent-directory ] must-fail +[ "foo/.." parent-directory ] must-fail +[ "foo/../" parent-directory ] must-fail +[ "" parent-directory ] must-fail +[ "." ] [ "boot.x86.64.image" parent-directory ] unit-test + +[ "bar/foo" ] [ "bar/baz" "..///foo" append-path ] unit-test +[ "bar/baz/foo" ] [ "bar/baz" ".///foo" append-path ] unit-test +[ "bar/foo" ] [ "bar/baz" "./..//foo" append-path ] unit-test +[ "bar/foo" ] [ "bar/baz" "./../././././././///foo" append-path ] unit-test + +[ t ] [ "resource:core" absolute-path? ] unit-test +[ f ] [ "" absolute-path? ] unit-test + +[ "touch-twice-test" temp-file delete-file ] ignore-errors +[ ] [ 2 [ "touch-twice-test" temp-file touch-file ] times ] unit-test + +! aum's bug +[ + "." current-directory set + ".." "resource-path" set + [ "../core/bootstrap/stage2.factor" ] + [ "resource:core/bootstrap/stage2.factor" (normalize-path) ] + unit-test +] with-scope + +[ t ] [ cwd "misc" resource-path [ ] with-directory cwd = ] unit-test diff --git a/core/io/pathnames/pathnames.factor b/core/io/pathnames/pathnames.factor new file mode 100644 index 0000000000..e81d8c2bfd --- /dev/null +++ b/core/io/pathnames/pathnames.factor @@ -0,0 +1,143 @@ +! Copyright (C) 2004, 2008 Slava Pestov, Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors combinators io.backend kernel math math.order +namespaces sequences splitting strings system ; +IN: io.pathnames + +SYMBOL: current-directory + +: path-separator? ( ch -- ? ) os windows? "/\\" "/" ? member? ; + +: path-separator ( -- string ) os windows? "\\" "/" ? ; + +: trim-right-separators ( str -- newstr ) + [ path-separator? ] trim-right ; + +: trim-left-separators ( str -- newstr ) + [ path-separator? ] trim-left ; + +: last-path-separator ( path -- n ? ) + [ length 1- ] keep [ path-separator? ] find-last-from ; + +HOOK: root-directory? io-backend ( path -- ? ) + +M: object root-directory? ( path -- ? ) + [ f ] [ [ path-separator? ] all? ] if-empty ; + +ERROR: no-parent-directory path ; + +: parent-directory ( path -- parent ) + dup root-directory? [ + trim-right-separators + dup last-path-separator [ + 1+ cut + ] [ + drop "." swap + ] if + { "" "." ".." } member? [ + no-parent-directory + ] when + ] unless ; + + + +: windows-absolute-path? ( path -- path ? ) + { + { [ dup "\\\\?\\" head? ] [ t ] } + { [ dup length 2 < ] [ f ] } + { [ dup second CHAR: : = ] [ t ] } + [ f ] + } cond ; + +: absolute-path? ( path -- ? ) + { + { [ dup empty? ] [ f ] } + { [ dup "resource:" head? ] [ t ] } + { [ os windows? ] [ windows-absolute-path? ] } + { [ dup first path-separator? ] [ t ] } + [ f ] + } cond nip ; + +: append-path ( str1 str2 -- str ) + { + { [ over empty? ] [ append-path-empty ] } + { [ dup empty? ] [ drop ] } + { [ over trim-right-separators "." = ] [ nip ] } + { [ dup absolute-path? ] [ nip ] } + { [ dup head.? ] [ rest trim-left-separators append-path ] } + { [ dup head..? ] [ + 2 tail trim-left-separators + [ parent-directory ] dip append-path + ] } + { [ over absolute-path? over first path-separator? and ] [ + [ 2 head ] dip append + ] } + [ + [ trim-right-separators "/" ] dip + trim-left-separators 3append + ] + } cond ; + +: prepend-path ( str1 str2 -- str ) + swap append-path ; inline + +: file-name ( path -- string ) + dup root-directory? [ + trim-right-separators + dup last-path-separator [ 1+ tail ] [ + drop "resource:" ?head [ file-name ] when + ] if + ] unless ; + +: file-extension ( filename -- extension ) + "." split1-last nip ; + +: resource-path ( path -- newpath ) + "resource-path" get prepend-path ; + +GENERIC: (normalize-path) ( path -- path' ) + +M: string (normalize-path) + "resource:" ?head [ + trim-left-separators resource-path + (normalize-path) + ] [ + current-directory get prepend-path + ] if ; + +M: object normalize-path ( path -- path' ) + (normalize-path) ; + +TUPLE: pathname string ; + +C: pathname + +M: pathname (normalize-path) string>> (normalize-path) ; + +M: pathname <=> [ string>> ] compare ; + +HOOK: home io-backend ( -- dir ) + +M: object home "" resource-path ; \ No newline at end of file diff --git a/core/source-files/source-files.factor b/core/source-files/source-files.factor index 3ae50a9a15..7ecc967e9e 100644 --- a/core/source-files/source-files.factor +++ b/core/source-files/source-files.factor @@ -1,9 +1,9 @@ ! Copyright (C) 2007, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: arrays definitions generic assocs kernel math namespaces -sequences strings vectors words quotations io -combinators sorting splitting math.parser effects continuations -io.files checksums checksums.crc32 vocabs hashtables graphs +sequences strings vectors words quotations io io.files +io.pathnames combinators sorting splitting math.parser effects +continuations checksums checksums.crc32 vocabs hashtables graphs compiler.units io.encodings.utf8 accessors ; IN: source-files diff --git a/core/syntax/syntax-docs.factor b/core/syntax/syntax-docs.factor index 2b7de36d56..c1e12ea133 100644 --- a/core/syntax/syntax-docs.factor +++ b/core/syntax/syntax-docs.factor @@ -1,6 +1,6 @@ USING: generic help.syntax help.markup kernel math parser words effects classes generic.standard classes.tuple generic.math -generic.standard arrays io.files vocabs.loader io sequences +generic.standard arrays io.pathnames vocabs.loader io sequences assocs ; IN: syntax diff --git a/core/syntax/syntax.factor b/core/syntax/syntax.factor index 0b7d9d008f..7d76bdd10b 100644 --- a/core/syntax/syntax.factor +++ b/core/syntax/syntax.factor @@ -4,7 +4,7 @@ USING: accessors alien arrays byte-arrays definitions generic hashtables kernel math namespaces parser lexer sequences strings strings.parser sbufs vectors words quotations io assocs splitting classes.tuple generic.standard generic.math -generic.parser classes io.files vocabs classes.parser +generic.parser classes io.pathnames vocabs classes.parser classes.union classes.intersection classes.mixin classes.predicate classes.singleton classes.tuple.parser compiler.units combinators effects.parser slots ; diff --git a/core/vocabs/loader/loader.factor b/core/vocabs/loader/loader.factor index 97fbfe8a07..53f8fbadf6 100644 --- a/core/vocabs/loader/loader.factor +++ b/core/vocabs/loader/loader.factor @@ -1,9 +1,9 @@ ! Copyright (C) 2007, 2008 Eduardo Cavazos, Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: namespaces make sequences io.files kernel assocs words -vocabs definitions parser continuations io hashtables sorting -source-files arrays combinators strings system math.parser -compiler.errors splitting init accessors sets ; +USING: namespaces make sequences io io.files io.pathnames kernel +assocs words vocabs definitions parser continuations hashtables +sorting source-files arrays combinators strings system +math.parser compiler.errors splitting init accessors sets ; IN: vocabs.loader SYMBOL: vocab-roots