Looking for a more flexible tool than GNU indent
Asked Answered
M

2

9

When I run indent with various options I want against my source, it does what I want but also messes with the placement of *s in pointer types:

  -int send_pkt(tpkt_t* pkt, void* opt_data);
  -void dump(tpkt_t* bp);
  +int send_pkt(tpkt_t * pkt, void *opt_data);
  +void dump(tpkt * bp);

I know my placement of *s next to the type not the variable is unconventional but how can I get indent to just leave them alone? Or is there another tool that will do what I want? I've looked in the man page, the info page, and visited a half a dozen pages that Google suggested and I can't find an option to do this.

I tried Artistic Style (a.k.a. AStyle) but can't seem to figure out how to make it indent in multiples of 4 but make every 8 a tab. That is:

if ( ... ) {
<4spaces>if ( ... ) {
<tab>...some code here...
<4spaces>}
}
Manny answered 19/9, 2008 at 13:30 Comment(2)
Indenting by four spaces with eight-space tab stops is likely to aggravate everyone else who tries to maintain your code. Those who use four-space tabs (say, Visual Studio programmers) will believe you screwed up indentation. Those who use eight-space tabs won't like indenting four characters.Carpometacarpus
By the way, this is supposed to be fixed in GNU indent 2.2.13, but I'm still seeing it, so apparently the fix is incomplete.Binah
D
19

Uncrustify

Uncrustify has several options on how to indent your files.

From the config file:

indent_with_tabs                           
  How to use tabs when indenting code  
  0=spaces only  
  1=indent with tabs, align with spaces  
  2=indent and align with tabs

You can find it here.

BCPP
From the website: "bcpp indents C/C++ source programs, replacing tabs with spaces or the reverse. Unlike indent, it does (by design) not attempt to wrap long statements."
Find it here.

UniversalIndentGUI
It's a tool which supports several beautifiers / formatters. It could lead you to even more alternatives.
Find it here.

Artistic Style
You could try Artistic Style aka AStyle instead (even though it doesn't do what you need it to do, I'll leave it here in case someone else finds it useful).

Dawnedawson answered 19/9, 2008 at 13:32 Comment(2)
Plus 1, just tried out the universal indent gui with uncrustify, gives you "real-time" preview of a source file.Luteous
I am just playing with astyle and am already finding it niceOxfordshire
F
2

Hack around and change its behavior editing the code. It's GNU after all. ;-)

As it's probably not the answer you wanted, here's another link: http://www.fnal.gov/docs/working-groups/c++wg/indenting.html.

Fawne answered 19/9, 2008 at 13:39 Comment(1)
That link doesn't work any more. It just redirects to the Fermilab homepage.Copra

© 2022 - 2024 — McMap. All rights reserved.