A Discrete-Event Network Simulator
API
check-style.py

The check-style.py script will test and reformat code according to the ns-3 coding style posted at https://www.nsnam.org/developers/contributing-code/coding-style/ It requires that you install 'uncrustify'.

+ Collaboration diagram for check-style.py:

The check-style.py script will test and reformat code according to the ns-3 coding style posted at https://www.nsnam.org/developers/contributing-code/coding-style/ It requires that you install 'uncrustify'.

It has multiple levels of conformance:

Examples:

check a single file (level 0 by default):

./check-style.py -f src/core/object.h

fix the style of a single file:

./check-style.py --level=2 --in-place -f src/core/object.h

look at the changes needed for a single file:

./check-style.py --diff --level=1 -f src/core/object.h | less

look at the status of all files modified in your mercurial repository:

./check-style.py --check-hg

look at the changes needed for all modified files in your mercurial repository:

./check-style.py --check-hg --diff |less

Enable this script to run as a 'commit' hook in your repository and disallow commits which contain files with invalid style:

cat hgrc (can be appended to .hg/hgrc or ~/.hg/hgrc or /etc/hg/hgrc
[hooks]
# uncomment below line to enable: works only with mercurial >= 1.3
#pretxncommit.indent = path-to-binary/check-indent.py --check-hg-hook
# uncomment below line to enable: works with all (?) versions 
# of mercurial but requires that PYTHONPATH is defined to point to 
# the directory which contains check-indent.py
#pretxncommit.indent = python:check-indent.run_as_hg_hook

Usage:

Usage: check-style.py [options]

Options:
  -h, --help            show this help message and exit
  --debug               Output some debugging information
  -l LEVEL, --level=LEVEL
                        Level of style conformance: higher levels include all
                        lower levels. level=0: re-indent only. level=1: add
                        extra spaces. level=2: insert extra newlines and extra
                        braces around single-line statements. level=3: remove
                        all trailing spaces
  --check-hg-hook       Get the list of files to check from mercurial's list
                        of modified and added files and assume that the script
                        runs as a pretxncommit mercurial hook
  --check-hg            Get the list of files to check from mercurial's list
                        of modified and added files
  -f FILE, --check-file=FILE
                        Check a single file
  --diff                Generate a diff on stdout of the indented files
  -i, --in-place        Indent the input files in-place