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 / labels.icn < prev    next >
Text File  |  2000-07-29  |  5KB  |  161 lines

  1. ############################################################################
  2. #
  3. #    File:     labels.icn
  4. #
  5. #    Subject:  Program to format mailing labels
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     December 30, 1991
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #  
  17. #     This program produces labels using coded information taken
  18. #  from the input file.  In the input file, a line beginning with #
  19. #  is a label header.  Subsequent lines up to the next header or
  20. #  end-of-file are accumulated and output so as to be centered hor-
  21. #  izontally and vertically on label forms.  Lines beginning with *
  22. #  are treated as comments and are ignored.
  23. #  
  24. #  Options: The following options are available:
  25. #  
  26. #       -c n Print n copies of each label.
  27. #  
  28. #       -s s Select only those labels whose headers contain a char-
  29. #            acter in s.
  30. #  
  31. #       -t   Format for curved tape labels (the default is to format
  32. #            for rectangular mailing labels).
  33. #  
  34. #       -w n Limit line width to n characters. The default width is
  35. #            40.
  36. #  
  37. #       -l n Limit the number of printed lines per label to n. The
  38. #            default is 8.
  39. #  
  40. #       -d n Limit the depth of the label to n. The default is 9 for
  41. #            rectangular labels and 12 for tape labels (-t).
  42. #  
  43. #     Options are processed from left to right.  If the number of
  44. #  printed lines is set to a value that exceeds the depth of the
  45. #  label, the depth is set to the number of lines.  If the depth is
  46. #  set to a value that is less than the number of printed lines, the
  47. #  number of printed lines is set to the depth. Note that the order
  48. #  in which these options are specified may affect the results.
  49. #  
  50. #  Printing Labels: Label forms should be used with a pin-feed pla-
  51. #  ten.  For mailing labels, the carriage should be adjusted so that
  52. #  the first character is printed at the leftmost position on the
  53. #  label and so that the first line of the output is printed on the
  54. #  topmost line of the label.  For curved tape labels, some experi-
  55. #  mentation may be required to get the text positioned properly.
  56. #  
  57. #  Diagnostics: If the limits on line width or the number of lines
  58. #  per label are exceeded, a label with an error message is written
  59. #  to standard error output.
  60. #  
  61. ############################################################################
  62. #
  63. #  Links: options, io
  64. #
  65. ############################################################################
  66. #
  67. #  See also:  address.doc, adllist.icn, adlfiltr.icn, adlcount.icn,
  68. #          adlcheck.icn, zipsort.icn
  69. #
  70. ############################################################################
  71.  
  72. link options, io
  73.  
  74. global lsize, repet, llength, ldepth, opts, selectors
  75.  
  76. procedure main(args)
  77.    local y, i, line
  78.  
  79.    selectors := '#'
  80.    lsize := 9
  81.    ldepth := 8
  82.    llength := 40
  83.    repet := 1
  84.    i := 0
  85.    opts := options(args,"c+d+l+s:tw+")
  86.    selectors := cset(\opts["s"])
  87.    if \opts["t"] then {
  88.       lsize := 12
  89.       if ldepth > lsize then ldepth := lsize
  90.       }
  91.    llength := nonneg("w")
  92.    if ldepth := nonneg("l") then {
  93.       if lsize < ldepth then lsize := ldepth
  94.       }
  95.    if lsize := nonneg("d") then {
  96.       if ldepth > lsize then ldepth := lsize
  97.       }
  98.    repet := nonneg("c")
  99.  
  100.    while line := Read() do
  101.       line ? {
  102.          if any('#') & upto(selectors) then nextlbl()
  103.          }
  104.  
  105. end
  106.  
  107. #  Obtain next label
  108. #
  109. procedure nextlbl()
  110.    local label, max, line
  111.    label := [Read()]
  112.    max := 0
  113.    while line := Read() do {
  114.       if line[1] == "*" then next
  115.       if line[1] == "#" then {
  116.          PutBack(line)
  117.          break
  118.          }
  119.       put(label,line)
  120.       max <:= *line
  121.       if *label > ldepth then {
  122.          error(label[1],1)
  123.          return
  124.          }
  125.       if max > llength then {
  126.          error(label[1],2)
  127.          return
  128.          }
  129.       }
  130.    every 1 to repet do format(label,max)
  131. end
  132.  
  133. #  Format a label
  134. #
  135. procedure format(label,width)
  136.    local j, indent
  137.    indent := repl(" ",(llength - width) / 2)
  138.    j := lsize - *label
  139.    every 1 to j / 2 do write()
  140.    every write(indent,!label)
  141.    every 1 to (j + 1) / 2 do write()
  142. end
  143.  
  144. #  Issue label for an error
  145. #
  146. procedure error(name,type)
  147.    static badform
  148.    initial badform := list(lsize)
  149.    case type of {
  150.       1:  badform[3] := "     **** too many lines"
  151.       2:  badform[3] := "     **** line too long"
  152.       }
  153.    badform[1] := name
  154.    every write(&errout,!badform)
  155. end
  156.  
  157. procedure nonneg(s)
  158.    s := \opts[s] | fail
  159.    return 0 < integer(s) | stop("-",s," needs postive numeric parameter")
  160. end
  161.