diff --git a/contrib/Makefile b/contrib/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..f74678b184cae6eec4be3f769291463a2d0fd17a
--- /dev/null
+++ b/contrib/Makefile
@@ -0,0 +1,45 @@
+# Makefile for contrib code
+#
+# The following subdirs don't have a Makefile:
+#
+#   apache_logging
+#   linux
+#   mSQL-interface
+#   noupdate
+#   unixdate
+#
+# The following subdirs give make errors:
+#
+#   earthdistance
+#   findoidjoins
+#   isbn_issn
+#   os2client
+#   pginterface
+
+all:	
+	for dir in *; do \
+	    if [ -e $$dir/Makefile ]; then \
+		$(MAKE) -C $$dir; \
+	    fi; \
+	done
+
+install:	
+	for dir in *; do \
+	    if [ -e $$dir/Makefile ]; then \
+		$(MAKE) -C $$dir $@ ; \
+	    fi; \
+	done
+
+clean:	
+	for dir in *; do \
+	    if [ -e $$dir/Makefile ]; then \
+		$(MAKE) -C $$dir $@ ; \
+	    fi; \
+	done || exit 0
+
+distclean:
+	for dir in *; do \
+	    if [ -e $$dir/Makefile ]; then \
+		$(MAKE) -C $$dir $@ ; \
+	    fi; \
+	done || exit 0
diff --git a/contrib/array/Makefile b/contrib/array/Makefile
index 9459f9c9bc3042e88d48e0e8e4bf53729c69ae72..5607b4e537032a2f06858bd98326b0aa5390e793 100644
--- a/contrib/array/Makefile
+++ b/contrib/array/Makefile
@@ -1,7 +1,8 @@
 #-------------------------------------------------------------------------
 #
-# Makefile--
-#    Makefile for array iterator functions.
+# Makefile --
+#
+#    Makefile for array iterator module.
 #
 #-------------------------------------------------------------------------
 
@@ -19,6 +20,8 @@ CFLAGS += $(INCLUDE_OPT) $(CFLAGS_SL)
 
 MODNAME =	array_iterator
 
+SQLDEFS =	$(MODNAME).sql
+
 MODULE =	$(MODNAME)$(DLSUFFIX)
 
 MODDIR =	$(LIBDIR)/modules
@@ -29,12 +32,12 @@ all:		module sql
 
 module:		$(MODULE)
 
-sql:		$(MODNAME).sql
+sql:		$(SQLDEFS)
 
-install:	$(MODULE) $(MODDIR) $(SQLDIR)
+install:	$(MODULE) $(SQLDEFS) $(MODDIR) $(SQLDIR)
 		cp -p $(MODULE) $(MODDIR)/
 		strip $(MODDIR)/$(MODULE)
-		cp -p $(MODNAME).sql $(SQLDIR)/
+		cp -p $(SQLDEFS) $(SQLDIR)/
 
 $(MODDIR):
 		mkdir -p $@
diff --git a/contrib/array/array_iterator.c b/contrib/array/array_iterator.c
index 1561c1b192b262086e2443d038a8f47e7cff32c9..27902e585f852b91365c4dc849152af57ee2bba9 100644
--- a/contrib/array/array_iterator.c
+++ b/contrib/array/array_iterator.c
@@ -141,7 +141,7 @@ array_texteq(ArrayType *array, char *value)
 {
 	return array_iterator((Oid) 25,		/* text */
 						  (Oid) 67,		/* texteq */
-						  0,	/* logical or */
+						  0,			/* logical or */
 						  array, (Datum) value);
 }
 
@@ -150,7 +150,7 @@ array_all_texteq(ArrayType *array, char *value)
 {
 	return array_iterator((Oid) 25,		/* text */
 						  (Oid) 67,		/* texteq */
-						  1,	/* logical and */
+						  1,			/* logical and */
 						  array, (Datum) value);
 }
 
@@ -159,7 +159,7 @@ array_textregexeq(ArrayType *array, char *value)
 {
 	return array_iterator((Oid) 25,		/* text */
 						  (Oid) 1254,	/* textregexeq */
-						  0,	/* logical or */
+						  0,			/* logical or */
 						  array, (Datum) value);
 }
 
@@ -168,48 +168,89 @@ array_all_textregexeq(ArrayType *array, char *value)
 {
 	return array_iterator((Oid) 25,		/* text */
 						  (Oid) 1254,	/* textregexeq */
-						  1,	/* logical and */
+						  1,			/* logical and */
 						  array, (Datum) value);
 }
 
 /*
- * Iterator functions for type _char16. Note that the regexp
+ * Iterator functions for type _varchar. Note that the regexp
  * operators take the second argument of type text.
  */
 
 int32
-array_char16eq(ArrayType *array, char *value)
+array_varchareq(ArrayType *array, char *value)
 {
-	return array_iterator((Oid) 20,		/* char16 */
-						  (Oid) 1275,	/* char16eq */
-						  0,	/* logical or */
+	return array_iterator((Oid) 20,		/* varchar */
+						  (Oid) 1070,	/* varchareq */
+						  0,			/* logical or */
 						  array, (Datum) value);
 }
 
 int32
-array_all_char16eq(ArrayType *array, char *value)
+array_all_varchareq(ArrayType *array, char *value)
 {
-	return array_iterator((Oid) 20,		/* char16 */
-						  (Oid) 1275,	/* char16eq */
-						  1,	/* logical and */
+	return array_iterator((Oid) 20,		/* varchar */
+						  (Oid) 1070,	/* varchareq */
+						  1,			/* logical and */
 						  array, (Datum) value);
 }
 
 int32
-array_char16regexeq(ArrayType *array, char *value)
+array_varcharregexeq(ArrayType *array, char *value)
 {
-	return array_iterator((Oid) 20,		/* char16 */
-						  (Oid) 1288,	/* char16regexeq */
-						  0,	/* logical or */
+	return array_iterator((Oid) 20,		/* varchar */
+						  (Oid) 1254,	/* textregexeq */
+						  0,			/* logical or */
+						  array, (Datum) value);
+}
+
+int32
+array_all_varcharregexeq(ArrayType *array, char *value)
+{
+	return array_iterator((Oid) 20,		/* varchar */
+						  (Oid) 1254,	/* textregexeq */
+						  1,			/* logical and */
+						  array, (Datum) value);
+}
+
+/*
+ * Iterator functions for type _bpchar. Note that the regexp
+ * operators take the second argument of type text.
+ */
+
+int32
+array_bpchareq(ArrayType *array, char *value)
+{
+	return array_iterator((Oid) 20,		/* bpchar */
+						  (Oid) 1048,	/* bpchareq */
+						  0,			/* logical or */
+						  array, (Datum) value);
+}
+
+int32
+array_all_bpchareq(ArrayType *array, char *value)
+{
+	return array_iterator((Oid) 20,		/* bpchar */
+						  (Oid) 1048,	/* bpchareq */
+						  1,			/* logical and */
+						  array, (Datum) value);
+}
+
+int32
+array_bpcharregexeq(ArrayType *array, char *value)
+{
+	return array_iterator((Oid) 20,		/* bpchar */
+						  (Oid) 1254,	/* textregexeq */
+						  0,			/* logical or */
 						  array, (Datum) value);
 }
 
 int32
-array_all_char16regexeq(ArrayType *array, char *value)
+array_all_bpcharregexeq(ArrayType *array, char *value)
 {
-	return array_iterator((Oid) 20,		/* char16 */
-						  (Oid) 1288,	/* char16regexeq */
-						  1,	/* logical and */
+	return array_iterator((Oid) 20,		/* bpchar */
+						  (Oid) 1254,	/* textregexeq */
+						  1,			/* logical and */
 						  array, (Datum) value);
 }
 
@@ -222,7 +263,7 @@ array_int4eq(ArrayType *array, int4 value)
 {
 	return array_iterator((Oid) 23,		/* int4 */
 						  (Oid) 65,		/* int4eq */
-						  0,	/* logical or */
+						  0,			/* logical or */
 						  array, (Datum) value);
 }
 
@@ -231,7 +272,7 @@ array_all_int4eq(ArrayType *array, int4 value)
 {
 	return array_iterator((Oid) 23,		/* int4 */
 						  (Oid) 65,		/* int4eq */
-						  1,	/* logical and */
+						  1,			/* logical and */
 						  array, (Datum) value);
 }
 
@@ -240,7 +281,7 @@ array_int4ne(ArrayType *array, int4 value)
 {
 	return array_iterator((Oid) 23,		/* int4 */
 						  (Oid) 144,	/* int4ne */
-						  0,	/* logical or */
+						  0,			/* logical or */
 						  array, (Datum) value);
 }
 
@@ -249,7 +290,7 @@ array_all_int4ne(ArrayType *array, int4 value)
 {
 	return array_iterator((Oid) 23,		/* int4 */
 						  (Oid) 144,	/* int4ne */
-						  1,	/* logical and */
+						  1,			/* logical and */
 						  array, (Datum) value);
 }
 
@@ -258,7 +299,7 @@ array_int4gt(ArrayType *array, int4 value)
 {
 	return array_iterator((Oid) 23,		/* int4 */
 						  (Oid) 147,	/* int4gt */
-						  0,	/* logical or */
+						  0,			/* logical or */
 						  array, (Datum) value);
 }
 
@@ -267,7 +308,7 @@ array_all_int4gt(ArrayType *array, int4 value)
 {
 	return array_iterator((Oid) 23,		/* int4 */
 						  (Oid) 147,	/* int4gt */
-						  1,	/* logical and */
+						  1,			/* logical and */
 						  array, (Datum) value);
 }
 
@@ -276,7 +317,7 @@ array_int4ge(ArrayType *array, int4 value)
 {
 	return array_iterator((Oid) 23,		/* int4 */
 						  (Oid) 150,	/* int4ge */
-						  0,	/* logical or */
+						  0,			/* logical or */
 						  array, (Datum) value);
 }
 
@@ -285,7 +326,7 @@ array_all_int4ge(ArrayType *array, int4 value)
 {
 	return array_iterator((Oid) 23,		/* int4 */
 						  (Oid) 150,	/* int4ge */
-						  1,	/* logical and */
+						  1,			/* logical and */
 						  array, (Datum) value);
 }
 
@@ -294,7 +335,7 @@ array_int4lt(ArrayType *array, int4 value)
 {
 	return array_iterator((Oid) 23,		/* int4 */
 						  (Oid) 66,		/* int4lt */
-						  0,	/* logical or */
+						  0,			/* logical or */
 						  array, (Datum) value);
 }
 
@@ -303,7 +344,7 @@ array_all_int4lt(ArrayType *array, int4 value)
 {
 	return array_iterator((Oid) 23,		/* int4 */
 						  (Oid) 66,		/* int4lt */
-						  1,	/* logical and */
+						  1,			/* logical and */
 						  array, (Datum) value);
 }
 
@@ -312,7 +353,7 @@ array_int4le(ArrayType *array, int4 value)
 {
 	return array_iterator((Oid) 23,		/* int4 */
 						  (Oid) 149,	/* int4le */
-						  0,	/* logical or */
+						  0,			/* logical or */
 						  array, (Datum) value);
 }
 
@@ -321,19 +362,18 @@ array_all_int4le(ArrayType *array, int4 value)
 {
 	return array_iterator((Oid) 23,		/* int4 */
 						  (Oid) 149,	/* int4le */
-						  1,	/* logical and */
+						  1,			/* logical and */
 						  array, (Datum) value);
 }
 
 /* new tobias gabele 1999 */
 
-
 int32
 array_oideq(ArrayType *array, Oid value)
 {
 	return array_iterator((Oid) 26,		/* oid */
 						  (Oid) 184,	/* oideq */
-						  0,	/* logical or */
+						  0,			/* logical or */
 						  array, (Datum) value);
 }
 
@@ -342,14 +382,16 @@ array_all_oidne(ArrayType *array, Oid value)
 {
 	return array_iterator((Oid) 26,		/* int4 */
 						  (Oid) 185,	/* oidne */
-						  1,	/* logical and */
+						  1,			/* logical and */
 						  array, (Datum) value);
 }
 
-
-
-
-
-
-
 /* end of file */
+
+/*
+ * Local Variables:
+ *  tab-width: 4
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
diff --git a/contrib/array/array_iterator.h b/contrib/array/array_iterator.h
index 6e84088487902e8d327f6f430633aa5fd8156f89..9a386abd2c7959dea151a0e2cfcb8408f56cbc5f 100644
--- a/contrib/array/array_iterator.h
+++ b/contrib/array/array_iterator.h
@@ -2,15 +2,23 @@
 #define ARRAY_ITERATOR_H
 
 static int32 array_iterator(Oid elemtype, Oid proc, int and,
-			   ArrayType *array, Datum value);
+							ArrayType *array, Datum value);
+
 int32		array_texteq(ArrayType *array, char *value);
 int32		array_all_texteq(ArrayType *array, char *value);
 int32		array_textregexeq(ArrayType *array, char *value);
 int32		array_all_textregexeq(ArrayType *array, char *value);
-int32		array_char16eq(ArrayType *array, char *value);
-int32		array_all_char16eq(ArrayType *array, char *value);
-int32		array_char16regexeq(ArrayType *array, char *value);
-int32		array_all_char16regexeq(ArrayType *array, char *value);
+
+int32		array_varchareq(ArrayType *array, char *value);
+int32		array_all_varchareq(ArrayType *array, char *value);
+int32		array_varcharregexeq(ArrayType *array, char *value);
+int32		array_all_varcharregexeq(ArrayType *array, char *value);
+
+int32		array_bpchareq(ArrayType *array, char *value);
+int32		array_all_bpchareq(ArrayType *array, char *value);
+int32		array_bpcharregexeq(ArrayType *array, char *value);
+int32		array_all_bpcharregexeq(ArrayType *array, char *value);
+
 int32		array_int4eq(ArrayType *array, int4 value);
 int32		array_all_int4eq(ArrayType *array, int4 value);
 int32		array_int4ne(ArrayType *array, int4 value);
@@ -23,7 +31,15 @@ int32		array_int4lt(ArrayType *array, int4 value);
 int32		array_all_int4lt(ArrayType *array, int4 value);
 int32		array_int4le(ArrayType *array, int4 value);
 int32		array_all_int4le(ArrayType *array, int4 value);
-int32		array_oideq(ArrayType *array, Oid value);
-int32		array_all_oidne(ArrayType *array, Oid value);
 
+int32       array_oideq(ArrayType *array, Oid value);
+int32       array_all_oidne(ArrayType *array, Oid value);
 #endif
+
+/*
+ * Local Variables:
+ *  tab-width: 4
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
diff --git a/contrib/array/array_iterator.sql.in b/contrib/array/array_iterator.sql.in
index cc95c8aea7b67ecb97d3ae2d9622a478f0e8895b..d4182b112e2bb0c80254f3887b64881929a962ca 100644
--- a/contrib/array/array_iterator.sql.in
+++ b/contrib/array/array_iterator.sql.in
@@ -39,43 +39,84 @@ create operator **~ (
   procedure=array_all_textregexeq);
 
 
--- define the array operators *=, **=, *~ and **~ for type _char16
+-- define the array operators *=, **=, *~ and **~ for type _varchar
 --
-create function array_char16eq(_char16, char16) returns bool
+-- NOTE: "varchar" is also a reserved word and must be quoted.
+--
+create function array_varchareq(_varchar, varchar) returns bool
   as 'MODULE_PATHNAME' 
   language 'c';
 
-create function array_all_char16eq(_char16, char16) returns bool
+create function array_all_varchareq(_varchar, varchar) returns bool
   as 'MODULE_PATHNAME' 
   language 'c';
 
-create function array_char16regexeq(_char16, text) returns bool
+create function array_varcharregexeq(_varchar, varchar) returns bool
   as 'MODULE_PATHNAME' 
   language 'c';
 
-create function array_all_char16regexeq(_char16, text) returns bool
+create function array_all_varcharregexeq(_varchar, varchar) returns bool
   as 'MODULE_PATHNAME' 
   language 'c';
 
 create operator *= (
-  leftarg=_char16,
-  rightarg=char16,
-  procedure=array_char16eq);
+  leftarg=_varchar, 
+  rightarg="varchar", 
+  procedure=array_varchareq);
 
 create operator **= (
-  leftarg=_char16,
-  rightarg=char16,
-  procedure=array_all_char16eq);
+  leftarg=_varchar,
+  rightarg="varchar",
+  procedure=array_all_varchareq);
 
 create operator *~ (
-  leftarg=_char16,
-  rightarg=text,
-  procedure=array_char16regexeq);
+  leftarg=_varchar,
+  rightarg="varchar",
+  procedure=array_varcharregexeq);
 
 create operator **~ (
-  leftarg=_char16,
-  rightarg=text,
-  procedure=array_all_char16regexeq);
+  leftarg=_varchar,
+  rightarg="varchar",
+  procedure=array_all_varcharregexeq);
+
+
+-- define the array operators *=, **=, *~ and **~ for type _bpchar
+--
+create function array_bpchareq(_bpchar, bpchar) returns bool
+  as 'MODULE_PATHNAME' 
+  language 'c';
+
+create function array_all_bpchareq(_bpchar, bpchar) returns bool
+  as 'MODULE_PATHNAME' 
+  language 'c';
+
+create function array_bpcharregexeq(_bpchar, bpchar) returns bool
+  as 'MODULE_PATHNAME' 
+  language 'c';
+
+create function array_all_bpcharregexeq(_bpchar, bpchar) returns bool
+  as 'MODULE_PATHNAME' 
+  language 'c';
+
+create operator *= (
+  leftarg=_bpchar, 
+  rightarg=bpchar, 
+  procedure=array_bpchareq);
+
+create operator **= (
+  leftarg=_bpchar,
+  rightarg=bpchar,
+  procedure=array_all_bpchareq);
+
+create operator *~ (
+  leftarg=_bpchar,
+  rightarg=bpchar,
+  procedure=array_bpcharregexeq);
+
+create operator **~ (
+  leftarg=_bpchar,
+  rightarg=bpchar,
+  procedure=array_all_bpcharregexeq);
 
 
 -- define the array operators *=, **=, *> and **> for type _int4
@@ -209,5 +250,4 @@ create operator **<> (
   procedure=array_all_oidne);
 
 
-
 -- end of file
diff --git a/contrib/datetime/Makefile b/contrib/datetime/Makefile
index 6754bce24f189fae5a140783fac8b89c5e3f0816..5a575d07eb4bf36d660eef30325d9cbd1c3e4b51 100644
--- a/contrib/datetime/Makefile
+++ b/contrib/datetime/Makefile
@@ -1,7 +1,8 @@
 #-------------------------------------------------------------------------
 #
-# Makefile--
-#    Makefile for new date/time functions.
+# Makefile --
+#
+#    Makefile for new datetime module.
 #
 #-------------------------------------------------------------------------
 
@@ -19,6 +20,8 @@ CFLAGS += $(INCLUDE_OPT) $(CFLAGS_SL)
 
 MODNAME =	datetime_functions
 
+SQLDEFS =	$(MODNAME).sql
+
 MODULE =	$(MODNAME)$(DLSUFFIX)
 
 MODDIR =	$(LIBDIR)/modules
@@ -29,12 +32,12 @@ all:		module sql
 
 module:		$(MODULE)
 
-sql:		$(MODNAME).sql
+sql:		$(SQLDEFS)
 
-install:	$(MODULE) $(MODDIR) $(SQLDIR)
+install:	$(MODULE) $(SQLDEFS) $(MODDIR) $(SQLDIR)
 		cp -p $(MODULE) $(MODDIR)/
 		strip $(MODDIR)/$(MODULE)
-		cp -p $(MODNAME).sql $(SQLDIR)/
+		cp -p $(SQLDEFS) $(SQLDIR)/
 
 $(MODDIR):
 		mkdir -p $@
diff --git a/contrib/datetime/datetime_functions.c b/contrib/datetime/datetime_functions.c
index 9dd0828457c0cca0ecb48dbc5e91bc94adef114f..54995220042434b6a07e33a5331c56c5ea577c2f 100644
--- a/contrib/datetime/datetime_functions.c
+++ b/contrib/datetime/datetime_functions.c
@@ -28,10 +28,61 @@
 /* Constant to replace calls to date2j(2000,1,1) */
 #define JDATE_2000	2451545
 
+/*
+ * decode_24h_time()
+ *
+ * Decode time string 00:00:00 through 24:00:00.
+ */
+static int
+decode_24h_time(char *str, struct tm *tm, double *fsec)
+{
+	char	   *cp;
+
+	tm->tm_hour = strtol(str, &cp, 10);
+	if (*cp != ':')
+		return -1;
+	str = cp + 1;
+	tm->tm_min = strtol(str, &cp, 10);
+	if (*cp == '\0')
+	{
+		tm->tm_sec = 0;
+		*fsec = 0;
+	}
+	else if (*cp != ':')
+	{
+		return -1;
+	}
+	else
+	{
+		str = cp + 1;
+		tm->tm_sec = strtol(str, &cp, 10);
+		if (*cp == '\0')
+			*fsec = 0;
+		else if (*cp == '.')
+		{
+			str = cp;
+			*fsec = strtod(str, &cp);
+			if (cp == str)
+				return -1;
+		}
+		else
+			return -1;
+	}
+
+	/* do a sanity check */
+	if (   (tm->tm_hour < 0) || (tm->tm_hour > 24)
+		|| (tm->tm_min  < 0) || (tm->tm_min  > 59)
+		|| (tm->tm_sec  < 0) || (tm->tm_sec  > 59)
+		|| (fsec        < 0) )
+		return -1;
+
+	return 0;
+}
+
 /*
  * A modified version of time_in which allows the value 24:00:00 for
  * time and converts it to TimeADT data type forcing seconds to 0.
- * This can be Useful if you need to handle TimeADT values limited
+ * This can be useful if you need to handle TimeADT values limited
  * to hh:mm like in timetables.
  */
 
@@ -44,35 +95,23 @@ hhmm_in(char *str)
 	struct tm	tt,
 			   *tm = &tt;
 
-	int			nf;
-	char		lowstr[MAXDATELEN + 1];
-	char	   *field[MAXDATEFIELDS];
-	int			dtype;
-	int			ftype[MAXDATEFIELDS];
-
 	if (!PointerIsValid(str))
 		elog(ERROR, "Bad (null) time external representation", NULL);
 
-	if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
-		|| (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec) != 0))
+	if (decode_24h_time(str, tm, &fsec) != 0)
 		elog(ERROR, "Bad time external representation '%s'", str);
 
-	if (tm->tm_hour < 0 || tm->tm_hour > 24 ||
-		(tm->tm_hour == 24 && (tm->tm_min != 0 || tm->tm_sec != 0 || fsec != 0)))
+	if ((tm->tm_hour < 0) || (tm->tm_hour > 24)
+		|| ((tm->tm_hour == 24)
+			&& ((tm->tm_min != 0) || (tm->tm_sec != 0) || (fsec != 0.0))))
 	{
 		elog(ERROR,
-			 "time_in: hour must be limited to values 0 through 24:00 "
+			 "Time must be limited to values 00:00:00 through 24:00:00 "
 			 "in \"%s\"",
 			 str);
 	}
-	if ((tm->tm_min < 0) || (tm->tm_min > 59))
-		elog(ERROR, "Minute must be limited to values 0 through 59 in '%s'", str);
-	if ((tm->tm_sec < 0) || ((tm->tm_sec + fsec) >= 60))
-		elog(ERROR, "Second must be limited to values 0 through < 60 in '%s'",
-			 str);
 
 	time = palloc(sizeof(TimeADT));
-
 	*time = ((((tm->tm_hour * 60) + tm->tm_min) * 60));
 
 	return (time);
@@ -224,9 +263,9 @@ currentdate()
 /* end of file */
 
 /*
- * Local variables:
- *	tab-width: 4
- *	c-indent-level: 4
- *	c-basic-offset: 4
+ * Local Variables:
+ *  tab-width: 4
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
  * End:
  */
diff --git a/contrib/datetime/datetime_functions.h b/contrib/datetime/datetime_functions.h
index 3a3de8ec52a04512273dc019c42e271517e4d695..ff2309d16f0543f4e080c282547ce427b492d8e1 100644
--- a/contrib/datetime/datetime_functions.h
+++ b/contrib/datetime/datetime_functions.h
@@ -17,3 +17,11 @@ TimeADT    *currenttime(void);
 DateADT		currentdate(void);
 
 #endif
+
+/*
+ * Local Variables:
+ *  tab-width: 4
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
diff --git a/contrib/datetime/datetime_functions.sql.in b/contrib/datetime/datetime_functions.sql.in
index 83e9eac9d4c0e8df95367a165d2f10b4fb785b82..8c35dad55f5f6c4decaff8e9932fa210a514fb4a 100644
--- a/contrib/datetime/datetime_functions.sql.in
+++ b/contrib/datetime/datetime_functions.sql.in
@@ -79,14 +79,14 @@ create operator - (
 --
 create function hhmm_mode() returns text
   as 'update pg_type set typinput =''hhmm_in''  where typname=''time'';
-      update pg_type set typoutput=''hhmm_out'' where typname=''time''
-      select ''hhmm_mode''::text'
+      update pg_type set typoutput=''hhmm_out'' where typname=''time'';
+      select ''hhmm_mode''::text;'
   language 'sql';
 
 create function time_mode() returns text
   as 'update pg_type set typinput =''time_in''  where typname=''time'';
-      update pg_type set typoutput=''time_out'' where typname=''time''
-      select ''time_mode''::text'
+      update pg_type set typoutput=''time_out'' where typname=''time'';
+      select ''time_mode''::text;'
   language 'sql';
 
 -- Use these to do the updates manually
diff --git a/contrib/miscutil/Makefile b/contrib/miscutil/Makefile
index ecb855e560073a1166c75e2564028c3a4b586434..88372da0f7a33ada550efd64d299fc2c7c79b1dd 100644
--- a/contrib/miscutil/Makefile
+++ b/contrib/miscutil/Makefile
@@ -20,6 +20,8 @@ CFLAGS += $(INCLUDE_OPT) $(CFLAGS_SL)
 
 MODNAME =	misc_utils
 
+SQLDEFS =	$(MODNAME).sql
+
 MODULE =	$(MODNAME)$(DLSUFFIX)
 
 MODDIR =	$(LIBDIR)/modules
@@ -30,12 +32,12 @@ all:		module sql
 
 module:		$(MODULE)
 
-sql:		$(MODNAME).sql
+sql:		$(SQLDEFS)
 
-install:	$(MODULE) $(MODDIR) $(SQLDIR)
+install:	$(MODULE) $(SQLDEFS) $(MODDIR) $(SQLDIR)
 		cp -p $(MODULE) $(MODDIR)/
 		strip $(MODDIR)/$(MODULE)
-		cp -p $(MODNAME).sql $(SQLDIR)/
+		cp -p $(SQLDEFS) $(SQLDIR)/
 
 $(MODDIR):
 		mkdir -p $@
diff --git a/contrib/miscutil/misc_utils.c b/contrib/miscutil/misc_utils.c
index 24d069f71c29bdf5b80172d50383fb96417f42f2..75184439717c37eb42f006a62794a73b3136abee 100644
--- a/contrib/miscutil/misc_utils.c
+++ b/contrib/miscutil/misc_utils.c
@@ -10,12 +10,27 @@
  */
 
 #include <unistd.h>
+#include <signal.h>
+#include <string.h>
+#include <errno.h>
 
 #include "postgres.h"
+#include "access/heapam.h"
+#include "access/htup.h"
+#include "access/relscan.h"
+#include "access/skey.h"
+#include "access/tupdesc.h"
+#include "catalog/catname.h"
+#include "catalog/pg_listener.h"
+#include "storage/lmgr.h"
+#include "utils/fmgr.h"
 #include "utils/palloc.h"
+#include "utils/rel.h"
+#include "utils/tqual.h"
 
 #include "misc_utils.h"
-#include "assert_test.h"
+
+#define MIN(x,y)	((x)<=(y) ? (x) : (y))
 
 extern int	ExecutorLimit(int limit);
 extern void Async_Unlisten(char *relname, int pid);
@@ -23,7 +38,6 @@ extern int	assertTest(int val);
 
 #ifdef ASSERT_CHECKING_TEST
 extern int	assertEnable(int val);
-
 #endif
 
 int
@@ -57,6 +71,62 @@ min(int x, int y)
 	return ((x < y) ? x : y);
 }
 
+/*
+ * Return the number of active listeners on a relation name.
+ */
+int
+active_listeners(text *relname)
+{
+	HeapTuple	lTuple;
+	Relation	lRel;
+	HeapScanDesc sRel;
+	TupleDesc	tdesc;
+	ScanKeyData key;
+	Datum		d;
+	bool		isnull;
+	int			len, pid;
+	int			count = 0;
+	int			ourpid = getpid();
+	char		listen_name[NAMEDATALEN];
+
+	lRel = heap_openr(ListenerRelationName);
+	tdesc = RelationGetDescr(lRel);
+	LockRelation(lRel, AccessShareLock);
+
+	if (relname && (VARSIZE(relname) > VARHDRSZ)) {
+		len = MIN(VARSIZE(relname)-VARHDRSZ, NAMEDATALEN-1);
+		strncpy(listen_name, VARDATA(relname), len);
+		listen_name[len] = '\0';
+		ScanKeyEntryInitialize(&key, 0,
+							   Anum_pg_listener_relname,
+							   F_NAMEEQ,
+							   PointerGetDatum(listen_name));
+		sRel = heap_beginscan(lRel, 0, SnapshotNow, 1, &key);
+	} else {
+		sRel = heap_beginscan(lRel, 0, SnapshotNow, 0, (ScanKey)NULL);
+	}
+
+	while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0)))
+	{
+		d = heap_getattr(lTuple, Anum_pg_listener_pid, tdesc, &isnull);
+		pid = DatumGetInt32(d);
+#ifdef HAVE_KILL
+		if ((pid == ourpid) || (kill(pid, SIGTSTP) == 0)) {
+			/* elog(NOTICE, "%d ok", pid); */
+			count++;
+		}
+#else
+		count++;
+#endif
+	}
+	heap_endscan(sRel);
+
+	UnlockRelation(lRel, AccessShareLock);
+	heap_close(lRel);
+
+	return count;
+}
+
 int
 assert_enable(int val)
 {
@@ -69,15 +139,14 @@ assert_test(int val)
 {
 	return assertTest(val);
 }
-
 #endif
 
 /* end of file */
 
 /*
- * Local variables:
- *	tab-width: 4
- *	c-indent-level: 4
- *	c-basic-offset: 4
+ * Local Variables:
+ *  tab-width: 4
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
  * End:
  */
diff --git a/contrib/miscutil/misc_utils.h b/contrib/miscutil/misc_utils.h
index e82fd4a29d1e5389d8457c392b869a9ec7cbd816..61217244a2d26539781a13eef124f08b85b041ef 100644
--- a/contrib/miscutil/misc_utils.h
+++ b/contrib/miscutil/misc_utils.h
@@ -10,15 +10,15 @@ int			assert_enable(int val);
 
 #ifdef ASSERT_CHECKING_TEST
 int			assert_test(int val);
-
 #endif
 
+int			active_listeners(text *relname);
 #endif
 
 /*
- * Local variables:
- *	tab-width: 4
- *	c-indent-level: 4
- *	c-basic-offset: 4
+ * Local Variables:
+ *  tab-width: 4
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
  * End:
  */
diff --git a/contrib/miscutil/misc_utils.sql.in b/contrib/miscutil/misc_utils.sql.in
index 1185d743e69ed0a26d6ad55299e593b2ef3a7628..a0418898c61f2d9f05b61c76fdf2c5ef1650ac57 100644
--- a/contrib/miscutil/misc_utils.sql.in
+++ b/contrib/miscutil/misc_utils.sql.in
@@ -43,16 +43,22 @@ create function max(int4,int4) returns int4
   as 'MODULE_PATHNAME'
   language 'C';
 
+-- Return the number of active listeners on a relation
+--
+create function active_listeners(text) returns int4
+  as 'MODULE_PATHNAME'
+  language 'C';
+
 -- Enable/disable Postgres assert checking.
 --
 create function assert_enable(int4) returns int4
-	as 'MODULE_PATHNAME'
-	language 'C';
+  as 'MODULE_PATHNAME'
+  language 'C';
 
 -- Test Postgres assert checking.
 --
 -- create function assert_test(int4) returns int4
---	as 'MODULE_PATHNAME'
---	language 'C';
+--   as 'MODULE_PATHNAME'
+--   language 'C';
 
 -- end of file
diff --git a/contrib/string/Makefile b/contrib/string/Makefile
index ea42cfa91b7df08ed1b43091e8af99ac4871846f..879fd2387f97eec1b867fe4e9f5a494a945bc1af 100644
--- a/contrib/string/Makefile
+++ b/contrib/string/Makefile
@@ -1,6 +1,7 @@
 #-------------------------------------------------------------------------
 #
 # Makefile --
+#
 #    Makefile for string I/O module.
 #
 #-------------------------------------------------------------------------
@@ -19,6 +20,8 @@ CFLAGS += $(INCLUDE_OPT) $(CFLAGS_SL)
 
 MODNAME =	string_io
 
+SQLDEFS =	$(MODNAME).sql
+
 MODULE =	$(MODNAME)$(DLSUFFIX)
 
 MODDIR =	$(LIBDIR)/modules
@@ -29,12 +32,12 @@ all:		module sql
 
 module:		$(MODULE)
 
-sql:		$(MODNAME).sql
+sql:		$(SQLDEFS)
 
-install:	$(MODULE) $(MODDIR) $(SQLDIR)
+install:	$(MODULE) $(SQLDEFS) $(MODDIR) $(SQLDIR)
 		cp -p $(MODULE) $(MODDIR)/
 		strip $(MODDIR)/$(MODULE)
-		cp -p $(MODNAME).sql $(SQLDIR)/
+		cp -p $(SQLDEFS) $(SQLDIR)/
 
 $(MODDIR):
 		mkdir -p $@
diff --git a/contrib/string/string_io.c b/contrib/string/string_io.c
index a83203887c85145647513e6562c3967153678caa..f28968cbe545161b2b26a269e1142cfdd207c4f1 100644
--- a/contrib/string/string_io.c
+++ b/contrib/string/string_io.c
@@ -23,7 +23,7 @@
 #define ISO8859
 
 #define MIN(x, y)	((x) < (y) ? (x) : (y))
-#define VALUE(char)		((char) - '0')
+#define VALUE(char)	((char) - '0')
 #define DIGIT(val)	((val) + '0')
 #define ISOCTAL(c)	(((c) >= '0') && ((c) <= '7'))
 #ifndef ISO8859
@@ -352,15 +352,14 @@ c_charin(char *str)
 {
 	return (string_input(str, 1, 0, NULL));
 }
-
 #endif
 
 /* end of file */
 
 /*
- * Local variables:
- *	tab-width: 4
- *	c-indent-level: 4
- *	c-basic-offset: 4
+ * Local Variables:
+ *  tab-width: 4
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
  * End:
  */
diff --git a/contrib/string/string_io.h b/contrib/string/string_io.h
index b4a900bbb965cb761284dcc1228a3482a36a6d5d..b1d2b7e2c28fd9b4c7eae76f0230aa2955988289 100644
--- a/contrib/string/string_io.h
+++ b/contrib/string/string_io.h
@@ -14,15 +14,14 @@ char	   *c_varcharout(char *s);
 #if 0
 struct varlena *c_textin(char *str);
 char	   *c_char16in(char *str);
-
 #endif
 
 #endif
 
 /*
- * Local variables:
- *	tab-width: 4
- *	c-indent-level: 4
- *	c-basic-offset: 4
+ * Local Variables:
+ *  tab-width: 4
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
  * End:
  */
diff --git a/contrib/string/string_io.sql.in b/contrib/string/string_io.sql.in
index a1fafbc3ae87e0ca9509e019942037d4b358a41d..2a15e4b53541d171ab195d5d2c55b0befa15af14 100644
--- a/contrib/string/string_io.sql.in
+++ b/contrib/string/string_io.sql.in
@@ -40,7 +40,7 @@ create function c_mode() returns text
       update pg_type set typoutput=''c_textout''    where typname=''text'';
       update pg_type set typoutput=''c_textout''    where typname=''unknown'';
       update pg_type set typoutput=''c_varcharout'' where typname=''varchar'';
-      select ''c_mode''::text'
+      select ''c_mode''::text;'
   language 'sql';
 
 -- Define a function which restores the standard routines for char types.
@@ -55,7 +55,7 @@ create function pg_mode() returns text
       update pg_type set typoutput=''textout''    where typname=''text'';
       update pg_type set typoutput=''textout''    where typname=''unknown'';
       update pg_type set typoutput=''varcharout'' where typname=''varchar'';
-      select ''pg_mode''::text'
+      select ''pg_mode''::text;'
   language 'sql';
 
 -- Use these to do the changes manually.
diff --git a/contrib/tools/Makefile b/contrib/tools/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..95e97d72badad897475d95ed34df54458f61c5d9
--- /dev/null
+++ b/contrib/tools/Makefile
@@ -0,0 +1,21 @@
+#-------------------------------------------------------------------------
+#
+# Makefile --
+#
+#    Makefile for contrib tools.
+#
+#-------------------------------------------------------------------------
+
+PGDIR = ../..
+SRCDIR = $(PGDIR)/src
+
+include $(SRCDIR)/Makefile.global
+
+all:		
+
+install:	
+
+clean:
+		rm -f *~
+
+distclean:	clean
diff --git a/contrib/tools/add-emacs-variables b/contrib/tools/add-emacs-variables
new file mode 100755
index 0000000000000000000000000000000000000000..7b50aef6593d5b79a4b6964e48bda21756ce6605
--- /dev/null
+++ b/contrib/tools/add-emacs-variables
@@ -0,0 +1,28 @@
+#!/bin/bash
+#
+# Add local variables to C sources files to set emacs C style to 4-space tabs.
+#
+# Usage:  cd $PG_HOME && add-emacs-variables `find . -name \*.[chy] -print`
+
+for f in $*; do
+    if [ -L $f ] || grep -q '^ \* Local Variables:' $f; then
+	continue
+    fi
+    echo $f
+    touch -r $f /tmp/.add-local-variables.$$
+    cat <<- '    EOF' >> $f 
+	
+	/*
+	 * Local Variables:
+	 *  tab-width: 4
+	 *  c-indent-level: 4
+	 *  c-basic-offset: 4
+	 * End:
+	 */
+    EOF
+    touch -r /tmp/.add-local-variables.$$ $f
+done
+
+rm -f /tmp/.add-local-variables.$$
+
+# end of file
diff --git a/contrib/tools/find-sources b/contrib/tools/find-sources
new file mode 100755
index 0000000000000000000000000000000000000000..6d4c5ae60e26d49b8f4803267b49f8e765f5572f
--- /dev/null
+++ b/contrib/tools/find-sources
@@ -0,0 +1,50 @@
+#!/bin/echo Usage: source
+#
+# Set the shell variables files, cfiles, hfiles, yfiles and sfiles with
+# the names of all .c, .h, .y, and .S files in current directory tree.
+# Define also some shell functions to grep the files. Typical usage is:
+#
+#   $ cd src/
+#   $ source ../contrib/tools/find-sources
+#   $ gh BLCKSZ			# grep BLCKSZ in .h files
+#   $ gcl MAXTUPLEN		# list all .c files containing MAXTUPLEN
+#
+# THIS SCRIPT MUST BE SOURCED FROM BASH.
+#
+# Copyright (C) 1999  Massimo Dal Zotto <dz@cs.unitn.it>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+
+# Build the file lists
+dir=${1-`pwd`}/
+cfiles=`find $dir -name \*.c | sort`
+hfiles=`find $dir -name \*.h | sort`
+yfiles=`find $dir -name \*.y | sort`
+sfiles=`find $dir -name \*.S | sort`
+files="$hfiles $cfiles $yfiles $sfiles"
+
+# Define some functions to grep the files in the lists
+function g()   { grep    -- "$*" $files  /dev/null; }
+function gc()  { grep    -- "$*" $cfiles /dev/null; }
+function gh()  { grep    -- "$*" $hfiles /dev/null; }
+function gy()  { grep    -- "$*" $yfiles /dev/null; }
+function gS()  { grep    -- "$*" $sfiles /dev/null; }
+function gl()  { grep -l -- "$*" $files  /dev/null; }
+function gcl() { grep -l -- "$*" $cfiles /dev/null; }
+function ghl() { grep -l -- "$*" $hfiles /dev/null; }
+function gyl() { grep -l -- "$*" $yfiles /dev/null; }
+function gSl() { grep -l -- "$*" $sfiles /dev/null; }
+
+# end of file
diff --git a/contrib/tools/make-tags b/contrib/tools/make-tags
new file mode 100755
index 0000000000000000000000000000000000000000..b5b606314a6e90d57f51e25976fdfb2f2a4f3f94
--- /dev/null
+++ b/contrib/tools/make-tags
@@ -0,0 +1,9 @@
+#!/bin/bash
+#
+# Makes an emacs tagfile for all .[chS] and .el files in the current
+# directory tree.
+
+etags    $(find . -name \*.h)  2>/dev/null || true
+etags -a $(find . -name \*.c)  2>/dev/null || true
+etags -a $(find . -name \*.S)  2>/dev/null || true
+etags -a $(find . -name \*.el) 2>/dev/null || true
diff --git a/contrib/userlock/Makefile b/contrib/userlock/Makefile
index ab43f6e388cc40ae0276d7ed0914e4856400cdf7..e6cc6c37affcb9ba06421e0c0f7ec60e7b68b149 100644
--- a/contrib/userlock/Makefile
+++ b/contrib/userlock/Makefile
@@ -1,6 +1,7 @@
 #-------------------------------------------------------------------------
 #
 # Makefile --
+#
 #    Makefile for the user_locks module.
 #
 #-------------------------------------------------------------------------
@@ -19,6 +20,8 @@ CFLAGS += $(INCLUDE_OPT) $(CFLAGS_SL)
 
 MODNAME =	user_locks
 
+SQLDEFS =	$(MODNAME).sql
+
 MODULE =	$(MODNAME)$(DLSUFFIX)
 
 MODDIR =	$(LIBDIR)/modules
@@ -29,12 +32,12 @@ all:		module sql
 
 module:		$(MODULE)
 
-sql:		$(MODNAME).sql
+sql:		$(SQLDEFS)
 
-install:	$(MODULE) $(MODDIR) $(SQLDIR)
+install:	$(MODULE) $(SQLDEFS) $(MODDIR) $(SQLDIR)
 		cp -p $(MODULE) $(MODDIR)/
 		strip $(MODDIR)/$(MODULE)
-		cp -p $(MODNAME).sql $(SQLDIR)/
+		cp -p $(SQLDEFS) $(SQLDIR)/
 
 $(MODDIR):
 		mkdir -p $@
diff --git a/contrib/userlock/user_locks.c b/contrib/userlock/user_locks.c
index 27415dabb903c3fd91b6b3baed235a55ec8eea17..8631d2f6067cc222bdcdb5d763614a8449ee70f3 100644
--- a/contrib/userlock/user_locks.c
+++ b/contrib/userlock/user_locks.c
@@ -95,9 +95,9 @@ user_unlock_all()
 /* end of file */
 
 /*
- * Local variables:
- *	tab-width: 4
- *	c-indent-level: 4
- *	c-basic-offset: 4
+ * Local Variables:
+ *  tab-width: 4
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
  * End:
  */
diff --git a/contrib/userlock/user_locks.doc b/contrib/userlock/user_locks.doc
index 87c474bd1cf02a216000d53227bde575175fcf7e..c7a4321dec7098102ce5a05d1cccc6dec69c46aa 100644
--- a/contrib/userlock/user_locks.doc
+++ b/contrib/userlock/user_locks.doc
@@ -33,8 +33,8 @@ a long period because other transactions would block completely.
 
 The generic user locks use two values, group and id, to identify a lock,
 which correspond to ip_posid and ip_blkid of an ItemPointerData.
-Group is a 16 bit value while id is a 32 bit integer which can also
-contain an oid. The oid user lock function, which take an oid as argument,
+Group is a 16 bit value while id is a 32 bit integer which could also be
+an oid. The oid user lock functions, which take only an oid as argument,
 use a group equal to 0.
 
 The meaning of group and id is defined by the application. The user
diff --git a/contrib/userlock/user_locks.h b/contrib/userlock/user_locks.h
index ae77839f37d3082fab54bd71d112678767a3f407..3f0449e7e4507a1ffae70bec4d28adcbb69329fb 100644
--- a/contrib/userlock/user_locks.h
+++ b/contrib/userlock/user_locks.h
@@ -12,9 +12,9 @@ int			user_unlock_all(void);
 #endif
 
 /*
- * Local variables:
- *	tab-width: 4
- *	c-indent-level: 4
- *	c-basic-offset: 4
+ * Local Variables:
+ *  tab-width: 4
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
  * End:
  */