1 ! Copyright (C) 2016 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: alien.data command-line formatting io io.encodings
5 io.encodings.binary io.files kernel math math.bitwise
6 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* ;
36 binary [ count-lines ] with-file-reader ;
40 wc-stdin "%8d\n" printf
42 [ [ wc ] keep dupd "%8d %s\n" printf ] map
43 dup length 1 > [ sum "%8d total\n" printf ] [ drop ] if