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 / adlcheck.icn next >
Text File  |  2000-07-29  |  3KB  |  106 lines

  1. ############################################################################
  2. #
  3. #    File:     adlcheck.icn
  4. #
  5. #    Subject:  Program to check for bad address list data
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     November 19, 1997
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #    This program checks address lists for correctness.
  18. #
  19. #    There are five options:
  20. #
  21. #    -s    Check state (U.S. labels only)
  22. #    -z    Check ZIP code (U.S. labels only)
  23. #    -c    Check country name (a very heuristic check)
  24. #    -a    Check all of the above
  25. #    -d    Report addresses that exceed "standard dimensions" for labels:
  26. #           40 character line length, 8 lines per entry
  27. #
  28. ############################################################################
  29. #
  30. #  See also: address.doc, adlcount.icn, adlfiltr.icn, adllist.icn,
  31. #     adlsort,icn, labels.icn
  32. #
  33. #  Links: adlutils, options
  34. #
  35. ############################################################################
  36.  
  37. link adlutils, options
  38.  
  39. procedure main(args)
  40.    local opts, choice, item, badchar, print, states, i, line, dim, add
  41.  
  42.    states := set(["AK", "AL", "AR", "AS", "AZ", "CA", "CO", "CT", "DC",
  43.       "DE", "FL", "FM", "GA", "GU", "HI", "IA", "ID", "IL", "IN", "KS",
  44.       "KY", "LA", "MA", "MD", "ME", "MH", "MI", "MN", "MO", "MP", "MS",
  45.       "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK",
  46.       "ON", "OR", "PA", "PR", "PW", "RI", "SC", "SD", "TN", "TX", "UT",
  47.       "VA", "VT", "WA", "WI", "WV", "WY"])
  48.  
  49.    print := ""
  50.  
  51.    badchar := ~&ucase -- ' .'        # very heuristic country name check
  52.  
  53.    opts := options(args,"acszd")
  54.    if \opts["a"] then {            # if -a, do all
  55.       opts["a"] := &null
  56.       every opts[!"csz"] := 1
  57.       }
  58.    if \opts["d"] then dim := write(1)        # dimension check
  59.  
  60.    while add := nextadd() do {
  61.       add.text ? {
  62.          i := 0
  63.          while line := tab(upto('\n') | 0) do {
  64.             i +:= 1
  65.             if *line > 40 then print ||:= "o"
  66.             move(1) | break
  67.             }
  68.          if i > 8 then print ||:= "o"
  69.          }
  70.  
  71.       every \opts[choice := !"csz"] do
  72.          case choice of {
  73.          "c":  {            # check country name
  74.             get_country(add) ? {
  75.                if upto(badchar) then {
  76.                   print ||:= choice
  77.                   }
  78.                }
  79.             }
  80.          "s":  {            # check state
  81.             if not member(states,get_state(add)) then {
  82.                print ||:= choice
  83.                }
  84.             }
  85.          "z":  {
  86.             if get_zipcode(add) == "9999999999" then {
  87.                print ||:= choice
  88.                }
  89.             }
  90.          }
  91.       if *print > 0 then {
  92.          every choice := !print do
  93.             write("*** ",case choice of {
  94.                "c":  "bad country name"
  95.                "s":  "bad state abbreviation"
  96.                "z":  "bad ZIP code"
  97.                "o":  \dim & "size exceeds label dimensions"
  98.                })
  99.          write()
  100.          writeadd(add)
  101.          print := ""
  102.          }
  103.    }
  104.  
  105. end
  106.