formatting C source code (adding brackets { } to if else )

T

tvn

[mod note: removed "alt.comp.lang.c" because my news server doesn't have it.]

Hi,

I am wondering if there's any C src format that can change something
like

if (something)
if(something)
stmt1;
else
stmt2;
else
stmt3;

into

if (something){
if(something){
stmt1;
}
else{
stmt2;
}
}
else{
stmt3;
}


I've looked at several ones such as astyle and gnu indent but they
can't seem to do this. astyle can put brackets {} if but only 1
line
e.g.,

if (isFoo)
isFoo = false;
becomes:

if (isFoo) {
isFoo = false;
}
 
G

Gene

[mod note:  removed "alt.comp.lang.c" because my news server doesn't have it.]

Hi,

I am wondering if there's any C src format that can change something
like

if (something)
   if(something)
      stmt1;
   else
      stmt2;
else
    stmt3;

into

if (something){
   if(something){
      stmt1;
   }
   else{
      stmt2;
   }}

else{
    stmt3;

}

I've looked at several ones such as astyle and gnu indent but they
can't seem to do this.  astyle can put brackets {} if  but only 1
line
e.g.,

if (isFoo)
    isFoo = false;
becomes:

if (isFoo) {
    isFoo = false;}

The tool TXL would be make it pretty easy to do this. See http://txl.ca
..
 
J

James Kuyper

ng2010 said:
tvn said:
[mod note: removed "alt.comp.lang.c" because my news server doesn't
have it.]

Since when is this ng moderated?

Check the cross-posting: comp.lang.c.moderated is moderated, odd as that
might seem ;-). I have no idea how the details are handled, but I gather
that if you cross-post to one or more moderated newsgroups, the
moderators from each of those groups must approve it before it becomes
available to the general public.
 
S

Stephen Sprunk

tvn said:
[mod note: removed "alt.comp.lang.c" because my news server doesn't
have it.]

Since when is this ng moderated?

Notice the "comp.lang.c.moderated" on the Newsgroups line. That is, as
one would expect from the name, a moderated group.

S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top