Apologies in advance for the bad font, but Slashdot stopped allowing because of the trolls, so this was the only way to get indentation. Ugh. There's some irony for you.
I've used GNU indent, and it is maybe 1% of the way to a complete solution, if that. A complete solution needs crazy things like:
* Variable weights for indentation priority between the minimum indentation of a continuation line relative to the first line and colon alignment in Objective-C
* Rules on where whitespace can and can't be inserted to correct alignment (e.g. rules like "Don't put any space between the (strong, atomic) and the subsequent type name in an Objective-C property, in such a way that they can be outweighed by other rules if it makes the line too long
* Choosing whether to indent function parameters by the standard n spaces instead of indenting to the open parenthesis if the latter approach would result in a single parameter getting split across multiple lines and the former approach wouldn't
* Closing up space between certain types of tokens (arbitrarily)
* Adding space between certain types of tokens (arbitrarily)
* Proper handling of comment markup (e.g. HeaderDoc, Doxygen, JavaDoc, etc.) with knowledge of where newlines and whitespace matter
* Ability to handle programming languages other than C and related languages
And so on. Basically, the set of rules would likely mean that everything on the left side of the language's BNF would be a named token type, and you could specify rules regarding whether spaces could be added before or after that token type. For example, you might write rules like this:
To specify that an if statement should be followed by exactly one space before the opening parenthesis, but a function should not, and any such space should be removed.
You'd also need to be able to contextually describe specific tokens like braces. For example, if you wanted to indent the opening brace of a function by 4 and every line nested inside it by 8, you might write something like:
min-indent: [previous-line] + 4;
child-indent: [previous-line] + 8;
So basically, something vaguely like CSS, but with weighting instead of order-based priority, plus the ability to define fallback rules with lower priority that get used if the higher-priority rule fails because it conflicts with another rule that has higher priority (e.g. an indent rule set that uses four-character indent if the first rule set for indenting to the open parenthesis gets overruled by a maximum line length rule).