views:

185

answers:

5

Possible Duplicates:
Code polisher / reformater for C, C++ or Fortran
Best C++ Code Formatter/Beautifier

I have code in C, C++ and Fortran (both f77 and f95) in a strong need for proper indentation (that is: they have none). I remember some tool to fix indentation, although I'm unable to find it, and as far as I recall, it just worked with C.

Is there a tool for this task ?

+2  A: 

For C and C++: http://stackoverflow.com/questions/841075/best-c-code-formatter-beautifier

For Fortran: http://stackoverflow.com/questions/3413391/code-polisher-reformater-for-c-c-or-fortran

ArunSaha
Identify duplicates in the comments, please.
dmckee
@dmckee: If the comment is directed to me: I don't see how to mark duplicate. I suspect that I do not have enough reputation.
ArunSaha
@Arun: You don't yet have the reputation to vote to close, but you have more than enough to post a comment.
dmckee
A: 

You can copy-paste your code to visual studio and then ctrl+A to select all of it. Then press ctrl+K and after that ctrl+F.

Green Code
A: 

For C-style languages, my tool of choice is Artistic Style (AKA astyle), which does its work fine and is widely customizable (although I like the default ansi style).

I even added a shortcut to gedit, so that the content of the buffer can be reindented without even saving it with a simple Ctrl+Shift+I; this has proven very useful for re-indenting code posted on SO and forums "on the fly".

Matteo Italia
A: 

If you want a "one for all" tool maybe uncrustify is right for you. It has about 385 config options and should be able to format C, C++ and Fortran (with the right config file). It's distributed with some sample configs and you may find configs for your language and format somewhere in the net.

Luminger
+1  A: 

This is a task that my editor looks after for me. I use Emacs, but I know that MS Visual Studio is also capable of indenting code in these languages, I guess most other programmers editors are too.

High Performance Mark