2017-03-06 89 views
1

我使用降价和M4的组合产生三个不同的版本取决于一开始给出的标志文档。我们称他们为金,银和铜牌。转义的逗号M4的ifdef语句

是我遇到的是,如果我有一个有逗号的ifdef的语句中出现一个部分,M4考虑节的其余部分是假的问题。

ifdef(`GOLDANDSILVER',dnl 
## Here's a subsection header 

### Subsubsection about this, that, and the other thing 

Aren't examples fun? Here's some punctuation, failure, and misfortune. 
)dnl 

有趣的是,它不会在子子部分失败,但在正文中失败。

我的电流,难看,解决方案是使用一个“哑逗号”,可以通过通过管道输送到,和更换,sed的。

ifdef(`GOLDANDSILVER',dnl 
## Here's a subsection header 

### Subsubsection about thisREPLACE_ME_COMMA thatREPLACE_ME_COMMA and the other thing 

Aren't examples fun? Here's some punctuationREPLACE_ME_COMMA failureREPLACE_ME_COMMA and misfortune. 
)dnl 

我在寻找一个更清洁,最好M4只解决方案,它让我有“”在我的ifdef语句的身体。


我已经通过试验和错误学到了什么:

  • M4似乎忽略与#
  • 前缀的行的任何内容或定义[,]不越狱逗号
  • [[,]]不能跳过逗号
+0

你看到我的答案?它工作吗? – uzsolt

+0

它的工作规模很小,但无论出于何种原因,文档中还有其他内容会导致它不再编译为HTML。 现在,我就坚持REPLACE_ME_COMMA。 – aepksbuck

+0

如果你提供一个复杂的例子,我可以检查它。 – uzsolt

回答

1

最好的办法是使用字符串分隔符。默认的字符串分隔符不是最好的解决方案(我认为) - 但你可以用changequote来改变它们。

您可以更改注释分隔符(默认为#和换行) - 甚至可以禁用它们。

我认为,以下将是对你有好处:

ifdef(`GOLDANDSILVER',changequote(XXX,YYY)dnl 
XXX## Here's a subsection header 

### Subsubsection about this, that, and the other thing 

Aren't examples fun? Here's some punctuation, failure, and misfortune.YYY changequote() 
)dnl 

请注意changequote(XXX,YYY):报价开始XXXYYY结束。在这种情况下,以#开头的行不是注释,因为它是字符串的一部分。请注意0​​:它会恢复默认的字符串分隔符。

$ cat x.m4 | m4 -DGOLDANDSILVER # GOLDANDSILVER is defined 
## Here's a subsection header 

### Subsubsection about this, that, and the other thing 

Aren't examples fun? Here's some punctuation, failure, and misfortune. 
$ cat x.m4 | m4 # GOLDANDSILVER isn't defined 
$