0

所以我需要在我的 .m4 文件中使用这个 autoconf 宏,这样:

if SomeCondition; then

    ...do_something...

    if OtherCondition; then
        AC_MSG_ERROR([This is the error message])
    fi
fi

出于充分的理由,该错误消息有点长。

今天,我刚刚决定要在消息中添加更多额外信息。但我不想让线路更长!所以我想把它分成不同的行。我尝试的第一件事是:

if SomeCondition; then
    if OtherCondition; then
        AC_MSG_ERROR([
            Blah blah blah blah blah blah blah blah.
            Or you can also do blah blah blah
            (but take in account that it will disable blah blah)
        ])
    fi
fi

当然,这种解决方案并不理想,因为在显示消息时,它会被不必要地缩进。解决此问题的唯一真正解决方案是使用这种丑陋的方法:

if SomeCondition; then
    if OtherCondition; then
        AC_MSG_ERROR([
Blah blah blah blah blah blah blah blah.
Or you can also do blah blah blah
(but take in account that it will disable blah blah)
        ])
    fi
fi

但是,正如我所说,这很丑陋。而且我敢打赌,将来某些开发人员会将其更改为“修复缩进”,而并不知道他们实际上正在破坏它。

有没有办法做到这一点,或者我会讨厌自动工具,直到时代结束?

4

2 回答 2

0

简单地:

m4_define([my_m4_error],[
Blah blah blah blah blah blah blah blah.
Or you can also do blah blah blah
(but take in account that it will disable blah blah)
])

AS_IF([SomeCondition],[AS_IF([OtherCondition],[AC_MSG_ERROR([my_m4_error])])])

或者因为它是缩进的:

m4_define([my_m4_error],[m4_joinall([m4_newline([])],[],
          [Blah blah blah blah blah blah blah blah.],
          [Or you can also do blah blah blah],
          [but take in account that it will disable blah blah])])
于 2014-01-23T15:51:26.910 回答
0

Autoconf 提供了一些易于使用的 m4字符串操作宏。m4_text_wrap例如,提供缩进和最大列宽。

于 2014-01-23T15:56:31.070 回答