C source code formatter: looking for a good one

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hi folls,

 I'm looking for a good C source code formatter that
 eventually be able to strip out comments from the
 source.

thanks
 Enrico



Re: C source code formatter: looking for a good one
Quoted text here. Click to load it

indent + a little perl-script does this for me.

---
42Bastian
Do not email to snipped-for-privacy@yahoo.com, it's a spam-only account :-)
We've slightly trimmed the long signature. Click to see the full one.
Re: C source code formatter: looking for a good one

Quoted text here. Click to load it

Are you thinking of some sort of automatic documentation tool?  If so, have
a look at http://www.doxygen.org/ .




Re: C source code formatter: looking for a good one
Hi Enrico,

In the Win32 world, I use to write my source using
a small freeware called "JFE".

In this editor, there is an automatic indent function
for C/C++ (edit/operations/align C syntax).
IMHO, this is a really good software you should try.
(thanks to Jens Altmann !)

Regards
Emmanuel.

Enrico Migliore wrote:
Quoted text here. Click to load it

Re: C source code formatter: looking for a good one

Quoted text here. Click to load it

The C preprocessor strips comments out of your source code for you already.
Look for the switch that enables preprocessor output and set it.

Regards
Sergio Masci

http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC compiler



Re: C source code formatter: looking for a good one



Quoted text here. Click to load it

thanks Sergio, I did it: the preprocessor does strip out all comments
but it adds also all header files.

Enrico


--
 ***********************************************************
 * Enrico Migliore - Co-founder and Senior Software Engineer
 *
We've slightly trimmed the long signature. Click to see the full one.
Re: C source code formatter: looking for a good one

Quoted text here. Click to load it
already.
compiler

So add a marker in your source file after the last include statement and
then just delete everything upto that marker by hand.

e.g.
        #include <stdin.h>
        #include "myhdr.h"

        char   this_is_my_magic_source_code_marker;


Regards
Sergio Masci

http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC compiler




Re: C source code formatter: looking for a good one
Quoted text here. Click to load it

GNU indent will handle the formatting.  To strip comments, see
uncmntc.zip, available in source form at:

   <http://cbfalconer.home.att.net/download/

which will not handle trigraphs, nor multi-char char constants
such as 'ab'.  Strings are alright.

--
Chuck F ( snipped-for-privacy@yahoo.com) ( snipped-for-privacy@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
We've slightly trimmed the long signature. Click to see the full one.
Re: C source code formatter: looking for a good one
Quoted text here. Click to load it

Why do you want to strip the comments out?


--
Peter Bushell
www.software-integrity.com




Re: C source code formatter: looking for a good one


[...]
Quoted text here. Click to load it

My question. I used to say that incorrect comments (stale or initially
wrong) are much worse than no comment at all. Maybe he wants to strip them
out and start over.


Re: C source code formatter: looking for a good one
Quoted text here. Click to load it

Amen.  I find that more often than not when given some old code
to fix/update I'm better off just deleting the comments so that
I don't get misled.

Somebody ought to write a paper entitled "Comments Considered
Harmful".  Maybe somebody already has...

--
Grant Edwards                   grante             Yow!  But they went to MARS
                                  at               around 1953!!
We've slightly trimmed the long signature. Click to see the full one.
Re: C source code formatter: looking for a good one

Quoted text here. Click to load it

Even so, I don't see how deleting them *all* in a single sweep, before
rewriting them from scratch is going to do you much good.  Just cut
out the old contents as you replace them with new ones, making sure
you leave a fingerprint to distinguish rewritten comments from legacy
ones if you don't do it strictly in linear order down the source...

Even a collection of mostly misguided comment may still contain the
occasional pearl you'll need to understand the program good enough to
write your own ones...  Classifying them all as wrong without
personally reading every last one of them (by letting a machine kill
them away) is arguably just as silly as taking them all to be written
gospel.

--
Hans-Bernhard Broeker ( snipped-for-privacy@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Re: C source code formatter: looking for a good one
Quoted text here. Click to load it

Agreed.  I didn't mean to imply that deleting them all
completely before starting was a good idea.

Quoted text here. Click to load it

Mostly I deleting the comment and replace the _code_ with code
that is readable.  The only comments I find generally useful
are a high-level description of what a function is supposed to
be used for.  Occasionally a comment describing what a
particular obtuse block of code is intended to do can be
helpful, but the low-level comments I often find trying to
explain what's going on line-by-line are usually worse than
useless.

--
Grant Edwards                   grante             Yow!  I guess it was all a
                                  at               DREAM... or an episode of
We've slightly trimmed the long signature. Click to see the full one.
Re: C source code formatter: looking for a good one


Quoted text here. Click to load it
[...]
Quoted text here. Click to load it

// declare local variables
int x, y;
// set x equal to 1
x = 1;
// set y equal to x times 3
y = x * 3;
...

:)


Re: C source code formatter: looking for a good one

Quoted text here. Click to load it

No kidding, I've seen code like that written be supposedly
educated and professional induhviduals.  Except it's often
something like this:

  // declare local variables
  int x, y;
  // set x equal to 1
  x = 1;
  // set y equal to x times 3
  y = x * (z/2 + 1);

Where they didn't want to use 3 anymore, and now there's a
global varaible "z" that controls something, and the expression
(z/2 + 1) probably isn't 3 anymore.



--
Grant Edwards                   grante             Yow!  Here I am in the
                                  at               POSTERIOR OLFACTORY LOBULE
We've slightly trimmed the long signature. Click to see the full one.
Re: C source code formatter: looking for a good one

Quoted text here. Click to load it

I get your picture.  My favourite one of this kind is this line, from
a venerable old Unix tool's source code:

        amtused = 16; /* leave no space - init 3 words + one for luck */

I don't usually resort to violence, but lines like that one do tend to
trigger an urge to track down whoever wrote and make rather liberal
use of a clue-by-four.  Deleting comments like that one from the
source before anybody has to read them may even improve the average
level of mental health of all persons involved.  And yes, that does
contradict to may earlier statement in this thread --- that's life.

--
Hans-Bernhard Broeker ( snipped-for-privacy@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Re: C source code formatter: looking for a good one

Quoted text here. Click to load it

With hopefully a word or two of explanation about what parameters are passed
in and what the return value is.

How I wish more people would put just this level of commenting in their
code. All to often I've worked on code where it's a battle to figure out
what functions actually do.

Good code:

foo()
// Read the comment- Ah foo does xyz [though the suspicious might have a
// read to make sure it really does that]

Bad Code

foo()
read
read
read - foo calls bar()
    bar()
    read
    read
    read - bar calls wibble()
        wibble()
        read
        read
        read...

Re: C source code formatter: looking for a good one
Quoted text here. Click to load it

In most cases, well-chosen formal parameter names should
suffice, though a comment about what the return value means is
often good.

--
Grant Edwards                   grante             Yow!  I'm rated PG-34!!
                                  at              
We've slightly trimmed the long signature. Click to see the full one.
Re: C source code formatter: looking for a good one
Quoted text here. Click to load it


Sometimes the parameter names are sufficient information, however often
there are preconditions that should be commented [ the called function is
expecting a certain level of initialisation, or if you want the function to
do xxx, make sure you set yyy in parameter zzz]. Documenting ownership of
dynamically allocated entities is a Good Thing too.

Re: C source code formatter: looking for a good one
Quoted text here. Click to load it
... snip ...
Quoted text here. Click to load it
                                                            ^well^
Quoted text here. Click to load it

Agreed.  If nothing else it may clue you in to how another
modifier fouled up.

BTW the indicated usage error is very common among non-native
English speakers or the poorly uneducated.

--
Chuck F ( snipped-for-privacy@yahoo.com) ( snipped-for-privacy@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline