In paragraph LETTURA of animator.cbl:
When we detect a comment line, we write it to the ani file and the line file, and then read the next line.
However we detect only fixed-format comments with an asterisk in column 7. We don't detect free-format comments, or fixed-format comment where the "*>" starts beyond column 7. Such a comment can confuse the parsing logic. For example:
PROCEDURE DIVISION.
*> This comment causes mayhem
DECLARATIVES.
When we look for DECLARATIVES we find the comment, conclude that there are no DECLARATIVES, and insert several lines of debugging code. Then DECLARATIVES shows up after all. The resulting ani file is invalid COBOL, because there are executable statements before DECLARATIVES.
The following paragraph detects every line that is all comment:
IS-COMMENT.
IF REC-IN(7:1) = "*"
AND SW-FREE = SPACE
MOVE "S" TO SW-COMMENT
ELSE
*> See if the line starts with "*>"
IF SW-FREE = SPACE
MOVE 8 TO IND3
ELSE
MOVE 1 TO IND3
END-IF
PERFORM VARYING IND3 FROM IND3 BY 1
UNTIL IND3 NOT < LENGTH OF REC-IN
OR REC-IN(IND3:1) NOT = SPACE
CONTINUE
END-PERFORM
IF IND3 < LENGTH OF REC-IN
AND REC-IN(IND3:2) = "*>"
MOVE "S" TO SW-COMMENT
ELSE
MOVE SPACE TO SW-COMMENT
END-IF
END-IF.
...where SW-COMMENT is declared as PIC X. I PERFORM IS-COMMENT from LETTURA and branch accordingly.
IS-COMMENT doesn't detect a "*>" comment if it follows real code on the same line. Such a comment can create problems too, but that's a separate topic.
For what it's worth, here's my version of LETTURA. I rewrote it to eliminate GO TOs and PERFORM THRUs:
LETTURA.
SET CODE-NOT-FOUND TO TRUE
PERFORM UNTIL CODE-FOUND OR FINE-FILE = "S"
MOVE SPACES TO REC-IN REC-OUT REC-LIN
READ ARK-IN NEXT
AT END
MOVE "S" TO FINE-FILE
END-READ
IF FINE-FILE NOT = "S"
IF REC-IN = SPACES
MOVE REC-IN TO REC-OUT
PERFORM SCRITTURA
ELSE
PERFORM IS-COMMENT
IF SW-COMMENT = "S"
MOVE REC-IN TO REC-OUT
PERFORM SCRITTURA
ELSE
** auto exclude copy when you are animating a part of the animator itself
MOVE ZEROS TO IND3
INSPECT FUNCTION UPPER-CASE(REC-IN)
TALLYING IND3 FOR ALL "WORKANIM.CPY"
IF IND3 NOT = 1
SET CODE-FOUND TO TRUE
END-IF
END-IF
END-IF
END-IF
END-PERFORM.
...where CODE-FOUND and CODE-NOT-FOUND are a pair of 88-levels.
Note that I treat blank lines the same way I treat comments: send them to SCRITTURA and then read the next line. I think the only time this makes a difference is when we're looking for DECLARATIVES. Currently we suppress blank lines -- probably by accident -- between PROCEDURE DIVISION and DECLARATIVES. We don't suppress blank lines anywhere else, and I see no reason to suppress them here.
This code is still pretty fresh, and I haven't tested it completely yet, but it seems to work so far.
Scott McKellar
Small correction to my LETTURA: the test for blank lines needs be different depending on whether the format is fixed or free.
...plus an extra END-IF below.
Ultimately I'd like for LETTURA to send every input line to SCRITTURA, so that we don't have to do so from half a dozen other places. However that won't work yet because LETTURA hasn't converted free format to fixed.
Scott McKellar