From 89a595703351646212b406c6ff7c57b9bb821eb0 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 13 Nov 2008 19:32:34 -0600 Subject: [PATCH 01/11] add file-type>ch and ch>file-type --- basis/io/unix/files/files.factor | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/basis/io/unix/files/files.factor b/basis/io/unix/files/files.factor index 9ebfdaaa5a..3f254e7713 100644 --- a/basis/io/unix/files/files.factor +++ b/basis/io/unix/files/files.factor @@ -172,6 +172,30 @@ M: unix (directory-entries) ( path -- seq ) PRIVATE> +: ch>file-type ( ch -- type ) + { + { CHAR: b [ +block-device+ ] } + { CHAR: c [ +character-device+ ] } + { CHAR: d [ +directory+ ] } + { CHAR: l [ +symbolic-link+ ] } + { CHAR: s [ +socket+ ] } + { CHAR: p [ +fifo+ ] } + { CHAR: - [ +regular-file+ ] } + [ drop +unknown+ ] + } case ; + +: file-type>ch ( type -- string ) + { + { +block-device+ [ CHAR: b ] } + { +character-device+ [ CHAR: c ] } + { +directory+ [ CHAR: d ] } + { +symbolic-link+ [ CHAR: l ] } + { +socket+ [ CHAR: s ] } + { +fifo+ [ CHAR: p ] } + { +regular-file+ [ CHAR: - ] } + [ drop CHAR: - ] + } case ; + : UID OCT: 0004000 ; inline : GID OCT: 0002000 ; inline : STICKY OCT: 0001000 ; inline From 617a4337068f9d8eb0a8efc8abdd4ac0de5539c1 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 13 Nov 2008 19:33:29 -0600 Subject: [PATCH 02/11] make a variable to set the ftp serving directory. fix changing directories so you can't escape the serving directory. requires ls vocab now --- extra/ftp/client/client.factor | 2 +- extra/ftp/ftp.factor | 32 ++------------------------------ extra/ftp/server/server.factor | 20 ++++++++++++++++---- 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/extra/ftp/client/client.factor b/extra/ftp/client/client.factor index 8413331c00..9251e1aa55 100644 --- a/extra/ftp/client/client.factor +++ b/extra/ftp/client/client.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays classes.singleton combinators continuations io io.encodings.binary io.encodings.utf8 -io.files io.sockets kernel io.streams.duplex math +io.files io.sockets kernel io.streams.duplex math ls math.parser sequences splitting namespaces strings fry ftp ; IN: ftp.client diff --git a/extra/ftp/ftp.factor b/extra/ftp/ftp.factor index 8f0b48bd4d..e396e36180 100644 --- a/extra/ftp/ftp.factor +++ b/extra/ftp/ftp.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays assocs combinators io io.files kernel -math.parser sequences strings ; +math.parser sequences strings ls ; IN: ftp SINGLETON: active @@ -32,35 +32,7 @@ TUPLE: ftp-response n strings parsed ; over strings>> push ; : ftp-send ( string -- ) write "\r\n" write flush ; - : ftp-ipv4 1 ; inline : ftp-ipv6 2 ; inline -: ch>type ( ch -- type ) - { - { CHAR: d [ +directory+ ] } - { CHAR: l [ +symbolic-link+ ] } - { CHAR: - [ +regular-file+ ] } - [ drop +unknown+ ] - } case ; - -: type>ch ( type -- string ) - { - { +directory+ [ CHAR: d ] } - { +symbolic-link+ [ CHAR: l ] } - { +regular-file+ [ CHAR: - ] } - [ drop CHAR: - ] - } case ; - -: file-info>string ( file-info name -- string ) - [ - [ - [ type>> type>ch 1string ] - [ drop "rwx------" append ] bi - ] - [ size>> number>string 15 CHAR: \s pad-left ] bi - ] dip 3array " " join ; - -: directory-list ( -- seq ) - "" directory-files - [ [ link-info ] keep file-info>string ] map ; +: directory-list ( -- seq ) "" ls ; diff --git a/extra/ftp/server/server.factor b/extra/ftp/server/server.factor index 170155bd43..969ec17224 100644 --- a/extra/ftp/server/server.factor +++ b/extra/ftp/server/server.factor @@ -6,12 +6,16 @@ io.encodings.utf8 io.files io.sockets kernel math.parser namespaces make sequences ftp io.unix.launcher.parser unicode.case splitting assocs classes io.servers.connection destructors calendar io.timeouts io.streams.duplex threads -continuations math concurrency.promises byte-arrays sequences.lib -hexdump ; +continuations math concurrency.promises byte-arrays +io.backend sequences.lib hexdump ; IN: ftp.server SYMBOL: client +: ftp-server-directory ( -- str ) + \ ftp-server-directory get-global "resource:temp" or + normalize-path ; + TUPLE: ftp-command raw tokenized ; : ( -- obj ) @@ -238,10 +242,16 @@ M: ftp-put service-command ( stream obj -- ) ! : handle-LPRT ( obj -- ) tokenized>> "," split ; ERROR: not-a-directory ; +ERROR: no-permissions ; : handle-CWD ( obj -- ) [ - tokenized>> second dup directory? [ + tokenized>> second dup normalize-path + dup ftp-server-directory head? [ + no-permissions + ] unless + + file-info directory? [ set-current-directory 250 "Directory successully changed." server-response ] [ @@ -256,6 +266,7 @@ ERROR: not-a-directory ; : handle-client-loop ( -- ) readln + USE: prettyprint global [ dup . flush ] bind [ >>raw ] [ tokenize-command >>tokenized ] bi dup tokenized>> first >upper { @@ -313,7 +324,7 @@ TUPLE: ftp-server < threaded-server ; M: ftp-server handle-client* ( server -- ) drop [ - "" [ + ftp-server-directory [ host-name client set send-banner handle-client-loop ] with-directory @@ -323,6 +334,7 @@ M: ftp-server handle-client* ( server -- ) ftp-server new-threaded-server swap >>insecure "ftp.server" >>name + 5 minutes >>timeout latin1 >>encoding ; : ftpd ( port -- ) From 294708cb797f4de6c0a37cbb872164186e1a9b8d Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 13 Nov 2008 19:39:40 -0600 Subject: [PATCH 03/11] ls works for unix, todo windows soon --- extra/ls/authors.txt | 1 + extra/ls/ls-tests.factor | 6 ++++ extra/ls/ls.factor | 63 ++++++++++++++++++++++++++++++++++++++++ extra/ls/tags.txt | 1 + 4 files changed, 71 insertions(+) create mode 100644 extra/ls/authors.txt create mode 100644 extra/ls/ls-tests.factor create mode 100644 extra/ls/ls.factor create mode 100644 extra/ls/tags.txt diff --git a/extra/ls/authors.txt b/extra/ls/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/ls/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/ls/ls-tests.factor b/extra/ls/ls-tests.factor new file mode 100644 index 0000000000..b1c1f18472 --- /dev/null +++ b/extra/ls/ls-tests.factor @@ -0,0 +1,6 @@ +! Copyright (C) 2008 Your name. +! See http://factorcode.org/license.txt for BSD license. +USING: tools.test ls strings kernel ; +IN: ls.tests + +[ ] [ "" ls drop ] unit-test diff --git a/extra/ls/ls.factor b/extra/ls/ls.factor new file mode 100644 index 0000000000..3e21873fec --- /dev/null +++ b/extra/ls/ls.factor @@ -0,0 +1,63 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors arrays assocs combinators generalizations +io.files io.unix.files math.parser sequences.lib calendar math +kernel sequences unix.groups unix.users combinators.cleave +strings combinators.short-circuit unicode.case ; +IN: ls + +TUPLE: ls-info path user group size ; + +: ls-time ( timestamp -- string ) + [ hour>> ] [ minute>> ] bi + [ number>string 2 CHAR: 0 pad-left ] bi@ ":" splice ; + +: ls-timestamp ( timestamp -- string ) + [ month>> month-abbreviation ] + [ day>> number>string 2 CHAR: \s pad-left ] + [ + dup year>> dup now year>> = + [ drop ls-time ] [ nip number>string ] if + 5 CHAR: \s pad-left + ] tri 3array " " join ; + +: read>string ( ? -- string ) "r" "-" ? ; inline + +: write>string ( ? -- string ) "w" "-" ? ; inline + +: execute-string ( str bools -- str' ) + swap { + { { t t } [ >lower ] } + { { t f } [ >upper ] } + { { f t } [ drop "x" ] } + [ 2drop "-" ] + } case ; + +: permissions-string ( permissions -- str ) + { + [ type>> file-type>ch 1string ] + [ user-read? read>string ] + [ user-write? write>string ] + [ [ uid? ] [ user-execute? ] bi 2array "s" execute-string ] + [ group-read? read>string ] + [ group-write? write>string ] + [ [ gid? ] [ group-execute? ] bi 2array "s" execute-string ] + [ other-read? read>string ] + [ other-write? write>string ] + [ [ sticky? ] [ other-execute? ] bi 2array "t" execute-string ] + } concat ; + +: ls ( path -- lines ) + [ [ [ + "" directory-files [ + dup file-info + { + [ permissions-string ] + [ nlink>> number>string 3 CHAR: \s pad-left ] + ! [ uid>> ] + ! [ gid>> ] + [ size>> number>string 15 CHAR: \s pad-left ] + [ modified>> ls-timestamp ] + } swap suffix " " join + ] map + ] with-group-cache ] with-user-cache ] with-directory ; diff --git a/extra/ls/tags.txt b/extra/ls/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/extra/ls/tags.txt @@ -0,0 +1 @@ +unportable From c613eca829aba268141c057de2b7d1c57e003297 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 13 Nov 2008 19:48:11 -0600 Subject: [PATCH 04/11] move hexdump to tools.hexdump --- basis/tools/hexdump/authors.txt | 1 + basis/tools/hexdump/hexdump-docs.factor | 22 +++++++++++++++ basis/tools/hexdump/hexdump-tests.factor | 11 ++++++++ basis/tools/hexdump/hexdump.factor | 36 ++++++++++++++++++++++++ basis/tools/hexdump/summary.txt | 1 + 5 files changed, 71 insertions(+) create mode 100644 basis/tools/hexdump/authors.txt create mode 100644 basis/tools/hexdump/hexdump-docs.factor create mode 100644 basis/tools/hexdump/hexdump-tests.factor create mode 100644 basis/tools/hexdump/hexdump.factor create mode 100644 basis/tools/hexdump/summary.txt diff --git a/basis/tools/hexdump/authors.txt b/basis/tools/hexdump/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/basis/tools/hexdump/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/basis/tools/hexdump/hexdump-docs.factor b/basis/tools/hexdump/hexdump-docs.factor new file mode 100644 index 0000000000..4278e92f0e --- /dev/null +++ b/basis/tools/hexdump/hexdump-docs.factor @@ -0,0 +1,22 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: help.markup help.syntax kernel sequences strings ; +IN: hexdump + +HELP: hexdump. +{ $values { "seq" sequence } } +{ $description "Converts a sequence to its hexadecimal and ASCII representation sixteen characters at a time and writes it to standard out." } ; + +HELP: hexdump +{ $values { "seq" sequence } { "str" string } } +{ $description "Converts a sequence to its hexadecimal and ASCII representation sixteen characters at a time. Lines are separated by a newline character." } +{ $see-also hexdump. } ; + +ARTICLE: "hexdump" "Hexdump" +"The " { $vocab-link "hexdump" } " vocabulary provides a traditional hexdump view of a sequence." $nl +"Write hexdump to string:" +{ $subsection hexdump } +"Write the hexdump to the output stream:" +{ $subsection hexdump. } ; + +ABOUT: "hexdump" diff --git a/basis/tools/hexdump/hexdump-tests.factor b/basis/tools/hexdump/hexdump-tests.factor new file mode 100644 index 0000000000..b3c03196f5 --- /dev/null +++ b/basis/tools/hexdump/hexdump-tests.factor @@ -0,0 +1,11 @@ +IN: hexdump.tests +USING: hexdump kernel sequences tools.test ; + +[ t ] [ "" hexdump "Length: 0, 0h\n" = ] unit-test +[ t ] [ "abcdefghijklmnopqrstuvwxyz" hexdump "Length: 26, 1ah\n00000000h: 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 abcdefghijklmnop\n00000010h: 71 72 73 74 75 76 77 78 79 7a qrstuvwxyz\n" = ] unit-test + +[ t ] [ 256 [ ] map hexdump "Length: 256, 100h\n00000000h: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................\n00000010h: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................\n00000020h: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./\n00000030h: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?\n00000040h: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO\n00000050h: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[\\]^_\n00000060h: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno\n00000070h: 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.\n00000080h: 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f ................\n00000090h: 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f ................\n000000a0h: a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af ................\n000000b0h: b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf ................\n000000c0h: c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf ................\n000000d0h: d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df ................\n000000e0h: e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef ................\n000000f0h: f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff ................\n" = ] unit-test + + +[ + "Length: 3, 3h\n00000000h: 01 02 03 ...\n" ] [ B{ 1 2 3 } hexdump ] unit-test diff --git a/basis/tools/hexdump/hexdump.factor b/basis/tools/hexdump/hexdump.factor new file mode 100644 index 0000000000..c8b9f4accc --- /dev/null +++ b/basis/tools/hexdump/hexdump.factor @@ -0,0 +1,36 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: arrays io io.streams.string kernel math math.parser +namespaces sequences splitting grouping strings ascii ; +IN: tools.hexdump + +string write ", " write ] + [ >hex write "h" write nl ] bi ; + +: write-offset ( lineno -- ) + 16 * >hex 8 CHAR: 0 pad-left write "h: " write ; + +: >hex-digit ( digit -- str ) + >hex 2 CHAR: 0 pad-left " " append ; + +: >hex-digits ( bytes -- str ) + [ >hex-digit ] { } map-as concat 48 CHAR: \s pad-right ; + +: >ascii ( bytes -- str ) + [ [ printable? ] keep CHAR: . ? ] "" map-as ; + +: write-hex-line ( bytes lineno -- ) + write-offset [ >hex-digits write ] [ >ascii write ] bi nl ; + +PRIVATE> + +: hexdump. ( seq -- ) + [ length write-header ] + [ 16 [ write-hex-line ] each-index ] bi ; + +: hexdump ( seq -- str ) + [ hexdump. ] with-string-writer ; diff --git a/basis/tools/hexdump/summary.txt b/basis/tools/hexdump/summary.txt new file mode 100644 index 0000000000..d860bd7f84 --- /dev/null +++ b/basis/tools/hexdump/summary.txt @@ -0,0 +1 @@ +Prints formatted hex dump of an arbitrary sequence From 47124b8aaa11508d2b4ba8d97d0d353f268b8468 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 13 Nov 2008 19:49:34 -0600 Subject: [PATCH 05/11] finish moving hexdump to tools.hexdump --- basis/tools/hexdump/hexdump-docs.factor | 2 +- basis/tools/hexdump/hexdump-tests.factor | 2 +- extra/ftp/server/server.factor | 2 +- extra/hexdump/authors.txt | 1 - extra/hexdump/hexdump-docs.factor | 22 --------------- extra/hexdump/hexdump-tests.factor | 11 -------- extra/hexdump/hexdump.factor | 36 ------------------------ extra/hexdump/summary.txt | 1 - extra/tar/tar.factor | 2 +- 9 files changed, 4 insertions(+), 75 deletions(-) delete mode 100644 extra/hexdump/authors.txt delete mode 100644 extra/hexdump/hexdump-docs.factor delete mode 100644 extra/hexdump/hexdump-tests.factor delete mode 100644 extra/hexdump/hexdump.factor delete mode 100644 extra/hexdump/summary.txt diff --git a/basis/tools/hexdump/hexdump-docs.factor b/basis/tools/hexdump/hexdump-docs.factor index 4278e92f0e..b24cc8ae33 100644 --- a/basis/tools/hexdump/hexdump-docs.factor +++ b/basis/tools/hexdump/hexdump-docs.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: help.markup help.syntax kernel sequences strings ; -IN: hexdump +IN: tools.hexdump HELP: hexdump. { $values { "seq" sequence } } diff --git a/basis/tools/hexdump/hexdump-tests.factor b/basis/tools/hexdump/hexdump-tests.factor index b3c03196f5..1a638a8586 100644 --- a/basis/tools/hexdump/hexdump-tests.factor +++ b/basis/tools/hexdump/hexdump-tests.factor @@ -1,5 +1,5 @@ -IN: hexdump.tests USING: hexdump kernel sequences tools.test ; +IN: tools.hexdump.tests [ t ] [ "" hexdump "Length: 0, 0h\n" = ] unit-test [ t ] [ "abcdefghijklmnopqrstuvwxyz" hexdump "Length: 26, 1ah\n00000000h: 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 abcdefghijklmnop\n00000010h: 71 72 73 74 75 76 77 78 79 7a qrstuvwxyz\n" = ] unit-test diff --git a/extra/ftp/server/server.factor b/extra/ftp/server/server.factor index 969ec17224..e40af2afbe 100644 --- a/extra/ftp/server/server.factor +++ b/extra/ftp/server/server.factor @@ -7,7 +7,7 @@ namespaces make sequences ftp io.unix.launcher.parser unicode.case splitting assocs classes io.servers.connection destructors calendar io.timeouts io.streams.duplex threads continuations math concurrency.promises byte-arrays -io.backend sequences.lib hexdump ; +io.backend sequences.lib tools.hexdump ; IN: ftp.server SYMBOL: client diff --git a/extra/hexdump/authors.txt b/extra/hexdump/authors.txt deleted file mode 100644 index 7c1b2f2279..0000000000 --- a/extra/hexdump/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Doug Coleman diff --git a/extra/hexdump/hexdump-docs.factor b/extra/hexdump/hexdump-docs.factor deleted file mode 100644 index 4278e92f0e..0000000000 --- a/extra/hexdump/hexdump-docs.factor +++ /dev/null @@ -1,22 +0,0 @@ -! Copyright (C) 2008 Doug Coleman. -! See http://factorcode.org/license.txt for BSD license. -USING: help.markup help.syntax kernel sequences strings ; -IN: hexdump - -HELP: hexdump. -{ $values { "seq" sequence } } -{ $description "Converts a sequence to its hexadecimal and ASCII representation sixteen characters at a time and writes it to standard out." } ; - -HELP: hexdump -{ $values { "seq" sequence } { "str" string } } -{ $description "Converts a sequence to its hexadecimal and ASCII representation sixteen characters at a time. Lines are separated by a newline character." } -{ $see-also hexdump. } ; - -ARTICLE: "hexdump" "Hexdump" -"The " { $vocab-link "hexdump" } " vocabulary provides a traditional hexdump view of a sequence." $nl -"Write hexdump to string:" -{ $subsection hexdump } -"Write the hexdump to the output stream:" -{ $subsection hexdump. } ; - -ABOUT: "hexdump" diff --git a/extra/hexdump/hexdump-tests.factor b/extra/hexdump/hexdump-tests.factor deleted file mode 100644 index b3c03196f5..0000000000 --- a/extra/hexdump/hexdump-tests.factor +++ /dev/null @@ -1,11 +0,0 @@ -IN: hexdump.tests -USING: hexdump kernel sequences tools.test ; - -[ t ] [ "" hexdump "Length: 0, 0h\n" = ] unit-test -[ t ] [ "abcdefghijklmnopqrstuvwxyz" hexdump "Length: 26, 1ah\n00000000h: 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 abcdefghijklmnop\n00000010h: 71 72 73 74 75 76 77 78 79 7a qrstuvwxyz\n" = ] unit-test - -[ t ] [ 256 [ ] map hexdump "Length: 256, 100h\n00000000h: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................\n00000010h: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................\n00000020h: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./\n00000030h: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?\n00000040h: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO\n00000050h: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[\\]^_\n00000060h: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno\n00000070h: 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.\n00000080h: 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f ................\n00000090h: 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f ................\n000000a0h: a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af ................\n000000b0h: b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf ................\n000000c0h: c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf ................\n000000d0h: d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df ................\n000000e0h: e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef ................\n000000f0h: f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff ................\n" = ] unit-test - - -[ - "Length: 3, 3h\n00000000h: 01 02 03 ...\n" ] [ B{ 1 2 3 } hexdump ] unit-test diff --git a/extra/hexdump/hexdump.factor b/extra/hexdump/hexdump.factor deleted file mode 100644 index ecbc2d6169..0000000000 --- a/extra/hexdump/hexdump.factor +++ /dev/null @@ -1,36 +0,0 @@ -! Copyright (C) 2008 Doug Coleman. -! See http://factorcode.org/license.txt for BSD license. -USING: arrays io io.streams.string kernel math math.parser -namespaces sequences splitting grouping strings ascii ; -IN: hexdump - -string write ", " write ] - [ >hex write "h" write nl ] bi ; - -: write-offset ( lineno -- ) - 16 * >hex 8 CHAR: 0 pad-left write "h: " write ; - -: >hex-digit ( digit -- str ) - >hex 2 CHAR: 0 pad-left " " append ; - -: >hex-digits ( bytes -- str ) - [ >hex-digit ] { } map-as concat 48 CHAR: \s pad-right ; - -: >ascii ( bytes -- str ) - [ [ printable? ] keep CHAR: . ? ] "" map-as ; - -: write-hex-line ( bytes lineno -- ) - write-offset [ >hex-digits write ] [ >ascii write ] bi nl ; - -PRIVATE> - -: hexdump. ( seq -- ) - [ length write-header ] - [ 16 [ write-hex-line ] each-index ] bi ; - -: hexdump ( seq -- str ) - [ hexdump. ] with-string-writer ; diff --git a/extra/hexdump/summary.txt b/extra/hexdump/summary.txt deleted file mode 100644 index d860bd7f84..0000000000 --- a/extra/hexdump/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Prints formatted hex dump of an arbitrary sequence diff --git a/extra/tar/tar.factor b/extra/tar/tar.factor index 286ac0183a..e3c14854d3 100755 --- a/extra/tar/tar.factor +++ b/extra/tar/tar.factor @@ -1,6 +1,6 @@ USING: combinators io io.files io.streams.string kernel math math.parser continuations namespaces pack prettyprint sequences -strings system hexdump io.encodings.binary summary accessors +strings system tools.hexdump io.encodings.binary summary accessors io.backend symbols byte-arrays ; IN: tar From 7a58500b0125b3e4bf108314a40c8949f800c7ce Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 13 Nov 2008 21:06:41 -0600 Subject: [PATCH 06/11] fix docs for hexdump --- basis/tools/hexdump/hexdump-docs.factor | 6 +++--- basis/tools/hexdump/hexdump-tests.factor | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/basis/tools/hexdump/hexdump-docs.factor b/basis/tools/hexdump/hexdump-docs.factor index b24cc8ae33..9579fb7f81 100644 --- a/basis/tools/hexdump/hexdump-docs.factor +++ b/basis/tools/hexdump/hexdump-docs.factor @@ -12,11 +12,11 @@ HELP: hexdump { $description "Converts a sequence to its hexadecimal and ASCII representation sixteen characters at a time. Lines are separated by a newline character." } { $see-also hexdump. } ; -ARTICLE: "hexdump" "Hexdump" -"The " { $vocab-link "hexdump" } " vocabulary provides a traditional hexdump view of a sequence." $nl +ARTICLE: "tools.hexdump" "Hexdump" +"The " { $vocab-link "tools.hexdump" } " vocabulary provides a traditional hexdump view of a sequence." $nl "Write hexdump to string:" { $subsection hexdump } "Write the hexdump to the output stream:" { $subsection hexdump. } ; -ABOUT: "hexdump" +ABOUT: "tools.hexdump" diff --git a/basis/tools/hexdump/hexdump-tests.factor b/basis/tools/hexdump/hexdump-tests.factor index 1a638a8586..7202e4402c 100644 --- a/basis/tools/hexdump/hexdump-tests.factor +++ b/basis/tools/hexdump/hexdump-tests.factor @@ -1,4 +1,4 @@ -USING: hexdump kernel sequences tools.test ; +USING: tools.hexdump kernel sequences tools.test ; IN: tools.hexdump.tests [ t ] [ "" hexdump "Length: 0, 0h\n" = ] unit-test From 5f6421af5d26ff14e5179898d1ad54b34962edbe Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 14 Nov 2008 00:03:24 -0600 Subject: [PATCH 07/11] use win32-file-attributes word --- basis/io/windows/files/files.factor | 43 ++++++++++++++++------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/basis/io/windows/files/files.factor b/basis/io/windows/files/files.factor index e3b96b98d8..d0409ce59a 100755 --- a/basis/io/windows/files/files.factor +++ b/basis/io/windows/files/files.factor @@ -149,35 +149,39 @@ SYMBOLS: +read-only+ +hidden+ +system+ +sparse-file+ +reparse-point+ +compressed+ +offline+ +not-content-indexed+ +encrypted+ ; -: win32-file-attribute ( n attr symbol -- n ) - >r dupd mask? r> swap [ , ] [ drop ] if ; +TUPLE: windows-file-info < file-info attributes ; + +: win32-file-attribute ( n attr symbol -- ) + rot mask? [ , ] [ drop ] if ; : win32-file-attributes ( n -- seq ) [ - FILE_ATTRIBUTE_READONLY +read-only+ win32-file-attribute - FILE_ATTRIBUTE_HIDDEN +hidden+ win32-file-attribute - FILE_ATTRIBUTE_SYSTEM +system+ win32-file-attribute - FILE_ATTRIBUTE_DIRECTORY +directory+ win32-file-attribute - FILE_ATTRIBUTE_ARCHIVE +archive+ win32-file-attribute - FILE_ATTRIBUTE_DEVICE +device+ win32-file-attribute - FILE_ATTRIBUTE_NORMAL +normal+ win32-file-attribute - FILE_ATTRIBUTE_TEMPORARY +temporary+ win32-file-attribute - FILE_ATTRIBUTE_SPARSE_FILE +sparse-file+ win32-file-attribute - FILE_ATTRIBUTE_REPARSE_POINT +reparse-point+ win32-file-attribute - FILE_ATTRIBUTE_COMPRESSED +compressed+ win32-file-attribute - FILE_ATTRIBUTE_OFFLINE +offline+ win32-file-attribute - FILE_ATTRIBUTE_NOT_CONTENT_INDEXED +not-content-indexed+ win32-file-attribute - FILE_ATTRIBUTE_ENCRYPTED +encrypted+ win32-file-attribute - drop + { + [ +read-only+ FILE_ATTRIBUTE_READONLY win32-file-attribute ] + [ +hidden+ FILE_ATTRIBUTE_HIDDEN win32-file-attribute ] + [ +system+ FILE_ATTRIBUTE_SYSTEM win32-file-attribute ] + [ +directory+ FILE_ATTRIBUTE_DIRECTORY win32-file-attribute ] + [ +archive+ FILE_ATTRIBUTE_ARCHIVE win32-file-attribute ] + [ +device+ FILE_ATTRIBUTE_DEVICE win32-file-attribute ] + [ +normal+ FILE_ATTRIBUTE_NORMAL win32-file-attribute ] + [ +temporary+ FILE_ATTRIBUTE_TEMPORARY win32-file-attribute ] + [ +sparse-file+ FILE_ATTRIBUTE_SPARSE_FILE win32-file-attribute ] + [ +reparse-point+ FILE_ATTRIBUTE_REPARSE_POINT win32-file-attribute ] + [ +compressed+ FILE_ATTRIBUTE_COMPRESSED win32-file-attribute ] + [ +offline+ FILE_ATTRIBUTE_OFFLINE win32-file-attribute ] + [ +not-content-indexed+ FILE_ATTRIBUTE_NOT_CONTENT_INDEXED win32-file-attribute ] + [ +encrypted+ FILE_ATTRIBUTE_ENCRYPTED win32-file-attribute ] + } cleave ] { } make ; : win32-file-type ( n -- symbol ) FILE_ATTRIBUTE_DIRECTORY mask? +directory+ +regular-file+ ? ; : WIN32_FIND_DATA>file-info ( WIN32_FIND_DATA -- file-info ) - [ \ file-info new ] dip + [ \ windows-file-info new ] dip { [ WIN32_FIND_DATA-dwFileAttributes win32-file-type >>type ] + [ WIN32_FIND_DATA-dwFileAttributes win32-file-attributes >>attributes ] [ [ WIN32_FIND_DATA-nFileSizeLow ] [ WIN32_FIND_DATA-nFileSizeHigh ] bi >64bit >>size @@ -196,9 +200,10 @@ SYMBOLS: +read-only+ +hidden+ +system+ ] keep ; : BY_HANDLE_FILE_INFORMATION>file-info ( HANDLE_FILE_INFORMATION -- file-info ) - [ \ file-info new ] dip + [ \ windows-file-info new ] dip { [ BY_HANDLE_FILE_INFORMATION-dwFileAttributes win32-file-type >>type ] + [ BY_HANDLE_FILE_INFORMATION-dwFileAttributes win32-file-attributes >>attributes ] [ [ BY_HANDLE_FILE_INFORMATION-nFileSizeLow ] [ BY_HANDLE_FILE_INFORMATION-nFileSizeHigh ] bi >64bit >>size From ba2d9bcd93e3249ebb99cfe82167a91b6812b2d4 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 14 Nov 2008 00:05:12 -0600 Subject: [PATCH 08/11] split list vocabulary into unix and windows sides --- extra/ls/ls.factor | 57 ++++++++++----------------------- extra/ls/unix/authors.txt | 1 + extra/ls/unix/tags.txt | 1 + extra/ls/unix/unix.factor | 41 ++++++++++++++++++++++++ extra/ls/windows/authors.txt | 1 + extra/ls/windows/tags.txt | 1 + extra/ls/windows/windows.factor | 20 ++++++++++++ 7 files changed, 82 insertions(+), 40 deletions(-) mode change 100644 => 100755 extra/ls/ls.factor create mode 100755 extra/ls/unix/authors.txt create mode 100644 extra/ls/unix/tags.txt create mode 100755 extra/ls/unix/unix.factor create mode 100755 extra/ls/windows/authors.txt create mode 100644 extra/ls/windows/tags.txt create mode 100755 extra/ls/windows/windows.factor diff --git a/extra/ls/ls.factor b/extra/ls/ls.factor old mode 100644 new mode 100755 index 3e21873fec..92aff714e6 --- a/extra/ls/ls.factor +++ b/extra/ls/ls.factor @@ -1,12 +1,10 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays assocs combinators generalizations -io.files io.unix.files math.parser sequences.lib calendar math -kernel sequences unix.groups unix.users combinators.cleave -strings combinators.short-circuit unicode.case ; -IN: ls +USING: accessors arrays combinators io io.files kernel +math.parser sequences system vocabs.loader calendar +sequences.lib ; -TUPLE: ls-info path user group size ; +IN: ls : ls-time ( timestamp -- string ) [ hour>> ] [ minute>> ] bi @@ -25,39 +23,18 @@ TUPLE: ls-info path user group size ; : write>string ( ? -- string ) "w" "-" ? ; inline -: execute-string ( str bools -- str' ) - swap { - { { t t } [ >lower ] } - { { t f } [ >upper ] } - { { f t } [ drop "x" ] } - [ 2drop "-" ] - } case ; +HOOK: execute>string os ( ? -- string ) -: permissions-string ( permissions -- str ) - { - [ type>> file-type>ch 1string ] - [ user-read? read>string ] - [ user-write? write>string ] - [ [ uid? ] [ user-execute? ] bi 2array "s" execute-string ] - [ group-read? read>string ] - [ group-write? write>string ] - [ [ gid? ] [ group-execute? ] bi 2array "s" execute-string ] - [ other-read? read>string ] - [ other-write? write>string ] - [ [ sticky? ] [ other-execute? ] bi 2array "t" execute-string ] - } concat ; +M: object execute>string ( ? -- string ) "x" "-" ? ; inline -: ls ( path -- lines ) - [ [ [ - "" directory-files [ - dup file-info - { - [ permissions-string ] - [ nlink>> number>string 3 CHAR: \s pad-left ] - ! [ uid>> ] - ! [ gid>> ] - [ size>> number>string 15 CHAR: \s pad-left ] - [ modified>> ls-timestamp ] - } swap suffix " " join - ] map - ] with-group-cache ] with-user-cache ] with-directory ; +HOOK: permissions-string os ( -- str ) + +HOOK: (directory.) os ( path -- lines ) + +: directory. ( path -- ) + [ (directory.) ] with-directory-files [ print ] each ; + +{ + { [ os unix? ] [ "ls.unix" ] } + { [ os windows? ] [ "ls.windows" ] } +} cond require \ No newline at end of file diff --git a/extra/ls/unix/authors.txt b/extra/ls/unix/authors.txt new file mode 100755 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/ls/unix/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/ls/unix/tags.txt b/extra/ls/unix/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/extra/ls/unix/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/extra/ls/unix/unix.factor b/extra/ls/unix/unix.factor new file mode 100755 index 0000000000..9a3f832961 --- /dev/null +++ b/extra/ls/unix/unix.factor @@ -0,0 +1,41 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors combinators combinators.cleave kernel system unicode.case +io.unix.files ls ; +IN: ls.unix + +M: unix execute-string ( str bools -- str' ) + swap { + { { t t } [ >lower ] } + { { t f } [ >upper ] } + { { f t } [ drop "x" ] } + [ 2drop "-" ] + } case ; + +M: unix permissions-string ( permissions -- str ) + { + [ type>> file-type>ch 1string ] + [ user-read? read>string ] + [ user-write? write>string ] + [ [ uid? ] [ user-execute? ] bi 2array "s" execute-string ] + [ group-read? read>string ] + [ group-write? write>string ] + [ [ gid? ] [ group-execute? ] bi 2array "s" execute-string ] + [ other-read? read>string ] + [ other-write? write>string ] + [ [ sticky? ] [ other-execute? ] bi 2array "t" execute-string ] + } concat ; + +M: unix ls ( path -- lines ) + [ [ + dup file-info + { + [ permissions-string ] + [ nlink>> number>string 3 CHAR: \s pad-left ] + ! [ uid>> ] + ! [ gid>> ] + [ size>> number>string 15 CHAR: \s pad-left ] + [ modified>> ls-timestamp ] + } swap suffix " " join + ] map + ] with-group-cache ] with-user-cache ; \ No newline at end of file diff --git a/extra/ls/windows/authors.txt b/extra/ls/windows/authors.txt new file mode 100755 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/ls/windows/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/ls/windows/tags.txt b/extra/ls/windows/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/extra/ls/windows/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/extra/ls/windows/windows.factor b/extra/ls/windows/windows.factor new file mode 100755 index 0000000000..b7d7eeeb0b --- /dev/null +++ b/extra/ls/windows/windows.factor @@ -0,0 +1,20 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors calendar.format combinators combinators.cleave +io.files kernel math.parser sequences splitting system ls sequences.lib ; +IN: ls.windows + +: directory-or-size ( file-info -- str ) + dup directory? [ + drop "" 20 CHAR: \s pad-right + ] [ + size>> number>string 20 CHAR: \s pad-left + ] if ; + +M: windows (directory.) ( entries -- lines ) + [ + dup file-info { + [ modified>> timestamp>ymdhms " " split1 " " splice ] + [ directory-or-size ] + } swap suffix " " join + ] map ; \ No newline at end of file From 739f02d7c0c6e4e3127be8ecc989b1e3564f53d7 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 14 Nov 2008 00:25:00 -0600 Subject: [PATCH 09/11] move ls to io.files.listing --- basis/io/files/listing/authors.txt | 1 + basis/io/files/listing/listing-tests.factor | 6 +++ basis/io/files/listing/listing.factor | 39 ++++++++++++++++++ basis/io/files/listing/tags.txt | 1 + basis/io/files/listing/unix/authors.txt | 1 + basis/io/files/listing/unix/tags.txt | 1 + basis/io/files/listing/unix/unix.factor | 41 +++++++++++++++++++ basis/io/files/listing/windows/authors.txt | 1 + basis/io/files/listing/windows/tags.txt | 1 + basis/io/files/listing/windows/windows.factor | 21 ++++++++++ 10 files changed, 113 insertions(+) create mode 100644 basis/io/files/listing/authors.txt create mode 100644 basis/io/files/listing/listing-tests.factor create mode 100755 basis/io/files/listing/listing.factor create mode 100644 basis/io/files/listing/tags.txt create mode 100755 basis/io/files/listing/unix/authors.txt create mode 100644 basis/io/files/listing/unix/tags.txt create mode 100755 basis/io/files/listing/unix/unix.factor create mode 100755 basis/io/files/listing/windows/authors.txt create mode 100644 basis/io/files/listing/windows/tags.txt create mode 100755 basis/io/files/listing/windows/windows.factor diff --git a/basis/io/files/listing/authors.txt b/basis/io/files/listing/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/basis/io/files/listing/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/basis/io/files/listing/listing-tests.factor b/basis/io/files/listing/listing-tests.factor new file mode 100644 index 0000000000..a2347c8db9 --- /dev/null +++ b/basis/io/files/listing/listing-tests.factor @@ -0,0 +1,6 @@ +! Copyright (C) 2008 Your name. +! See http://factorcode.org/license.txt for BSD license. +USING: tools.test io.files.listing strings kernel ; +IN: io.files.listing.tests + +[ ] [ "" directory. ] unit-test diff --git a/basis/io/files/listing/listing.factor b/basis/io/files/listing/listing.factor new file mode 100755 index 0000000000..314010b75d --- /dev/null +++ b/basis/io/files/listing/listing.factor @@ -0,0 +1,39 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors arrays combinators io io.files kernel +math.parser sequences system vocabs.loader calendar ; + +IN: io.files.listing + +: ls-time ( timestamp -- string ) + [ hour>> ] [ minute>> ] bi + [ number>string 2 CHAR: 0 pad-left ] bi@ ":" swap 3append ; + +: ls-timestamp ( timestamp -- string ) + [ month>> month-abbreviation ] + [ day>> number>string 2 CHAR: \s pad-left ] + [ + dup year>> dup now year>> = + [ drop ls-time ] [ nip number>string ] if + 5 CHAR: \s pad-left + ] tri 3array " " join ; + +: read>string ( ? -- string ) "r" "-" ? ; inline + +: write>string ( ? -- string ) "w" "-" ? ; inline + +HOOK: execute>string os ( ? -- string ) + +M: object execute>string ( ? -- string ) "x" "-" ? ; inline + +HOOK: permissions-string os ( -- str ) + +HOOK: (directory.) os ( path -- lines ) + +: directory. ( path -- ) + [ (directory.) ] with-directory-files [ print ] each ; + +{ + { [ os unix? ] [ "io.files.listing.unix" ] } + { [ os windows? ] [ "io.files.listing.windows" ] } +} cond require diff --git a/basis/io/files/listing/tags.txt b/basis/io/files/listing/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/io/files/listing/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/basis/io/files/listing/unix/authors.txt b/basis/io/files/listing/unix/authors.txt new file mode 100755 index 0000000000..7c1b2f2279 --- /dev/null +++ b/basis/io/files/listing/unix/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/basis/io/files/listing/unix/tags.txt b/basis/io/files/listing/unix/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/io/files/listing/unix/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/basis/io/files/listing/unix/unix.factor b/basis/io/files/listing/unix/unix.factor new file mode 100755 index 0000000000..c7f25f001b --- /dev/null +++ b/basis/io/files/listing/unix/unix.factor @@ -0,0 +1,41 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors combinators kernel system unicode.case +io.unix.files io.files.listing generalizations ; +IN: io.files.listing.unix + +M: unix execute-string ( str bools -- str' ) + swap { + { { t t } [ >lower ] } + { { t f } [ >upper ] } + { { f t } [ drop "x" ] } + [ 2drop "-" ] + } case ; + +M: unix permissions-string ( permissions -- str ) + { + [ type>> file-type>ch 1string ] + [ user-read? read>string ] + [ user-write? write>string ] + [ [ uid? ] [ user-execute? ] bi 2array "s" execute-string ] + [ group-read? read>string ] + [ group-write? write>string ] + [ [ gid? ] [ group-execute? ] bi 2array "s" execute-string ] + [ other-read? read>string ] + [ other-write? write>string ] + [ [ sticky? ] [ other-execute? ] bi 2array "t" execute-string ] + } cleave 10 narray concat ; + +M: unix ls ( path -- lines ) + [ [ + dup file-info + { + [ permissions-string ] + [ nlink>> number>string 3 CHAR: \s pad-left ] + ! [ uid>> ] + ! [ gid>> ] + [ size>> number>string 15 CHAR: \s pad-left ] + [ modified>> ls-timestamp ] + } cleave 4 narray swap suffix " " join + ] map + ] with-group-cache ] with-user-cache ; diff --git a/basis/io/files/listing/windows/authors.txt b/basis/io/files/listing/windows/authors.txt new file mode 100755 index 0000000000..7c1b2f2279 --- /dev/null +++ b/basis/io/files/listing/windows/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/basis/io/files/listing/windows/tags.txt b/basis/io/files/listing/windows/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/io/files/listing/windows/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/basis/io/files/listing/windows/windows.factor b/basis/io/files/listing/windows/windows.factor new file mode 100755 index 0000000000..53481fc7f8 --- /dev/null +++ b/basis/io/files/listing/windows/windows.factor @@ -0,0 +1,21 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors calendar.format combinators io.files +kernel math.parser sequences splitting system io.files.listing +generalizations ; +IN: io.files.listing.windows + +: directory-or-size ( file-info -- str ) + dup directory? [ + drop "" 20 CHAR: \s pad-right + ] [ + size>> number>string 20 CHAR: \s pad-left + ] if ; + +M: windows (directory.) ( entries -- lines ) + [ + dup file-info { + [ modified>> timestamp>ymdhms ] + [ directory-or-size ] + } cleave 2 narray swap suffix " " join + ] map ; From bc97c989c9ca0f7708f494f4f779b0a9bd6cbf22 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 14 Nov 2008 00:37:56 -0600 Subject: [PATCH 10/11] remove ls --- extra/ls/authors.txt | 1 - extra/ls/ls-tests.factor | 6 ----- extra/ls/ls.factor | 40 -------------------------------- extra/ls/tags.txt | 1 - extra/ls/unix/authors.txt | 1 - extra/ls/unix/tags.txt | 1 - extra/ls/unix/unix.factor | 41 --------------------------------- extra/ls/windows/authors.txt | 1 - extra/ls/windows/tags.txt | 1 - extra/ls/windows/windows.factor | 20 ---------------- 10 files changed, 113 deletions(-) delete mode 100644 extra/ls/authors.txt delete mode 100644 extra/ls/ls-tests.factor delete mode 100755 extra/ls/ls.factor delete mode 100644 extra/ls/tags.txt delete mode 100755 extra/ls/unix/authors.txt delete mode 100644 extra/ls/unix/tags.txt delete mode 100755 extra/ls/unix/unix.factor delete mode 100755 extra/ls/windows/authors.txt delete mode 100644 extra/ls/windows/tags.txt delete mode 100755 extra/ls/windows/windows.factor diff --git a/extra/ls/authors.txt b/extra/ls/authors.txt deleted file mode 100644 index 7c1b2f2279..0000000000 --- a/extra/ls/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Doug Coleman diff --git a/extra/ls/ls-tests.factor b/extra/ls/ls-tests.factor deleted file mode 100644 index b1c1f18472..0000000000 --- a/extra/ls/ls-tests.factor +++ /dev/null @@ -1,6 +0,0 @@ -! Copyright (C) 2008 Your name. -! See http://factorcode.org/license.txt for BSD license. -USING: tools.test ls strings kernel ; -IN: ls.tests - -[ ] [ "" ls drop ] unit-test diff --git a/extra/ls/ls.factor b/extra/ls/ls.factor deleted file mode 100755 index 92aff714e6..0000000000 --- a/extra/ls/ls.factor +++ /dev/null @@ -1,40 +0,0 @@ -! Copyright (C) 2008 Doug Coleman. -! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays combinators io io.files kernel -math.parser sequences system vocabs.loader calendar -sequences.lib ; - -IN: ls - -: ls-time ( timestamp -- string ) - [ hour>> ] [ minute>> ] bi - [ number>string 2 CHAR: 0 pad-left ] bi@ ":" splice ; - -: ls-timestamp ( timestamp -- string ) - [ month>> month-abbreviation ] - [ day>> number>string 2 CHAR: \s pad-left ] - [ - dup year>> dup now year>> = - [ drop ls-time ] [ nip number>string ] if - 5 CHAR: \s pad-left - ] tri 3array " " join ; - -: read>string ( ? -- string ) "r" "-" ? ; inline - -: write>string ( ? -- string ) "w" "-" ? ; inline - -HOOK: execute>string os ( ? -- string ) - -M: object execute>string ( ? -- string ) "x" "-" ? ; inline - -HOOK: permissions-string os ( -- str ) - -HOOK: (directory.) os ( path -- lines ) - -: directory. ( path -- ) - [ (directory.) ] with-directory-files [ print ] each ; - -{ - { [ os unix? ] [ "ls.unix" ] } - { [ os windows? ] [ "ls.windows" ] } -} cond require \ No newline at end of file diff --git a/extra/ls/tags.txt b/extra/ls/tags.txt deleted file mode 100644 index 6bf68304bb..0000000000 --- a/extra/ls/tags.txt +++ /dev/null @@ -1 +0,0 @@ -unportable diff --git a/extra/ls/unix/authors.txt b/extra/ls/unix/authors.txt deleted file mode 100755 index 7c1b2f2279..0000000000 --- a/extra/ls/unix/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Doug Coleman diff --git a/extra/ls/unix/tags.txt b/extra/ls/unix/tags.txt deleted file mode 100644 index 6bf68304bb..0000000000 --- a/extra/ls/unix/tags.txt +++ /dev/null @@ -1 +0,0 @@ -unportable diff --git a/extra/ls/unix/unix.factor b/extra/ls/unix/unix.factor deleted file mode 100755 index 9a3f832961..0000000000 --- a/extra/ls/unix/unix.factor +++ /dev/null @@ -1,41 +0,0 @@ -! Copyright (C) 2008 Doug Coleman. -! See http://factorcode.org/license.txt for BSD license. -USING: accessors combinators combinators.cleave kernel system unicode.case -io.unix.files ls ; -IN: ls.unix - -M: unix execute-string ( str bools -- str' ) - swap { - { { t t } [ >lower ] } - { { t f } [ >upper ] } - { { f t } [ drop "x" ] } - [ 2drop "-" ] - } case ; - -M: unix permissions-string ( permissions -- str ) - { - [ type>> file-type>ch 1string ] - [ user-read? read>string ] - [ user-write? write>string ] - [ [ uid? ] [ user-execute? ] bi 2array "s" execute-string ] - [ group-read? read>string ] - [ group-write? write>string ] - [ [ gid? ] [ group-execute? ] bi 2array "s" execute-string ] - [ other-read? read>string ] - [ other-write? write>string ] - [ [ sticky? ] [ other-execute? ] bi 2array "t" execute-string ] - } concat ; - -M: unix ls ( path -- lines ) - [ [ - dup file-info - { - [ permissions-string ] - [ nlink>> number>string 3 CHAR: \s pad-left ] - ! [ uid>> ] - ! [ gid>> ] - [ size>> number>string 15 CHAR: \s pad-left ] - [ modified>> ls-timestamp ] - } swap suffix " " join - ] map - ] with-group-cache ] with-user-cache ; \ No newline at end of file diff --git a/extra/ls/windows/authors.txt b/extra/ls/windows/authors.txt deleted file mode 100755 index 7c1b2f2279..0000000000 --- a/extra/ls/windows/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Doug Coleman diff --git a/extra/ls/windows/tags.txt b/extra/ls/windows/tags.txt deleted file mode 100644 index 6bf68304bb..0000000000 --- a/extra/ls/windows/tags.txt +++ /dev/null @@ -1 +0,0 @@ -unportable diff --git a/extra/ls/windows/windows.factor b/extra/ls/windows/windows.factor deleted file mode 100755 index b7d7eeeb0b..0000000000 --- a/extra/ls/windows/windows.factor +++ /dev/null @@ -1,20 +0,0 @@ -! Copyright (C) 2008 Doug Coleman. -! See http://factorcode.org/license.txt for BSD license. -USING: accessors calendar.format combinators combinators.cleave -io.files kernel math.parser sequences splitting system ls sequences.lib ; -IN: ls.windows - -: directory-or-size ( file-info -- str ) - dup directory? [ - drop "" 20 CHAR: \s pad-right - ] [ - size>> number>string 20 CHAR: \s pad-left - ] if ; - -M: windows (directory.) ( entries -- lines ) - [ - dup file-info { - [ modified>> timestamp>ymdhms " " split1 " " splice ] - [ directory-or-size ] - } swap suffix " " join - ] map ; \ No newline at end of file From 867669f208c2ab155692e345efc78c8092dc7adc Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 14 Nov 2008 00:44:01 -0600 Subject: [PATCH 11/11] fix listing on unix --- basis/io/files/listing/listing.factor | 6 +----- basis/io/files/listing/unix/unix.factor | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/basis/io/files/listing/listing.factor b/basis/io/files/listing/listing.factor index 314010b75d..a740b2b7be 100755 --- a/basis/io/files/listing/listing.factor +++ b/basis/io/files/listing/listing.factor @@ -22,11 +22,7 @@ IN: io.files.listing : write>string ( ? -- string ) "w" "-" ? ; inline -HOOK: execute>string os ( ? -- string ) - -M: object execute>string ( ? -- string ) "x" "-" ? ; inline - -HOOK: permissions-string os ( -- str ) +: execute>string ( ? -- string ) "x" "-" ? ; inline HOOK: (directory.) os ( path -- lines ) diff --git a/basis/io/files/listing/unix/unix.factor b/basis/io/files/listing/unix/unix.factor index c7f25f001b..f024b1238e 100755 --- a/basis/io/files/listing/unix/unix.factor +++ b/basis/io/files/listing/unix/unix.factor @@ -1,10 +1,11 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors combinators kernel system unicode.case -io.unix.files io.files.listing generalizations ; +io.unix.files io.files.listing generalizations strings +arrays sequences io.files math.parser unix.groups unix.users ; IN: io.files.listing.unix -M: unix execute-string ( str bools -- str' ) +: unix-execute>string ( str bools -- str' ) swap { { { t t } [ >lower ] } { { t f } [ >upper ] } @@ -12,22 +13,23 @@ M: unix execute-string ( str bools -- str' ) [ 2drop "-" ] } case ; -M: unix permissions-string ( permissions -- str ) +: permissions-string ( permissions -- str ) { [ type>> file-type>ch 1string ] [ user-read? read>string ] [ user-write? write>string ] - [ [ uid? ] [ user-execute? ] bi 2array "s" execute-string ] + [ [ uid? ] [ user-execute? ] bi 2array "s" unix-execute>string ] [ group-read? read>string ] [ group-write? write>string ] - [ [ gid? ] [ group-execute? ] bi 2array "s" execute-string ] + [ [ gid? ] [ group-execute? ] bi 2array "s" unix-execute>string ] [ other-read? read>string ] [ other-write? write>string ] - [ [ sticky? ] [ other-execute? ] bi 2array "t" execute-string ] + [ [ sticky? ] [ other-execute? ] bi 2array "t" unix-execute>string ] } cleave 10 narray concat ; -M: unix ls ( path -- lines ) - [ [ +M: unix (directory.) ( path -- lines ) + [ [ + [ dup file-info { [ permissions-string ]