Any indent tools for Informix-4GL?
Posted in 1994
> > After digging through another set of changes to a 4GL program, where someone > grafted statements into existing code and did not properly indent them > (based on the rest of the code), I am in need of a tool. > > What I need is something like the GNU indent tool (for C code) that will > correct the indenting of 4GL code. > > Does such a tool exist? > I have dbbeauty, but that only deals with keywords (upcasing them). > -- > Donald E. Amby, Senior Software Engineer (and software tools guy) > amby@mixcom.com 414-797-6713 (voice) 414-797-6741 (FAX) > Harnischfeger Engineers, Inc., 13400 Bishops Lane, Brookfield, WI 53005 > The following is an imperfect indent program, it is pretty sloppy - but it does 95% of the work. I haven't played with it for some time but hope to clean it up some day. If you are on a Sun look out - the awk is totally different and will generate garbage. Please make sure you do a backup of your code first. Although the code is not supposed to overwrite the original unless it detects no substantive changes (diff -b) you never know - there is a piece of code there which overwrites your original source file. I never run this on the original - always a copy. I would appreciate comments - who knows I might even go back to work on it. j. --- cut here ----- #!/bin/sh # # This is a shell archive. To extract its contents, # execute this file with /bin/sh to create the file(s): # # indent indent.awk indent.doc # # This shell archive created: Thu Jun 3 09:32:59 MDT 1993 # echo "Extracting file indent" sed -e 's/^X//' <<\\SHAR_EOF > indent X######################################################################## X# X# indent: a little script which indents 4gl source. X# X# syntax: indent file.4gl X# X# If output is different than source, it is left as file.4gl.ind X# otherwise (if the only difference is white space) the .ind file X# is moved over the original source file. X# X# JParker 5/6/93 - No warranties expressed or implied X# X######################################################################## Xwhile [ $# -gt 0 ] Xdo X echo "Indenting" $1 X # change all tabs to spaces X expand $1 > /tmp/indenting X # indent.awk does the real work X awk -f ./indent.awk < /tmp/indenting > $1.ind X # is the output different? X diff -b $1 $1.ind > /dev/null X if [ $? -eq 0 ] X then mv $1.ind $1 X echo "No differences found, replacing source" X else echo "Differences found between $1 and $1.ind" X fi X # cleanup X rm -f /tmp/indenting X X shift Xdone SHAR_EOF if [ `wc -c < indent` -ne 942 ] then echo "Lengths do not match -- Bad Copy of indent" fi echo "Extracting file indent.awk" sed -e 's/^X//' <<\\SHAR_EOF > indent.awk X############################################################################ X# X# indent.awk: indent 4gl source. X# X# JParker 5/6/93 - No warranty expressed or implied X# X############################################################################ XBEGIN { X id_amt=3 # number of white spaces to use in indenting X nest_level = 0 # level of indenting X cmnt_level = 0 # comment level (using "{}") - only handles X # one of each per line X in_input=0 # within an INPUT statement X in_menu=0 # within a MENU X in_case=0 # within a CASE X in_define=0 # within a DEFINE X in_report=0 # within a REPORT X } X X{ X # what are last and first characters? Xfirst_char=substr($0,1,1) # test for '#' or '{' Xst_cmmnt=index($0,"{") # start of comment block Xend_cmmnt=index($0,"}") # end of comment block Xif (st_cmmnt > 0) cmnt_level+=1 # set comment nest level Xif (end_cmmnt > 0) cmnt_level-=1 X Xif (cmnt_level == 0 && NF > 0) { # if within comment - don't indent X # also ignore blank lines X # NOTE FOLLOWING BLOCK NOT INDENTED X X # standard indenation words Xif ($1 == "FOR" || $1 == "for" ) nest_level+=1 Xif ($1 == "FOREACH" || $1 == "foreach") nest_level+=1 Xif ($1 == "WHILE" || $1 == "while" ) nest_level+=1 Xif ($1 == "IF" || $1 == "if" ) nest_level+=1 Xif ($1 == "FUNCTION" || $1 == "function") nest_level=1 Xif ($1 == "MAIN" || $1 == "main") nest_level=1 Xif ($1 == "REPORT" || $1 == "report") { X nest_level=1 X in_report = 1 X } Xif (in_report == 1) { X if ($1 == "OUTPUT" || $1 == "output") { X nest_level=2 X ident = " " X } X if ($1 == "FORMAT" || $1 == "format") { X nest_level=2 X ident = " " X } X if ($1 == "PAGE" || $1 == "page") nest_level=3 X if ($1 == "ON" || $1 == "on") nest_level=3 X if ($1 == "BEFORE" || $1 == "before") nest_level=3 X if ($1 == "AFTER" || $1 == "after") nest_level=3 X } X X # start of INPUT nest Xif ($1 == "INPUT" || $1 == "input") { X nest_level+=1 X in_input=1 X } Xif (in_input == 1) { X if ( $1 == "BEFORE" || $1 == "before" ) { X iident="" X niident=" " X } X if ( $1 == "AFTER" || $1 == "after" ) { X iident="" X niident=" " X } X if ( $1 == "ON" || $1 == "on" ) { X iident="" X niident=" " X } X } # end in_input X X # start of menu nest Xif ($1 == "MENU" || $1 == "menu") { X nest_level+=1 X in_menu=1 X } X Xif (in_menu == 1) { X if ( $1 == "COMMAND" || $1 == "command" ) { X mident="" X nmident=" " X } X } # end in_menu X X # start of case nest Xif ($1 == "CASE" || $1 == "case") { X nest_level+=1 X in_case=1 X } X Xif (in_case == 1) { X if ( $1 == "WHEN" || $1 == "when" ) { X cident="" X ncident=" " X } X if ( $1 == "OTHERWISE" || $1 == "otherwise" ) { X cident="" X ncident=" " X } X } # end in_case X Xif (in_define == 0) { X ntident = "" X tident = "" X } X # start of define nest Xif ($1 == "DEFINE" || $1 == "define" ) { X if (NF == 1 || index($0,",") != 0) # may be lonely X ntident = " " X in_define=1 X } X # lack of comma ends - except when X # starting RECORD Xelse if (index($0,",") == 0 && in_define > 0 && (index($0,"RECORD") == 0 && index($0,"record") == 0)) in_define-=1 X Xif ((index($0,"RECORD") != 0 || index($0,"record") != 0) && in_define > 0) {@@