Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using (abusing) cpp...

2 views
Skip to first unread message

Basil Hashem

unread,
Apr 11, 1990, 4:08:15 PM4/11/90
to
I'm using the cpp program (the SunOS C pre-processor) for filtering some
files which are not C programs.

I have been successful in doing #include's, #ifdef's, and #defines's. What I
need to do is pass a file such as the following through cpp. (Don't worry
about the extra lines and comment lines that cpp generates.)

----
#define LANGUAGE English

#if (LANGUAGE == French)
#define GREETING Bonjour
#define FAREWELL Salut
#define GENTLEMEN Monsieurs
#else
#define GREETING Good Morning
#define FAREWELL Bye
#define GENTLEMEN Sirs
#endif

Dear GENTELMEN,

GREETING

blah blah

FAREWELL
----

The results are not what is expected since cpp doesn't do the compare properly.
What I really need is a strcmp(LANGUAGE, "French") but I can't really do
that considering this is not C.

Anyone have suggestions?

"WOOOSH! If they only knew what I was up to."
Basil Hashem
has...@mars.jpl.nasa.gov
Jet Propulsion Laboratory La Canada Flintridge, CA

Martin Weitzel

unread,
Apr 12, 1990, 9:00:18 AM4/12/90
to
In article <33...@jato.Jpl.Nasa.Gov> has...@mars.jpl.nasa.gov (Basil Hashem) writes:
>I'm using the cpp program (the SunOS C pre-processor) for filtering some
>files which are not C programs.

Just one small hint in case you want to expand your technique or make
it portable across different flavours of Unix: Have a look to your
manual and try to locate `m4'. (I don't know how the SunOS manuals are
structured, normally it belongs to the program development tools.)

`m4' is an independant macro processor which has all the features of `cpp'
(of course, the notation differs!) and *much* more, including reliable
semantics in case of nested macro calls, quotation (sometimes you may
want to use a word litterally that is defined as macro), ...
--
Martin Weitzel, email: mar...@mwtech.UUCP, voice: 49-(0)6151-6 56 83

Larry Wall

unread,
Apr 11, 1990, 4:48:26 PM4/11/90
to
In article <33...@jato.Jpl.Nasa.Gov> has...@mars.jpl.nasa.gov (Basil Hashem) writes:
: I'm using the cpp program (the SunOS C pre-processor) for filtering some
: files which are not C programs.
:
: I have been successful in doing #include's, #ifdef's, and #defines's. What I
: need to do is pass a file such as the following through cpp. (Don't worry
: about the extra lines and comment lines that cpp generates.)
:
: ----
: #define LANGUAGE English
:
: #if (LANGUAGE == French)
: #define GREETING Bonjour
: #define FAREWELL Salut
: #define GENTLEMEN Monsieurs
: #else
: #define GREETING Good Morning
: #define FAREWELL Bye
: #define GENTLEMEN Sirs
: #endif
:
: Dear GENTELMEN,
:
: GREETING
:
: blah blah
:
: FAREWELL
: ----
:
: The results are not what is expected since cpp doesn't do the compare properly.
: What I really need is a strcmp(LANGUAGE, "French") but I can't really do
: that considering this is not C.

#define English 1
#define French 2
#define Spanish 3
#define Basque 4

#define LANGUAGE Basque

#if LANGUAGE == Basque
#define GREETING Agur!
#endif

Larry Wall
lw...@jpl-devvax.jpl.nasa.gov

0 new messages