helpGNU M4 - Support: sr #105015, variable syntax for parameter...


sr #105015: variable syntax for parameter separation

Submitted by:  None
Submitted on:  Sun 08 Jan 2006 04:36:42 AM UTC  
Category:  None Priority:  5 - Normal
Severity:  1 - Wish Status:  Ready For Test
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  None

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Fri 14 Jul 2006 04:03:24 AM UTC, comment #1: 

I think you will find that the new changesyntax builtin on CVS head does exactly what you are asking for.  It will be released as part of m4 2.0, but you can experiment with it now if you are willing to build from CVS.

Eric Blake <ericb>
Project Administrator
Sun 08 Jan 2006 04:36:42 AM UTC, original submission:  

i will try to explain my feature-request by means of an example:

consider putting ldap distinguished names (which always contain at least one comma) into m4 macros:

  define(`basedn', `dc=expample,dc=com')
  define(`rootdn', `cn=manager,'basedn)

results in a
  m4: Warning: Excess arguments to built-in `define' ignored

of course, we could

  define(`basedn', ``dc=expample,dc=com'')
  define(`rootdn', `cn=manager,'basedn)

to get the desired

  rootdn -> cn=manager,dc=example,dc=com

but then we must know in advance, how many quote-removals a
macro will undergo during macro expansion. but what if this depends on some facts unknown at the time of writing these macros? for example, we want to define a recursive macro which converts all users from /etc/passwd into ldap user-dn's:

  define(`uiddn', `ou=people,'basedn)

  define(`nextdn', `ifdef(`list',
    `define(`list', list`:uid=$1,'uiddn)list',
    `define(`list', `uid=$1,'uiddn)list')')

now we can collect all user-dn's:

  define(`all', `esyscmd(cat /etc/passwd|cut -d: -f1|
    sed -e "s/^/`next'(/;s/$/)/")')

and would get the list of user-dn's with


... if there would be a way to disable the syntactic role of ',' as separator of macro parameters because the number of quote-removals the comma-containing "list" macro undergoes when "all" is expanded, depends on the number of lines the "esyscmd" returns and, therefore, we can't insert a suitable amount of quotes at design-time.

(if you exchange ',' with an other character, say '_', then the above macros would work fine, ... but, of course, then you won't get syntactical correct ldap dn's.)

for the moment the only thing (at least the only thing i can think of) we can do is to define macros

  define(`protect', `esyscmd(`echo "$*"|tr "," ";"')')
  define(`unprotect', `esyscmd(`echo "$*"|tr ";" ","')')

and change the above into

  define(`uiddn', `protect(`ou=people,'basedn)')

  define(`nextdn', `ifdef(`list',
    `define(`list', protect(list`:uid=$1,'uiddn))list',
    `define(`list', protect(`uid=$1,'uiddn))list')')

to get the list with


which works quite well ... but now ';' mustn't appear in the parameters so that this solution is at least not a general one. in a next step we can make the ';' flexible by introducing a new macro

  define(`delim', `;')

and use this inside the protect() and unprotect() macros ...

i hope these rather lengthly explaination could convince you that a more flexible (i.e., changeable at runtime) syntax scheme for m4 would rather useful -- and prior to version 1.4 there had been a (now obviously abandoned) builtin "changesyntax" which seemed to do exactly these things.

by the way, if you take a look at tex's concept of reassigning category codes of input tokens (which is inside the token-based world of tex the same as exchanging characters of particular syntactic roles in the character-based world of m4), you will find that this concept greatly enlarges the expressiveness (and, therefore, the application domain) of a macro language.



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


CC list is empty


Do you think this task is very important?
If so, you can add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.




Follow 2 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2006-07-14 ericb StatusNone => Ready For Test
2006-01-08 None Carbon-Copy- => Added m --DOT-- pietsch --AT-- uke --DOT-- uni-hamburg --DOT-- de

Back to the top

Powered by Savane 3.5