views:

242

answers:

5

Hello,

suppose you have got a bunch of files written in C, C++ or Fortran, by different authors with different opinions on formating, how to comment (...) and so on. I think many people know situations like these.

Are there any free tools for ends like:

  • uniform format of code (indent etc.)
  • create standard comment bodies
  • rename variables

Thanks, morgennebel

+4  A: 

You can have a look at the indent (unix) command. It doesn't do everything you are asking for , but that's a good start I think

mb14
+1. Scary tool. Anything and everything can be configured. Runs from command line and can do batch indenting.
Dummy00001
+5  A: 

Have a look at AStyle. It's a command line based formatter/beautifier. It doesn't handle Fortran though it works with C, C++, C# and Java

Glen
+1: I love astyle!
Luther Blissett
This looks positively awesome, however it seems primarily intended for C code and I wonder how it performs when C++ specifics are thrown in (template, lambda), I'll give it a try for sure!
Matthieu M.
+1: I use AStyle regularly with generally good results too.
S.C. Madsen
Thanks, this seems to be a very powerful tool, albeit not for Fortran.
A: 

The CDT Plugin for Eclipse has great formatting and refactoring tools for C/C++.

The formatter can be customized to fit almost all needs.

Also the refactoring tools are quite powerful and renaming variables, classes etc. is an easy and safe task with them. (They use the indexer/parser to recognize scope of variables, so its not a simple search and replace. Matching patterns within comments can be changed automatically, too).

However, as far as I know there is no batch processing possible.

Edit: Another - obvious - drawback is, that you have to create a project to make the indexer (and thus the refactoring tools) work. So at least you have to add all include paths and important compiler defines to project settings. I never tried, but the indexer should work fine without a real compiler available, but it may be necessary to make the project to use the "internal builder", otherwise you cannot set include paths. (I'm unsure about this, because I use the internal builder with gcc in my projects - this works fine.)

IanH
A: 

I've used Uncrustify with UniversalIndentGui for formatting C++ code. It works pretty well. Uncrustify offers many customization options and UniversalIndentGui "offers a live preview for setting the parameters of nearly any indenter. You change the value of a parameter and directly see how your reformatted code will look like."

foven
A: 

For Fortran there is plusFORT, which can do much more than what you ask for, such as reorganizing code and translating from FORTRAN 77 to Fortran 90. See http://www.polyhedron.com/pf-plusfort0html and http://www.polyhedron.com/pflinux0html

M. S. B.