Annotation of 43BSD/contrib/icon/src/cmd/tablw.icn, revision 1.1

1.1     ! root        1: #      TABLW(1)
        !             2: #
        !             3: #      Tabulate words
        !             4: #
        !             5: #      Ralph E. Griswold
        !             6: #
        !             7: #      Last modified 8/11/84
        !             8: #
        !             9: 
        !            10: global limit, icase
        !            11: 
        !            12: procedure main(x)
        !            13:    local wcount, unique, order, i, s, a, pair, lwidth, rwidth, max
        !            14:    limit := 0                          # lower limit on usage to list
        !            15:    unique := 0                         # switch to list unique usage only
        !            16:    order := 1                          # alphabetical ordering switch
        !            17:    i := 0
        !            18:    while i < *x do {
        !            19:       s := x[i +:= 1] | break
        !            20:       case s of {
        !            21:          "-a":  order := 1
        !            22:          "-i":  icase := 1
        !            23:          "-n":  order := 2
        !            24:          "-s":  limit := (0 < integer(x[i +:= 1])) | Usage()
        !            25:          "-u":  unique := 1
        !            26:          default:  Usage()
        !            27:          }
        !            28:       }
        !            29:    wcount := table(0)                  # table of words
        !            30:    every wcount[words()] +:= 1
        !            31:    a := sort(wcount,order)
        !            32:    if unique = 1 then {
        !            33:       every pair := !a do
        !            34:          if pair[2] = 1 then write(pair[1])
        !            35:       }
        !            36:    else {
        !            37:       max := 0
        !            38:       every max <:= *((!a)[1])
        !            39:       lwidth := max + 3
        !            40:       rwidth := 0
        !            41:       every rwidth <:= *((!a)[2])
        !            42:       every pair := !a do
        !            43:          write(left(pair[1],lwidth),right(pair[2],rwidth))
        !            44:       }
        !            45: end
        !            46: 
        !            47: #  generate words
        !            48: #
        !            49: procedure words()
        !            50:    local wchar, line, word
        !            51:    wchar := &lcase ++ &ucase
        !            52:    while line := read() do {
        !            53:       if \icase then line := map(line)
        !            54:       line ? while tab(upto(wchar)) do {
        !            55:          word := tab(many(wchar)) || ((tab(any('-\'')) || tab(many(wchar))) | "")
        !            56:          if *word > limit then suspend word
        !            57:          }
        !            58:       }
        !            59: end
        !            60: 
        !            61: procedure Usage()
        !            62:    stop("usage:  tablw [-a -i -n -s n -u]")
        !            63: end

unix.superglobalmegacorp.com

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