Annotation of researchv10dc/cmd/icon/ipl/source/tablw.icn, revision 1.1.1.1

1.1       root        1: #      TABLW
                      2: #
                      3: #      Tabulate words
                      4: #
                      5: #      Ralph E. Griswold
                      6: #
                      7: #      Last modified 4/29/86
                      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 := 3                          # alphabetical ordering switch
                     17:    i := 0
                     18:    while i < *x do {
                     19:       s := x[i +:= 1] | break
                     20:       case s of {
                     21:          "-a":  order := 3
                     22:          "-i":  icase := 1
                     23:          "-n":  order := 4
                     24:          "-l":  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:       while s := get(a) do
                     34:          if get(a) = 1 then write(s)
                     35:       }
                     36:    else {
                     37:       max := 0
                     38:       rwidth := 0
                     39:       i := 1
                     40:       while i < *a do {
                     41:          max <:= *a[i]
                     42:          rwidth <:= *a[i +:= 1]
                     43:         }
                     44:       lwidth := max + 3
                     45:       while write(left(get(a),lwidth),right(get(a),rwidth))
                     46:       }
                     47: end
                     48: 
                     49: #  generate words
                     50: #
                     51: procedure words()
                     52:    local wchar, line, word
                     53:    wchar := &lcase ++ &ucase
                     54:    while line := read() do {
                     55:       if \icase then line := map(line)
                     56:       line ? while tab(upto(wchar)) do {
                     57:          word := tab(many(wchar)) || ((tab(any('-\'')) || tab(many(wchar))) | "")
                     58:          if *word > limit then suspend word
                     59:          }
                     60:       }
                     61: end
                     62: 
                     63: procedure Usage()
                     64:    stop("usage:  tablw [-a -i -n -l n -u]")
                     65: end

unix.superglobalmegacorp.com

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