]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/tools/cat/cat.factor
factor: trim using lists
[factor.git] / extra / tools / cat / cat.factor
index 0d9ac2927af12ada4bfd7baa33e2ff7c0d907d91..093872bec89eebc7831da0ea701c1cb197a82ec4 100644 (file)
@@ -1,27 +1,25 @@
 ! Copyright (C) 2010 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: command-line formatting kernel io io.encodings.binary
-io.files namespaces sequences strings ;
+USING: command-line formatting io io.encodings
+io.encodings.binary io.files kernel namespaces sequences ;
 
 IN: tools.cat
 
-: cat-lines ( -- )
-    [ print flush ] each-line ;
-
 : cat-stream ( -- )
-    [ >string write flush ] each-block ;
+    input-stream get binary re-decode
+    output-stream get binary re-encode
+    '[ _ stream-write ] each-stream-block ;
 
 : cat-file ( path -- )
-    dup exists? [
+    dup file-exists? [
         binary [ cat-stream ] with-file-reader
     ] [ "%s: not found\n" printf flush ] if ;
 
 : cat-files ( paths -- )
-    [ dup "-" = [ drop cat-lines ] [ cat-file ] if ] each ;
+    [ dup "-" = [ drop cat-stream ] [ cat-file ] if ] each ;
 
 : run-cat ( -- )
-    command-line get [ cat-lines ] [ cat-files ] if-empty ;
+    command-line get [ cat-stream ] [ cat-files ] if-empty ;
 
 MAIN: run-cat
-