Update copyright for 2022
[pgsql.git] / src / pl / tcl / generate-pltclerrcodes.pl
blobe2aeefa05e5451999851f46f38db9fd5e1ae70ac
1 #!/usr/bin/perl
3 # Generate the pltclerrcodes.h header from errcodes.txt
4 # Copyright (c) 2000-2022, PostgreSQL Global Development Group
6 use strict;
7 use warnings;
9 print
10 "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
11 print "/* there is deliberately not an #ifndef PLTCLERRCODES_H here */\n";
13 open my $errcodes, '<', $ARGV[0] or die;
15 while (<$errcodes>)
17 chomp;
19 # Skip comments
20 next if /^#/;
21 next if /^\s*$/;
23 # Skip section headers
24 next if /^Section:/;
26 die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/;
28 (my $sqlstate, my $type, my $errcode_macro, my $condition_name) =
29 ($1, $2, $3, $4);
31 # Skip non-errors
32 next unless $type eq 'E';
34 # Skip lines without PL/pgSQL condition names
35 next unless defined($condition_name);
37 print "\n{\n\t\"$condition_name\", $errcode_macro\n},\n";
40 close $errcodes;