1 ! Copyright (C) 2016 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: alien.data command-line io io.encodings
5 io.encodings.binary io.files kernel math math.bitwise
6 math.parser math.vectors math.vectors.simd namespaces sequences
9 SPECIALIZED-ARRAY: uchar-16
15 : aligned-slices ( seq -- head tail )
16 dup length 0xf unmask cut-slice ; inline
18 : count-characters ( -- n )
19 0 [ length + ] each-block-slice ; inline
21 : count-lines ( -- n )
24 uchar-16 cast-array swap
25 [ CHAR: \n uchar-16-with v= vcount + >fixnum ] reduce
26 ] [ [ CHAR: \n = ] count + >fixnum ] bi*
27 ] each-block-slice ; inline
30 input-stream get binary re-decode
31 [ count-lines ] with-input-stream* ;
33 : print-wc ( n name/f -- )
34 [ number>string 8 CHAR: \s pad-head write ]
35 [ bl [ write ] when* ] bi* nl ;
40 binary [ count-lines ] with-file-reader ;
48 [ wc ] keep dupd print-wc
50 write ": not found" print flush f
52 ] map sift dup length 1 > [ sum "total" print-wc ] [ drop ] if