]> gitweb.factorcode.org Git - factor.git/blob - extra/tools/file-to-directory/file-to-directory.factor
Switch to https urls
[factor.git] / extra / tools / file-to-directory / file-to-directory.factor
1 ! Copyright (C) 2018 Doug Coleman.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: base91 combinators command-line fry io.directories
4 io.encodings.binary io.encodings.utf8 io.files io.pathnames
5 kernel modern modern.out namespaces sequences splitting strings ;
6 IN: tools.file-to-directory
7
8 ERROR: expected-one-path got ;
9 ERROR: expected-modern-path got ;
10
11 : write-directory-files ( path -- )
12     [ ".modern" ?tail drop dup make-directories ]
13     [ path>literals ] bi
14     '[
15         _ first second rest [
16             dup first "DIRECTORY:" head?
17             [ second first second >string make-directories ]
18             [
19                 second first2
20                 [ second >string ] [
21                     first3 nip swap "base91" head? [
22                         base91> binary
23                     ] [
24                         utf8
25                     ] if
26                 ] bi* swapd
27                 [ dup parent-directory make-directories ] dip set-file-contents
28             ] if
29         ] each
30     ] with-directory ;
31
32 : get-file-to-directory-path ( array -- path )
33     dup length 1 = [ expected-one-path ] unless
34     first dup ".modern" tail? [ expected-modern-path ] unless ;
35
36 : file-to-directory ( -- )
37     command-line get get-file-to-directory-path write-directory-files ;
38
39 MAIN: file-to-directory