11

I'm fixing up a large, old, crufty project and want to introduce broad changes carefully, both because it will cause merge problems and because the old, crufty project contributors will get upset. At this point I just want to fix the indentation. Braces, comments... leave them all be for now.

Every tool I've tried (bcpp, uncrustify and GNU indent) all have their own ideas about how code should be formatted and I have to spend a lot of time figuring out how to turn them off, if they can be turned off. I also tried the Universal Indent GUI to configure them, but they still reformatted things I didn't ask for.

I need a C code beautifier that by default does nothing. Everything feature has to be turned on. Alternatively, I need a config file for one of the C beautifiers which turns everything off.

2

I wish there was a tool that behaved like you describe. We gave up on using code formatting tools in our projects because the formatting changes they enforced annoyed developers far more than we annoyed each other with our own formatting quirks.

For indentation, in particular, most editors have functions to just indent without otherwise formatting, and you probably have one set up like you want it already. If your favorite editor has a batch mode, then that is probably your best option.

For example, vim has the cindent feature, which after configured as you wish can be invoked at the command line as vim MyFile.cpp -c "%normal ==" -c "wq"

If even that is too structured, you could try using retab or the super retab macros.

0

The 'gc' code beautifier would do what you want, especially with the -no-output-option.

It can be downloaded from: http://sourceforge.net/projects/gcgreatcode/?source=typ_redirect

  • gc -file-foo.c -no-output- did nothing. gc -file-foo.c reformatted the code like all the rest (with a very odd style, too) and changed the file permissions to write-only (?!) and pooped a banner in the file. Is there something I'm missing? – Schwern Oct 14 '15 at 17:43
  • re-route the output to a new file, so the original file is unchanged. The source code is available as a .zip file, so you could unpack the .zip file, make any changes you would like, for instance if no parameters, other than the input file name, to always output the new file to /dev/NULL or to /tmp/samename as input file. – user3629249 Oct 15 '15 at 3:45
  • 4
    If I wanted to do nothing to my code I just wouldn't run gc! The point is to be able to turn features on one at a time. – Schwern Oct 15 '15 at 3:48
  • You have misunderstood the question. – Schwern Oct 15 '15 at 3:55
  • 2
    This is so far off base it's getting weird. – Schwern Oct 15 '15 at 5:21
0

Artistic Style (Astyle) appears to only adjust the indentation by default.

It has options for braces and comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.