I write a lot of C code. I almost always use indent to reformat my code, using the -gnu and some tweaks.
Does anyone know of a simple way to extend the gnu indent to put blank lines around do while and while loops. Here is one code fragment that I have formatted with indent. Notice that the loops with while are cuddled.
Code:
pivot = first;
pivotHash = d->hash[pivot];
i = first;
j = last;
while (i < j)
{
/* for items less than pivot, move index to right */
while (d->hash[i] <= pivotHash && i < last)
i++;
/* if the items are greater than pivot
working from array end
*/
while (d->hash[j] > pivotHash)
j--;
if (i < j)
doSwap (d, i, j);
}
I would like to have an indent option to yield
Code:
pivot = first;
pivotHash = d->hash[pivot];
i = first;
j = last;
while (i < j)
{
/* for items less than pivot, move index to right */
while (d->hash[i] <= pivotHash && i < last)
i++;
/* if the items are greater than pivot
working from array end
*/
while (d->hash[j] > pivotHash)
j--;
if (i < j)
doSwap (d, i, j);
}
When the while loop is a few lines, as above, it matters not, but if the while loop has 25+ lines, it helps to have a blank line before and after as visual clue to where the while starts
and ends.
I am more keen to see the blank line above and after if there are braces as single while statements are easy to follow. Consider
while ( ) {
}
or
while ( )
{
}
It would be great if that same logic can apply the same rule to
Code:
do {
blah blah
} while (dddd);
x=y;
or
Code:
do
{
blah blah
}
while (dddd);
x=y;
Thanks
PS, I currently use indent and then manually add the blank lines. Surely there must be an extension to indent to allow me to avoid the manual post processing.