############################################################################ # # Name: itab.icn # # Title: Entab an Icon program # # Author: Robert J. Alexander # # Date: December 5, 1989 # ############################################################################ # # itab -- Entab an Icon program, leaving quoted strings alone. # # itab [input-tab-spacing] [output-tab-spacing] # < source-program > entabbed-program # # Observes Icon Programming Language conventions for escapes and # continuations in string constants. Input and output tab spacing # defaults to 8. # ############################################################################ global mapchars,intabs procedure main(arg) local outtabs, line, c, nonwhite, delim intabs := (arg[1] | 8) + 1 outtabs := (arg[2] | 8) + 1 line := "" while c := readx() do { if not any(' \t',c) then nonwhite := 1 case c of { "\n": { write(map(entab(line,outtabs),\mapchars," \t") | line) line := "" nonwhite := &null } "'" | "\"": { (/delim := c) | (delim := &null) line ||:= c } "\\": line ||:= c || readx() default: { line ||:= if \delim & \nonwhite & \mapchars then map(c," \t",mapchars) else c } } } end procedure readx() static buf,printchars initial { buf := "" printchars := &cset[33:128] } if *buf = 0 then { buf := detab(read(),intabs) || "\n" | fail mapchars := (printchars -- buf)[1+:2] | &null } return 1(.buf[1],buf[1] := "") end