1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-07 19:06:32 +03:00
Files
postgres/src/backend/utils/generate-errcodes.pl
Tom Lane 0245f8db36 Pre-beta mechanical code beautification.
Run pgindent, pgperltidy, and reformat-dat-files.

This set of diffs is a bit larger than typical.  We've updated to
pg_bsd_indent 2.1.2, which properly indents variable declarations that
have multi-line initialization expressions (the continuation lines are
now indented one tab stop).  We've also updated to perltidy version
20230309 and changed some of its settings, which reduces its desire to
add whitespace to lines to make assignments etc. line up.  Going
forward, that should make for fewer random-seeming changes to existing
code.

Discussion: https://postgr.es/m/20230428092545.qfb3y5wcu4cm75ur@alvherre.pgsql
2023-05-19 17:24:48 -04:00

66 lines
1.3 KiB
Perl

#!/usr/bin/perl
#
# Generate the errcodes.h header from errcodes.txt
# Copyright (c) 2000-2023, PostgreSQL Global Development Group
use strict;
use warnings;
use Getopt::Long;
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
"/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
print $outfh "/* there is deliberately not an #ifndef ERRCODES_H here */\n";
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 $outfh "\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 $outfh "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n";
}
close $errcodes;
close $outfh if ($outfile);