210Chapter7 • Miscellaneous Tools
By adding
n
in the start of these options, their effect may be reversed. For example, the
-nbad
option will not add any blank line after declaration.
7.1.4Formatting Braces
People have different tastes about how braces should be formatted in C language. Using
indent
you can specify different ways of formatting braces. Let us consider a poorly formatted
piece of C source code and see different ways of formatting it. The input segment of source code
is shown below:
if (counter > 0)
{
counter-- ;
printf ("Counter value is: %d \n");
}
else
{
printf("Counter reached zero. Resetting counter\n");
counter = 100;
}
The default indentation of this segment of code is shown below. This is the default GNU
indentation when you use no command line switches with
indent
.
if (counter > 0)
{
counter--;
printf ("Counter value is: %d \n");
}
else
{
printf ("Counter reached zero. Resetting counter\n");
counter = 100;
}
-bbb
This option is used to add a blank line before a boxed comment. An example of a
boxed comment is shown below.
/**************************************
* hello.c
*
* This file is used to demonstrate use
* of indent utility
*************************************/
-sob
This option is used to remove unnecessary blank lines from the source code.
Next Page >>
<< Previous Page
Back to the Table of Contents