Subject: Re: FVWM: M4 examples?

From: Bill Hails <[email-masked]>
Date: Tue, 02 Jan 1996 09:48:40 +0000

In message <[email-masked]>,
Nicholas Vargish writes:
>Hi,
>
>Sorry to be an idiot, but I can't figure this m4 macro language out.
[...]
>I think I must be confused about m4 quoting rules, but I'm not sure
>exactly where I'm going wrong. I'd appreciate any advice people might
>have... Examples would be especially welcome -- I learn well from those.
>
>Nick
>
>p.s. Is there any way to make those m4 definitions "prettier"? I'm just not
>a big fan of 220-character lines...
>

I'm using m4 to an almost obscene degree (according to my workmates :-)

Your code looks fine, and I can't at first glance see much wrong with
it, but a few things need clarifying.

The m4_* forms imply that you're using gnu m4, and invoking it
with the -P option, i.e. your .xsession/.xinitrc starts fvwm2
with something like:

fvwm2 -f "FvwmM4 -m4prog g4 -m4-prefix .fvwm2rc"

(I have gnu m4 installed as `g4', and the `-m4-prefix' switch not only
tells FvwmM4 to pass g4 the -P switch, but also to pass in the prologue
as `m4_define(...) etc. instead of just `define(...))

How do you know what FvwmM4 is defining HOSTNAME to be?

I have the following:

m4_define(`BASEHOSTNAME',m4_substr(HOSTNAME, 0, m4_index(HOSTNAME, .)))

AddToMenu "FvwmInfo" "Constants Known to FVWM" Title
m4_define(`ShowValue', `AddToMenu "FvwmInfo" "`$1' is $1" Nop')
ShowValue(`WIDTH')
ShowValue(`HEIGHT')
ShowValue(`TWM_TYPE')
ShowValue(`SERVERHOST')
ShowValue(`CLIENTHOST')
ShowValue(`HOSTNAME')
ShowValue(`BASEHOSTNAME')
ShowValue(`OSTYPE')
ShowValue(`USER')
ShowValue(`VERSION')
ShowValue(`REVISION')
ShowValue(`VENDOR')
ShowValue(`RELEASE')
ShowValue(`X_RESOLUTION')
ShowValue(`Y_RESOLUTION')
ShowValue(`PLANES')
ShowValue(`BITS_PER_RGB')
ShowValue(`CLASS')
ShowValue(`COLOR')
ShowValue(`FVWM_VERSION')
ShowValue(`OPTIONS')
ShowValue(`FVWMDIR')

Then just pop up the FvwmInfo Menu as you wish.

There exists the `dnl' macro, invoked in your case as `m4_dnl'
which will discard all subsequent text up to and including the
next new line, so I have:

PixmapPath m4_dnl
/home/bill/lib/images/icons/xpm:m4_dnl
/home/bill/trees:m4_dnl
/vol/images/3d_pixmaps_1.0/3dpixmaps_100colors

which looks a little prettier than one long line.

Persevere with m4. It's well worth the effort of learning, and 
you can get a *lot* more out of it than cpp (for example recursive
macros, macros which define macros, macro stacks etc. etc. etc.)

Hope this helps.

Cheers
	Bill

Bill Hails <[email-masked]>
Tel (UK) 01483 300 200 x415
Fax (UK) 01483 461 046

--
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Chris Taylor <[email-masked]>
Date: Tue, 2 Jan 1996 09:06:07 -0500 (EST)

Nicholas Vargish <[email-masked]> wrote:
> This is the basic definition, establish the default:
> m4_define(`icopath',`/homes/critters/vargish/lib/icons:/var/local/X11R6/include/X11/bitmaps:/usr/local/X11R6/include/X11/bitmaps')

This line is OK.

> Then check the HOSTNAME and change the definition if needed:
> 
> m4_ifelse(`HOSTNAME',`imrryr',`m4_define(`icopath',`/homes/nick/lib/icons:/usr/X11R6/include/X11/bitmaps')')

This is where it falls down. Putting quotation marks around HOSTNAME
prevents m4 from interpreting it. As used here, it will always compare
the literal string "HOSTNAME" to the literal string "imrryr".

If you remove the quotation marks from HOSTNAME, the ifelse statement
works. This is also true for the second ifelse statement you described.

> Is there any way to make those m4 definitions "prettier"?

If it's not enclosed in quotation marks, you can put newlines where
you wish (after a comma, for example).

Chris Taylor     / My views do not represent \ PGP public key available
[email-masked] \    those of Cabletron.    / via keyserver or request