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 / zipsort.icn < prev   
Text File  |  2000-07-29  |  2KB  |  69 lines

  1. ############################################################################
  2. #
  3. #    File:     zipsort.icn
  4. #
  5. #    Subject:  Program to sort mailing labels by ZIP code
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     November 17, 1994
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #  
  17. #     This program sorts labels produced by labels in ascending
  18. #  order of their postal zip codes.
  19. #  
  20. #  Option:
  21. #
  22. #     The option -d n sets the number of lines per label to n.
  23. #  The default is 9. This value must agree with the value used to
  24. #  format the labels.
  25. #  
  26. #  Zip Codes:
  27. #
  28. #     The zip code must be the last nonblank string at the
  29. #  end of the label.  It must consist of digits but may have an
  30. #  embedded dash for extended zip codes.  If a label does not end
  31. #  with a legal zip code, it is placed after all labels with legal
  32. #  zip codes.  In such a case, an error messages also is written to
  33. #  standard error output.
  34. #  
  35. ############################################################################
  36. #
  37. #  Links: options
  38. #
  39. #  See also: labels.icn
  40. #
  41. ############################################################################
  42.  
  43. link options
  44.  
  45. procedure main(args)
  46.    local t, a, label, zip, y, lsize, opts
  47.  
  48.    opts := options(args,"d+")
  49.    lsize := (0 < integer(opts["d"])) | 9
  50.  
  51.    t := table("")
  52.    repeat {
  53.       label := ""
  54.       every 1 to lsize do
  55.          label ||:= read() || "\n" | break break
  56.       label ? {
  57.          while tab(upto(' ')) do tab(many(' '))
  58.          zip := tab(upto('-') | 0)
  59.          zip := integer(zip) | write(&errout,"*** illegal zipcode:  ",label)
  60.          }
  61.       t[zip] ||:= label
  62.       }
  63.  
  64.    a := sort(t,3)
  65.    while get(a) do
  66.       writes(get(a))
  67.  
  68. end
  69.