11#! /bin/sh
22
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 $
44
55# Known bugs:
66#
4747sed' s;\([} ]\)else[ ]*\(/\*.*[^\*][^/]\)$;\1else\
4848 \2;g' |
4949detab -t4 -qc|
50+
5051# work around bug where function that defines no local variables misindents
5152# switch() case lines and line after #else. Do not do for struct/enum.
5253awk' BEGIN{line1 = ""; line2 = ""}
6970if (NR >= 1)
7071print line1;
7172}' |
73+
7274# prevent indenting of code in 'extern "C"' blocks
7375awk' BEGIN{line1 = ""; line2 = ""; skips = 0}
7476{
103105if (NR >= 1 && skips <= 1)
104106print line1;
105107}' |
108+
106109# protect backslashes in DATA()
107110sed' s;^DATA(.*$;/*&*/;' |
111+
108112# protect wrapping in CATALOG()
109113sed' s;^CATALOG(.*$;/*&*/;' > /tmp/$$ a
110114
@@ -1878,30 +1882,37 @@ do
18781882-Tz_stream \
18791883-Tz_streamp \
18801884/tmp/$$ a> /tmp/$$ 2>&1
1885+
18811886if [" $? " -ne 0-o -s /tmp/$$ ]
18821887then echo
18831888echo " $FILE "
18841889cat /tmp/$$
18851890fi
18861891cat /tmp/$$ a|
1892+
18871893# restore DATA/CATALOG lines
18881894sed' s;^/\*\(DATA(.*\)\*/$;\1;' |
18891895sed' s;^/\*\(CATALOG(.*\)\*/$;\1;' |
1896+
18901897# remove tabs and retab with four spaces
18911898detab -t8 -qc|
18921899entab -t4 -qc|
18931900sed' s;^/\* Open extern \"C\" \*/$;{;' |
18941901sed' s;^/\* Close extern \"C\" \*/$;};' |
18951902sed' s;/\*---X_X;/* ---;g' |
1903+
18961904# workaround indent bug for 'static'
18971905sed' s;^static[ ][ ]*;static ;g' |
1906+
18981907# remove too much indenting after closing brace
18991908sed' s;^}[ ]*;};' |
1909+
19001910# indent single-line after-'else' comment by only one tab
19011911sed' s;\([} ]\)else[ ]*\(/\*.*\*/\)[ ]*$;\1else\2;g' |
1912+
19021913# pull in #endif comments
19031914sed' s;^#endif[ ][ ]*/\*;#endif /*;' |
1904- # work around #else indenting next line if #ifdef defines variables at top
1915+
19051916# work around misindenting of function with no variables defined
19061917awk'
19071918{
@@ -1912,10 +1923,13 @@ do
19121923}
19131924else print $0;
19141925}' |
1926+
19151927# add space after comments that start on tab stops
19161928sed' s;\([^ ]\)\(/\*.*\*/\)$;\1\2;' |
1929+
19171930# move trailing * in function return type
19181931sed' s;^\([A-Za-z_][^ ]*\)[ ][ ]*\*$;\1 *;' |
1932+
19191933# remove un-needed braces around single statements
19201934# Do not use because it uglifies PG_TRY/PG_CATCH blocks and probably
19211935# isn't needed for general use.
19451959# if (NR >= 1 && skips <= 2)
19461960# print line2;
19471961# }' |
1962+
19481963# remove blank line between opening brace and block comment
19491964awk'
19501965{
19731988if (NR >= 1 && skips <= 2)
19741989print line2;
19751990}' |
1991+
19761992# remove trailing blank lines, helps with adding blank before trailing #endif
19771993awk' BEGIN{blank_lines = 0;}
19781994{
19862002print line1;
19872003}
19882004}' |
2005+
19892006# remove blank line before #else, #elif, and #endif
19902007awk' BEGIN{line1 = ""; line2 = ""; skips = 0}
19912008{
20102027if (NR >= 1 && skips <= 1)
20112028print line1;
20122029}' |
2030+
20132031# add blank line before #endif if it is the last line in the file
20142032awk' BEGIN{line1 = ""; line2 = ""}
20152033{
20232041printf "\n";
20242042print line1;
20252043}' |
2044+
20262045# Move prototype names to the same line as return type. Useful for ctags.
20272046# Indent should do this, but it does not. It formats prototypes just
20282047# like real functions.
20662085}
20672086elseprint $0;
20682087}' |
2088+
20692089# fix indenting of typedef caused by __cplusplus in libpq-fe.h
20702090(
20712091if echo " $FILE " | grep -q' libpq-fe.h$'