]> gitweb.factorcode.org Git - factor.git/blob - extra/tools/cat/cat.factor
0d9ac2927af12ada4bfd7baa33e2ff7c0d907d91
[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 kernel io io.encodings.binary
5 io.files namespaces sequences strings ;
6
7 IN: tools.cat
8
9 : cat-lines ( -- )
10     [ print flush ] each-line ;
11
12 : cat-stream ( -- )
13     [ >string write flush ] each-block ;
14
15 : cat-file ( path -- )
16     dup exists? [
17         binary [ cat-stream ] with-file-reader
18     ] [ "%s: not found\n" printf flush ] if ;
19
20 : cat-files ( paths -- )
21     [ dup "-" = [ drop cat-lines ] [ cat-file ] if ] each ;
22
23 : run-cat ( -- )
24     command-line get [ cat-lines ] [ cat-files ] if-empty ;
25
26 MAIN: run-cat
27