tzwenn
tzwenn

Reputation: 303

Rearranging badly styled C code

I've got around 12,000 lines of badly styled C code, e.g.

initholeend=(mm_footer *) (end-sizeof(mm_footer));
initholeend->magic=MM_MAGIC;
initholestart->used+=amount;

What I'd like to do is automatically adding spaces around all binary operands and assigments:

initholeend = (mm_footer *) (end - sizeof(mm_footer));
initholeend->magic = MM_MAGIC;
initholestart->used += amount;

Is there any recommended tool to do so?

Thanks in advance.

Upvotes: 3

Views: 346

Answers (5)

Isaac
Isaac

Reputation: 625

If using unix, just open it up in vi with the autoformat feature turned on. If you're on Windows or Mac, use Codeblocks --or Notepad++ if you don't like IDEs -- where indentation and color coding for paren balancing is the default.

Upvotes: 0

Jörgen Sigvardsson
Jörgen Sigvardsson

Reputation: 4887

astyle isn't bad.

Upvotes: 4

The Archetypal Paul
The Archetypal Paul

Reputation: 41749

The classic answer is indent(1).

It has about a billion options, which should handle your requirements

Upvotes: 1

jdehaan
jdehaan

Reputation: 19928

I would like to recommend you uncrustify. I am quite satisfied with that code beautifier and provides good results for even more programming languages.

Upvotes: 4

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272487

Most IDEs (and several command-line options) have an option to "auto-format" code according to a coding style of your choice. Eclipse is one such IDE.

Upvotes: 1

Related Questions