Thread: Counting Source Lines?

  1. #1
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812

    Counting Source Lines?

    Anyone know where I can get a simple source line number counter from? I just want to count non-blank lines in a C++ project. Something with a windows GUI is preferable.

    I used to use a thing called C Metrics, but it seems to have vanished from the face of the Earth.

    Thanks
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    C-Metrics!

    huzzah!

    -just realized that it's doubly zipped/rarred for some reason...hope that's no big problem for anyone

    Get winrar if you don't have it already! (which you should...)
    Last edited by jverkoey; 08-12-2004 at 10:17 PM.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Interesting, 7-zip doesnt have rar compression capability, and using zip compression gives a 871 KB filesize. Same for gzip on a tar archive. bzip2 only gives 841 KB as improvement.
    7-zip itself gives a 691 KB archive.

    Either way I cant reduce the filesize enough to attach it to my post though
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Thanks!

    I don't seem to be able to write anything under 38,000 lines.


    Found a nice completely free compression utility which did the job:

    http://www.izsoft.dir.bg/izarc.htm
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  5. #5
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    why don't you try searching. We have done this before here

    the answer you probably want is by Perspective
    Code:
    grep -n .\* in-file > out-file

  6. #6
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    That command adds line numbers to a file, to count lines in one file:
    Code:
    $ wc -l filename
    To count lines in the source tree:
    Code:
    $ grep "" -R source_dir | wc -l
    To count non-blank lines:
    Code:
    $ grep -v "^$" -R source_dir | wc -l
    If you run Windows, you can get grep.exe by installing Cygwin, it's a free download, just google for the name.
    Last edited by glUser3f; 08-13-2004 at 10:14 AM.

  7. #7
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    or just change -n to -c, no need to pipe to wc

    grep -c .\* in-file

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Open Source Licenses
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 10-10-2006, 08:53 PM
  2. starting linux's source code and kernel
    By sawer in forum Linux Programming
    Replies: 9
    Last Post: 08-01-2006, 07:46 AM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Counting Lines
    By drdroid in forum C++ Programming
    Replies: 7
    Last Post: 11-18-2002, 05:09 AM