【发布时间】:2021-07-02 09:31:23
【问题描述】:
类似于this question,我需要在多个 c 文件中打印所有 printf。 printf 可以是多行的,每个文件可以有多个 printf。我宁愿不在行上打印任何前导/尾随 cmets... 例如,如果我有以下文件:
// do not print this
rc = printf("blah");
//do not print this
rc = printf("a multiline printf %d %d",
1, 2);
//do not print this
应该输出:
printf("blah");
printf("a multiline printf %d %d",
1, 2);
我假设 printf 在格式字符串中没有任何 ; 字符,因此这将是 -- 找到 printf 字符串,打印直到找到 ;,重复... 有没有简单的在 awk/sed 中如何做到这一点?
【问题讨论】:
-
应该打印像
char *str = "we like using printf(foo);"这样的行吗?像x = 7; // later we will do printf(bar);这样的行怎么样? -
我不介意这些出现在结果中(这些将很少而且相差甚远)。这是寻找滥用某些格式说明符的更大努力的一部分,因此误报不会花费我太多时间
-
StackOverflow 不是免费的编码服务。你应该try to solve the problem first。请更新您的问题以在minimal reproducible example 中显示您已经尝试过的内容。如需更多信息,请参阅How to Ask,并拨打tour :)
-
@Barmar -- 我认为通过添加指向其他 SO 问题的链接,很明显我确实尝试了其他事情。但是这些东西没有用,所以我觉得它们没有为这个问题增加任何好处。
-
那些东西没有用,因为它们解决了不同的问题。所以你需要为你的问题写一个解决方案,也许以你在这些问题中的发现为起点。然后您发布您的想法,我们会帮助您解决问题。