1
1
#! /bin/sh
2
2
3
- # $PostgreSQL: pgsql/src/tools/pgindent/pgindent,v 1.90 2006/12/27 23:03:52 momjian Exp $
3
+ # $PostgreSQL: pgsql/src/tools/pgindent/pgindent,v 1.91 2007/11/15 21:52:39 momjian Exp $
4
4
5
5
# Known bugs:
6
6
#
47
47
sed ' s;\([} ]\)else[ ]*\(/\*.*[^\*][^/]\)$;\1else\
48
48
\2;g' |
49
49
detab -t4 -qc |
50
+
50
51
# work around bug where function that defines no local variables misindents
51
52
# switch() case lines and line after #else. Do not do for struct/enum.
52
53
awk ' BEGIN {line1 = ""; line2 = ""}
69
70
if (NR >= 1)
70
71
print line1;
71
72
}' |
73
+
72
74
# prevent indenting of code in 'extern "C"' blocks
73
75
awk ' BEGIN {line1 = ""; line2 = ""; skips = 0}
74
76
{
103
105
if (NR >= 1 && skips <= 1)
104
106
print line1;
105
107
}' |
108
+
106
109
# protect backslashes in DATA()
107
110
sed ' s;^DATA(.*$;/*&*/;' |
111
+
108
112
# protect wrapping in CATALOG()
109
113
sed ' s;^CATALOG(.*$;/*&*/;' > /tmp/$$ a
110
114
@@ -1878,30 +1882,37 @@ do
1878
1882
-Tz_stream \
1879
1883
-Tz_streamp \
1880
1884
/tmp/$$ a > /tmp/$$ 2>&1
1885
+
1881
1886
if [ " $? " -ne 0 -o -s /tmp/$$ ]
1882
1887
then echo
1883
1888
echo " $FILE "
1884
1889
cat /tmp/$$
1885
1890
fi
1886
1891
cat /tmp/$$ a |
1892
+
1887
1893
# restore DATA/CATALOG lines
1888
1894
sed ' s;^/\*\(DATA(.*\)\*/$;\1;' |
1889
1895
sed ' s;^/\*\(CATALOG(.*\)\*/$;\1;' |
1896
+
1890
1897
# remove tabs and retab with four spaces
1891
1898
detab -t8 -qc |
1892
1899
entab -t4 -qc |
1893
1900
sed ' s;^/\* Open extern \"C\" \*/$;{;' |
1894
1901
sed ' s;^/\* Close extern \"C\" \*/$;};' |
1895
1902
sed ' s;/\*---X_X;/* ---;g' |
1903
+
1896
1904
# workaround indent bug for 'static'
1897
1905
sed ' s;^static[ ][ ]*;static ;g' |
1906
+
1898
1907
# remove too much indenting after closing brace
1899
1908
sed ' s;^} [ ]*;} ;' |
1909
+
1900
1910
# indent single-line after-'else' comment by only one tab
1901
1911
sed ' s;\([} ]\)else[ ]*\(/\*.*\*/\)[ ]*$;\1else \2;g' |
1912
+
1902
1913
# pull in #endif comments
1903
1914
sed ' s;^#endif[ ][ ]*/\*;#endif /*;' |
1904
- # work around #else indenting next line if #ifdef defines variables at top
1915
+
1905
1916
# work around misindenting of function with no variables defined
1906
1917
awk '
1907
1918
{
@@ -1912,10 +1923,13 @@ do
1912
1923
}
1913
1924
else print $0;
1914
1925
}' |
1926
+
1915
1927
# add space after comments that start on tab stops
1916
1928
sed ' s;\([^ ]\)\(/\*.*\*/\)$;\1 \2;' |
1929
+
1917
1930
# move trailing * in function return type
1918
1931
sed ' s;^\([A-Za-z_][^ ]*\)[ ][ ]*\*$;\1 *;' |
1932
+
1919
1933
# remove un-needed braces around single statements
1920
1934
# Do not use because it uglifies PG_TRY/PG_CATCH blocks and probably
1921
1935
# isn't needed for general use.
1945
1959
# if (NR >= 1 && skips <= 2)
1946
1960
# print line2;
1947
1961
# }' |
1962
+
1948
1963
# remove blank line between opening brace and block comment
1949
1964
awk '
1950
1965
{
1973
1988
if (NR >= 1 && skips <= 2)
1974
1989
print line2;
1975
1990
}' |
1991
+
1976
1992
# remove trailing blank lines, helps with adding blank before trailing #endif
1977
1993
awk ' BEGIN {blank_lines = 0;}
1978
1994
{
1986
2002
print line1;
1987
2003
}
1988
2004
}' |
2005
+
1989
2006
# remove blank line before #else, #elif, and #endif
1990
2007
awk ' BEGIN {line1 = ""; line2 = ""; skips = 0}
1991
2008
{
2010
2027
if (NR >= 1 && skips <= 1)
2011
2028
print line1;
2012
2029
}' |
2030
+
2013
2031
# add blank line before #endif if it is the last line in the file
2014
2032
awk ' BEGIN {line1 = ""; line2 = ""}
2015
2033
{
2023
2041
printf "\n";
2024
2042
print line1;
2025
2043
}' |
2044
+
2026
2045
# Move prototype names to the same line as return type. Useful for ctags.
2027
2046
# Indent should do this, but it does not. It formats prototypes just
2028
2047
# like real functions.
2066
2085
}
2067
2086
else print $0;
2068
2087
}' |
2088
+
2069
2089
# fix indenting of typedef caused by __cplusplus in libpq-fe.h
2070
2090
(
2071
2091
if echo " $FILE " | grep -q ' libpq-fe.h$'
0 commit comments