Annotation of 43BSD/contrib/icon/src/cmd/i-split.icn, revision 1.1.1.1

1.1       root        1: #      I-SPLIT(1)
                      2: #
                      3: #      Split Icon program into separate files
                      4: #
                      5: #      Ralph E. Griswold
                      6: #
                      7: #      Last modified 5/28/83
                      8: #
                      9: 
                     10: procedure main(o)
                     11:    local line, x, i, proctable, proclist, comments, gfile, ofile
                     12:    comments := []
                     13:    if o[1] := "-g" then gfile := open(o[2],"w") |
                     14:       stop("usage:  i-split [-g file]")
                     15:    proctable := table()
                     16:    while line := read() do {
                     17:       if line ? {
                     18:          ="procedure" &                        #  procedure declaration
                     19:          tab(many(" ")) &
                     20:          proctable[tab(upto("("))] := x := []
                     21:          } then {
                     22:             while put(x,get(comments)) #  save it
                     23:             put(x,line)
                     24:             i := 1
                     25:             while line := read() do {
                     26:                put(x,line)
                     27:                if line == "end" then break
                     28:                }
                     29:             }
                     30:                                        #  other declarations
                     31:          else if \gfile & line ? =("global" | "record" | "external")
                     32:          then {
                     33:             while write(gfile,get(comments))
                     34:             write(gfile,line)
                     35:             }
                     36:          else put(comments,line)
                     37:          }
                     38:    while write(\gfile,get(comments))
                     39:    proclist := sort(proctable)         #  sort procedures
                     40:    if *proclist > 1 then
                     41:       every i := 1 to *proclist do     #  get main procedure to front
                     42:          if proclist[i][1] == "main" then {
                     43:             proclist := proclist[i+:1] ||| proclist[1:i] ||| proclist[i + 1:0]
                     44:             break
                     45:             }
                     46:    every x := !proclist do {           #  output procedures
                     47:       ofile := open(x[1] || ".icn","w") | stop("cannot write ",x[1],".icn")
                     48:       every write(ofile,!(x[2]))
                     49:       close(ofile)
                     50:       }
                     51: end

unix.superglobalmegacorp.com

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