假设我定义了一个包含段落的m4宏FOOBAR 任意文本,可能包含逗号字符。请 创建一个m4宏来添加5个空格的左边距 扩展FOOBAR文本。
问题很简单(只需使用patsubst w /" ^"正则表达式)如果 文本不包含任何逗号。但我需要处理逗号。
谢谢!
答案 0 :(得分:0)
需要抛光,但这是一个开始:
m4_divert(-1)
I changed the m4 quoting to use [<{}>]
m4_define(_spaces,[<{m4_format([<{%}>]$1[<{s}>],)}>])
m4_define(_indent,[<{m4_patsubst($1,[<{^}>],_spaces($2))}>])
m4_define(_Comma_and_Paren_Safe,[<{m4_patsubst([<{[<{Some. arbitrary text,with unbalanced parentheses like:
((()((((
and several commas ,,,, and a few, more , of those
commas,,.
}>]}>],[<{,}>],[<{[<{,}>]}>])}>])
m4_divert(0)m4_dnl
_indent([<{_Comma_and_Paren_Safe}>],7)
示例运行(_m42是简单的m4包装脚本):
$ _m42 < ~/tmp/2v.STDIN.m4-margin.SatMay16.2052.190
Some. arbitrary text,with unbalanced parentheses like:
((()((((
and several commas ,,,, and a few, more , of those
commas,,.
答案 1 :(得分:0)
比先前尝试更简单:保存到宏FOOBAR - 任意文本 段落嵌套在四重报价中以保护逗号,和 不平衡的括号:
m4_divert(-1)
m4_define(_spaces,[<{m4_format([<{%}>]$1[<{s}>],)}>])
m4_define(_indent,[<{m4_patsubst($1,[<{^}>],_spaces($2))}>])
--
Simpler than prior attempt: save arbitrary text paragraph nested inside
quadruple quote to protect commas, and unbalanced parentheses:
m4_define(FOOBAR,[<{[<{[<{[<{Some. arbitrary text,with unbalanced parentheses like:
((()((((
and several commas ,,,, and a few, more , of those
commas,,.
}>]}>] }>]}>])
m4_divert(0)m4_dnl
_indent(FOOBAR,15)
示例运行:
$ _m42 < ~/tmp/2v.STDIN.m4-margin.SatMay16.2052.190
Some. arbitrary text,with unbalanced parentheses like:
((()((((
and several commas ,,,, and a few, more , of those
commas,,.