206Chapter7 • Miscellaneous Tools
This is sometimes useful if you just want to test the behavior of
indent
without modify-
ing a file.
The most efficient use of
indent
is through a shell script that goes into each directory of
the source code tree and indents each and every file in the project. You may also create a rule in
the makefile of a project to indent all files in one or all directories. A typical makefile rule may
look like the following:
indent:
indent *.c
indent *.cpp
indent *.h
In the case of a project with multiple subdirectories, you can have a more sophisticated
rule. Taking an example from Chapter 4, where we have four subdirectories, you can use the fol-
lowing rule to go into each directory and indent all C source code files.
SUBDIRS = $(COMDIR) $(FTPDIR) $(TFTPDIR) $(DNSDIR)
indent:
for i in $(SUBDIRS) ; do \
( cd $$i ; indent *.c) ; \
done
Keep in mind that after indenting all of the files, you may have to build the whole project
because source code files have been modified. In big projects this process may take a while.
Indent uses a configuration file called
.indent.pro
, which should be present in the
current directory or in your home directory. You can use this file to set options that you always
use. If the file is present in the current directory, it is used instead of the file in the home direc-
tory of the user. By creating a different
.indent.pro
file in different directories of a project,
you can apply different indentation rules in different directories. This is especially useful when a
project uses multiple languages. For example, indentation rules may be different for C, C++ and
assembly language files.
7.1.2Selecting Coding Styles
Different coding styles are in use by programmers. Some common styles are defined in
indent
program and these may be invoked by a single option at the command line. The most
common style of coding in the open source is the GNU style. This style can be applied using –
gnu
option at the command line. Options, which are used with the GNU style, are listed below:
-nbad
-bap
-nbc
-bbo
-bl
-bli2
Next Page >>
<< Previous Page
Back to the Table of Contents