473,811 Members | 3,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2313
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.ex e" 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.c om...
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.ex e" 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************ *********@twist er.tampabay.rr. com>,
da********@hotm ail.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1833
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 to go in and check files by date and then generate a CDO script. Another possibility would be to limit the tool to database portions of the site where I can track changes. But, both approaches are complicated by the need to automatically...
1
2885
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 options) will be "executed". This feature maybe used for: a) exclude some (nonpublic, temple or test) parts of source code. b) simplify source code (remove unused macros, replace some macros to better undestanding). Example (PRIVATE macro executed,...
2
1810
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 macros alone? Take this code for an example: /* start of code */
20
1970
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 UndesirableTag YYY #ifdef TagB ZZZ
17
3984
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 http://forta.com/books/0672325667/
12
8250
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 the preprocessor to detect that ui32 already exists, when preprocessing F.c? The idea is that F.c will typedef ui32 as above if and only if such typedef is not already in some include file used by F.c.
1
2192
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 record - category, event ID, etc. I would like to make use of a message file as well. I have created a message file DLL per the instructions at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wes/wes/sample_message_text_file.asp...
28
3458
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 is too good. When I revisit the page or refresh the page, and then redo the script insertion, the browser doesn't even hit the server to check for a newer version of the JavaScript file. The same old script runs with each insertion.
5
6303
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 directive in the middle of macro arguments, which comes handy e.g. to
0
9724
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5552
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4336
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.