LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-17-2007, 05:07 AM   #1
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
m4 and white space, does it exist?


I've been scouring the 'net looking for how to use "whitespace" in the m4 macro processor... with no luck. So my question is, how do I insert white space into output??? Example:

Code:
format("This is a line\nThis is another line")
=>This is a line\nThis is another line
This, as you can see, doesn't work, I want the output to be:
Code:
=>This is a line
=>This is another line
But it isn't.


I CAN NOT find anywhere how to insert a newline, tab, carrige return, etc...

The reason I started looking is because I want to be able to make a macro that will grab the rest of the line for me, as an argument, example:

Code:
define(`getline', `Got line: $1 changequote(``', `'')')
changequote('"', '<newline>')
getline("This is a line
=>Got line: This is a line
This wont work however, because I can't find anything about the newline character itself! (It isn't <newline>)

Help!

Last edited by The_Nerd; 04-17-2007 at 05:09 AM.
 
Old 04-17-2007, 10:56 AM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,495

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
<NL> seems to work for changequote but not format , problem with the parenthesis though:
Code:
~% m4                                                                          
define(`getline', `Got line: $1 changequote(``', `'')')

changequote('"', '<NL>')

getline("This is a line )
Got line: "This is a line
getline("This is a line)
Got line: "This is a line 
getline("This is a line\))
Got line: "This is a line\ )
getline("This is a line))
Got line: "This is a line )
They should really have a section about that stuff in the manual, I only found it by accident as I was looking up the other commands in there.
 
Old 04-17-2007, 03:48 PM   #3
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
Are you saying that <NL> really is newline (\n)?

If so, why is it that:

Code:
=><NL>
<NL>
=>
instead of:
Code:
=><NL>

=>
???

Besides, I've been thinking about it, and I see know way this could work anyhow, since it "has" to have the closing bracket:

Code:
getline(' This is a line
)
#^(needs this)
#What I want is:
getline(' This is a line
=> Got line: This is a line
#Notice no closing of arguments
I was sorta hoping there was a way to run a macro that would put out the ending bracket, so that:

Code:
define('close_bracket', ')')
define('getline', 'Got line: $1 close_bracket')
But obviously, this doesn't work, because the macro wont get called in the first place until m4 hits the closing of the argument list, which means I have to type it manually. The only way I see it as possible is if there was a preparse, which would be fine, if I could get the line in the first place...

chicken and the egg...
 
Old 04-18-2007, 05:19 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,495

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
Um, I think you should ignore my first post, I saw <NL> used in the manual so I leapt to conclusions...

It just might be possible to do what want, but I think you need something more flexible then m4 for your problem.

Note that this requires the changeword feature, which is not compiled in by default and the manual expicitly discourges its use. Parts in blue are the command prompt, bold is what I typed in...
Code:
~/tmp% cat wierd.m4 
define(`getline_1', `Got line:$1:')

define(`getline', `getline_1(')

define(`
', `)')

changeword(`[a-zA-Z][_a-zA-Z0-9]*\|
')

changequote(`"', `
')

getline"This is a line

~/tmp% ~/downloads/m4-1.4.9/src/m4 <wierd.m4                                    






))))Got line:This is a line:%
Almost there, except for a bunch of extra brackets and newlines in the wrong place, maybe divert could help...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Just white space in video placeholder..!! Hitboxx General 3 03-27-2007 11:13 AM
show white space characters slzckboy Programming 2 01-18-2006 04:49 PM
striping white space and line blackzone Programming 2 11-22-2004 02:04 AM
removing white space accent11 Linux - Software 4 10-06-2004 01:30 AM
Two Tuxes with block of white space??? robbow52 Debian 1 07-04-2004 01:05 PM


All times are GMT -5. The time now is 04:25 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration