summaryrefslogtreecommitdiff
path: root/ipl/progs/streamer.icn
blob: ae6e9d622ea02449c5e85a34b5c648a025df5896 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
############################################################################
#
#	File:     streamer.icn
#
#	Subject:  Program to append lines of file into one long line
#
#	Author:   Ralph E. Griswold
#
#	Date:     June 12, 1995
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This program outputs one long line obtained by concatenating the
#  lines of the input file.
#
#  The supported options are:
#
#	-l i	stop when line reaches or exceeds i; default no limit
#	-s s	insert s after each line; default no separator
#
#  Separators are counted in the length limit.
#
############################################################################
#
#  Links:  options
#
############################################################################

link options

procedure main(args)
   local opts, length, line, limit, sep, ssize

   opts := options(args, "l+s:")
   limit := opts["l"]
   sep := \opts["s"] | ""
   ssize := *sep

   length := 0

   while line := writes(read(), sep) do {
      length +:= *line + ssize
      if length >= \limit then break
      }

   write()

end