home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / PROGS.LZH / LABELS.ICN < prev    next >
Text File  |  1991-09-05  |  5KB  |  154 lines

  1. ############################################################################
  2. #
  3. #    Name:    labels.icn
  4. #
  5. #    Title:    Format mailing labels
  6. #
  7. #    Author:    Ralph E. Griswold
  8. #
  9. #    Date:    July 26, 1991
  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. #     Options are processed from left to right.  If the number of
  40. #  printed lines is set to a value that exceeds the depth of the
  41. #  label, the depth is set to the number of lines.  If the depth is
  42. #  set to a value that is less than the number of printed lines, the
  43. #  number of printed lines is set to the depth. Note that the order
  44. #  in which these options are specified may affect the results.
  45. #  
  46. #  Printing Labels: Label forms should be used with a pin-feed pla-
  47. #  ten.  For mailing labels, the carriage should be adjusted so that
  48. #  the first character is printed at the leftmost position on the
  49. #  label and so that the first line of the output is printed on the
  50. #  topmost line of the label.  For curved tape labels, some experi-
  51. #  mentation may be required to get the text positioned properly.
  52. #  
  53. #  Diagnostics: If the limits on line width or the number of lines
  54. #  per label are exceeded, a label with an error message is written
  55. #  to standard error output.
  56. #  
  57. ############################################################################
  58. #
  59. #  Links: options, buffer
  60. #
  61. #  See also:  address.doc, adllist.icn, adlfiltr.icn, adlcount.icn,
  62. #          adlcheck.icn, zipsort.icn
  63. #
  64. ############################################################################
  65.  
  66. link options, buffer
  67.  
  68. global lsize, repet, llength, ldepth, opts, selectors
  69.  
  70. procedure main(args)
  71.    local y, i
  72.    selectors := '#'
  73.    lsize := 9
  74.    ldepth := 8
  75.    llength := 40
  76.    repet := 1
  77.    i := 0
  78.    opts := options(args,"c+d+l+s:tw+")
  79.    selectors := cset(\opts["s"])
  80.    if \opts["t"] then {
  81.       lsize := 12
  82.       if ldepth > lsize then ldepth := lsize
  83.       }
  84.    llength := nonneg("w")
  85.    if ldepth := nonneg("l") then {
  86.       if lsize < ldepth then lsize := ldepth
  87.       }
  88.    if lsize := nonneg("d") then {
  89.       if ldepth > lsize then ldepth := lsize
  90.       }
  91.    repet := nonneg("c")
  92.  
  93.    while line := Read() do
  94.       line ? {
  95.          if any('#') & upto(selectors) then nextlbl()
  96.          }
  97.  
  98. end
  99.  
  100. #  Obtain next label
  101. #
  102. procedure nextlbl()
  103.    local label, max, line
  104.    label := [Read()]
  105.    max := 0
  106.    while line := Read() do {
  107.       if line[1] == "*" then next
  108.       if line[1] == "#" then {
  109.          PutBack(line)
  110.          break
  111.          }
  112.       put(label,line)
  113.       max <:= *line
  114.       if *label > ldepth then {
  115.          error(label[1],1)
  116.          return
  117.          }
  118.       if max > llength then {
  119.          error(label[1],2)
  120.          return
  121.          }
  122.       }
  123.    every 1 to repet do format(label,max)
  124. end
  125.  
  126. #  Format a label
  127. #
  128. procedure format(label,width)
  129.    local j, indent
  130.    indent := repl(" ",(llength - width) / 2)
  131.    j := lsize - *label
  132.    every 1 to j / 2 do write()
  133.    every write(indent,!label)
  134.    every 1 to (j + 1) / 2 do write()
  135. end
  136.  
  137. #  Issue label for an error
  138. #
  139. procedure error(name,type)
  140.    static badform
  141.    initial badform := list(lsize)
  142.    case type of {
  143.       1:  badform[3] := "     **** too many lines"
  144.       2:  badform[3] := "     **** line too long"
  145.       }
  146.    badform[1] := name
  147.    every write(&errout,!badform)
  148. end
  149.  
  150. procedure nonneg(s)
  151.    s := \opts[s] | fail
  152.    return 0 < integer(s) | stop("-",s," needs postive numeric parameter")
  153. end
  154.