472,328 Members | 997 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

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.
May 29 '07 #1
5 14778
"John Speth" <jo*******@yahoo.comwrites:
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[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\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;}
May 29 '07 #2
On May 29, 5:23 pm, "John Speth" <johnsp...@yahoo.comwrote:
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.
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

May 29 '07 #3
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.
May 29 '07 #4
On 29 May 2007, "John Speth" <jo*******@yahoo.comwrote:
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
May 29 '07 #5

"David Tiktin" <dt*****@nospam.totally-bogus.comwrote in message
news:Xn**********************************@216.196. 97.136...
On 29 May 2007, "John Speth" <jo*******@yahoo.comwrote:
>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.
(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
May 29 '07 #6

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

Similar topics

5
by: Vittal | last post by:
Hello All, I have one doubt. I got the preprocessor output of registry_servd.c (one of the source files of my application). In the preprocessor...
6
by: Edd Dawson | last post by:
Hi. I have a strange problem involving the passing of command line arguments to a C program I'm writing. I tried posting this in comp.programming...
9
by: Walter Roberson | last post by:
I have run into a peculiarity with SGI's C compiler (7.3.1.2m). I have been reading carefully over the ANSI X3.159-1989 specification, but I cannot...
16
by: Puneet | last post by:
Hi ALL, I have a silly question... (may be) Can we write a single line C program whose output is the program itself? Is anybody know the...
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The...
32
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their...
8
by: mohdalibaig | last post by:
C preprocessor generates the expanded version of our source code. In order to view this expanded code, I made use of the command cpp filename.c on...
0
by: 7stud | last post by:
Hi, 1) Does this make any sense: """ Thus, the loop: for line in f: iterates on each line of the file. Due to buffering issues,
10
by: Itaichuk | last post by:
Hi I read in several CSS tutorials that block-level elements, such as <div& <pare rendered with an implicit line break before and after. I...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...

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.