home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / sharew / exoten / icon / labels.icn < prev    next >
Encoding:
Text File  |  1990-03-08  |  4.6 KB  |  161 lines

  1. ############################################################################
  2. #
  3. #    Name:    labels.icn
  4. #
  5. #    Title:    Format mailing labels
  6. #
  7. #    Author:    Ralph E. Griswold
  8. #
  9. #    Date:    June 10, 1988
  10. #
  11. ############################################################################
  12. #  
  13. #     This program produces labels using coded information taken
  14. #  from the input file.  In the input file, a line beginning with #
  15. #  is a label header.  Subsequent lines up to the next header or
  16. #  end-of-file are accumulated and output so as to be centered hor-
  17. #  izontally and vertically on label forms.  Lines beginning with *
  18. #  are treated as comments and are ignored.
  19. #  
  20. #  Options: The following options are available:
  21. #  
  22. #       -c n Print n copies of each label.
  23. #  
  24. #       -s s Select only those labels whose headers contain a char-
  25. #            acter in s.
  26. #  
  27. #       -t   Format for curved tape labels (the default is to format
  28. #            for rectangular mailing labels).
  29. #  
  30. #       -w n Limit line width to n characters. The default width is
  31. #            40.
  32. #  
  33. #       -l n Limit the number of printed lines per label to n. The
  34. #            default is 8.
  35. #  
  36. #       -d n Limit the depth of the label to n. The default is 9 for
  37. #            rectangular labels and 12 for tape labels (-t).
  38. #  
  39. #       -f   Print the first line of each selected entry instead of
  40. #            labels.
  41. #  
  42. #     Options are processed from left to right.  If the number of
  43. #  printed lines is set to a value that exceeds the depth of the
  44. #  label, the depth is set to the number of lines.  If the depth is
  45. #  set to a value that is less than the number of printed lines, the
  46. #  number of printed lines is set to the depth. Note that the order
  47. #  in which these options are specified may affect the results.
  48. #  
  49. #  Printing Labels: Label forms should be used with a pin-feed pla-
  50. #  ten.  For mailing labels, the carriage should be adjusted so that
  51. #  the first character is printed at the leftmost position on the
  52. #  label and so that the first line of the output is printed on the
  53. #  topmost line of the label.  For curved tape labels, some experi-
  54. #  mentation may be required to get the text positioned properly.
  55. #  
  56. #  Diagnostics: If the limits on line width or the number of lines
  57. #  per label are exceeded, a label with an error message is written
  58. #  to standard error output.
  59. #  
  60. ############################################################################
  61. #
  62. #  Links: options
  63. #
  64. #  See also:  zipsort
  65. #
  66. ############################################################################
  67.  
  68. link options
  69.  
  70. global line, lsize, repet, llength, ldepth, first, opts
  71.  
  72. procedure main(args)
  73.    local selectors, y, i
  74.    line := ""
  75.    selectors := '#'
  76.    lsize := 9
  77.    ldepth := 8
  78.    llength := 40
  79.    repet := 1
  80.    i := 0
  81.    opts := options(args,"cfd+l+s:tw+")
  82.    if \opts["f"] then first := 1
  83.    selectors := cset(\opts["s"])
  84.    if \opts["t"] then {
  85.       lsize := 12
  86.       if ldepth > lsize then ldepth := lsize
  87.       }
  88.    llength := nonneg("w")
  89.    if ldepth := nonneg("l") then {
  90.       if lsize < ldepth then lsize := ldepth
  91.       }
  92.    if lsize := nonneg("d") then {
  93.       if ldepth > lsize then ldepth := lsize
  94.       }
  95.    repet := nonneg("c")
  96.  
  97.    repeat {                # processing loop
  98.       if line[1] == "#" & upto(selectors,line)
  99.          then obtain() else {
  100.             line := read() | break
  101.             }
  102.       }
  103. end
  104.  
  105. #  Obtain next label
  106. #
  107. procedure obtain()
  108.    local label, max
  109.    label := []
  110.    max := 0
  111.    line := ""
  112.    while line := read() do {
  113.       if line[1] == "*" then next
  114.       if line[1] == "#" then break
  115.       if \first then {
  116.          write(line)
  117.          return
  118.          }
  119.       else 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.