Hi,
I've been trying to get asyle to reformat C++ code such that every statement in a for() loop body gets brackets placed around it (while, if, etc. also desirable).
e.g. the code
Code:
for(int i = 0; i < 10; i++)
for(int j = 0; j < 10; j++)
arr[i][j] = i*j;
would be converted to
Code:
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
arr[i][j] = i*j;
}
}
The asyle -j option only does this for the second loop, which gives the following. I'm using -A1 style btw.
Code:
for(int i = 0; i < 10; i++)
for(int j = 0; j < 10; j++)
{
arr[i][j] = i*j;
}
Any help would be appreciated. If it's not possible with the current astyle, how hard is it to modify the astyle code for such functionality?
EDIT:
I may be mistaken, but from the source code it appears that this functionality has been explicitly disabled, which is a shame (as I don't know how to fix it quickly without destroying everything). Lines 5286 of ASFormatter.cpp have the telltale code (a 'header' is defined as a for/while/if/etc. keyword):
Code:
// do not add if a header follows
if (isCharPotentialHeader(currentLine, charNum))
if (findHeader(headers) != NULL)
return false;
This can't simply be removed, as the next lines find the first ';' character to put a bracket after (this will screw up a for loop, for example - actually it will screw up an already-bracketed block too). Any help fixing the code still appreciated