2011-02-04 04:32:49 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# Generate the errcodes.h header from errcodes.txt
|
2023-01-02 21:00:37 +01:00
|
|
|
# Copyright (c) 2000-2023, PostgreSQL Global Development Group
|
2011-02-04 04:32:49 +01:00
|
|
|
|
|
|
|
use strict;
|
2020-09-21 15:22:41 +02:00
|
|
|
use warnings;
|
2022-07-18 21:15:09 +02:00
|
|
|
use Getopt::Long;
|
2011-02-04 04:32:49 +01:00
|
|
|
|
2022-07-18 21:15:09 +02:00
|
|
|
my $outfile = '';
|
|
|
|
|
|
|
|
GetOptions(
|
|
|
|
'outfile=s' => \$outfile) or die "$0: wrong arguments";
|
|
|
|
|
|
|
|
open my $errcodes, '<', $ARGV[0]
|
|
|
|
or die "$0: could not open input file '$ARGV[0]': $!\n";
|
|
|
|
|
|
|
|
my $outfh;
|
|
|
|
if ($outfile)
|
|
|
|
{
|
|
|
|
open $outfh, '>', $outfile
|
|
|
|
or die "$0: could not open output file '$outfile': $!\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$outfh = *STDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
print $outfh
|
2012-07-05 03:47:49 +02:00
|
|
|
"/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
|
2022-07-18 21:15:09 +02:00
|
|
|
print $outfh "/* there is deliberately not an #ifndef ERRCODES_H here */\n";
|
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+//;
|
2022-07-18 21:15:09 +02:00
|
|
|
print $outfh "\n/* $header */\n";
|
2011-02-04 04:32:49 +01:00
|
|
|
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;
|
|
|
|
|
2022-07-18 21:15:09 +02:00
|
|
|
print $outfh "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n";
|
2011-02-04 04:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
close $errcodes;
|
2022-07-18 21:15:09 +02:00
|
|
|
close $outfh if ($outfile);
|