Table of ContentsClose
Coder for Life

LineCount - 2005 to 2007

This is a very tiny Java program (total of 122 lines of code), but it is pretty useful. I have been working on it off and on throughout a couple years, adding new features and tweaks as I used the program and wanted it to change. It counts It the total number of bytes (or characters), total number of lines, and also total number of lines excluding blank lines and comments. Below I have included both the source code and the compiled version. It requires Java 1.5 because of my use of generics. You could easily modify the source code to allow any version of Java. It currently assumes that // is a single line comment and /* */ are block comments (so does not ignore comments in HTML). It will only not count lines that are white-space after removing commented areas. This could once again be changed to fit your needs in the source code. Please tell me how you modified it and I may include it here! The source code is provided without any license, but I would appreciate it if you mentioned me as a source where ever you use it.

This program was superseded by a more advanced version written in PHP that outputs HTML content to be viewed in a web browser and provides a much nicer interface to the data.

Command Line

The command line options allow this to be pretty useful, and I usually make a bat file with my choice of the command line options. There are three option which are:

  1. -inc (or -include) file1 file2 file3 ...
  2. -exc (or -exclude) file1 file2 file3 ...
  3. -ext extension1 extension2 extension2 ...

Each argument can have any number of things after it, and each one can be used any number of times, in any order. The files can actually be files or folders. If it is a folder, then all sub-folders are included as well. If you do not want a particular subfolder (or sub-file) included then you can exclude it. The extensions are the file extensions to check. If you are writing a Java program, then you would include .java and maybe .xml if you had some import files that you wanted checked too.

Example

Here is a pretty complicated example I used with my Popcorn Manager program.

  1. java LineCount -inc . ..\signup\ ..\supersunday\
  2.   -exc .\calendar.js .\dragndrop.js .\tiny_mce .\jsmart
  3.   -ext .php .inc .css .js .java

This is a PHP and Java based program spread out over many folders. I include the current directory (.) and the sibling directories signup (..\signup) and supersunday (..\supersunday). I exclude the calendar and dragndrop JavaScript files because I did not write them, and the entire TinyMCE and JSmart libraries. I check all PHP, PHP Include, CSS, JS, and Java files.

Comments

0 Responses to 'LineCount - 2005 to 2007' Feed for this Entry

There are currently no comments.


Leave a Reply >
Note: If you are having a problem with Windows 7 Boot Updater please email me. Include the description of the problem, the output of boot-info, and any other relevant information (e.g. if you are dual-booting).
If your question has already been answered it will simply be deleted.
Automatically creates links and paragraphs.
Many HTML tags are supported.
Use <code language=""></code> for code.
Language can be dos, java, php, c, ...
(not published)