Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

The Ohloh source code line counter

tag: 1.0.1

Fetching latest commit…

Cannot retrieve the latest commit at this time

README
= 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 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.4 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.7.3. You will
also require a C compiler to build the native extensions.

Ohcount requires the pcre library (http:///www.pcre.org).

== Download

The source code for ohcount is available as a tarball:

  http://labs.ohloh.net/download/ohcount-1.0.0.tgz

You can also download the source code as a Git repository:

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

== Installation

Ohcount is packaged as a RubyGem. To build and install the gem (you will need
root priveleges for the install):

  $ rake install

To uninstall the RubyGem:

  $ gem uninstall ohcount

If you do not want to install the gem, you can simply build and run it like this:

  $ rake
  $ bin/ohcount

== First Steps

To measure the lines of code, simply pass filenames or directory names
to the +ohcount+ script:

  $ 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 installed ohcount as a gem, you can load it like this:

  require 'rubygems'
  require 'ohcount'

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'

The <tt>bin/ohcount</tt> 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.
* In Ohcount::Generator, instantiate a new Ohcount::Monoglot or
  Ohcount::Polyglot to parse the language.
* In Ohcount::SlocInfo, 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
Something went wrong with that request. Please try again.