# README

Path: | README
Last Update: | Thu Apr 18 18:50:26 +0000 2013

# 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 <www.gnu.org/licenses/>.

## Overview

Ohcount is a library for counting lines of source code. It was originally developed at Ohloh, and is 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 two main components: a detector which determines the primary language family used by a particular source file, and a parser which provides a line-by-line breakdown of the contents of a source file.

Ohcount includes a command line tool that allows you to count individual files or whole directory trees. It also allows you to find source code files by language family, or to create a detailed annotation of an individual source file.

Ohcount includes a Ruby binding which allows you to directly access its language detection features from a Ruby application.

## System Requirements

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

Ohcount does not support Windows.

Ohcount targets Ruby 1.8.6. The build script targets Rake 0.8.1. You will also require a C compiler to build the native extensions.

## Download

Ohcount source code is available as a Git repository:

      git clone http://git.ohloh.net/git/ohcount.git

## Building Ohcount

During the build process, Ohcount requires Ragel version 6.3 or later. Older versions of Ragel are not compatible. Visit the Ragel homepage at:

      http://research.cs.queensu.ca/~thurston/ragel/

Once Rake, GCC, and Ragel 6.3 are installed, you can build Ohcount as follows:

      $ rake

Ohcount can optionally be installed as a RubyGem. To build and install the gem (you will need root priveleges for the gem install):

      $ rake gem
      $ gem install pkg/ohcount-2.0.0

To uninstall the RubyGem:

      $ gem uninstall ohcount

## First Steps

To measure lines of code, simply pass file or directory names to the `ohcount` script, located in the `bin` subdirectory:

      $ 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

## Loading Ohcount From Ruby

If you have not installed the gem, you‘ll have to make sure that ohcount is on your Ruby load path and then require:

      require 'ohcount'

If you have installed ohcount as a gem, you can load it like this:

      require 'rubygems'
      require 'ohcount'

The `bin/ohcount` script shows examples of calling the ohcount libraries from Ruby.

## How to Add a New Language

These are the steps required to add a new language to ohcount:

- Update Ohcount::Detector to identify files that use the new language.
- Update Ohcount::DetectorTest to confirm the Detector changes.
- Follow the detailed instructions in PARSER_DOC.
- In Ohcount::Language, provide a "nice name" and category (procedural code vs. markup) for the new language.
- Create a new Ohcount::Test to verify the parser.

## Contact Ohloh

For more information visit the Ohloh website:

       http://labs.ohloh.net

You can reach Ohloh via email at:

       info@ohloh.net

[Validate]