Annotation of researchv10dc/cmd/icon/ipl/source/labels.icn, revision 1.1

1.1     ! root        1: #      LABELS
        !             2: #
        !             3: #      Format mailing labels
        !             4: #
        !             5: #      Ralph E. Griswold
        !             6: #
        !             7: #      Last modified 12/25/85
        !             8: #
        !             9: 
        !            10: global line, lsize, repet, llength, ldepth, first
        !            11: 
        !            12: procedure main(x)
        !            13:    local selectors, use, y, i
        !            14:    line := ""
        !            15:    selectors := '#'
        !            16:    lsize := 9
        !            17:    ldepth := 8
        !            18:    llength := 40
        !            19:    repet := 1
        !            20:    i := 0
        !            21:    use := "usage: labels [-c n] [-s s] [-t] [-d n] [-w n] [-l n] [-f]"
        !            22:    while y := x[i +:= 1] do
        !            23:       case y of {
        !            24:          "-f":  first := 1
        !            25:          "-s": selectors := cset(x[i +:= 1]) | stop(use)
        !            26:          "-t":  {
        !            27:             lsize := 12
        !            28:             if ldepth > lsize then ldepth := lsize
        !            29:             }
        !            30:          "-w":  llength := (0 < integer(x[i +:= 1])) | stop(use)
        !            31:          "-l":  {
        !            32:             ldepth := (0 < integer(x[i +:= 1])) | stop(use)
        !            33:             if lsize < ldepth then lsize := ldepth
        !            34:             }
        !            35:          "-d":  {
        !            36:             lsize := (0 < integer(x[i +:= 1])) | stop(use)
        !            37:             if ldepth > lsize then ldepth := lsize
        !            38:             }
        !            39:          "-c": repet := (0 < integer(x[i +:= 1])) | stop(use)
        !            40:          default: stop(use)
        !            41:          }
        !            42:    repeat {                            # processing loop
        !            43:       if line[1] == "#" & upto(selectors,line)
        !            44:          then obtain() else {
        !            45:             line := read() | break
        !            46:             }
        !            47:       }
        !            48: end
        !            49: 
        !            50: #  Obtain next label
        !            51: #
        !            52: procedure obtain()
        !            53:    local label, max
        !            54:    label := []
        !            55:    max := 0
        !            56:    line := ""
        !            57:    while line := read() do {
        !            58:       if line[1] == "*" then next
        !            59:       if line[1] == "#" then break
        !            60:       if \first then {
        !            61:          write(line)
        !            62:          return
        !            63:          }
        !            64:       else put(label,line)
        !            65:       max <:= *line
        !            66:       if *label > ldepth then {
        !            67:          error(label[1],1)
        !            68:          return
        !            69:          }
        !            70:       if max > llength then {
        !            71:          error(label[1],2)
        !            72:          return
        !            73:          }
        !            74:       }
        !            75:    every 1 to repet do format(label,max)
        !            76: end
        !            77: 
        !            78: #  Format a label
        !            79: #
        !            80: procedure format(label,width)
        !            81:    local j, indent
        !            82:    indent := repl(" ",(llength - width) / 2)
        !            83:    j := lsize - *label
        !            84:    every 1 to j / 2 do write()
        !            85:    every write(indent,!label)
        !            86:    every 1 to (j + 1) / 2 do write()
        !            87: end
        !            88: 
        !            89: #  Issue label for an error
        !            90: #
        !            91: procedure error(name,type)
        !            92:    static badform
        !            93:    initial badform := list(lsize)
        !            94:    case type of {
        !            95:       1:  badform[3] := "     **** too many lines"
        !            96:       2:  badform[3] := "     **** line too long"
        !            97:       }
        !            98:    badform[1] := name
        !            99:    every write(&errout,!badform)
        !           100: end

unix.superglobalmegacorp.com

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