summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian2001-09-07 21:25:44 +0000
committerBruce Momjian2001-09-07 21:25:44 +0000
commit3fb36784091e52ff59f1f1a74410c2705801ff64 (patch)
treeaafb2525664acfa691a28f08bbb443218b8e0cda
parent17c03b30b0f191e62e992dc6af8c995fd2b007a2 (diff)
Create pgjindent for java.
-rw-r--r--src/tools/pgindent/README6
-rwxr-xr-xsrc/tools/pgindent/pgindent7
-rwxr-xr-xsrc/tools/pgindent/pgjindent27
3 files changed, 37 insertions, 3 deletions
diff --git a/src/tools/pgindent/README b/src/tools/pgindent/README
index 5a5f4e1a776..18fe4b27ee7 100644
--- a/src/tools/pgindent/README
+++ b/src/tools/pgindent/README
@@ -30,3 +30,9 @@ We get the list of typedef's included in pgindent by running:
Make sure to do the pgsql/bin directory, and the src/interfaces/odbc
directory. Merge the output of these and remove duplicates.
+---------------------------------------------------------------------------
+
+For java, we use astyle, http://astyle.sourceforge.net/, with the
+following options:
+
+ find . -name '*.java' -type f -print | xargs -n100 pgjindent
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index f316781e332..72c4ecc9171 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -24,7 +24,7 @@ fi
for FILE
do
- cat $FILE |
+ cat "$FILE" |
# convert // comments to /* */
sed 's;^\([ ]*\)//\(.*\)$;\1/* \2 */;g' |
# mark some comments for special treatment later
@@ -1319,7 +1319,7 @@ int pgindent_func_no_var_fix;\
# add space after comments that start on tab stops
sed 's,;\(/\*.*\*/\)$,; \1,' |
# work around #else indenting next line if #ifdef defines variables at top
-# work around case misindenting function has no variables defined
+# work around misindenting of function with no variables defined
awk '
{
if ($0 ~ "^[ ]*int[ ]*pgindent_func_no_var_fix;")
@@ -1329,6 +1329,7 @@ int pgindent_func_no_var_fix;\
}
else print $0;
}' |
+# remove tabs and retab with four spaces
detab -t8 -qc |
entab -t4 -qc |
# move trailing * in function return type
@@ -1459,7 +1460,7 @@ int pgindent_func_no_var_fix;\
}
else print $0;
}' |
- cat >/tmp/$$ && cat /tmp/$$ >$FILE
+ cat >/tmp/$$ && cat /tmp/$$ >"$FILE"
done
# The 'for' loop makes these backup files useless so delete them
diff --git a/src/tools/pgindent/pgjindent b/src/tools/pgindent/pgjindent
new file mode 100755
index 00000000000..40cbf3d9039
--- /dev/null
+++ b/src/tools/pgindent/pgjindent
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+trap "rm -f /tmp/$$ /tmp/$$a" 0 1 2 3 15
+entab </dev/null >/dev/null
+if [ "$?" -ne 0 ]
+then echo "Go to the src/tools/entab directory and do a 'make' and 'make install'." >&2
+ echo "This will put the 'entab' command in your path." >&2
+ echo "Then run $0 again."
+ exit 1
+fi
+astyle --version </dev/null >/dev/null 2>&1
+if [ "$?" -eq 0 ]
+then echo "You do not appear to have 'astyle' installed on your system." >&2
+ exit 1
+fi
+
+for FILE
+do
+ astyle --style=java -b -p -j < "$FILE" >/tmp/$$ 2>/tmp/$$a
+ if [ "$?" -ne 0 -o -s /tmp/$$a ]
+ then echo "$FILE"
+ cat /tmp/$$a
+ fi
+ cat /tmp/$$ |
+ entab -t4 -qc |
+ cat >/tmp/$$a && cat /tmp/$$a >"$FILE"
+done