diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index 05f69ef..08dde0c 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -13,13 +13,32 @@
 #
 #	void x(struct xxc * a);
 
-if [ "$#" -lt 2 ]
-then	echo "Usage:  $(basename $0) typedefs file [...]" 1>&2
-	exit 1
+# look for typedefs in the first argument, if there is a second argument and
+# the first argument contains the string 'typedef' in its name, or in the
+# environment setting PGTYPEDEFS, or in a hardcoded location, whichever
+# matches first.
+
+
+if [ $# -gt 1 ]
+then
+	case `basenname $0` in
+		*typedef*) 
+			TYPDEFS=$1
+			shift
+			;;
+		*)
+			;;
+	esac
 fi
 
-TYPEDEFS="$1"
-shift
+test -z "$TYPEDEFS" && TYPEDEFS=$PGTYPEDEFS
+test -z "$TYPEDEFS" && TYPEDEFS=/usr/local/etc/pgtypedefs.list
+
+if [ ! -f "$TYPEDEFS" ]
+then
+	echo "Cannot find typedefs file '$TYPEDEFS'"
+	exit 1
+fi 
 
 if [ -z "$INDENT" ]
 then
