Annotation of 43BSD/contrib/icon/src/cmd/labels.icn, revision 1.1.1.1

1.1       root        1: #      LABELS(1)
                      2: #
                      3: #      Format mailing labels
                      4: #
                      5: #      Ralph E. Griswold
                      6: #
                      7: #      Last modified 4/27/83
                      8: #
                      9: 
                     10: global line, lsize, repet
                     11: 
                     12: procedure main(x)
                     13:    local selectors, use, y, i
                     14:    line := ""
                     15:    selectors := '#'
                     16:    lsize := 9
                     17:    repet := 1
                     18:    i := 0
                     19:    use := "usage: labels [-n] [-s string] [-t]"
                     20:    while y := x[i +:= 1] do
                     21:       if y == "-s" then selectors := cset(x[i +:= 1]) | stop(use)
                     22:       else if y == "-t" then lsize := 12       #  tape labels
                     23:       else if y[1] == "-" then
                     24:          repet := integer(y[2:0]) | stop(use)
                     25:          else stop(use)
                     26:    repeat {
                     27:       if line[1] == "#" & upto(selectors,line)
                     28:          then obtain() else {line := read() | break}
                     29:       }
                     30: end
                     31: 
                     32: #  format and write label
                     33: #
                     34: procedure format(label,width)
                     35:    local j, indent
                     36:    indent := repl(" ",(40-width)/2)
                     37:    j := lsize - *label
                     38:    every 1 to j/2 do write()
                     39:    every write(indent,!label)
                     40:    every 1 to (j+1)/2 do write()
                     41: end
                     42: 
                     43: #  format error message as label
                     44: #
                     45: procedure error(name,type)
                     46:    static badform
                     47:    initial badform := list(lsize)
                     48:    case type of {
                     49:       1:  badform[4] := "     **** too many lines"
                     50:       2:  badform[4] := "     **** line too long"
                     51:       }
                     52:    badform[1] := name
                     53:    every write(&errout,!badform)
                     54: end
                     55: 
                     56: #  obtain label
                     57: #
                     58: procedure obtain()
                     59:    local label, max
                     60:    label := []
                     61:    max := 0
                     62:    while line := read() do {
                     63:       if line[1] == "*" then next              #  comment
                     64:       if line[1] == "#" then break             #  new label
                     65:       put(label,line)
                     66:       if *line > max then max := *line
                     67:       if *label > 8 then {error(label[1],1); return}
                     68:       if max > 40 then {error(label[1],2); return}
                     69:       }
                     70:    every 1 to repet do format(label,max)
                     71: end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.