将 C 代码中的左大括号移到下一行? [英] Moving left brace in C code to the next line?

查看:49
本文介绍了将 C 代码中的左大括号移到下一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个 C 源文件需要更改一个特定的格式设置功能.在文件的某些部分,

I have several C source files that need to have one particular formatting feature changed. In some parts of the file,

if (x == NULL) {
    ...
}

需要改成

if (x == NULL)
{
    ...
}

我希望使用缩进"命令,但它太激进了.它想用所有选项更改整个文件.

I was hoping to use the "indent" command, but it's far too aggressive. It wants to change the entire file with all options.

我想我可以在 Perl 甚至 Sed 中做到这一点,但我对这两者的了解还不够清楚.

I suppose I can do this in Perl or maybe even Sed, but I don't know either well enough to figure that out.

推荐答案

看来今天是我的幸运日,看来我想通了:

Looks like today is my lucky day, as it appears I figured it out:

sed 's/^\([ ]*\)\(if (.* == NULL)\) {$/\1\2\n\1{/g' <filename>

有人可以确认这是正确的吗?

Can someone confirm that this is correct?

这篇关于将 C 代码中的左大括号移到下一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆