2015-04-01 17:26:22 -04:00
|
|
|
! Copyright (C) 2010 John Benediktsson
|
|
|
|
! See http://factorcode.org/license.txt for BSD license
|
|
|
|
|
2018-08-01 17:25:25 -04:00
|
|
|
USING: command-line formatting fry io io.encodings
|
2018-08-01 15:52:33 -04:00
|
|
|
io.encodings.binary io.files kernel namespaces sequences ;
|
2015-04-01 17:26:22 -04:00
|
|
|
|
|
|
|
IN: tools.cat
|
|
|
|
|
|
|
|
: cat-stream ( -- )
|
2018-08-01 17:25:25 -04:00
|
|
|
input-stream get binary re-decode
|
|
|
|
output-stream get binary re-encode
|
2018-08-01 15:52:33 -04:00
|
|
|
'[ _ stream-write ] each-stream-block ;
|
2015-04-01 17:26:22 -04:00
|
|
|
|
|
|
|
: cat-file ( path -- )
|
|
|
|
dup exists? [
|
|
|
|
binary [ cat-stream ] with-file-reader
|
|
|
|
] [ "%s: not found\n" printf flush ] if ;
|
|
|
|
|
|
|
|
: cat-files ( paths -- )
|
2018-08-01 15:52:33 -04:00
|
|
|
[ dup "-" = [ drop cat-stream ] [ cat-file ] if ] each ;
|
2015-04-01 17:26:22 -04:00
|
|
|
|
|
|
|
: run-cat ( -- )
|
2018-08-01 15:52:33 -04:00
|
|
|
command-line get [ cat-stream ] [ cat-files ] if-empty ;
|
2015-04-01 17:26:22 -04:00
|
|
|
|
|
|
|
MAIN: run-cat
|