【问题标题】:Dealing with line endings (carriage returns, EOLs) in AC_MSG_ERROR([foo])在 AC_MSG_ERROR([foo]) 中处理行尾(回车,EOL)
【发布时间】:2014-01-23 15:19:04
【问题描述】:

所以我需要在我的 .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

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

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

【问题讨论】:

  • 有一种方法可以解决所有问题,但您仍然会讨厌自动工具,直到时间结束!
  • @WilliamPursell - 好建议。如果你选择cmake,你注定要重复整个过程。
  • 不了解自动工具的人注定要重新实现它们!

标签: autotools autoconf m4


【解决方案1】:

Autoconf 提供了一些易于使用的 m4 string manipulation macros。 例如m4_text_wrap,提供缩进和最大列宽。

【讨论】:

  • 看来 m4_text_wrap 没有提供我正在寻找的东西,我认为 m4_normalize 最接近我需要的东西,但是它删除的标签只是尾随,而不是在字符串的中间 :(
【解决方案2】:

简单地说:

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])])

【讨论】:

  • 谢谢,但这对我来说不是一个合适的解决方案,因为我正在编写一个宏,这意味着文档的全部内容已经缩进,因为它在 AC_DEFUN 声明中
  • 实际上,我猜第二个解决方案会起作用,但是如果你试图假装你的答案“简单”的第一个词仍然适用于第二个解决方案,我要上吊
  • 第二种解决方案并不“简单”,我同意。 @BrettHale 发布的链接中有很多 M4Sugar 字符串操作选项。
猜你喜欢
  • 1970-01-01
  • 2014-07-10
  • 2018-07-06
  • 1970-01-01
  • 2016-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多