Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C Programming Language

Line break in preprocessor output


Hi Group-

I want to use the C preprocessor to generate expanded text as a text
processor for software test script generation.  The preprocessor output will
never be compiled.  I need to insert newlines in the preprocessed output
file but I can't figure out how to do it.

Here's a stab at what I'm trying to do but failing:

#define CMD(s) text s \
               enter \
               sleep 500

CMD(mmem:mdir "a1")
CMD(mmem:mdir "a2")

I'd like to output a literal newline for every macro line continuation
character ('\').  I know my example won't work but it's the closest I've
been able to get to actually get the output that I'd like to get, which is:

text mmem:mdir "a1"
enter
sleep 500
text mmem:mdir "a2"
enter
sleep 500

What I get instead is:

text mmem:mdir "a1" enter sleep 500
text mmem:mdir "a2" enter sleep 500

The desired newlines are missing.

Does anyone know how to get the C proeprocessor to output a literal newline
using macros?

Thanks, John.

"John Speth" <johnsp@yahoo.com> writes:
> Does anyone know how to get the C proeprocessor to output a literal newline
> using macros?

I don't think that there is a way to do it.  You might consider
designating a character sequence to represent a new-line
character and then postprocess the C preprocessor's output with
another program that can replace that sequence with a new-line.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.\
 \n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
On May 29, 5:23 pm, "John Speth" <johnsp@yahoo.com> wrote:

With some preprocessors, it's possible that the sequence of characters
\u000A will expand into a newline during preprocessing (this is almost
legal C99 syntax, but the standard specifically says that this sort of
thing isn't allowed (6.4.3:2 in N1124.pdf)). (I haven't tested, but it
seems reasonable that at least one preprocessor will get confused into
emitting a newline in this situation; the #defines would be
substituted in stage 4, before the universal character names are even
considered by the compiler.) One point of interest is that universal
character names are one C99 feature that I've actually used in
practice.
--
ais523

John Speth wrote:
> Hi Group-

> I want to use the C preprocessor to generate expanded text as a text
> processor for software test script generation.  The preprocessor output will
> never be compiled.  I need to insert newlines in the preprocessed output
> file but I can't figure out how to do it.

The C preprocessor is probably the wrong tool.  You might look into a
program designed as a stand-alone macro language, like the old, I know,
but trusty M4.
On 29 May 2007, "John Speth" <johnsp@yahoo.com> wrote:

> I want to use the C preprocessor to generate expanded text as a
> text processor for software test script generation.  The
> preprocessor output will never be compiled.  I need to insert
> newlines in the preprocessed output file but I can't figure out
> how to do it.

Like others who have responded, I don't think there's a way to do this
portably with the C preprocessor.  But could you explain why you chose
that particular tool?  Why not use a "real" macro processor like m4?

  http://en.wikipedia.org/wiki/M4_(computer_language)

Since it's usually written in C, you should be able to build it for
just about any platform.

Dave

--
D.a.v.i.d  T.i.k.t.i.n
t.i.k.t.i.n [at] a.d.v.a.n.c.e.d.r.e.l.a.y [dot] c.o.m

"David Tiktin" <dtik@nospam.totally-bogus.com> wrote in message

news:Xns993F77B3CA75Adtiktinnospambogusco@216.196.97.136...

(I'm the OP) I chose the C preprocessor because it seemed like a capable
tool for the job AND it was at my fingertips.  I'm looking for instant
gratification.  M4 looks like it'll work but now I have to spend an hour or
two learning it.

It appears simply outputting a newline is just plain not possible using the
C proeprocessor.  It's such a simple thing too :(

Thanks to everyone for your help and suggestions.

JJS

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc