-3

I have OpenGL code for which I would like to have some special indentation after running astyle. For example,

glBegin(GL_LINES);
glVertex2f(1.0f, 2.0f);
glVertex2f(1.0f, 2.0f);
glVertex2f(1.0f, 2.0f);
glVertex2f(1.0f, 2.0f);
glEnd();

The above code I want to change to some thing like below.

glBegin(GL_LINES);
    glVertex2f(1.0f, 2.0f);
    glVertex2f(1.0f, 2.0f);
    glVertex2f(1.0f, 2.0f);
    glVertex2f(1.0f, 2.0f);
glEnd();

In this special case whatever is there in between glBegin and glEnd I want to shift by 4 white spaces.

I want to do this inline and using perl.

4

1 回答 1

2

很难说“内联”是什么意思。我假设您想使用-e命令行选项。这是 perl 的一个非常简单的用法。您应该花一些时间阅读文档。在 Windows cmd 外壳中:

perl -p -e "$i=0 if/glEnd/;s/^/    / if $i;$i=1 if /glBegin/" < infile.c > outfile.c

在 bash 中,将双引号替换为单引号。

于 2013-08-24T03:06:47.497 回答