# IPSPLIT # # Split Icon program into separate files # # Ralph E. Griswold # # Last modified 4/29/86 # procedure main(o) local line, x, i, proctable, proclist, comments, gfile, ofile comments := [] if o[1] := "-g" then gfile := open(o[2],"w") | stop("usage: i-split [-g file]") proctable := table() while line := read() do { if line ? { ="procedure" & # procedure declaration tab(many(' ')) & proctable[tab(upto('('))] := x := [] } then { while put(x,get(comments)) # save it put(x,line) i := 1 while line := read() do { put(x,line) if line == "end" then break } } # other declarations else if \gfile & line ? =("global" | "record" | "link") then { while write(gfile,get(comments)) write(gfile,line) } else put(comments,line) } while write(\gfile,get(comments)) proclist := sort(proctable,3) # sort procedures while x := get(proclist) do { # output procedures ofile := open(x || ".icn","w") | stop("cannot write ",x,".icn") every write(ofile,!get(proclist)) close(ofile) } end