Skip to content

Commit 3878ecb

Browse files
author
tthomps
committed
Add some improvements to LineCounter script:
Display a progress bar for initially counting the number of files. This is useful for really big projects like Linux and ReactOS. Add numerical formatting to TODOs and HACKs. Add some screenshots analyzing some other projects.
1 parent 6a92832 commit 3878ecb

File tree

7 files changed

+48
-10
lines changed

7 files changed

+48
-10
lines changed

Media/Screenshots/LineCounter.png

-1.31 KB
Loading

Media/Screenshots/linux_lines.png

7.46 KB
Loading

Media/Screenshots/managarm_lines.png

6.81 KB
Loading

Media/Screenshots/reactos_lines.png

7.29 KB
Loading
6.98 KB
Loading

Media/Screenshots/toaruos_lines.png

6.78 KB
Loading

SupportApps/CountLines.ahk

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ TotalDirectories := 0
77
SourceFiles := 0
88
SourceFilesCounted := 0
99
NonSourceExts = dll
10-
ExtensionsToParse = cs,c,cpp,h,ahk,hpp,cc
10+
ExtensionsToParse = cs,c,cpp,h,ahk,hpp,cc,py,sh
1111
;ExcludeFolders = SDL,My-Doom
1212
SourceOnlyLines := 0
1313
CommentOnlyLines := 0
@@ -17,15 +17,50 @@ BracesOnlyLines := 0
1717
SkippedLines := 0
1818
TODOs := 0
1919
HACKs := 0
20+
2021
Directories :=
2122
SourceFileList :=
2223
Comments :=
2324

2425
SetWorkingDir, %A_ScriptDir%\..
2526

27+
; Let the user know that we're doing something
28+
Progress, M2, (1 / 3), Counting Directories, Counting...
29+
30+
; Just determine how many directories there are, for really big source trees (like ReactOS and Linux)
31+
JustDirectories := 0
32+
Loop, Files, *, DR
33+
{
34+
; Even though this code isn't really meant for MyOS, I'll skip these directories for consistency:
35+
IfInString, A_LoopFileFullPath,SDL\
36+
continue
37+
IfInString A_LoopFileFullPath,My-Doom\
38+
continue
39+
IfInString A_LoopFileFullPath,.git
40+
continue
41+
IfInString A_LoopFileFullPath,.vs
42+
continue
43+
IfInString A_LoopFileFullPath,font
44+
continue
45+
IfInString A_LoopFileFullPath,spf
46+
continue
47+
IfInString A_LoopFileFullPath,Debug
48+
continue
49+
IfInString A_LoopFileFullPath,Release
50+
continue
51+
IfInString A_LoopFileFullPath,x64
52+
continue
53+
54+
JustDirectories += 1
55+
}
56+
57+
Progress, R0-%JustDirectories% M2, (2 / 3), Counting Numer of Files, Counting...
58+
2659
; Determine how many files and directories we need to scan
2760
Loop, Files, *, DFR
2861
{
62+
Progress, %TotalDirectories%, (2 / 3), Counting Numer of Files, Counting...
63+
2964
; Don't include files or folders which mostly contain source I didn't write
3065
IfInString, A_LoopFileFullPath,SDL\
3166
continue
@@ -78,7 +113,7 @@ Loop, Files, *, DFR
78113

79114
; Display a window with a progress bar
80115
;totalEverything := TotalFiles + TotalDirectories
81-
Progress, R0-%SourceFiles%, %a_index%, %a_loopfilename%, Counting..., Counting Lines
116+
Progress, R0-%SourceFiles% M2, %a_index%, %a_loopfilename%, Counting..., Counting Lines
82117
Loop, Files, *, DFR
83118
{
84119
Progress, %SourceFilesCounted%, %a_loopfilename%, Counting..., Counting Lines
@@ -133,27 +168,30 @@ StringTrimRight, StringLines, StringLines, 3
133168

134169
;MsgBox %Directories%
135170
CountSummary :=
136-
CountSummary .= NumericalFormat(SourceOnlyLines + SourceLinesWithComments + CommentOnlyLines) . " Total Unique and meaningful lines`r`r"
171+
CountSummary .= NumericalFormat(SourceOnlyLines + SourceLinesWithComments + CommentOnlyLines) . " Total unique and meaningful lines`r`r"
137172
CountSummary .= NumericalFormat(SourceOnlyLines + SourceLinesWithComments) . " Total lines with code`r"
138173
CountSummary .= NumericalFormat(CommentOnlyLines + SourceLinesWithComments) . " Total lines with comments`r`r"
139174
CountSummary .= NumericalFormat(SourceOnlyLines) . " lines with only code`r"
140175
CountSummary .= NumericalFormat(SourceLinesWithComments) . " lines with comments and code`r"
141176
CountSummary .= NumericalFormat(CommentOnlyLines) . " lines with only comments`r"
142177
CountSummary .= NumericalFormat(BracesOnlyLines) . " lines with only braces`r"
143-
CountSummary .= NumericalFormat(BlankLines) . " blank lines"
144-
145-
CommentOnlyLines := 0
146-
SourceLinesWithComments := 0
147-
BlankLines := 0
148-
BracesOnlyLines := 0
178+
CountSummary .= NumericalFormat(BlankLines) . " blank lines`r"
179+
CountSummary .= NumericalFormat(TODOs) . " TODOs`r"
180+
CountSummary .= NumericalFormat(HACKs) . " HACKs`r"
181+
CountSummary .= "`rCounted in`r"
182+
CountSummary .= NumericalFormat(SourceFiles) . " source files in`r"
183+
CountSummary .= NumericalFormat(TotalDirectories) . " directories"
149184

150185
; This can be used for debugging. Here I've set it out to show me lines with comments and code:
151186
;Gui, Add, Edit, R50 w900 Multi vListingBox
152187
;GuiControl,, ListingBox, %Comments%
153188
;GuiControl,, ListingBox, %Directories%
154189
;Gui, Show
155190

156-
MsgBox Results of scanning %A_WorkingDir%:`r`r%CountSummary%`r%TODOs% TODOs`r%HACKs% HACKs`r`rCounted in `r%TotalDirectories% directories`r%SourceFiles% source files
191+
; Isolate the OS name from the working dir
192+
StringGetPos, NameStart, A_WorkingDir,\,R
193+
OSName := SubStr(A_WorkingDir, NameStart + 2)
194+
MsgBox Results of scanning %OSName%:`r`r%CountSummary%
157195
;`rNon-Source files with extensions of %NonSourceExts%
158196
ExitApp ; Replace this with return during development
159197

0 commit comments

Comments
 (0)