Source code formatting tools
-
ack! noooooo! Not someone who gets rid of tabs... hehe. /me runs from the ensuing holy war :) Jim Wuerch www.miwasoft.com Quote from my readme files: "This is BETA software, and as such may completely destroy your computer, change the alignment of the planets and invert the structure of the universe."
Recently found the tool Artistic Style [1] to format source code. Even thought it's not perfect it does a far better job than VC. Bjørn. [1] http://astyle.sourceforge.net/
-
Can anyone recommend a C++ source code formatting tool? I've inherited a project where the programmer was tab happy, there's whitespace everywhere. Of course, it's just not formatted to my liking either and I'd like to replace the tabs with spaces and remove the extra whitespace that makes the cursor jump all over the place when you arrow through the code. Anyhow, any recommendations are appreciated, the more flexible and complex the better. Thanks, Bill http://www.ratebeer.com
I haven't used in in quite a while, but GNU indent used to be phenomenally flexible and powerful at this kind of thing. For an example how flexible and complex, the manual tells us that
The Kernighan & Ritchie style corresponds to the following set of options:
-nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0
-cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs
-nprs -npsl -saf -sai -saw -nsc -nsob -nsswhile
Option settings which correspond to the GNU style are:
-nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2
-ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -nprs -psl -saf -sai
-saw -nsc -nsobIs that complex enough for you? But seriously, this should do everything you want in terms of reformatting arbitrarily pathologically formatted code into something you can read! Bomb our homes and threaten our children, and, as difficult as it is, we will still love you --- Martin Luther King, Jr.
-
ack! noooooo! Not someone who gets rid of tabs... hehe. /me runs from the ensuing holy war :) Jim Wuerch www.miwasoft.com Quote from my readme files: "This is BETA software, and as such may completely destroy your computer, change the alignment of the planets and invert the structure of the universe."
Personally I can't stand tabs in code becuase I often open source files in WordPad and it always has tabbed code out of alignment (I think it's default tab size is 8?). Whitespace doesn't make programs run any slower, but they do make it easier to read the code when opened in any text viewer. Just my contribution to the start of the next religious war ;) cheers, Chris Maunder (CodeProject)
-
Personally I can't stand tabs in code becuase I often open source files in WordPad and it always has tabbed code out of alignment (I think it's default tab size is 8?). Whitespace doesn't make programs run any slower, but they do make it easier to read the code when opened in any text viewer. Just my contribution to the start of the next religious war ;) cheers, Chris Maunder (CodeProject)
Just looking for something to say to rack up number 700 and what do I see Chris flapping his gums. :-D I gotten hold of this and now I won't let go. What in the hell would you want to use WordPad for? Even if it is just to view source. Don't you find it a major pain in the arse when you add // to the beginning of a line? Screws up the formatting something chronic. Gotta go, have a train to catch, will pick this up hen I get home and login. Anyway shouldn't you be using your spare time to answer questions in your CComboCompletion article and organising that beer with me in the near future? ;P Michael Martin Pegasystems Pty Ltd Australia martm@pegasystems.com +61 413-004-018 "Don't belong. Never join. Think for yourself. Peace" - Victor Stone
-
In MSDEV: CTRL+A CTRL+F8 (it may be F7) It isn't felxible, but it will make it look prettier in the meant time whilst you find a suitable alternative.
:cool: -=:suss:=-
David Wulff dwulff@battleaxesoftware.com
-
I haven't used in in quite a while, but GNU indent used to be phenomenally flexible and powerful at this kind of thing. For an example how flexible and complex, the manual tells us that
The Kernighan & Ritchie style corresponds to the following set of options:
-nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0
-cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs
-nprs -npsl -saf -sai -saw -nsc -nsob -nsswhile
Option settings which correspond to the GNU style are:
-nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2
-ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -nprs -psl -saf -sai
-saw -nsc -nsobIs that complex enough for you? But seriously, this should do everything you want in terms of reformatting arbitrarily pathologically formatted code into something you can read! Bomb our homes and threaten our children, and, as difficult as it is, we will still love you --- Martin Luther King, Jr.
Ya, now we're getting somewhere. I guess one thing that I forgot to mention that makes things look bad are the tons of tabs/spaces in between function names and return types in the prototype. I can see where you'd want to perhaps line up all of the names, but having void, then the function name is a little ridiculous. There is also erratic tabbing inside of things that conditions. if (blah ) { } I don't get what someone was trying to accomplish in that sort of situation. This is going to be a doozy I think :> Thanks for all of the help and posts so far folks.
-
I haven't used in in quite a while, but GNU indent used to be phenomenally flexible and powerful at this kind of thing. For an example how flexible and complex, the manual tells us that
The Kernighan & Ritchie style corresponds to the following set of options:
-nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0
-cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs
-nprs -npsl -saf -sai -saw -nsc -nsob -nsswhile
Option settings which correspond to the GNU style are:
-nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2
-ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -nprs -psl -saf -sai
-saw -nsc -nsobIs that complex enough for you? But seriously, this should do everything you want in terms of reformatting arbitrarily pathologically formatted code into something you can read! Bomb our homes and threaten our children, and, as difficult as it is, we will still love you --- Martin Luther King, Jr.
i see a program that needs a GUI front end. -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com
-
Hi Bill, Have you tried my DevStudio macro? It works with DevStudio's Smart Indent and Tab settings, but it does a lot more. It also ensures that operators, curly braces, case statements, and other such things are properly formatted and spaced. Your code will end up looking a lot like MFC's source code, which I happen to like. Regards, Alvaro
Bill, I recommend you give this a go. Works perfectly for me, corrects all those formatting screwups Chris puts in his code. ;) Michael Martin Pegasystems Pty Ltd Australia martm@pegasystems.com +61 413-004-018 "Don't belong. Never join. Think for yourself. Peace" - Victor Stone
-
I haven't used in in quite a while, but GNU indent used to be phenomenally flexible and powerful at this kind of thing. For an example how flexible and complex, the manual tells us that
The Kernighan & Ritchie style corresponds to the following set of options:
-nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0
-cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs
-nprs -npsl -saf -sai -saw -nsc -nsob -nsswhile
Option settings which correspond to the GNU style are:
-nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2
-ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -nprs -psl -saf -sai
-saw -nsc -nsobIs that complex enough for you? But seriously, this should do everything you want in terms of reformatting arbitrarily pathologically formatted code into something you can read! Bomb our homes and threaten our children, and, as difficult as it is, we will still love you --- Martin Luther King, Jr.
The main issue with GNU indent is that it does not understand C++, only plain C. To illustrate this problem I can mention that code after running through indent can stop compiling. Something like vector > can become vector>. Artistic Style does understand C++ but lacks all the options which indent has. The macro on codeproject.com does not have any configuration, but I personally like its setup. Unfortunately there are still some bugs in it. Hope it helps. Igor Proskuriakov
-
Can anyone recommend a C++ source code formatting tool? I've inherited a project where the programmer was tab happy, there's whitespace everywhere. Of course, it's just not formatted to my liking either and I'd like to replace the tabs with spaces and remove the extra whitespace that makes the cursor jump all over the place when you arrow through the code. Anyhow, any recommendations are appreciated, the more flexible and complex the better. Thanks, Bill http://www.ratebeer.com
Try http://www.ochre.com.au/ Joel Lucsy (jjlucsy@concentric.net)