>Hello:
>I'm writing a program to count the lines of code in my programs.
>I need to be able the count the lines of code without including the comments and blank spaces. Any ideas on how to do this? THis is the code that I'm using that returns the total number of lines including comments.
>gnfilehandle = fopen("mainlib.prg")
>nsize = fseek(gnfilehandle,0,2)
>if nsize <= 0
>wait window "this file is empty!" nowait
>else
>=fseek(gnfilehandle, 0)
>lctext = fread(gnfilehandle, nsize)
>lnlines = occurs(chr(13), lctext)
>? lnlines
>endif
>
>This works and returns total number of lines. Any suggestions would be greatly appreciated.
I've done this before, here it is:
crea curs tm (m m)
appe blank
#define cr chr(13)+chr(10)
_cnt=0
_cnc=0
n=adir(a,"*.prg")
=asort(a)
for i= 1 to n
appe memo m from (a(i,1)) over
_x=occu(cr,m)
_c=occu(cr+"*",m)
? a(i,1), tran(_x, "999999") at 26, tran(_c, "999999") at 40
_cnt=_cnt+_x
_cnc=_cnc+_c
endf
? "Total",_cnt, "commented",_cnc
It'd probably need some more work to do, because it doesn't actually count the lines - i.e. doesn't discount empty lines, multiline comments etc. It's just a quick'n'dirty solution I wrote once, which served as a minimal statistic tool once. It discovered some funny programmer's habits - my specialistic polyclinic app had about 26000 lines altogether, while the other two guy's water billing app had 52000 lines. Reason? Excessive cut&paste of code, lots of almost repeated things, keeping four versions of the same long thing (being different by two or three lines only) etc.