# LABELS(1) # # Format mailing labels # # Ralph E. Griswold # # Last modified 4/27/83 # global line, lsize, repet procedure main(x) local selectors, use, y, i line := "" selectors := '#' lsize := 9 repet := 1 i := 0 use := "usage: labels [-n] [-s string] [-t]" while y := x[i +:= 1] do if y == "-s" then selectors := cset(x[i +:= 1]) | stop(use) else if y == "-t" then lsize := 12 # tape labels else if y[1] == "-" then repet := integer(y[2:0]) | stop(use) else stop(use) repeat { if line[1] == "#" & upto(selectors,line) then obtain() else {line := read() | break} } end # format and write label # procedure format(label,width) local j, indent indent := repl(" ",(40-width)/2) j := lsize - *label every 1 to j/2 do write() every write(indent,!label) every 1 to (j+1)/2 do write() end # format error message as label # procedure error(name,type) static badform initial badform := list(lsize) case type of { 1: badform[4] := " **** too many lines" 2: badform[4] := " **** line too long" } badform[1] := name every write(&errout,!badform) end # obtain label # procedure obtain() local label, max label := [] max := 0 while line := read() do { if line[1] == "*" then next # comment if line[1] == "#" then break # new label put(label,line) if *line > max then max := *line if *label > 8 then {error(label[1],1); return} if max > 40 then {error(label[1],2); return} } every 1 to repet do format(label,max) end