just because i needed to know the number of lines for each of my sources programs, i made this little code, i also added the number of procedures inside each program
The program counts only line of code and extracts empty and remarks' lines
Code: Select all
./pblc *.pb
or
./pblc adir_*.pb
or
./pblc adir_*.pb adir_*.pbi
or
./pblc adir_*.pb?
Code: Select all
; *****************************
; *** ***
; *** pblc - count line ***
; *** ***
; *****************************
;
; count effectives lines of PureBasic programs without remarks and empty lines
; and count number of procedures
Global argc.i, thefile.s, totline.i, totproc.i
Procedure.i Get_NBLINE(thefile.s)
Protected NewList line_prg.s(), tmp.s
Protected ligne.i = 0, proc.i = 0, i.i = 1
Protected rem.i = #False : car.i = #False
ClearList(Line_prg())
If ReadFile(0, thefile)
While Eof(0) = 0
tmp = ReadString(0)
AddElement(Line_prg())
line_prg() = tmp
Wend
CloseFile(0)
Else
PrintN("Unable to read " + thefile)
End
EndIf
ResetList(line_prg())
ForEach line_prg()
l = Len(line_prg())
rem = #False : car = #False : i = 1
While i <= l
a$ = Mid(line_prg(),i,1)
If a$ = Chr(32) : i + 1 : EndIf
If a$ = ";" And car = #False : i + 1 : rem = #True : EndIf
If a$ > Chr(32) And a$ < Chr(128) : car = #True : EndIf
i + 1
Wend
If car = #True And rem = #False : ligne + 1 : EndIf
If FindString(line_prg(),"EndProcedure",1) And rem = #False : proc + 1 : EndIf
Next
PrintN(RSet(Str(ligne),6," ") + " " + thefile + "("+Str(proc)+")")
totproc + proc
ProcedureReturn ligne
EndProcedure
OpenConsole()
argc = CountProgramParameters()
totproc = 0
If argc = 0
PrintN("Usage : pblc <filename>")
End
EndIf
If argc > 1 ; several files (because we're using joker/wildcard "*" or "?")
For i = 0 To argc - 1
thefile = ProgramParameter(i)
totline + Get_NBLINE(thefile)
Next i
PrintN("------------")
PrintN(RSet(Str(totline),6," ") + " total("+Str(totproc)+")")
Else
Get_NBLINE(ProgramParameter())
EndIf
CloseConsole()
Thanks to Captn. Jinguji & GBeebe for the ProgramParameter joker/wildcard.
not tested under win