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 / longest.icn < prev    next >
Text File  |  2000-07-29  |  1KB  |  44 lines

  1. ############################################################################
  2. #
  3. #    File:     longest.icn
  4. #
  5. #    Subject:  Program to write longest line in a file
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     November 25, 1992
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program writes the (last) longest line in the input file.  If the
  18. #  command-line option -# is given, the number of the longest line is
  19. #  written first.
  20. #
  21. ############################################################################
  22.  
  23. procedure main(argl)
  24.    local longest, max, count, countl, number, line
  25.  
  26.    if argl[1] == "-#" then number := 1
  27.  
  28.    count := 0
  29.    max := -1
  30.  
  31.    every line := !&input do {
  32.       count +:= 1
  33.       if *line >= max then {
  34.          max := *line
  35.          longest := line
  36.          countl := count
  37.          }
  38.       }
  39.  
  40.    if \number then write(countl)
  41.    write(longest)
  42.  
  43. end
  44.