2017-03-06 86 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 
$