Using indent Utility211
Among other things, note that
indent
has placed a space after the second
printf
func-
tion call. This is the default style of putting braces in C code. Since the GNU formatting style is
used with GNU
indent
by default, and it uses the –
bl
option, the result is as shown above. To
put the starting brace on the same line, you can use the –
br
command line switch and the result
is as follows:
if (counter > 0) {
counter--;
printf ("Counter value is: %d \n");
}
else {
printf ("Counter reached zero. Resetting counter\n");
counter = 100;
}
Other forms of
indent
can be used with different statements. See the manual pages of
indent
for a detailed list of all options.
7.1.5Formatting Declarations
You can tell
indent
to handle the variable declarations in other ways by using different
options to separate the declaration lines from other code. The most common method is to
place a blank line after the declaration’s end. As an example, if you use the –
bad
option
(blank line after declarations),
indent
will place a blank line wherever it finds end of the
declaration part. In the previous example of
hello.c
program, the result of using this option
will be as follows:
1 /**************************************
2 * hello.c
3 *
4 * This file is used to demonstrate use
5 * of indent utility
6 *************************************/
7 #include
8
9 main ()
10 {
11 char string[25];
12
13 printf ("Enter a string of characters : ");
14 scanf ("%s", string);
15 printf ("The entered string is : %s\n ", string);
16 }
Note that line number 12 is inserted into the file. You can also use the –
di
option with
indent
to align an identifier to a particular column. For example, using –
di8
will align all
identifiers to column number 8. Consider the following two lines in a C source code file.