un petit programme en mode console permettant de compter le nombre effectifs de lignes de code d'un programme Purebasic, avec possibilité de faire un total sur +sieurs fichiers.
Il compte chaque ligne du programme en ne comptabilisant pas les lignes avec commentaire seule ou lignes vides.
J'ai fait ce programme pour connaitre le nombre total de ligne du programme que je suis entrain de faire.
Code : Tout sélectionner
; *****************************
; *** ***
; *** 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()
NB2 : wc c'est pour word count, pas autre chose

*** EDIT *** : affiche le nombre de procédures