summaryrefslogtreecommitdiffstats
path: root/src/backend/utils/generate-errcodes.pl
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
commit46651ce6fe013220ed397add242004d764fc0153 (patch)
tree6e5299f990f88e60174a1d3ae6e48eedd2688b2b /src/backend/utils/generate-errcodes.pl
parentInitial commit. (diff)
downloadpostgresql-14-46651ce6fe013220ed397add242004d764fc0153.tar.xz
postgresql-14-46651ce6fe013220ed397add242004d764fc0153.zip
Adding upstream version 14.5.upstream/14.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/backend/utils/generate-errcodes.pl')
-rw-r--r--src/backend/utils/generate-errcodes.pl46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/backend/utils/generate-errcodes.pl b/src/backend/utils/generate-errcodes.pl
new file mode 100644
index 0000000..c5cdd38
--- /dev/null
+++ b/src/backend/utils/generate-errcodes.pl
@@ -0,0 +1,46 @@
+#!/usr/bin/perl
+#
+# Generate the errcodes.h header from errcodes.txt
+# Copyright (c) 2000-2021, PostgreSQL Global Development Group
+
+use strict;
+use warnings;
+
+print
+ "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
+print "/* there is deliberately not an #ifndef ERRCODES_H here */\n";
+
+open my $errcodes, '<', $ARGV[0] or die;
+
+while (<$errcodes>)
+{
+ chomp;
+
+ # Skip comments
+ next if /^#/;
+ next if /^\s*$/;
+
+ # Emit a comment for each section header
+ if (/^Section:(.*)/)
+ {
+ my $header = $1;
+ $header =~ s/^\s+//;
+ print "\n/* $header */\n";
+ next;
+ }
+
+ die "unable to parse errcodes.txt"
+ unless /^([^\s]{5})\s+[EWS]\s+([^\s]+)/;
+
+ (my $sqlstate, my $errcode_macro) = ($1, $2);
+
+ # Split the sqlstate letters
+ $sqlstate = join ",", split "", $sqlstate;
+
+ # And quote them
+ $sqlstate =~ s/([^,])/'$1'/g;
+
+ print "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n";
+}
+
+close $errcodes;