Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e644fc2

Browse files
committed
Prevent indenting of 'extern "C"' blocks.
1 parent a69833c commit e644fc2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/tools/pgindent/pgindent

+34
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,37 @@ do
6161
if (NR >= 1)
6262
print line1;
6363
}' |
64+
# prevent indenting of code in 'extern "C"' blocks
65+
awk ' BEGIN {line1 = ""; line2 = ""; skips = 0}
66+
{
67+
line2 = $0;
68+
if (skips > 0)
69+
skips--;
70+
if (line1 ~ "^extern[ ]*\"C\"" &&
71+
line2 ~ "^{[ ]*$")
72+
{
73+
# don't print first line
74+
print "/* Open extern \"C\" */";
75+
line2 = "";
76+
skips = 2;
77+
}
78+
else if (line1 ~ "^#ifdef[ ]*__cplusplus" &&
79+
line2 ~ "^}[ ]*$")
80+
{
81+
print line1;
82+
print "/* Close extern \"C\" */";
83+
line2 = "";
84+
skips = 2;
85+
}
86+
else
87+
if (skips == 0 && NR >= 2)
88+
print line1;
89+
line1 = line2;
90+
}
91+
END {
92+
if (NR >= 1 && skips <= 1)
93+
print line1;
94+
}' |
6495
# protect backslashes in DATA()
6596
sed 's;^DATA(.*$;/*&*/;' |
6697
# protect wrapping in CATALOG()
@@ -1456,6 +1487,9 @@ do
14561487
cat /tmp/$$a |
14571488
sed 's;^/\*\(DATA(.*\)\*/$;\1;' |
14581489
sed 's;^/\*\(CATALOG(.*\)\*/$;\1;' |
1490+
sed 's;^/\* Open extern \"C\" \*/$;extern "C"\
1491+
{;' |
1492+
sed 's;^/\* Close extern \"C\" \*/$;};' |
14591493
# remove tabs and retab with four spaces
14601494
detab -t8 -qc |
14611495
entab -t4 -qc |

0 commit comments

Comments
 (0)