From 9bf8603c7a9153cada7e32eb0cf7ac1feb1d3b56 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Mon, 27 Feb 2012 13:53:12 +0200
Subject: [PATCH] Call check_keywords.pl in maintainer-check

For that purpose, have check_keywords.pl print errors to stderr and
return a useful exit status.
---
 src/backend/common.mk       |  2 +-
 src/backend/parser/Makefile |  4 ++++
 src/tools/check_keywords.pl | 25 +++++++++++++++++--------
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/backend/common.mk b/src/backend/common.mk
index 5d599dbd0ca..2e56151e2b4 100644
--- a/src/backend/common.mk
+++ b/src/backend/common.mk
@@ -45,4 +45,4 @@ clean: clean-local
 clean-local:
 	rm -f $(subsysfilename) $(OBJS)
 
-$(call recurse,coverage)
+$(call recurse,coverage maintainer-check)
diff --git a/src/backend/parser/Makefile b/src/backend/parser/Makefile
index 0bdb3249a2e..00e8e88e9c2 100644
--- a/src/backend/parser/Makefile
+++ b/src/backend/parser/Makefile
@@ -65,3 +65,7 @@ gram.o keywords.o parser.o: gram.h
 # are not cleaned here.
 clean distclean maintainer-clean:
 	rm -f lex.backup
+
+
+maintainer-check:
+	$(PERL) $(top_srcdir)/src/tools/check_keywords.pl $(top_srcdir)
diff --git a/src/tools/check_keywords.pl b/src/tools/check_keywords.pl
index 17877548400..33816c51332 100755
--- a/src/tools/check_keywords.pl
+++ b/src/tools/check_keywords.pl
@@ -7,8 +7,14 @@ use strict;
 #
 # src/tools/check_keywords.pl
 
+my $errors = 0;
 my $path;
 
+sub error(@) {
+    print STDERR @_;
+    $errors = 1;
+}
+
 if (@ARGV) {
 	$path = $ARGV[0];
 	shift @ARGV;
@@ -102,7 +108,8 @@ foreach $kcat (keys %keyword_categories) {
 	$bare_kword = $kword;
 	$bare_kword =~ s/_P$//;
 	if ($bare_kword le $prevkword) {
-	    print "'$bare_kword' after '$prevkword' in $kcat list is misplaced";
+	    error "'$bare_kword' after '$prevkword' in $kcat list is misplaced";
+	    $errors = 1;
 	}
 	$prevkword = $bare_kword;
     }
@@ -141,35 +148,35 @@ kwlist_line: while (<KWLIST>) {
 
 	# Check that the list is in alphabetical order
 	if ($kwstring le $prevkwstring) {
-	    print "'$kwstring' after '$prevkwstring' in kwlist.h is misplaced";
+	    error "'$kwstring' after '$prevkwstring' in kwlist.h is misplaced";
 	}
 	$prevkwstring = $kwstring;
 
 	# Check that the keyword string is valid: all lower-case ASCII chars
 	if ($kwstring !~ /^[a-z_]*$/) {
-	    print "'$kwstring' is not a valid keyword string, must be all lower-case ASCII chars";
+	    error "'$kwstring' is not a valid keyword string, must be all lower-case ASCII chars";
 	}
 
 	# Check that the keyword name is valid: all upper-case ASCII chars
 	if ($kwname !~ /^[A-Z_]*$/) {
-	    print "'$kwname' is not a valid keyword name, must be all upper-case ASCII chars";
+	    error "'$kwname' is not a valid keyword name, must be all upper-case ASCII chars";
 	}
 
 	# Check that the keyword string matches keyword name
 	$bare_kwname = $kwname;
 	$bare_kwname =~ s/_P$//;
 	if ($bare_kwname ne uc($kwstring)) {
-	    print "keyword name '$kwname' doesn't match keyword string '$kwstring'";
+	    error "keyword name '$kwname' doesn't match keyword string '$kwstring'";
 	}
 
 	# Check that the keyword is present in the grammar
 	%kwhash = %{$kwhashes{$kwcat_id}};
 
 	if (!(%kwhash))	{
-	    #print "Unknown kwcat_id: $kwcat_id";
+	    #error "Unknown kwcat_id: $kwcat_id";
 	} else {
 	    if (!($kwhash{$kwname})) {
-		print "'$kwname' not present in $kwcat_id section of gram.y";
+		error "'$kwname' not present in $kwcat_id section of gram.y";
 	    } else {
 		# Remove it from the hash, so that we can complain at the end
 		# if there's keywords left that were not found in kwlist.h
@@ -185,6 +192,8 @@ while ( my ($kwcat, $kwcat_id) = each(%keyword_categories) ) {
     %kwhash = %{$kwhashes{$kwcat_id}};
 
     for my $kw ( keys %kwhash ) {
-	print "'$kw' found in gram.y $kwcat category, but not in kwlist.h"
+	error "'$kw' found in gram.y $kwcat category, but not in kwlist.h"
     }
 }
+
+exit $errors;
-- 
GitLab