Easy way to count total lines of code?

Working on new editor enhancements?
Nituvious
Addict
Addict
Posts: 1029
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Easy way to count total lines of code?

Post by Nituvious »

How can I view how many lines of code my program has? For example if I am building a project that spans several include files?
▓▓▓▓▓▒▒▒▒▒░░░░░
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Easy way to count total lines of code?

Post by ts-soft »

Click on details when compiling!
But the project must be large to see the lines :wink:
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Easy way to count total lines of code?

Post by Trond »

If you put all your code in one folder (with subfolders) you can use this code:

Code: Select all

Procedure ExamineDirectoryRecursive(Path.s, Pattern.s, List _List.s())
  Protected Dir = ExamineDirectory(#PB_Any, Path, Pattern)
  If Dir
    While NextDirectoryEntry(Dir)
      AddElement(_List())
      _List() = Path + DirectoryEntryName(Dir)
    Wend
    FinishDirectory(Dir)
  EndIf
  Dir = ExamineDirectory(#PB_Any, Path, "")
  If Dir
    While NextDirectoryEntry(Dir)
      If DirectoryEntryType(Dir) = #PB_DirectoryEntry_Directory
        If DirectoryEntryName(Dir) <> "." And DirectoryEntryName(Dir) <> ".." And FindString(DirectoryEntryName(Dir), "Examples", 0) = 0
          ExamineDirectoryRecursive(Path + DirectoryEntryName(Dir) + "\", Pattern, _List())
        EndIf
      EndIf
    Wend
    FinishDirectory(Dir)
  EndIf
EndProcedure

Dir.s = "C:\project\" ; use final \
NewList _List.s()
ExamineDirectoryRecursive(Dir, "*.pp", _List())

I = 0
ForEach _List()
  ;Debug _List()
  ReadFile(0, _List())
  N = I
  While Not Eof(0)
    I + 1
    S.s = ReadString(0)
    If Trim(s) = ""
      Empty + 1
    EndIf
  Wend
  Debug LSet(Str(I-N), 5) + _list() ;ReplaceString(_List(), Dir, "")
Next
Debug "Total lines: " + Str(I)
Debug "Non-empty lines: " + Str(I - Empty)
Debug "Empty lines: " + Str(Empty)
Nituvious
Addict
Addict
Posts: 1029
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: Easy way to count total lines of code?

Post by Nituvious »

:shock:

You mean to tell me there isn't a magic button I can press to get it? I guess writing a compiler tool for this would be an excellent learning experiment. :?
▓▓▓▓▓▒▒▒▒▒░░░░░
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: Easy way to count total lines of code?

Post by Fluid Byte »

What's the point of counting the lines? Wanna' show off?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Nituvious
Addict
Addict
Posts: 1029
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: Easy way to count total lines of code?

Post by Nituvious »

Fluid Byte wrote:What's the point of counting the lines? Wanna' show off?
Curiosity mainly. And trimming redundant code. And it would just be nice to know.
▓▓▓▓▓▒▒▒▒▒░░░░░
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Re: Easy way to count total lines of code?

Post by Rings »

Nituvious wrote:
Fluid Byte wrote:What's the point of counting the lines? Wanna' show off?
Curiosity mainly. And trimming redundant code. And it would just be nice to know.
could it possible that you use the DEMO version
and wanna avoid the Restrictions ?
SPAMINATOR NR.1
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Easy way to count total lines of code?

Post by blueznl »

Would it matter? :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Easy way to count total lines of code?

Post by Trond »

Type "pbcompiler yourfile.pb" and it will tell you the number of lines processed. If you include some file multiple times it will get counted multiple times, though.
Nituvious
Addict
Addict
Posts: 1029
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: Easy way to count total lines of code?

Post by Nituvious »

Rings wrote:could it possible that you use the DEMO version
and wanna avoid the Restrictions ?
Yes I use the demo version but it's not because I want to avoid the restriction. I haven't ever gotten close to the restriction before. I am simply curious how many lines of code I put into a project, that's all.
▓▓▓▓▓▒▒▒▒▒░░░░░
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: Easy way to count total lines of code?

Post by Fluid Byte »

:lol:
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Easy way to count total lines of code?

Post by PB »

There's nothing illegal about reducing the number of lines anyway.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Nituvious
Addict
Addict
Posts: 1029
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: Easy way to count total lines of code?

Post by Nituvious »

PB wrote:There's nothing illegal about reducing the number of lines anyway.
Thank you! :?
▓▓▓▓▓▒▒▒▒▒░░░░░
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Easy way to count total lines of code?

Post by Kwai chang caine »

It's not for a project...but if that can help you ...
http://www.purebasic.fr/english/viewtop ... 60#p274560
ImageThe happiness is a road...
Not a destination
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Easy way to count total lines of code?

Post by Vera »

Hi Trond,

thanks for your edifying snippet :)

here are the actual results of the pb\example\sources codes-lines from the Linux edition ;)
Total lines: 5644
Non-empty lines: 4266
Empty lines: 1378
cheers ~ Vera
Post Reply