C formatter

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have to clean up in some C mess!

 

What is the best tool (on windows), to format C code?

(it has to have a setup for formatting! I don't always agree with default settings ;) )

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Programmers notepad is a favorite of mine

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Linux has "indent". I'm pretty sure there must be Windows ports of this.

 

indent has hundreds of tunable parameters though there are some predefined "group" options that preselect a load of them. I just tend to use the "-kr" option for a Kerninghan & Ritchie layout but realise this is not to everyone's taste!

 

Be warned that one thing indent does not know about is the 0b????? numeric prefix and if it's been used in AVR code (for GCC) it can cause all kinds of issues.

 

EDIT: yup a gnuwin32 build of it here... http://gnuwin32.sourceforge.net/...

 

EDIT2:

C:\Users\cliff>type foo.c
#include <stdio.h >
int
main(void)
                 {

        }

C:\Users\cliff>indent -kr foo.c

C:\Users\cliff>type foo.c
#include <stdio.h >
int main(void)
{

}

To be  honest I don't actually like the fact that it has not vertically spaced the function header from the #include. Sure there must be an option to control that too.

Last Edited: Mon. Jan 30, 2017 - 02:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have downloaded it, but can't find the "formatter" is there an extension I need to add? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use Notepad++ all the time but wasn't aware of it having reformat capabilities. When I Google that I hit this:

 

http://www.andrewhazelden.com/bl...

 

So it sounds like it may be offered by "plugins" not the core tool. When I look at hte plugin manager it says this...

 

 

So that one sounds like it just does intelligent indents. The other one...

 

 

That sounds a lot more likely.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok I tried indent, but could not find the exe file !

 

But I have a copy of WinAVR-20100110 on this computer, and it in that packet ;)

It works fine thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried the textFX as well , but I like your -kr better.

 

I really don't like that comments get's indented, they should start far left! (like your -kr do) 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have always used indent.exe

 

You can configure it to your own personal preferences.

If you are supposed to use a "Company style",  you can set that up too. 

i.e. read code in your style.  write it in the company style.

 

AS7 has a formatter.   I avoid it.

In practice,  I often use ctrl-T in the Arduino IDE.   It is not very clever but it gets your blocks indented ok.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

In practice,  I often use ctrl-T in the Arduino IDE.   It is not very clever but it gets your blocks indented ok.

 

Arduino uses a built in version of astyle, but a standalone version can be downloaded from http://astyle.sourceforge.net/

Bob.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Code-Blocks installs with the astyle plugin. That's virtually plug-n-play and works fairly well allowing many built-in standard formatting, It doesn't do too well when adding or removing lines though.

 

Otherwise for something altogether better, the Eclipse CDT formatter is really really good and highly configurable, however it isn't quite so plug-n-play. It can even make a good stab at re-organising many statements and code blocks  on "one-line" of code.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

N.Winterbottom wrote:

Code-Blocks installs with the astyle plugin.

 

I use the command line version of astyle and just run it using a batch file on all files in a project directory as the mood takes me.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Eclipse has autoformatter with predefined main styles and possibility to change each rule.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Eclipse CDT formatter is good. Eclipse is a bit of a sledgehammer to crack a nut, but now I have got used to it I quite like it.

 

 

Bob.