467,132 Members | 1,149 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,132 developers. It's quick & easy.

Any preprocessing tool with {} insertion option?

Is there a preprocessor (or utility) that has option to insert absent
braces to clarify control syntax, ie for/while/if/else/etc ?
for(.....)
for(....)
statement;

to

for(....)
{
for(...)
{
statement;
}
}




Nov 13 '05 #1
  • viewed: 2066
Share:
18 Replies
David Frank wrote:
Is there a preprocessor (or utility) that has option to insert absent
braces to clarify control syntax, ie for/while/if/else/etc ?
for(.....)
for(....)
statement;

to

for(....)
{
for(...)
{
statement;
}
}


Hi David,

I'm looking for one of them too.. I haven't had any luck so far.
The closest I've come across so far is to take ctree/ctool
http://www.google.com/search?hl=en&l...&q=ctool+ctree
which is then trivial to adapt to make it do this. Unfortunately, what
you get out is pre-processed source (macros expanded :-( ) which isn't
always ideal.

The question has been asked here previously, but I don't recall ever
seeing the 'right' answer (i.e. "Yes. It's called <name of tool>")

You could just run your source through indent or whatever, to make
the structure obvious, but that's not what you asked for (nor what I'm
looking for).

Cheers,

William.

--
William McNicol Picsel Technologies Ltd http://www.picsel.com
wi*************@picsel.com Glasgow, Scotland.
[Give a man a fish and he will eat for a day,
Give him a dictionary and he will know the meaning of life.]

Nov 13 '05 #2
David Frank wrote:

Is there a preprocessor (or utility) that has option to insert absent
braces to clarify control syntax, ie for/while/if/else/etc ?

for(.....)
for(....)
statement;

to

for(....)
{
for(...)
{
statement;
}
}


You could try writing a script which inserts braces if an open-brace is
not found on the current or next line when you encounter a loop/test
statement. This will probably get you 90% of the way there.

/david

--
Andre, a simple peasant, had only one thing on his mind as he crept
along the East wall: 'Andre, creep... Andre, creep... Andre, creep.'
-- unknown
Nov 13 '05 #3
David Frank wrote:
Is there a preprocessor (or utility) that has option to insert absent
braces to clarify control syntax, ie for/while/if/else/etc ?

for(.....)
for(....)
statement;

to

for(....)
{
for(...)
{
statement;
}
}


No preprocessor option is needed... I'd like a utility that
removes all braces that aren't strictly required. ;)
--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c

Nov 13 '05 #4
I was thinking about improving my C2F -- C to Fortran translator tool
by inserting a "off-the-shelf" braces insertion tool in its "front
end"
processing (it already invokes a old DOS CPP pre-processor to remove
macros).

But since a Google search doesnt reveal a braces insertion tool, I am
currently inclined to start a project to write one.

With the existing input parsing code provided by C2F to give me a
start, I shud be able to provide a "cbraces.exe" tool for testing (and
feedback) by anyone interested..

In a few days, try looking in my index of files at:

http://home.cfl.rr.com/davegemini

"William McNicol" <wi*************@picsel.com> wrote in message
news:3F**************@picsel.com...
David Frank wrote:
Is there a preprocessor (or utility) that has option to insert absent braces to clarify control syntax, ie for/while/if/else/etc ?
for(.....)
for(....)
statement;

to

for(....)
{
for(...)
{
statement;
}
}
Hi David,

I'm looking for one of them too.. I haven't had any luck so

far. The closest I've come across so far is to take ctree/ctool
http://www.google.com/search?hl=en&l...&q=ctool+ctree which is then trivial to adapt to make it do this. Unfortunately, what you get out is pre-processed source (macros expanded :-( ) which isn't always ideal.

The question has been asked here previously, but I don't recall ever seeing the 'right' answer (i.e. "Yes. It's called <name of tool>")

You could just run your source through indent or whatever, to make the structure obvious, but that's not what you asked for (nor what I'm looking for).

Cheers,

William.

--
William McNicol Picsel Technologies Ltd http://www.picsel.com wi*************@picsel.com Glasgow, Scotland.
[Give a man a fish and he will eat for a day,
Give him a dictionary and he will know the meaning of life.]

Nov 13 '05 #5
*** evil topposting and overlong lines repaired ***

David Frank wrote:
"William McNicol" <wi*************@picsel.com> wrote in message
David Frank wrote:

Is there a preprocessor (or utility) that has option to
insert absent braces to clarify control syntax,
ie for/while/if/else/etc ?

for(.....)
for(....)
statement;

to

for(....)
{
for(...)
{
statement;
}
}


I'm looking for one of them too.. I haven't had any luck so
far. The closest I've come across so far is to take ctree/ctool

http://www.google.com/search?hl=en&l...&q=ctool+ctree
.... snip ...
You could just run your source through indent or whatever, to
make the structure obvious, but that's not what you asked for
(nor what I'm looking for).


I was thinking about improving my C2F -- C to Fortran translator
tool by inserting a "off-the-shelf" braces insertion tool in its
"front end" processing (it already invokes a old DOS CPP
pre-processor to remove macros).

But since a Google search doesnt reveal a braces insertion tool,
I am currently inclined to start a project to write one.

With the existing input parsing code provided by C2F to give me
a start, I shud be able to provide a "cbraces.exe" tool for
testing (and feedback) by anyone interested..

In a few days, try looking in my index of files at:

http://home.cfl.rr.com/davegemini


Please do not toppost.

I suggest that your whole idea is flawed (or requires much more
detail). The expression of an algorithm or section of code
should not usually be forced into such a limited arrangement. As
an example, I will frequently code as follows:

if (conditiona) docondastuff();
else if (conditionb) docondbstuff();
else if (conditionc) docondcstuff();
....
else dodefaultstuff();

which is compact, closely allied to a table, and easily
maintained. It is extremely easy for the reader to follow the
flow of control. Such a 'table' may occupy a single screenful,
but if passed through your filter will become inscrutable. Use
of indent will probable foul it also, but it will only double the
line count, while your filter would quadruple it.

I will concede that there can be other reasons for such
reformatting, such as convenient setting of debugger
breakpoints. These still do not require the addition of multiple
sets of braces. It amazes me that people who often squeal about
the use of redundant clarifying parentheses in logical, return,
sizeof expressions also often insist on such redundant
obscurative braces.

All this is worth an observation or two, but should not
degenerate into a style war.

--
Replies should be to the newsgroup
Chuck Falconer, on vacation.
Nov 13 '05 #6
in comp.lang.c i read:
David Frank wrote:
Is there a preprocessor (or utility) that has option to insert absent
braces to clarify control syntax, ie for/while/if/else/etc ?

The question has been asked here previously, but I don't recall
ever seeing the 'right' answer (i.e. "Yes. It's called <name of
tool>")


but it has been answered. there is no such tool known, and in those few
cases where someone has needed it they have coded a trivial parser of their
own, perhaps having been done in some language other than c. it's likely
that those trivial tools get some things wrong, but that it is acceptable
that the result need some manual corrections because it is not used with
any regularity.

the op's need probably isn't the same as yours, in that he isn't interested
in the c language, merely converting c programs into his favorite language,
fortran. you would need something that not only can parse the c language
but can handle source alteration. whereas he has already run the code
through a pre-processor so comments are gone and the source itself need not
be altered; rather i think the braces are need because the next step in his
translation isn't able to handle the full syntax of c.

--
a signature
Nov 13 '05 #7
In article <7W*********************@twister.tampabay.rr.com >,
da********@hotmail.com says...
Is there a preprocessor (or utility) that has option to insert absent
braces to clarify control syntax, ie for/while/if/else/etc ?
for(.....)
for(....)
statement;

to

for(....)
{
for(...)
{
statement;
}
}

The GNU indent program allows you to modify how braces are handled
in some cases. If it doesn't do everything you want (I haven't
checked), it is freely available open source code, so you'd be
90% of the way there almost instantly.

--
Randy Howard _o
2reply remove FOOBAR \<,
______________________()/ ()______________________________________________
SCO Spam-magnet: po********@sco.com
Nov 13 '05 #8
William McNicol <wi*************@picsel.com> wrote in message news:<3F**************@picsel.com>...
David Frank wrote:
Is there a preprocessor (or utility) that has option to insert absent
braces to clarify control syntax, ie for/while/if/else/etc ?
for(.....)
for(....)
statement;

to

for(....)
{
for(...)
{
statement;
}
}


Hi David,

I'm looking for one of them too.. I haven't had any luck so far.
The closest I've come across so far is to take ctree/ctool
http://www.google.com/search?hl=en&l...&q=ctool+ctree
which is then trivial to adapt to make it do this. Unfortunately, what
you get out is pre-processed source (macros expanded :-( ) which isn't
always ideal.

The question has been asked here previously, but I don't recall ever
seeing the 'right' answer (i.e. "Yes. It's called <name of tool>")


Yes. It's called SourceStylerC++.
http://www.sourcestyler.com
The aforementioned feature was just added to the latest version.
Nov 13 '05 #9
As advertised a few days back, I have worked mightily and have
produced a decent 1st effort at a braces insertion tool.
However, being a Fortran programmer interested in translating
C to Fortran, I lack C skills and source to give this 1st try
a really hard test. Perhaps some here will provide it..

BTW, the large 500kb cbraces.exe size is due only to the inefficient
Fortran compiler/linker including unneeded library routines,
sorry 'bout that..
More info is at: http://home.cfl.rr.com/davegemini/cbraces.txt

and the exe http://home.cfl.rr.com/davegemini/cbraces.exe

Nov 13 '05 #10
David Frank wrote:
As advertised a few days back, I have worked mightily and have
produced a decent 1st effort at a braces insertion tool.
However, being a Fortran programmer interested in translating
C to Fortran, I lack C skills and source to give this 1st try
a really hard test. Perhaps some here will provide it..

BTW, the large 500kb cbraces.exe size is due only to the inefficient
Fortran compiler/linker including unneeded library routines,
sorry 'bout that..
More info is at: http://home.cfl.rr.com/davegemini/cbraces.txt

and the exe http://home.cfl.rr.com/davegemini/cbraces.exe


Throwing virus caution to the winds, and laughing in the face of limited
dialup bandwidth, I took the several minutes it needed to download your
program, and ran it. Here is the result:

rjh@tux:~/scratch> ./cbraces.exe
bash: ./cbraces.exe: Permission denied
rjh@tux:~/scratch> chmod +x ./cbraces.exe
rjh@tux:~/scratch> ./cbraces.exe foo.c
bash: ./cbraces.exe: cannot execute binary file

Your program would appear to have a problem.
(Of course, had it been a /Linux/ binary, I would have copied it onto a
Win32 system for testing...)
--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #11
Richard Heathfield <do******@address.co.uk.invalid> wrote:

Throwing virus caution to the winds, and laughing in the face of limited
dialup bandwidth, I took the several minutes it needed to download your
program, and ran it. Here is the result:

rjh@tux:~/scratch> ./cbraces.exe
bash: ./cbraces.exe: Permission denied
rjh@tux:~/scratch> chmod +x ./cbraces.exe
rjh@tux:~/scratch> ./cbraces.exe foo.c
bash: ./cbraces.exe: cannot execute binary file

Your program would appear to have a problem.
(Of course, had it been a /Linux/ binary, I would have copied it onto a
Win32 system for testing...)


Why bother to copy it to ~/scratch instead of /dev/null in the first
place, then? ;-)

Irrwahn
<looking puzzled>
--
do not write: void main(...)
do not use gets()
do not cast the return value of malloc()
do not fflush( stdin )
read the c.l.c-faq: http://www.eskimo.com/~scs/C-faq/top.html
Nov 13 '05 #12

On Sat, 13 Sep 2003, Richard Heathfield wrote:

David Frank wrote:

As advertised a few days back, I have worked mightily and have
produced a decent 1st effort at a braces insertion tool.
However, being a Fortran programmer interested in translating
C to Fortran, I lack C skills and source to give this 1st try
a really hard test. Perhaps some here will provide it.. More info is at: http://home.cfl.rr.com/davegemini/cbraces.txt
and the exe http://home.cfl.rr.com/davegemini/cbraces.exe


Throwing virus caution to the winds, and laughing in the face of limited
dialup bandwidth, I took the several minutes it needed to download your
program, and ran it. Here is the result:

rjh@tux:~/scratch> ./cbraces.exe
bash: ./cbraces.exe: Permission denied
rjh@tux:~/scratch> chmod +x ./cbraces.exe
rjh@tux:~/scratch> ./cbraces.exe foo.c
bash: ./cbraces.exe: cannot execute binary file

Your program would appear to have a problem.
(Of course, had it been a /Linux/ binary, I would have copied it onto a
Win32 system for testing...)

For the humour-impaired, I believe Richard is saying in
his own special way:

How are we supposed to "test" this program if we don't
have the source code? Remember, this is c.l.c, where
portability and good style are emphasized. If you
give us a chunk of machine code for one particular
OS/processor combination and ask us to find the bugs,
we won't be able to help. Try comp.lang.asm.x86 or
something.

It appears the source code is in Fortran. That's okay;
there are still people out there who can read Fortran.
Someone might even take the time to translate the program
into C, if it looks useful enough!

-Arthur

Nov 13 '05 #13

"Arthur J. O'Dwyer" <aj*@andrew.cmu.edu> wrote in message
news:Pi***********************************@unix46. andrew.cmu.edu...

For the humour-impaired, I believe Richard is saying in
his own special way:

How are we supposed to "test" this program if we don't
have the source code? Remember, this is c.l.c, where
portability and good style are emphasized. If you
give us a chunk of machine code for one particular
OS/processor combination and ask us to find the bugs,
we won't be able to help. Try comp.lang.asm.x86 or
something.

It appears the source code is in Fortran. That's okay;
there are still people out there who can read Fortran.
Someone might even take the time to translate the program
into C, if it looks useful enough!

-Arthur


re: How are we supposed to "test" this program if we don't
have the source code?

Thats hilarious!!

In the case of CBRACES you pass a few large C sources thru it
and see if compile/link/run produces identical results as original.

I'm sure there are syntax cases (perhaps a lot) that present problems.
But if the statements that produce problems can be sent as a bug
report, I will make a effort to update CBRACES to handle the
offending code in a future version.

Everyone has my word that the final tool will be "free",
I have no interest in programming for money anymore.


Nov 13 '05 #14
David Frank wrote:
re: How are we supposed to "test" this program if we don't
have the source code?

Thats hilarious!!
Not as hilarious as your apparent belief that otherwise intelligent people
would be prepared to run an unknown binary from (forgive me) an untrusted
source.
In the case of CBRACES you pass a few large C sources thru it
and see if compile/link/run produces identical results as original.


Well, it didn't produce any output at all on my system. I guess that's a
bug.

<snip>

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #15
In article <oi*********************@twister.tampabay.rr.com >,
da********@hotmail.com says...
re: How are we supposed to "test" this program if we don't
have the source code?

Thats hilarious!!
Actually, the fact that you consider it so is the funniest
thing I've seen so far today in c.l.c.
In the case of CBRACES you pass a few large C sources thru it
and see if compile/link/run produces identical results as original.
What if you don't use Windoze? You seem to have completely missed
that. BTW, did you actually write a program to muck w/C source
files in Fortran? That would really be interesting to see, not to
mention bizarre. I can't remember the last time I wrote anything new
in Fortran (probably 1983 or '84). To use it today for a program
to manipulate C source is quite interesting.
I'm sure there are syntax cases (perhaps a lot) that present problems.
But if the statements that produce problems can be sent as a bug
report, I will make a effort to update CBRACES to handle the
offending code in a future version.


Sorry, but I won't be executing it, even on a Windoze box. It might
be the next slammer virus and John Ashcroft would set fire to my
computer and hold me in a foreign country for life without access
to an attorney, even though it's not my program.
--
Randy Howard _o
2reply remove FOOBAR \<,
______________________()/ ()______________________________________________
SCO Spam-magnet: po********@sco.com
Nov 13 '05 #16
On Wed, 10 Sep 2003 07:58:17 -0400, LibraryUser wrote:
All this is worth an observation or two, but should not
degenerate into a style war.


It hasn't.

He is asking for a tool to convert C code to HIS favorite style, not
saying that anyone else should use his style.

You are free to ask if anyone knows a tool that will convert

if (condition) {
single_statement;
}

into:

if (condition) single_statement;

And I don't expect anyone will flame you for it unless you claim that your
way of doing things is "the one true C style"

regards

--
NPV
"Linux is to Lego as Windows is to Fisher Price." - Doctor J Frink

Nov 13 '05 #17
Nils Petter Vaskinn wrote:
You are free to ask if anyone knows a tool


Not really.
Nov 13 '05 #18
On Mon, 15 Sep 2003 14:43:25 +0000, pete wrote:
Nils Petter Vaskinn wrote:
You are free to ask if anyone knows a tool


Not really.


Actually you're right, since this is CLC it could be deemed offtopic. But
he would be flamed for beeing offtopic not for preferring:

if (cond) single_statement;

over

if (cond) {
single_statement;
}

Basicalli what I was saying was that as long as the OP presented things as
"his preferred style" and not "the one true style" the style war wasn't
going to happen.

regards

--
NPV
"Linux is to Lego as Windows is to Fisher Price." - Doctor J Frink

Nov 13 '05 #19

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by jason | last post: by
1 post views Thread by Alex Sedow | last post: by
2 posts views Thread by Theron Stanford | last post: by
17 posts views Thread by clintonG | last post: by
12 posts views Thread by Thomas Carter | last post: by
1 post views Thread by =?Utf-8?B?TWljaGFlbCBCbHVtZW50aGFsLCBNQ1NFLCBNQ0FE | last post: by
5 posts views Thread by Francois Grieu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.