简体   繁体   中英

How to scan source of a RPGLE program?

I want to scan source from a RPGLE program but there is a problem. I explain problem below. Source is:

fTcsprefix if   e             disk    rename(tcsprefix:testpr)  
f                                     prefix (@)    

I want to scan the PREFIX keyword if it exists in the source code. But when scanning it is found in the record format name. How can I avoid this?

I am using:

**C   'PREFIX'     SCAN    SRCDTA     S1**

Try scanning for ' PREFIX' , ie, with a leading space. Unless you can guarantee that there is always a space after the PREFIX keyword, you can't also rely on a trailing space in the search-string. (You can try it.)


For more extensive testing:

If coding standards don't maintain clear syntax, you need to extend the logic. This statement finds where PREFIX is found:

 C   'PREFIX'     SCAN    SRCDTA     S1

It stores the location in S1 . You can then use S1 to test if the position before contains a blank or a ')'. If you find any other characters that are valid, the logic can be extended to test for added valid characters. Also, you know that PREFIX is six characters long, so you can test the character at position S1+6 to see if it is a blank or a '(' or other valid character.

When your program finds PREFIX and it also finds that both the preceding and succeeding characters are acceptable, it should know that it found a match that fits.

When SCAN finds a match, you probably should pass the source line to a sub-procedure that tests the preceding and succeeding characters and returns an indicator value. The indicator will tell your program if it's a good match or not.

You might also consider not using SCAN at all. Use the %scan() BIF instead and use a free-form coding style.

You can make use of the ILE C runtime regex procedures from ILE RPG.

http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rtref/regexh.htm%23regexh
Note that the RE library on the IBM i follows POSIX standards.
http://www.regular-expressions.info/posix.html

Here's an article to look at; complete with source containing the prototypes you'd need to call the functions.
http://iprodeveloper.com/rpg-programming/validate-e-mail-address-regular-expression

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM