1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors combinators io.files.types kernel math.parser
5 IN: ftp.client.listing-parser
7 : ch>file-type ( ch -- type )
9 { CHAR: b [ +block-device+ ] }
10 { CHAR: c [ +character-device+ ] }
11 { CHAR: d [ +directory+ ] }
12 { CHAR: l [ +symbolic-link+ ] }
13 { CHAR: s [ +socket+ ] }
14 { CHAR: p [ +fifo+ ] }
15 { CHAR: - [ +regular-file+ ] }
19 : file-type>ch ( type -- string )
21 { +block-device+ [ CHAR: b ] }
22 { +character-device+ [ CHAR: c ] }
23 { +directory+ [ CHAR: d ] }
24 { +symbolic-link+ [ CHAR: l ] }
25 { +socket+ [ CHAR: s ] }
26 { +fifo+ [ CHAR: p ] }
27 { +regular-file+ [ CHAR: - ] }
31 : parse-permissions ( remote-file str -- remote-file )
32 [ first ch>file-type >>type ] [ rest >>permissions ] bi ;
35 type permissions links owner group size month day time year
38 : <remote-file> ( -- remote-file ) remote-file new ;
40 : parse-list-11 ( lines -- seq )
44 [ 0 swap nth parse-permissions ]
45 [ 1 swap nth string>number >>links ]
46 [ 2 swap nth >>owner ]
47 [ 3 swap nth >>group ]
48 [ 4 swap nth string>number >>size ]
49 [ 5 swap nth >>month ]
53 [ 10 swap nth >>target ]
57 : parse-list-8 ( lines -- seq )
60 [ 0 swap nth parse-permissions ]
61 [ 1 swap nth string>number >>links ]
62 [ 2 swap nth >>owner ]
64 [ 4 swap nth >>month ]
71 : parse-list-3 ( lines -- seq )
74 [ 0 swap nth parse-permissions ]
75 [ 1 swap nth string>number >>links ]
80 : parse-list ( ftp-response -- ftp-response )
82 [ " " split harvest ] map
84 { 11 [ parse-list-11 ] }
85 { 9 [ parse-list-11 ] }
86 { 8 [ parse-list-8 ] }
87 { 3 [ parse-list-3 ] }