factor/extra/tools/cat/cat.factor

26 lines
679 B
Factor
Raw Permalink Normal View History

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
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
'[ _ 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 -- )
[ dup "-" = [ drop cat-stream ] [ cat-file ] if ] each ;
2015-04-01 17:26:22 -04:00
: run-cat ( -- )
command-line get [ cat-stream ] [ cat-files ] if-empty ;
2015-04-01 17:26:22 -04:00
MAIN: run-cat