Version 2.1 5-20-2002
Download LOC.jar
java -jar LOC.jar
1) Click the "Choose File" button to open a standard file chooser dialog and then navigate to the desired file. When you select a file, the filename and the line count will appear in the display window.
2) Uncheck the check box if you don't want comments included in your
line count.
4) Don't count comments:
java -cp LOC.jar textui.LOC -n sourcefile.java
5) Count lines in a file in specified directory
java -cp LOC.jar textui.LOC -d C:\somedir\ sourcefile.java
6) Count lines in multiple files from stdin
dir /b | java -cp LOC.jar textui.LOC
7) Count lines in multiple files in specified directory.
Note: the directory name must end with a backslash.
dir /b C:\myproject | java -cp LOC.jar textui.LOC -d C:\myproject\
This rule means that a single brace or a comment line containing only double slashes won't count.
This rule places some responsibility on the programmer to format his
or her code in a sensible fashion.
If you do silly things like this
public static
void main
(Strings args[])
each line will be counted, which probably is cheating. The best way to
manage this is to follow an established coding standard.
If you elect to NOT count comments, your source code needs to follow
certain conventions to be counted properly:
// Lines that start with two slashes or
-- two dashes are considered comments
/* C-style comments can end on the same line like this */
/* A "block" comment may continue across
lines like this, as long as you started the first
line with the slash-star */
But if you start the line with code you
can't continue across lines /* by starting
at the end of a line
like this */
Because you should // use trailing comments
// like this
// instead
/* Similarly, don't put code
you want counted */ after a close block comment like this
We can't deal with nested block comments -- the first star-slash
will
terminate the block (as do most compilers).
/*
Since there must be 4 or more non-blank characters on the
line to be counted, the above
line won't count (even if you are counting comments).
Nor will the following:
*/
(Windows) If you specify a directory name on the command line that contains embedded blanks, you must omit the trailing quote. For example:
C:\>dir /b "C:\Try Me" | java -cp LOC.jar textui.LOC -d "C:\Try Me\ 00403 C:\Try Me\Rational.java 00394 C:\Try Me\RationalDriver.java 00123 C:\Try Me\NaturalDriver.java 00231 C:\Try Me\Natural.java ----- 01151
Test Data File
Here is the file we used as test data to verify the software: LOCtestcase1.txt