473,382 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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
18 2280
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jason | last post by:
Does anyone have any ideas on a PAGE WATCH tool or an application that allows a user to be notified when page changes automatically by email. My immediate thoughts would be to use the FSO object...
1
by: Alex Sedow | last post by:
Where to get/buy tool for partial preprocessing? 1. What I mean by partial macro preprocessing. This is mode in which almost sources (>99%) is not preprocessed. But some macros (setted by...
2
by: Theron Stanford | last post by:
I've inherited a bunch of code that contains a lot of conditional preprocessing commands. Is there a way to run the preprocessor so that it processes the conditionals but leaves the rest of the...
20
by: jvankay | last post by:
Does any C guru out there know of a C pre-processing tool that will allow limited pruning of C source based on a single #define variable. That is, in the code fragment below: XXX #ifdef...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
12
by: Thomas Carter | last post by:
Imagine that there is some include file f.h that contains the following line: typedef unsigned int ui32 ; My question is: If I have a C source file F.c that includes f.h, is it possible for...
1
by: =?Utf-8?B?TWljaGFlbCBCbHVtZW50aGFsLCBNQ1NFLCBNQ0FE | last post by:
I am writing a .NET 1.1 C# windows service that writes to a dedicated event log (not the application event log, but one that I created). I want to make full use of all the fields in an event log...
28
by: Peter Michaux | last post by:
Hi, I'm playing with dynamic script insertion to make a request to the server for a JavaScript file to be automatically run when it arrives in the browser. It works but... The page caching...
5
by: Francois Grieu | last post by:
One of the C compiler that I use <OT>(Keil's CX51)</OTbarks at #define a(b) b int main(void){return a( #if 0 #endif 0);} More generally, this compiler seems confused by any preprocessing...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.