]> gitweb.factorcode.org Git - factor.git/blob - extra/tools/cat/cat.factor
Switch to https urls
[factor.git] / extra / tools / cat / cat.factor
1 ! Copyright (C) 2010 John Benediktsson
2 ! See https://factorcode.org/license.txt for BSD license
3
4 USING: command-line io io.encodings io.encodings.binary io.files
5 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 ] [ stream-flush ] bi ] each-stream-block ;
13
14 : cat-file ( path -- )
15     dup file-exists? [
16         binary [ cat-stream ] with-file-reader
17     ] [ write ": not found" print flush ] if ;
18
19 : cat-files ( paths -- )
20     [ dup "-" = [ drop cat-stream ] [ cat-file ] if flush ] each ;
21
22 : run-cat ( -- )
23     command-line get [ cat-stream ] [ cat-files ] if-empty ;
24
25 MAIN: run-cat