2011-02-04 04:32:49 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# Generate the errcodes.h header from errcodes.txt
|
2017-01-03 19:48:53 +01:00
|
|
|
# Copyright (c) 2000-2017, PostgreSQL Global Development Group
|
2011-02-04 04:32:49 +01:00
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
print
|
|
|
|
"/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
|
2011-02-04 04:32:49 +01:00
|
|
|
print "/* there is deliberately not an #ifndef ERRCODES_H here */\n";
|
|
|
|
|
2017-03-27 04:24:13 +02:00
|
|
|
open my $errcodes, '<', $ARGV[0] or die;
|
2011-02-04 04:32:49 +01:00
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
while (<$errcodes>)
|
|
|
|
{
|
|
|
|
chomp;
|
2011-02-04 04:32:49 +01:00
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
# Skip comments
|
|
|
|
next if /^#/;
|
|
|
|
next if /^\s*$/;
|
2011-02-04 04:32:49 +01:00
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
# Emit a comment for each section header
|
|
|
|
if (/^Section:(.*)/)
|
|
|
|
{
|
2011-02-04 04:32:49 +01:00
|
|
|
my $header = $1;
|
|
|
|
$header =~ s/^\s+//;
|
|
|
|
print "\n/* $header */\n";
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
die "unable to parse errcodes.txt"
|
|
|
|
unless /^([^\s]{5})\s+[EWS]\s+([^\s]+)/;
|
2011-02-04 04:32:49 +01:00
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
(my $sqlstate, my $errcode_macro) = ($1, $2);
|
2011-02-04 04:32:49 +01:00
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
# Split the sqlstate letters
|
|
|
|
$sqlstate = join ",", split "", $sqlstate;
|
2011-02-04 04:32:49 +01:00
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
# And quote them
|
|
|
|
$sqlstate =~ s/([^,])/'$1'/g;
|
|
|
|
|
|
|
|
print "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n";
|
2011-02-04 04:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
close $errcodes;
|