]> granicus.if.org Git - postgresql/blob - src/pl/plpgsql/src/generate-plerrcodes.pl
Avoid maintaining three separate copies of the error codes list.
[postgresql] / src / pl / plpgsql / src / generate-plerrcodes.pl
1 #!/usr/bin/perl
2 #
3 # Generate the plerrcodes.h header from errcodes.txt
4 # Copyright (c) 2000-2011, PostgreSQL Global Development Group
5
6 use warnings;
7 use strict;
8
9 print "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
10 print "/* there is deliberately not an #ifndef PLERRCODES_H here */\n";
11
12 open my $errcodes, $ARGV[0] or die;
13
14 while (<$errcodes>) {
15     chomp;
16
17     # Skip comments
18     next if /^#/;
19     next if /^\s*$/;
20
21     # Skip section headers
22     next if /^Section:/;
23
24     die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/;
25
26     (my $sqlstate,
27      my $type,
28      my $errcode_macro,
29      my $condition_name) = ($1, $2, $3, $4);
30
31     # Skip non-errors
32     next unless $type eq 'E';
33
34     # Skip lines without PL/pgSQL condition names
35     next unless defined($condition_name);
36
37     print "{\n\t\"$condition_name\", $errcode_macro\n},\n\n";
38 }
39
40 close $errcodes;