Saving comments from the Informix ESQL/COBOL Pre-Processor
Posted in 1994
In converting an old COBOL system to ESQL/COBAL we ran into a problem with the pre-processor striping the comments out of the code. This made it difficult to compare a old listing to a new listing. Vijay came up with a solution and wanted to share it with other Informix ESQL/COBOL users. Regards - Lester ---------------------------------------------------------------- Saving Comments from the INFORMIX-ESQL/COBOL Pre-Processor by Vijay Voleti INFORMIX-ESQL/COBOL Pre-Processor (Ver. 5.00) deletes all the comments in COBOL and ESQL statements, while processing a SQL embedded COBOL file. This article provides a work-around method for saving COBOL comments. The output of the pre-processor is a COBOL file with all embedded SQL statements replaced by the COBOL statements. The COBOL file is then compiled with the COBOL compiler, which optionally generates a list file. This list file is a very useful reference as it contains main code along with all copy code, showing entire code of the module. So, the absence of the comments in the file reduces the readability of the code and makes it hard for the analysis. If the list files are final delivarables for the customers, then the document will be incomplete with out the comments. This work-around introduces two additional steps into the process, encoding the comments before pre-processing and then decoding the comments after pre-processing. Two scripts encom.ksh and decom.ksh are developed to perform encoding and decoding. The following shows the steps involved to preprocess the SQL embedded COBOL file : STEP 1: encom.ksh esqlcobol_file generates an output file with encoded comments. The output file name is input file name with a prefix "en_". Example: encom.ksh example.eco generates an output file en_example.eco. STEP 2: esqlcobol -e encoded_file This is an esql pre-processor which translates all ESQL statements to its equivalent COBOL statements. The output file name is input file name with its extension replaced by ".cob". Example: esqlcobol -e en_example.eco generates an output file en_example.cob. STEP 3: decom.ksh encoded_cob_file decodes all the COBOL comments that are encoded by encom.ksh utility. The output file name is input file name with its prefix "en_" stripped off. Example: decom.ksh en_example.cob generates an output file example.cob. BUGS: This work around holds good for COBOL comments only. The comments made on SQL statements are not touched by these utilities and are deleted by pre-processor. The SQL statements shouldn't exceed 72th column, otherwise the utility encodes it as a comment. "encom.ksh" Script: ------------------- ################################################################### # # Program Name: encom.ksh # Date Created: 05/16/94 # Author : Vijay Voleti # # Purpose: # INFORMIX-ESQL/COBOL pre-processor, deletes all the statements with # a "*" in 7th column, splits statements of length greater than # 72 and deletes statements of length 7 with any control characters # like page eject ("/") etc. in column 7. This script encodes all the # statements with above cases to pass them through pre-processer # undetected. Use the script "decom.ksh" to decode these lines after # pre-processing. The above cases may not be complete and if user # finds any statements being deleted by the pre-processor, the # user can include the proper condition in the first "if" stmt. below. # # Logic: # Pre-processor does not process COBOL statements other than those # cases listed above. The script modifies the statements with above # cases look like general COBOL statements, so that the pre-processor # does not touch them. Two strings "!#@$%&" and "!#@$%$" are used as # tags in line-number-field for the decoder to detect these modified # lines. # ################################################################## #!/bin/ksh awk ' BEGIN { outfile = "en_" FILENAME } #Adds Prefix to input file { if((substr($0,7,1) == "*") || (length($0) > 72) || (length($0) < 8)) # Decodes if the statement contains a "*" at 7th column or # if the length is > 72 or < 8. Any other cases found could be # included by user in the above expression and they will be encoded. { i = 1; outbuf = "" while(length(substr($0,i))) { if(length(substr($0,i)) > 65) { outbuf = outbuf "!#@$%& " substr($0,i,65) "\\n" i = i + 65 } else { outbuf = outbuf "!#@$%$ " substr($0,i,length(substr($0,i))) i = i + length(substr($0,i)) } } } else outbuf = $0 print outbuf > outfile } ' $1; "decom.ksh" Script: ------------------- ################################################################## # # Program Name: decom.ksh # Date Created: 05/16/94 # Author : Vijay Voleti # # Purpose: # INFORMIX-ESQL/COBOL pre-processor, deletes all the statements with # a "*" in 7th column, splits statements of length greater than # 72 and deletes statements of length 7 with any control characters # like page eject ("/") etc. in column 7. This script decodes all the # lines (with above cases) that were encoded by utility "encom.ksh". # # Logic: # The statements with strings "!#@$%&" and "!#@$%$" in line-number-field # are detected and decoded to its original form. # ################################################################## #!/bin/ksh awk ' BEGIN { outbuf = ""; outfile = substr(FILENAME,4) } { if((substr($0,1,6) == "!#@$%&")) outbuf = outbuf substr($0,8) else if(substr($0,1,6) == "!#@$%$") { outbuf = outbuf substr($0,8) print outbuf > outfile outbuf = "" } else print $0 > outfile } ' $1; Vijay Voleti Computer Sciences Corporation/Jodian 15245 Shady Grove Road, #3-654 Rockville, MD 20850 301-670-3782