count of "/*" and "*/"

confidentbala

New Member
Hi all,
In a line i want to compare "/*" is equal to "*/". I used num-entries but it checks correct for single character only. anybody as any idea to do this.

Thanks in Advance.
Bala :(
 
I think it is a bit more complicated then that.
This is comment as well for instance:

Code:
  for each customer where custnum = 12:  /* exclusive-lock:
 
        assign custnum = 13.  */
  end.

Is there any reason you want to do this?
If you compile the source and the comments doesn't match then you get error 134 including linenumber where the error occurred ......

Casper
 
thanks for reply.

I have to take a program and get the details in it. (i.e.) i want to know how many GetTermLabels present in it. It should not include the commented line (i.e.) i should not read the GetTermLabel that is commented. Any idea
 
Do you mean the number of times /* and */ are present in a string?
(Does /*/ also count as 1 /* and 1 */ ?)

Casper.
 
Hai confidentbala,

The only way without getting an error:

1) Make a backup. (always handy)
2) Convert the file you want to count in by replacing every "/*" into "/.!!.*" for example. You can use every unique string between the "/" and the "*".
3) Do the same for the "*/". Use the same unique string you have inserted between "/" and the "*" into the "*" and "/".

4) Then count these entry's or use what is in between these "tags".

MDaanje
 
Well, that's not true, you can escape any chracter in progress....

Quick and dirty example:
Code:
DEFINE VARIABLE cString AS CHARACTER  NO-UNDO.
DEFINE VARIABLE iTmp AS INTEGER    NO-UNDO.
DEFINE VARIABLE iTmp2 AS INTEGER    NO-UNDO.
DEFINE VARIABLE iTmp3 AS INTEGER    NO-UNDO.
DEFINE VARIABLE cHelp AS CHARACTER  NO-UNDO.
 
ASSIGN cString = '/* /* /* */ */ */    /*/'.
/* first check for number of times /*  are in the string */*/
ASSIGN cHelp = cString
       iTmp2 = 0.
DO WHILE cHelp <> '':
    ASSIGN iTmp = INDEX(cHelp,'/~*').
    IF iTmp > 0
    THEN DO: 
        ASSIGN iTmp2 = iTmp2 + 1
               cHelp = SUBSTRING(cHelp,iTmp + 2).
    END.
    ELSE ASSIGN cHelp = ''.
END.
/*/* next check how many time */ occurs in the string */
ASSIGN cHelp = cString
       iTmp3 = 0.
DO WHILE cHelp <> '':
    ASSIGN iTmp = INDEX(cHelp,'~*/').
    IF iTmp > 0
    THEN DO: 
        ASSIGN iTmp3 = iTmp3 + 1
               cHelp = SUBSTRING(cHelp,iTmp + 2).
    END.
    ELSE ASSIGN cHelp = ''.
END.
 
/* Message the total counter  */
MESSAGE iTmp2 - iTmp3
    VIEW-AS ALERT-BOX INFO BUTTONS OK.

Casper.
 
thanks somewhat i am near to my solution.
if suppose i have a line like this

/*hi*/ m_tin_lbl = GetTermLabel("XX_TIN:",4). /*"TIN:".*/ /*PSK01*/

then this line is not commented actually how to get the actual line.

this is a sample and can u explain it when this happens for multiline and multicommended program.
 

In other words, your problem isn't really about counting comments at all, but rather about being able to analyze the program in a syntactically correct way. In this case it is omitting what is in comments, but you might equally care about cases where a particular string might be part of a keyword or a variable name or a constant, for example.

The perfect solution to this is ProParse http://www.oehive.org/proparse . You will probably also want to take a look at ProLint since it might be easier to build what you want as a rule in ProLint than to build from scratch on top of Proparse. And, if not, ProLint will at least show you some practical examples of how to accomplish certain tests.
 
Back
Top