]> gitweb.factorcode.org Git - factor.git/blob - extra/tools/cat/cat.factor
factor: trim using lists
[factor.git] / extra / tools / cat / cat.factor
1 ! Copyright (C) 2010 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: command-line formatting io io.encodings
5 io.encodings.binary io.files kernel namespaces sequences ;
6
7 IN: tools.cat
8
9 : cat-stream ( -- )
10     input-stream get binary re-decode
11     output-stream get binary re-encode
12     '[ _ stream-write ] each-stream-block ;
13
14 : cat-file ( path -- )
15     dup file-exists? [
16         binary [ cat-stream ] with-file-reader
17     ] [ "%s: not found\n" printf flush ] if ;
18
19 : cat-files ( paths -- )
20     [ dup "-" = [ drop cat-stream ] [ cat-file ] if ] each ;
21
22 : run-cat ( -- )
23     command-line get [ cat-stream ] [ cat-files ] if-empty ;
24
25 MAIN: run-cat