# I-SPLIT(1) # # Split Icon program into separate files # # Ralph E. Griswold # # Last modified 5/28/83 # 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" | "external") then { while write(gfile,get(comments)) write(gfile,line) } else put(comments,line) } while write(\gfile,get(comments)) proclist := sort(proctable) # sort procedures if *proclist > 1 then every i := 1 to *proclist do # get main procedure to front if proclist[i][1] == "main" then { proclist := proclist[i+:1] ||| proclist[1:i] ||| proclist[i + 1:0] break } every x := !proclist do { # output procedures ofile := open(x[1] || ".icn","w") | stop("cannot write ",x[1],".icn") every write(ofile,!(x[2])) close(ofile) } end