home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-05-09 | 1.7 KB | 62 lines | [TEXT/PICN] |
- ############################################################################
- #
- # characters.icn
- #
- # 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. The user is prompted
- # with as Get File dialog box. Files are processed until the user selects
- # Cancel.
- #
- # Options: The following options are available via the parameter string:
- #
- # -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: getopt
- #
- ############################################################################
-
- link getopt
-
- procedure main(args)
- local ccount, unique, order, s, a, pair, rwidth, opts, name, infile
-
- unique := 0 # switch to list unique usage only
- order := 3 # alphabetical ordering switch
-
- opts := getopt(args,"anu")[1]
- if \opts["a"] then order := 3
- if \opts["n"] then order := 4
- if \opts["u"] then unique := 1
-
- while name := getfile("File?") do {
- close(\infile)
- infile := open(name) | {
- write(&errout,"*** cannot open ",name)
- next
- }
-
- ccount := table(0) # table of characters
- while ccount[reads(infile)] +:= 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
-