× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On 19-May-2015 11:58 -0500, Mark S Waterbury wrote:

You do not need the full "parser" for ILE RPG IV in order to strip
out comments.

Just create a "filter" -- a program that makes one pass over the
source code, writing the code without any comments to a temporary
source file member (e.g. in QTEMP), and then scan that for what you
are looking for.

The rules for RPG IV comments are pretty simple:

First, strip anything beyond column 80, that is, overlay that with
blanks, as those are always comments for "fixed form" RPG.

Start scanning in column 6.

If column 6 contains a " " (blank space) then the line is in "free
form" ...

If column 6 contains an "*" then the entire line is a comment line
-- either suppress the line entirely or just print a blank line.

For me, a sole asterisk in column six gives either RNF0257 "Form-Type entry for main procedure not valid or out of sequence." or RNF5505 "Positions 6-7 are not blank in a free-format calculation specification."


If column 6 contains a non-blank (F, I, D, C, etc.) then if column 7
contains an "*" the entire line is a comment line -- either suppress
the line entirely or just print the line up through column 7.

In a fixed-form area, just the asterisk in column seven is enough to designate a comment line. The compiler does not care if the form-type entry is blank. For free-form, see RNF5505.


Scan from left to right, starting at column 7, for "//" and if you
find it, blank out the "// and everything to the end of the line,
then write out that line.

If safely can be *assumed*, that the characters are not part of a character string literal. Otherwise parsing for string literals, and even those spanning lines, may be necessary; i.e. no way to know if within a string literal spanning multiple lines when not continuing the scanning from a prior line.


Repeat the above for each source line in the input member, creating
a temporary member to be scanned "without comments" ...

Now, scan that using whatever tool(s) you want.

<<SNIP>>

Described like that however, an SQL query should be quite capable against RPG sources. After OVRDBF RPG TOFILE(RPGSRCPF) TOMBR(RPGPGM):

with
sst as
(select substr(srcdta, 6, 80) as dta
substr(srcdta, 6, 80) as dta
, srcseq, srcdat
, int( locate('//', srcdta, 8) ) as spos
, substr(srcdta, 6, 1) as c6
, substr(srcdta, 7, 1) as c7
from rpg
)
select srcseq, srcdat
, case when c7 = '*' then ''
when spos = 0 then dta
else left( dta, spos+1 )
end as srcdta
from sst
/* order by RRN(sst) */

Note: I did not do anything with C6; every example I have of RPG with an asterisk in position-6 has an asterisk also in position-7.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.