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 / textcnt.icn < prev    next >
Text File  |  2001-05-02  |  1KB  |  52 lines

  1. ############################################################################
  2. #
  3. #    File:     textcnt.icn
  4. #
  5. #    Subject:  Program to tabulate properties of text file
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     May 2, 2001
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #     This program tabulates the number of characters, "words", and
  18. #  lines in standard input and gives the maximum and minimum line length.
  19. #  
  20. ############################################################################
  21.  
  22. procedure main()
  23.    local chars, words, lines, name, infile, max, min, line
  24.  
  25.    chars := words := lines := 0
  26.    max := 0
  27.    min := 2 ^ 30            # larger than possible line length
  28.    
  29.      while line := read(infile) do {
  30.         max <:= *line
  31.         min >:= *line
  32.         lines +:= 1
  33.         chars +:= *line + 1
  34.         line ? while tab(upto(&letters)) do {
  35.            words +:= 1
  36.            tab(many(&letters))
  37.            }
  38.         }
  39.    
  40.      if min = 2 ^ 30 then
  41.         write("empty file")
  42.      else {
  43.         write("number of lines:     ",right(lines,8))
  44.         write("number of words:     ",right(words,8))
  45.         write("number of characters:",right(chars,8))
  46.         write()
  47.         write("longest line:        ",right(max,8))
  48.         write("shortest line:       ",right(min,8))
  49.         }
  50.  
  51. end
  52.