home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / tablc.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  63 lines

  1. ############################################################################
  2. #
  3. #    File:     tablc.icn
  4. #
  5. #    Subject:  Program to tabulate characters in a file
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     June 10, 1988
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #  
  17. #     This program tabulates characters and lists each character and
  18. #  the number of times it occurs. Characters are written using
  19. #  Icon's escape conventions.  Line termination characters and other
  20. #  control characters are included in the tabulation.
  21. #  
  22. #  Options: The following options are available:
  23. #  
  24. #       -a   Write the summary in alphabetical order of the charac-
  25. #            ters. This is the default.
  26. #  
  27. #       -n   Write the summary in numerical order of the counts.
  28. #  
  29. #       -u   Write only the characters that occur just once.
  30. #  
  31. ############################################################################
  32. #
  33. #  Links: options
  34. #
  35. ############################################################################
  36.  
  37. link options
  38.  
  39. procedure main(args)
  40.    local ccount, unique, order, s, a, pair, rwidth, opts
  41.    unique := 0                # switch to list unique usage only
  42.    order := 3                # alphabetical ordering switch
  43.  
  44.    opts := options(args,"anu")
  45.    if \opts["a"] then order := 3
  46.    if \opts["n"] then order := 4
  47.    if \opts["u"] then unique := 1
  48.  
  49.    ccount := table(0)            # table of characters
  50.    while ccount[reads()] +:= 1
  51.    a := sort(ccount,order)
  52.    if unique = 1 then {
  53.       while s := get(a) do
  54.      if get(a) = 1 then write(s)
  55.       }
  56.    else {
  57.       rwidth := 0
  58.       every rwidth <:= *!a
  59.       while s := get(a) do
  60.          write(left(image(s),10),right(get(a),rwidth))
  61.       }
  62. end
  63.