summaryrefslogtreecommitdiff
path: root/ipl/progs/textcnt.icn
blob: 48f0bf603d501332d47c045e967f605a45ce0aae (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
############################################################################
#
#	File:     textcnt.icn
#
#	Subject:  Program to tabulate properties of text file
#
#	Author:   Ralph E. Griswold
#
#	Date:     May 2, 2001
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#     This program tabulates the number of characters, "words", and
#  lines in standard input and gives the maximum and minimum line length.
#  
############################################################################

procedure main()
   local chars, words, lines, name, infile, max, min, line

   chars := words := lines := 0
   max := 0
   min := 2 ^ 30			# larger than possible line length
   
     while line := read(infile) do {
        max <:= *line
        min >:= *line
        lines +:= 1
        chars +:= *line + 1
        line ? while tab(upto(&letters)) do {
           words +:= 1
           tab(many(&letters))
           }
        }
   
     if min = 2 ^ 30 then
        write("empty file")
     else {
        write("number of lines:     ",right(lines,8))
        write("number of words:     ",right(words,8))
        write("number of characters:",right(chars,8))
        write()
        write("longest line:        ",right(max,8))
        write("shortest line:       ",right(min,8))
        }

end