Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Special C Preprocessing Tool Needed for Pruning of #ifdefs in code

Reply
Thread Tools

Special C Preprocessing Tool Needed for Pruning of #ifdefs in code

 
 
jvankay
Guest
Posts: n/a
 
      01-11-2005
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
#endif
AAA
#endif
BBB
#ifdef TagC
CCC.
#endif
DDD

If "UndesirableTag" and all of its code is to be removed from a file (with
other #defines in it), then the outer #ifdef and the code all the way to the
2nd #endif inclusive should be removed, but nothing else touched.

Cpp is not suitable because it will remove all the defines and inline the
#includes. Ideally the tool will handle ifdef, ifndef, else, elif, endif,
if Defined, if expr, and nested ifs. We need this for a project with many
source files and many defines in the project.

Anyone know of a tool that will do this, or something close to this?

Any help would be appreciated. Please email to http://www.velocityreviews.com/forums/(E-Mail Removed).

Thanks and best regards.


 
Reply With Quote
 
 
 
 
Chris Croughton
Guest
Posts: n/a
 
      01-11-2005
On Mon, 10 Jan 2005 23:36:56 -0500, jvankay
<(E-Mail Removed)> wrote:

> 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
> #endif
> AAA
> #endif
> BBB
> #ifdef TagC
> CCC.
> #endif
> DDD
>
> If "UndesirableTag" and all of its code is to be removed from a file (with
> other #defines in it), then the outer #ifdef and the code all the way to the
> 2nd #endif inclusive should be removed, but nothing else touched.


Yes. You can look for things called rmif and scpp, if you can get them
to compile and run on your system. Or I have one which I wrote
recently:

http://www.keristor.co.uk/stuff/xcpp-0.4.0.tar.gz

Mine is ISO C89 (other versions are pre-ISO, as I recall). It's coped
with everything I've thrown at it, I'd be interested if you find any
bugs in it or any problems compiling it on some platform, I'd like to
fix them if found. It also handles things like limits.h, float.h and
autoconf type config.h files which use #define and #undef, which the
others don't, as well as -D and -U to defined and undefine macros. It
doesn't hadle macros with varargs but I doubt you want that...

> Cpp is not suitable because it will remove all the defines and inline the
> #includes. Ideally the tool will handle ifdef, ifndef, else, elif, endif,
> if Defined, if expr, and nested ifs. We need this for a project with many
> source files and many defines in the project.


Yup, that's what mine is designed for. It's released as Free Software
(Zlib type licence).

> Anyone know of a tool that will do this, or something close to this?
>
> Any help would be appreciated. Please email to (E-Mail Removed).


Emailed as well as posted.

Chris C
 
Reply With Quote
 
 
 
 
Chris Croughton
Guest
Posts: n/a
 
      01-11-2005
On Tue, 11 Jan 2005 08:53:01 +0000, Chris Croughton
<(E-Mail Removed)> wrote:

> On Mon, 10 Jan 2005 23:36:56 -0500, jvankay
> <(E-Mail Removed)> wrote:
>
>> 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.

>
> Yes. You can look for things called rmif and scpp, if you can get them
> to compile and run on your system. Or I have one which I wrote
> recently:
>
> http://www.keristor.co.uk/stuff/xcpp-0.4.0.tar.gz


Oops, that should be

http://www.keristor.co.uk/stuff/xcpp-0.5.0.tar.gz

I fixed some bugs and uploaded it to the website but didn't regenerate
my web page to indicate the latest version.

Emailed as well as posted.

Chris C
 
Reply With Quote
 
Ira Baxter
Guest
Posts: n/a
 
      01-12-2005
"jvankay" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
> #endif
> AAA
> #endif
> BBB
> #ifdef TagC
> CCC.
> #endif
> DDD
>
> If "UndesirableTag" and all of its code is to be removed from a file (with
> other #defines in it), then the outer #ifdef and the code all the way to

the
> 2nd #endif inclusive should be removed, but nothing else touched.
>
> Cpp is not suitable because it will remove all the defines and inline the
> #includes. Ideally the tool will handle ifdef, ifndef, else, elif, endif,
> if Defined, if expr, and nested ifs. We need this for a project with many
> source files and many defines in the project.
>
> Anyone know of a tool that will do this, or something close to this?


See http://www.semanticdesigns.com/Products/Tools.html

-- IDB


 
Reply With Quote
 
jvankay
Guest
Posts: n/a
 
      01-12-2005
Thank you very much Chris,

We will try yours out

Regards,

Joseph V.

"Chris Croughton" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Tue, 11 Jan 2005 08:53:01 +0000, Chris Croughton
> <(E-Mail Removed)> wrote:
>
> > On Mon, 10 Jan 2005 23:36:56 -0500, jvankay
> > <(E-Mail Removed)> wrote:
> >
> >> 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.

> >
> > Yes. You can look for things called rmif and scpp, if you can get them
> > to compile and run on your system. Or I have one which I wrote
> > recently:
> >
> > http://www.keristor.co.uk/stuff/xcpp-0.4.0.tar.gz

>
> Oops, that should be
>
> http://www.keristor.co.uk/stuff/xcpp-0.5.0.tar.gz
>
> I fixed some bugs and uploaded it to the website but didn't regenerate
> my web page to indicate the latest version.
>
> Emailed as well as posted.
>
> Chris C



 
Reply With Quote
 
jvankay
Guest
Posts: n/a
 
      01-12-2005
Thank you Chris. We will try out your tool on some nasty code

Regards,

Joseph V.

"Chris Croughton" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Tue, 11 Jan 2005 08:53:01 +0000, Chris Croughton
> <(E-Mail Removed)> wrote:
>
> > On Mon, 10 Jan 2005 23:36:56 -0500, jvankay
> > <(E-Mail Removed)> wrote:
> >
> >> 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.

> >
> > Yes. You can look for things called rmif and scpp, if you can get them
> > to compile and run on your system. Or I have one which I wrote
> > recently:
> >
> > http://www.keristor.co.uk/stuff/xcpp-0.4.0.tar.gz

>
> Oops, that should be
>
> http://www.keristor.co.uk/stuff/xcpp-0.5.0.tar.gz
>
> I fixed some bugs and uploaded it to the website but didn't regenerate
> my web page to indicate the latest version.
>
> Emailed as well as posted.
>
> Chris C



 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      01-12-2005
Chris Croughton wrote:
> <(E-Mail Removed)> wrote:
>> <(E-Mail Removed)> wrote:
>>
>>> 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.

>>
>> Yes. You can look for things called rmif and scpp, if you can
>> get them to compile and run on your system. Or I have one which
>> I wrote recently:
>>
>> http://www.keristor.co.uk/stuff/xcpp-0.4.0.tar.gz

>
> Oops, that should be
>
> http://www.keristor.co.uk/stuff/xcpp-0.5.0.tar.gz
>
> I fixed some bugs and uploaded it to the website but didn't
> regenerate my web page to indicate the latest version.


You may or may not be interested to know that it compiled out of
the box under DJGPP. However note the warnings below. I haven't
attempted to do anything about them. Offhand it looks like a well
done piece.

It would also be pleasant to have the man page in info format.

c:\dnld\scratch\junk>make
gcc -g -Wall -W -pedantic -ansi -c -o xcpp.o xcpp.c
xcpp.c: In function `tracemem':
xcpp.c:2712: warning: int format, long unsigned int arg (arg 3)
xcpp.c:2713: warning: int format, long unsigned int arg (arg 3)
xcpp.c:2714: warning: int format, long unsigned int arg (arg 3)
xcpp.c:2716: warning: int format, long unsigned int arg (arg 3)
xcpp.c: In function `main':
xcpp.c:2811: warning: int format, long unsigned int arg (arg 3)
gcc -g -Wall -W -pedantic -ansi -c -o xcppopt.o xcppopt.c
gcc -g -Wall -W -pedantic -ansi -c -o xcppmem.o xcppmem.c
gcc -g -Wall -W -pedantic -ansi -c -o xcppmath.o xcppmath.c
gcc -g -Wall -W -pedantic -ansi -o xcpp xcpp.o xcppopt.o xcppmem.o
xcppmath.o

You might also want to look on my page (URL below), download
section, for id2id-20.zip. It contains a simple technique for
automatic help when stdin on filters has not been redirected.
Steal it.

--
Chuck F ((E-Mail Removed)) ((E-Mail Removed))
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!

 
Reply With Quote
 
Chris Croughton
Guest
Posts: n/a
 
      01-12-2005
On Wed, 12 Jan 2005 07:05:18 GMT, CBFalconer
<(E-Mail Removed)> wrote:

> Chris Croughton wrote:
>> <(E-Mail Removed)> wrote:
>>> <(E-Mail Removed)> wrote:
>>>
>>>> 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.
>>>
>>> Yes. You can look for things called rmif and scpp, if you can
>>> get them to compile and run on your system. Or I have one which
>>> I wrote recently:
>>>
>>> http://www.keristor.co.uk/stuff/xcpp-0.4.0.tar.gz

>>
>> Oops, that should be
>>
>> http://www.keristor.co.uk/stuff/xcpp-0.5.0.tar.gz
>>
>> I fixed some bugs and uploaded it to the website but didn't
>> regenerate my web page to indicate the latest version.

>
> You may or may not be interested to know that it compiled out of
> the box under DJGPP. However note the warnings below. I haven't
> attempted to do anything about them. Offhand it looks like a well
> done piece.


Thanks. DJGPP is a version of gcc, so it should have compiled, but it
probably has different memory options from the Linux and Cygwin
versions. Borland C 5.6 gives a load of warnings about unused variables
which I need to check sometime (and I may include a Borland makefile
with the next version).

> It would also be pleasant to have the man page in info format.


I'll have to learn the texinfo stuff sometime. Or there might be a tool
which does the conversion.

> c:\dnld\scratch\junk>make
> gcc -g -Wall -W -pedantic -ansi -c -o xcpp.o xcpp.c
> xcpp.c: In function `tracemem':
> xcpp.c:2712: warning: int format, long unsigned int arg (arg 3)
> xcpp.c:2713: warning: int format, long unsigned int arg (arg 3)
> xcpp.c:2714: warning: int format, long unsigned int arg (arg 3)
> xcpp.c:2716: warning: int format, long unsigned int arg (arg 3)
> xcpp.c: In function `main':
> xcpp.c:2811: warning: int format, long unsigned int arg (arg 3)


Ah yes. I wonder why gcc didn't report them for me. Which version of
gcc are you using (which base version, that is)? Neither 2.95.4 (Debian
GNU/Linux) nor 3.3.3 (Cygwin) produce any of those warnings with those
options. Which is odd, since I know I've seen gcc complain about printf
mismatches before. Perhaps they don't care because long and int are the
same size on those platforms?

> gcc -g -Wall -W -pedantic -ansi -c -o xcppopt.o xcppopt.c
> gcc -g -Wall -W -pedantic -ansi -c -o xcppmem.o xcppmem.c
> gcc -g -Wall -W -pedantic -ansi -c -o xcppmath.o xcppmath.c
> gcc -g -Wall -W -pedantic -ansi -o xcpp xcpp.o xcppopt.o xcppmem.o
> xcppmath.o
>
> You might also want to look on my page (URL below), download
> section, for id2id-20.zip. It contains a simple technique for
> automatic help when stdin on filters has not been redirected.
> Steal it.


It seems to use non-C POSIX functions fileno() and isatty() to determine
whether stdin has been redirected, which makes it not standard C (it's
not often I get to tease /you/ about being off-topic <g>). AS far as I
know there is no portable way to do it. I might just disable the
automatic filter mode since an argument of just '-' means "use stdin"
anyway (indeed, when it finds there are no arguments it just calls the
function which does the work with "-").

Chris C
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      01-12-2005
Chris Croughton wrote:
> <(E-Mail Removed)> wrote:
>

.... snip ...
>>
>> You might also want to look on my page (URL below), download
>> section, for id2id-20.zip. It contains a simple technique for
>> automatic help when stdin on filters has not been redirected.

> Steal it.
>
> It seems to use non-C POSIX functions fileno() and isatty() to
> determine whether stdin has been redirected, which makes it not
> standard C (it's not often I get to tease /you/ about being
> off-topic <g>). AS far as I know there is no portable way to
> do it. I might just disable the automatic filter mode since an
> argument of just '-' means "use stdin" anyway (indeed, when it
> finds there are no arguments it just calls the function which
> does the work with "-").


The routine is labelled as non-standard, but organized to co-exist
with the -pedantic option. If it can't be used on a system all you
have to do is return 0 from a replacement routine, and you are back
to the existing situation. At any rate, most of the time our
systems are running on something that has Posix functions
available, and this takes advantage of that without insisting on
it.

The other way you have to put in code to handle the '-' and
remember to use that argument in any chained commands, etc.

"something | operate thing"

is easier to remember or create than

"something | operate thing -"

especially when you are used to using operate with redirection.

--
Chuck F ((E-Mail Removed)) ((E-Mail Removed))
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-12-2005
Chris Croughton <(E-Mail Removed)> writes:
[...]
> Oops, that should be
>
> http://www.keristor.co.uk/stuff/xcpp-0.5.0.tar.gz


I haven't tried it, but I did download it, and the packaging is a bit
odd. Generally a tarball named "xcpp-0.5.0.tar.gz" should contain a
directory called "xcpp-0.5.0"; yours contains all the files directly.
Also, one of the files is called "xcpp-0.5.0.tar.gz", which causes
problems when I unpack it into the current directory.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Manual VLAN pruning on a Cat 3550 Mikey Cisco 1 06-12-2006 09:05 PM
Pruning on 3500 and 3550 series switches Fred Atkinson Cisco 1 11-01-2005 09:20 PM
Tool for partial C++ preprocessing Alex Sedow C++ 1 07-30-2004 04:02 PM
Ethernet packet size and pruning issue. Mark Cisco 4 01-06-2004 08:47 PM
Any preprocessing tool with {} insertion option? David Frank C Programming 18 09-16-2003 07:50 AM



Advertisments