summaryrefslogtreecommitdiff
path: root/ipl/progs/tablc.icn
blob: 96b2524aa5c4a99df70f68b4fc777c224ff362d2 (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
53
54
55
56
57
58
59
60
61
62
############################################################################
#
#	File:     tablc.icn
#
#	Subject:  Program to tabulate characters in a file
#
#	Author:   Ralph E. Griswold
#
#	Date:     June 10, 1988
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#  
#     This program tabulates characters and lists each character and
#  the number of times it occurs. Characters are written using
#  Icon's escape conventions.  Line termination characters and other
#  control characters are included in the tabulation.
#  
#  Options: The following options are available:
#  
#       -a   Write the summary in alphabetical order of the charac-
#            ters. This is the default.
#  
#       -n   Write the summary in numerical order of the counts.
#  
#       -u   Write only the characters that occur just once.
#  
############################################################################
#
#  Links: options
#
############################################################################

link options

procedure main(args)
   local ccount, unique, order, s, a, pair, rwidth, opts
   unique := 0				# switch to list unique usage only
   order := 3				# alphabetical ordering switch

   opts := options(args,"anu")
   if \opts["a"] then order := 3
   if \opts["n"] then order := 4
   if \opts["u"] then unique := 1

   ccount := table(0)			# table of characters
   while ccount[reads()] +:= 1
   a := sort(ccount,order)
   if unique = 1 then {
      while s := get(a) do
	 if get(a) = 1 then write(s)
      }
   else {
      rwidth := 0
      every rwidth <:= *!a
      while s := get(a) do
         write(left(image(s),10),right(get(a),rwidth))
      }
end