ohcount: Ohcount

# Ohcount

The Ohloh source code line counter

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License Version 2 as published by the Free Software Foundation.

Ohcount is specifically licensed under GPL v2.0, and no later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

## Overview

Ohcount is a program for counting lines of source code. It was originally developed at Ohloh and used to generate the reports at www.ohloh.net

Ohcount supports multiple languages within a single file: for example a complex HTML document might include regions of both CSS and Javascript.

Ohcount has 4 main components:

- A detector which determines the primary language family used by a particular source file.
- A parser which provides a line-by-line breakdown of the contents of a source file.
- Another detector which tries to determine the license(s) the source file is licensed under.
- A final detector for gestalts (via the Ruby extension).

The command line tool allows you to profile individual files or whole directory trees.

## System Requirements

Ohcount is supported on Mac OSX 10.5 and Ubuntu 6.06 LTS. Other Linux environments should also work, but your mileage may vary. Windows is not supported.

## Download

Ohcount source code is available as a Git repository:

git clone git://ohcount.git.sourceforge.net/gitroot/ohcount/ohcount

## Building Ohcount

In order to build Ohcount, the following is required:

- GNU C compiler - http://gcc.gnu.org/
- Ragel 6.3 or later - http://research.cs.queensu.ca/~thurston/ragel/
- GNU gperf - http://www.gnu.org/software/gperf/
- PCRE - http://pcre.sourceforge.net/

Run the 'build' script to build Ohcount.

     $ ./build

You may then link or copy 'bin/ohcount' to your system's PATH.

Building the Ruby extension of Ohcount requires:

- Ruby - http://ruby-lang.org/
- Swig - http://swig.org/

     $ ./build ruby

You may then link or copy 'ruby/ohcount.{rb,so}' and 'ruby/gestalt{/,.rb}' to the appropriate places in your Ruby installation.

## First Steps

To measure lines of code, simply pass file or directory names to the bin/ohcount executable:

     $ ohcount helloworld.c

Directories will be probed recursively. If you do not pass any parameters, the current directory tree will be counted.

You can use the ohcount 'detect' option to simply determine the language family of each source file. The files will not be parsed or counted. For example, to find all of the Ruby files in the current directory tree:

     $ ohcount --detect | grep ^ruby

The 'annotate' option presents a line-by-line accounting of the languages used in a source code file. For example:

     $ ohcount --annotate ./test/src_dir/php1.php

More options can be found by typing:

     $ ohcount --help

## Additional Documentation

See the Related Pages tab at the top of the page.

## Contact Ohloh

For more information visit the Ohloh website: http://labs.ohloh.net

You can reach Ohloh via email at: info@ohloh.net