public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Can CPP process only one "conditional" ?
@ 2008-06-11  7:47 adlv
  2008-06-11  8:28 ` Fabian Cenedese
  0 siblings, 1 reply; 6+ messages in thread
From: adlv @ 2008-06-11  7:47 UTC (permalink / raw)
  To: gcc-help


Hello

I want to give the source code of my software (written in C and C++), either
in a freeware version or in a shareware version.

I could put something like this in my code :

#if FREE_VERSION
 …code A...
#else
 …code B...
#endif

then source files with the "code A" part would be given with the freeware
package.
and source files with the "code B" part would be given with the shareware
package.

I am wandering if CPP can generate output files corresponding to these two
different versions of my source code. In other words I would like CPP to
process only this conditional statement (FREE_VERSION), and _only_ this one!

In other words :) I would like CPP to give the exact same output files as
it's input files, except for this specific conditional.

From what I have read in the CPP documentation and some faqs, I don't think
CPP can do the job. But if someone here thinks it can, then it would make
mine easier :)

Thanks in advance...
-- 
View this message in context: http://www.nabble.com/Can-CPP-process-only-one-%22conditional%22---tp17771975p17771975.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Can CPP process only one "conditional" ?
  2008-06-11  7:47 Can CPP process only one "conditional" ? adlv
@ 2008-06-11  8:28 ` Fabian Cenedese
  2008-06-11 14:30   ` adlv
  0 siblings, 1 reply; 6+ messages in thread
From: Fabian Cenedese @ 2008-06-11  8:28 UTC (permalink / raw)
  To: gcc-help

At 00:47 11.06.2008 -0700, adlv wrote:

>Hello
>
>I want to give the source code of my software (written in C and C++), either
>in a freeware version or in a shareware version.
>
>I could put something like this in my code :
>
>#if FREE_VERSION
> …code A...
>#else
> …code B...
>#endif
>
>then source files with the "code A" part would be given with the freeware
>package.
>and source files with the "code B" part would be given with the shareware
>package.
>
>I am wandering if CPP can generate output files corresponding to these two
>different versions of my source code. In other words I would like CPP to
>process only this conditional statement (FREE_VERSION), and _only_ this one!
>
>In other words :) I would like CPP to give the exact same output files as
>it's input files, except for this specific conditional.
>
> From what I have read in the CPP documentation and some faqs, I don't think
>CPP can do the job. But if someone here thinks it can, then it would make
>mine easier :)

You may want to give doxygen a try. It includes a preprocessor and can
be configured what macros to expand. That may give you the processed
source files as you want (and some nice documentation as well :)

I have never used it for that purpose but I think it can do it.

If that doesn't work you may want to write a script to filter the text files.
sed can probably do it.

bye  Fabi


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Can CPP process only one "conditional" ?
  2008-06-11  8:28 ` Fabian Cenedese
@ 2008-06-11 14:30   ` adlv
  2008-06-11 14:41     ` Young, Michael
  0 siblings, 1 reply; 6+ messages in thread
From: adlv @ 2008-06-11 14:30 UTC (permalink / raw)
  To: gcc-help




Fabian Cenedese wrote:
> 
> At 00:47 11.06.2008 -0700, adlv wrote:
> 
>>Hello
>>
>>I want to give the source code of my software (written in C and C++),
either
>>in a freeware version or in a shareware version.
>>
>>I could put something like this in my code :
>>
>>#if FREE_VERSION
>> …code A...
>>#else
>> …code B...
>>#endif
>>
>>then source files with the "code A" part would be given with the freeware
>>package.
>>and source files with the "code B" part would be given with the shareware
>>package.
>>
>>I am wandering if CPP can generate output files corresponding to these two
>>different versions of my source code. In other words I would like CPP to
>>process only this conditional statement (FREE_VERSION), and _only_ this
one!
>>
>>In other words :) I would like CPP to give the exact same output files as
>>it's input files, except for this specific conditional.
>>
>> From what I have read in the CPP documentation and some faqs, I don't
>> think
>>CPP can do the job. But if someone here thinks it can, then it would make
>>mine easier :)
> 
> You may want to give doxygen a try. It includes a preprocessor and can
> be configured what macros to expand. That may give you the processed
> source files as you want (and some nice documentation as well :)
> 
> I have never used it for that purpose but I think it can do it.
> 
> If that doesn't work you may want to write a script to filter the text
> files.
> sed can probably do it.
> 
> bye  Fabi
> 

Thank you Fabi. Here is some feedback on the ideas you suggested.

Using sed seems difficult because it is mainly aimed at line after line
processsing.
awk might be able to do it, although it would require some script
programming.

Doxygen's preprocessor is a very good candidate, as it seems to be doing
exactly what I want with the tag EXPAND_ONLY_PREDEF.
More info here : http://www.stack.nl/~dimitri/doxygen/preprocessing.html

That solves my question, although I would be curious to know if CPP can do
the equivalent of doxygen.

Best regards
-- 
View this message in context: http://www.nabble.com/Can-CPP-process-only-one-%22conditional%22---tp17771975p17779209.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Can CPP process only one "conditional" ?
  2008-06-11 14:30   ` adlv
@ 2008-06-11 14:41     ` Young, Michael
  2008-07-24 19:45       ` adlv
  0 siblings, 1 reply; 6+ messages in thread
From: Young, Michael @ 2008-06-11 14:41 UTC (permalink / raw)
  To: adlv, gcc-help

> Doxygen's preprocessor is a very good candidate, as it seems to be
doing exactly what I want with the tag EXPAND_ONLY_PREDEF.
> More info here :
http://www.stack.nl/~dimitri/doxygen/preprocessing.html
> 
> That solves my question, although I would be curious to know if CPP
can do the equivalent of doxygen.

I don't believe this functionality is available as part of a standard
CPP (i.e., it's not a requirement of the standard), and I don't recall
any similar functionality in the actual implementations I've used.  (Of
course, I could be wrong - I wasn't explicitly looking for this
particular behavior.)
However, you might want to check out Wave
(http://spirit.sourceforge.net/old_docs/wave_v1_0/index.html) - it's a
CPP based on the Boost Spirit parser.  I looked at it awhile back for a
project - it's fairly capable; I don't know if it has what you want out
of the box, but you can always modify it.  :-)
  - Mike


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Can CPP process only one "conditional" ?
  2008-06-11 14:41     ` Young, Michael
@ 2008-07-24 19:45       ` adlv
  2008-07-24 20:23         ` adlv
  0 siblings, 1 reply; 6+ messages in thread
From: adlv @ 2008-07-24 19:45 UTC (permalink / raw)
  To: gcc-help



Young, Michael wrote:
> 
>> Doxygen's preprocessor is a very good candidate, as it seems to be
> doing exactly what I want with the tag EXPAND_ONLY_PREDEF.
>> More info here :
> http://www.stack.nl/~dimitri/doxygen/preprocessing.html
>> 
>> That solves my question, although I would be curious to know if CPP
> can do the equivalent of doxygen.
> 
> I don't believe this functionality is available as part of a standard
> CPP (i.e., it's not a requirement of the standard), and I don't recall
> any similar functionality in the actual implementations I've used.  (Of
> course, I could be wrong - I wasn't explicitly looking for this
> particular behavior.)
> However, you might want to check out Wave
> (http://spirit.sourceforge.net/old_docs/wave_v1_0/index.html) - it's a
> CPP based on the Boost Spirit parser.  I looked at it awhile back for a
> project - it's fairly capable; I don't know if it has what you want out
> of the box, but you can always modify it.  :-)
>   - Mike
> 

Hello

A little to give a last feedback on this question.

In the end we decided to develop a perl script to expand our one specific
macro only.
The problem with Doxygen was that, even with the tag EXPAND_ONLY_PREDEF, it
expands all the #include. And we didn't want any other processing than just
one macro.

For our perl script I took inspiration from this
http://www.cabaret.demon.co.uk/filepp/ which I recommend.

Thanks to all for your help !
-- 
View this message in context: http://www.nabble.com/Can-CPP-process-only-one-%22conditional%22---tp17771975p18636734.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Can CPP process only one "conditional" ?
  2008-07-24 19:45       ` adlv
@ 2008-07-24 20:23         ` adlv
  0 siblings, 0 replies; 6+ messages in thread
From: adlv @ 2008-07-24 20:23 UTC (permalink / raw)
  To: gcc-help



Young, Michael wrote:
> 
>> Doxygen's preprocessor is a very good candidate, as it seems to be
> doing exactly what I want with the tag EXPAND_ONLY_PREDEF.
>> More info here :
> http://www.stack.nl/~dimitri/doxygen/preprocessing.html
>> 
>> That solves my question, although I would be curious to know if CPP
> can do the equivalent of doxygen.
> 
> I don't believe this functionality is available as part of a standard
> CPP (i.e., it's not a requirement of the standard), and I don't recall
> any similar functionality in the actual implementations I've used.  (Of
> course, I could be wrong - I wasn't explicitly looking for this
> particular behavior.)
> However, you might want to check out Wave
> (http://spirit.sourceforge.net/old_docs/wave_v1_0/index.html) - it's a
> CPP based on the Boost Spirit parser.  I looked at it awhile back for a
> project - it's fairly capable; I don't know if it has what you want out
> of the box, but you can always modify it.  :-)
>   - Mike
> 

Hello

A little messge to give a last feedback on this question.

In the end we decided to develop a perl script to expand our one specific
macro only.
The problem with Doxygen was that, even with the tag EXPAND_ONLY_PREDEF, it
expands all the #include. And we didn't want any other processing than just
one macro.

For our perl script I took inspiration from this
http://www.cabaret.demon.co.uk/filepp/ which I recommend.

Thanks to all for your help !
-- 
View this message in context: http://www.nabble.com/Can-CPP-process-only-one-%22conditional%22---tp17771975p18636734.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-07-24 17:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-11  7:47 Can CPP process only one "conditional" ? adlv
2008-06-11  8:28 ` Fabian Cenedese
2008-06-11 14:30   ` adlv
2008-06-11 14:41     ` Young, Michael
2008-07-24 19:45       ` adlv
2008-07-24 20:23         ` adlv

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).