LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-06-2011, 09:27 AM   #1
skiron.liu
Member
 
Registered: Jun 2009
Location: Harbin
Posts: 32

Rep: Reputation: 0
About M4


I seen the "DOL" m4 Macro in the book of <sendmail.4th.edition> of 17.1.4
but why I directly use it in my script that can't run. For example:
Code:
define(DOWN,DOL(*)$1)dnl
DOWN(x)
i want see "$*x" but it show me "DOL(*)x".How to fix it?
 
Old 04-07-2011, 06:12 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Are you sure it isn't "#define"?
 
Old 04-09-2011, 02:14 PM   #3
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 727

Rep: Reputation: 74
Hi.

Here is one solution found by becoming re-acquainted with man m4:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate transliteration with m4 macro processor.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for i;do printf "%s" "$i";done; printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && . $C m4

FILE=${1-data1}
pl " Input macro file is:"
cat $FILE

pl " Result with m4 macro processor:"
m4 $FILE

exit 0
producing:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.7 (lenny) 
GNU bash 3.2.39
m4 (GNU M4) 1.4.11

-----
 Input macro file is:
define(DOL,$)dnl
define(DOWN,DOL * $1)dnl
translit(DOWN(x),' ',)

-----
 Result with m4 macro processor:
$*x
Best wishes ... cheers, makyo
 
Old 04-09-2011, 02:39 PM   #4
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 727

Rep: Reputation: 74
Hi.

This macro file -- closer to the original -- also seems to work:
Code:
define(DOL,$ $1)dnl
define(DOWN,DOL(*)$1)dnl
translit(DOWN(x),' ',)
producing:
Code:
% ./s1 data2
...
$*x
cheers, makyo
 
Old 04-10-2011, 10:00 PM   #5
skiron.liu
Member
 
Registered: Jun 2009
Location: Harbin
Posts: 32

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by makyo View Post
Hi.

This macro file -- closer to the original -- also seems to work:
Code:
define(DOL,$ $1)dnl
define(DOWN,DOL(*)$1)dnl
translit(DOWN(x),' ',)
producing:
Code:
% ./s1 data2
...
$*x
cheers, makyo
I redefine my macro like this:
Code:
define(DOL, $ $1)dnl attention this between "$" and "$1" have a space
define(DOWN, R DOL(*) < @ $1 > DOL(*)  DOL(1) < @ $2 > DOL(2))dnl
DOWN(badhost, outhost)
the result is :
Code:
R $ * < @ badhost > $ *  $ 1 < @ outhost > $ 2
but I need the result is no space between "$" and "*" :
Code:
R $* < @ badhost > $*   $1 < @ outhost > $2
how to fix it ?
 
Old 04-11-2011, 11:22 AM   #6
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 727

Rep: Reputation: 74
Hi.
Quote:
Originally Posted by skiron.liu View Post
I redefine my macro like this:
Code:
define(DOL, $ $1)dnl attention this between "$" and "$1" have a space
define(DOWN, R DOL(*) < @ $1 > DOL(*)  DOL(1) < @ $2 > DOL(2))dnl
DOWN(badhost, outhost)
the result is :
Code:
R $ * < @ badhost > $ *  $ 1 < @ outhost > $ 2
but I need the result is no space between "$" and "*" :
Code:
R $* < @ badhost > $*   $1 < @ outhost > $2
how to fix it ?
Changing the macro definitions to apply to the new problem, results in:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.7 (lenny) 
GNU bash 3.2.39
m4 (GNU M4) 1.4.11

-----
 Your macro output:
R $ * < @ badhost > $ *  $ 1 < @ outhost > $ 2

-----
 Desired:
R $* < @ badhost > $*   $1 < @ outhost > $2

-----
 Input macro file data4 is:
define(DOL, translit($ $1,' ',))dnl
define(DOWN, R DOL('*') < @ $1 > DOL('*')  DOL('1') < @ $2 > DOL('2'))dnl
translit('DOWN(badhost, outhost)',''')

-----
 My result with m4 macro processor:
R $* < @ badhost > $*  $1 < @ outhost > $2
Best wishes ... makyo
 
Old 04-13-2011, 10:05 PM   #7
skiron.liu
Member
 
Registered: Jun 2009
Location: Harbin
Posts: 32

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by makyo View Post
Hi.

Changing the macro definitions to apply to the new problem, results in:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.7 (lenny) 
GNU bash 3.2.39
m4 (GNU M4) 1.4.11

-----
 Your macro output:
R $ * < @ badhost > $ *  $ 1 < @ outhost > $ 2

-----
 Desired:
R $* < @ badhost > $*   $1 < @ outhost > $2

-----
 Input macro file data4 is:
define(DOL, translit($ $1,' ',))dnl
define(DOWN, R DOL('*') < @ $1 > DOL('*')  DOL('1') < @ $2 > DOL('2'))dnl
translit('DOWN(badhost, outhost)',''')

-----
 My result with m4 macro processor:
R $* < @ badhost > $*  $1 < @ outhost > $2
Best wishes ... makyo
thx~~~ The last questions! where find the manual page about 'translit' and so on ? And how to learn m4?

below macro can do this too!
Code:
define(DOL, $$1))dnl
define(DOWN, R DOL('*') < @ $1 > DOL('*')  DOL('1') < @ $2 > DOL('2'))dnl
translit(DOWN(badhost, outhost),''')

Last edited by skiron.liu; 04-13-2011 at 10:12 PM.
 
Old 04-13-2011, 10:26 PM   #8
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 727

Rep: Reputation: 74
Hi.

Good, glad to see that you solved it.
Quote:
Originally Posted by skiron.liu View Post
thx~~~ The last questions! where find the manual page about 'translit' and so on ? And how to learn m4?
If you do not have:
Code:
info m4
then try one of the formats at:

http://www.gnu.org/software/m4/manual/index.html

I find info difficult to use, so I usually use one of the formats above if they are available.

Best wishes ... cheers, makyo
 
  


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




All times are GMT -5. The time now is 11:02 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration