Программа выдает кол-во строк кода, комментариев и разных элементов программы:
SuperStrict
Global Files:Int = 1
Global Comments:Int
Global CodeLines:Int
Global CommentLines:Int
Global Classes:Int
Global CommentedClasses:Int
Global Methods:Int
Global CommentedMethods:Int
Global Fields:Int
Global CommentedFields:Int
Global GlobalFunctions:Int
Global CommentedGlobalFunctions:Int
Global GlobalVariables:Int
Global CommentedGlobalVariables:Int
Global Constants:Int
Global CommentedConstants:Int
Local FileName:String = RequestFile( "Select bmx file to process...", "bmx" )
Print "File " + StripDir( FileName ) + ":"
ProcessFile( FileName )
Print ""
Print "Files: " + Files
Print "Code lines: " + CodeLines
Print "Comment lines: " + CommentLines
Print ""
Print "Classes: " + StatEntry( Classes, CommentedClasses, False )
Print "Class fields: " + StatEntry( Fields, CommentedFields )
Print "Class methods / functions: " + StatEntry( Methods, CommentedMethods )
Print ""
Print "Global functions: " + StatEntry( GlobalFunctions, CommentedGlobalFunctions, False )
Print "Global variables: " + StatEntry( GlobalVariables, CommentedGlobalVariables, False )
Print "Constants: " + StatEntry( Constants, CommentedConstants, False )
Print ""
Print "Total items: " + StatEntry( Classes + Methods + Fields + GlobalFunctions + GlobalVariables + Constants, CommentedClasses + ..
CommentedMethods + CommentedFields + CommentedGlobalFunctions + CommentedGlobalVariables + CommentedConstants, False )
Function ProcessFile( FileName:String )
Local File:TStream = ReadFile( FileName )
Local OldDir:String = CurrentDir()
ChangeDir( ExtractDir( FileName ) )
Local RemFlag:Int
Local InClass:Int
Local Commented:Int
Local FirstLines:Int = True
While Not EOF( File )
Local Line:String = Trim( ReadLine( File ) ).ToLower()
If RemFlag Then
If Line.StartsWith( "endrem" ) Or Line.StartsWith( "end rem" ) Then
RemFlag = False
Else
If Line.StartsWith( "bbdoc" ) Then Commented = True
If Not FirstLines Then CommentLines :+ 1
End If
Else If Line = "rem" Or Line.StartsWith( "rem " ) Then
RemFlag = True
Else If Line.StartsWith( "'" )
If Not FirstLines Then CommentLines :+ 1
Else If Line.StartsWith( "include" )
ProcessFile( Line[ 8.. ].Replace( "~q", "" ) )
Files :+ 1
ElseIf Line <> "" Then
FirstLines = False
CodeLines :+ 1
If Line.StartsWith( "type" ) Then
InClass = True
Set( Classes, CommentedClasses, Commented )
Else If Line.StartsWith( "endtype" ) Or Line.StartsWith( "end type" ) Then
InClass = False
Else If Line.StartsWith( "method" ) Then
Set( Methods, CommentedMethods, Commented )
Else If Line.StartsWith( "function" ) Then
If InClass Then Set( Methods, CommentedMethods, Commented ) Else Set( GlobalFunctions, CommentedGlobalFunctions, Commented )
Else If Line.StartsWith( "field" ) Then
Set( Fields, CommentedFields, Commented )
Fields :+ CountCommas( Line )
ElseIf Line.StartsWith( "global" ) Then
Set( GlobalVariables, CommentedGlobalVariables, Commented )
ElseIf Line.StartsWith( "const" ) Then
Set( Constants, CommentedConstants, Commented )
End If
End If
WEnd
CloseFile( File )
ChangeDir( OldDir )
End Function
Function Set( Items:Int Var, CommentedItems:Int Var, Commented:Int Var )
Items :+ 1
If Commented Then CommentedItems :+ 1
Commented = False
End Function
Function CountCommas:Int( Line:String )
Local Commas:Int
Local Quotes:Int
For Local N:Int = 0 Until Len( Line )
If Line[ N ] = Asc( "~q" ) Then
Quotes = Not Quotes
ElseIf Not Quotes Then
If Line[ N ] = Asc( "," ) Then Commas :+ 1
End If
Next
Return Commas
End Function
Function TrimDouble:String( Value:Double )
Local StringValue:String = Value
Return StringValue[ ..StringValue.Find( "." ) + 3 ]
End Function
Function StatEntry:String( Items:Int, CommentedItems:Int, WithClasses:Int = True )
Local ClassString:String = ""
If WithClasses Then ClassString = TrimDouble( 1.0 * Fields / ( Classes + ( Classes = 0 ) ) ) + " per class, "
Return Items + " (" + ClassString + CommentedItems + " or " + TrimDouble( 100.0 * CommentedItems / ( Items + ( Items = 0 ) ) ) + "% commented)"
End Function
DWLab framework:
Files: 41
Code lines: 4215
Comment lines: 999
Classes: 49 (37 or 75.51% commented)
Class fields: 175 (3.57 per class, 62 or 35.42% commented)
Class methods / functions: 365 (3.57 per class, 233 or 63.83% commented)
Global functions: 43 (25 or 58.13% commented)
Global variables: 27 (4 or 14.81% commented)
Constants: 29 (16 or 55.17% commented)
Total items: 688 (377 or 54.79% commented)
Редактор миров DWLab:
Files: 21
Code lines: 2895
Comment lines: 13
Classes: 17 (0 or 0.00% commented)
Class fields: 195 (11.47 per class, 0 or 0.00% commented)
Class methods / functions: 94 (11.47 per class, 0 or 0.00% commented)
Global functions: 11 (0 or 0.00% commented)
Global variables: 7 (0 or 0.00% commented)
Constants: 73 (0 or 0.00% commented)
Total items: 397 (0 or 0.00% commented)
Ремейк Super Mario Bros:
Files: 26
Code lines: 1129
Comment lines: 5
Classes: 53 (0 or 0.00% commented)
Class fields: 117 (2.20 per class, 0 or 0.00% commented)
Class methods / functions: 112 (2.20 per class, 0 or 0.00% commented)
Global functions: 0 (0 or 0.00% commented)
Global variables: 1 (0 or 0.00% commented)
Constants: 83 (0 or 0.00% commented)
Total items: 366 (0 or 0.00% commented)
MindStorm:
Files: 11
Code lines: 379
Comment lines: 0
Classes: 10 (0 or 0.00% commented)
Class fields: 48 (4.79 per class, 0 or 0.00% commented)
Class methods / functions: 22 (4.79 per class, 0 or 0.00% commented)
Global functions: 0 (0 or 0.00% commented)
Global variables: 1 (0 or 0.00% commented)
Constants: 30 (0 or 0.00% commented)
Total items: 111 (0 or 0.00% commented)
Большой изометрический лабиринт:
Files: 5
Code lines: 263
Comment lines: 0
Classes: 6 (0 or 0.00% commented)
Class fields: 20 (3.33 per class, 0 or 0.00% commented)
Class methods / functions: 13 (3.33 per class, 0 or 0.00% commented)
Global functions: 1 (0 or 0.00% commented)
Global variables: 2 (0 or 0.00% commented)
Constants: 11 (0 or 0.00% commented)
Total items: 53 (0 or 0.00% commented)