mainGNU M4 - Support: sr #103417, Cannot insert sharps

 
 

sr #103417: Cannot insert sharps

Submitter:  Matthieu Pupat <mpupat>
Submitted:  Thu 30 Sep 2004 08:38:27 AM UTC
Votes: 49
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Invalid
Privacy:  Public Assigned to:  ericb
Open/Closed:  Closed Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 28 May 2006 08:30:41 PM UTC, comment #1: 

Sorry for the long delay; the web forum is not tracked as actively as the -email is unavailable- mailing list (Gary, could we get savannah set up to carbon the list when someone posts here?)

Anyway, your problem is that by default, # starts a comment, so as m4 expands the macro, it is coming across a comment and getting lost.  Furthermore, you are not using enough quoting - a good rule of thumb is to use one level of quotes inside every () unless you WANT macro expansion.

Look at what happens when you run with 'm4 -dteaq':

define(`QuoteVariable', `ifelse(substr($1,0,1), i, #$1, ifelse(substr($1,0,1), o, #$1, "$1" ) ) ')
m4trace: -1- define(`QuoteVariable', `ifelse(substr($1,0,1), i, #$1, ifelse(substr($1,0,1), o, #$1, "$1" ) ) ')

QuoteVariable(iTestI);
m4trace: -1- QuoteVariable(`iTestI') -> `ifelse(substr(iTestI,0,1), i, #iTestI, ifelse(substr(iTestI,0,1), o, #iTestI, "iTestI" ) ) '
m4trace: -2- substr(`iTestI', `0', `1') -> `i'

The first expansion has an unquoted comment in the place where the third argument to ifelse starts, and that comment consumes everything to the end of the line, meaning that the ifelse is unterminated until the ) on the next line.

Try instead using this approach, which uses enough quoting, and simplifies the ifelse (there is no need to nest):

define(`QuoteVariable', `ifelse(substr(`$1',`0',`1'), `i', ``#'$1', substr(`$1', `0', `1'), `o', ``#'$1', `"$1"')')
QuoteVariable(`iTestI')
#iTestI
QuoteVariable(`oTestO')
#oTestO
QuoteVariable(`lTestL')
"lTestL"

Also take a look at changecom.

Eric Blake <ericb>
Group administrator
Thu 30 Sep 2004 08:38:27 AM UTC, original submission:  

I try a simple macro that prepone a sharp (#) before names beginning with i or o and quoting other names :

define(`QuoteVariable', `ifelse(substr($1,0,1), i, #$1, ifelse(substr($1,0,1), o, #$1, "$1" ) ) ')

QuoteVariable(iTestI);
QuoteVariable(oTestO);
QuoteVariable(lTestL);

If I replace my sharps by A for example this works fine.

There I get the message:

m4: file "Test.m4": line 5: EOF in arg list

What can I do to get rid of this ?

Matthieu Pupat <mpupat>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

There are 49 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

Only logged-in users can vote.

 

Follow 6 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2006-05-28 ericb Severity6 - Security 3 - Normal
    StatusNone Invalid
    Assigned toNone ericb
    Open/ClosedOpen Closed
    Carbon-Copy- Added -email is unavailable-
2006-04-28 saugart Carbon-Copy- Added saugart

Back to the top

Powered by Savane 3.13-f14d.
Corresponding source code