Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
counting lines of code/low level file functions
Message
 
À
20/05/1998 09:39:53
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00100503
Message ID:
00100534
Vues:
36
>>Hello:
>>
>>I'm writing a program to count the lines of code in my program
>>that must count lines of code, comments and blank spaces separately.
>>I'm using the following code and it returns blanks and comments but
>>any indentation i.e. of comments in my code is counted as a blank line. Any idea of how I can get around this, any help would be greatly appreciated. Thanks.
>>set defa to \wincats
>>gnfilehandle = fopen("mainlib.prg")
>>
>>blanklines = 0
>>astlines = 0
>>amplines = 0
>>
>>do while not feof(gnfilehandle)
>>
>>cstring = fgets(gnfilehandle)
>>
>>If empty(cstring)
>> blanklines = blanklines + 1
>>endif
>>? blanklines
>>
>>If left(cstring) = "*"
>> astlines = astlines + 1
>>endif
>>?astlines
>Also continuation lines count as one ?
*function countlines
>lparameters cFileName
>store 0 to blanklines, astlines, codelines
>gnfilehandle = fopen(cFileName)
>do while !feof(gnfilehandle)
>  cstring = upper(alltrim(fgets(gnfilehandle)))
>  do case
>  	case empty(cString)
>		blanklines = blanklines + 1
>  	case inlist(cString,"*","NOTE") or (cString = "&" and substr(cString,2)="&")
>    	astlines = astlines + 1
>	otherwise
>		if right(cString,1) # ";"
>			codelines = codelines + 1
>	  	endif
>  endcase
>enddo
>fclose(gnfilehandle)
>? Blanklines, astlines, codelines
Cetin

Cetin,

Nice stuff. I was going to do much the same, except I realized there's one condition that I didn't know how to handle. Consider:
lnresult = lnsomevar + lnothervar && Get the total
The above code won't count the comment. I don't know if Sheena would want it counted or not. If so, then some adjustment needs to be made.
George

Ubi caritas et amor, deus ibi est
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform