summaryrefslogtreecommitdiffstats
path: root/src/pl/tcl/generate-pltclerrcodes.pl
blob: e2aeefa05e5451999851f46f38db9fd5e1ae70ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl
#
# Generate the pltclerrcodes.h header from errcodes.txt
# Copyright (c) 2000-2022, PostgreSQL Global Development Group

use strict;
use warnings;

print
  "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
print "/* there is deliberately not an #ifndef PLTCLERRCODES_H here */\n";

open my $errcodes, '<', $ARGV[0] or die;

while (<$errcodes>)
{
	chomp;

	# Skip comments
	next if /^#/;
	next if /^\s*$/;

	# Skip section headers
	next if /^Section:/;

	die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/;

	(my $sqlstate, my $type, my $errcode_macro, my $condition_name) =
	  ($1, $2, $3, $4);

	# Skip non-errors
	next unless $type eq 'E';

	# Skip lines without PL/pgSQL condition names
	next unless defined($condition_name);

	print "\n{\n\t\"$condition_name\", $errcode_macro\n},\n";
}

close $errcodes;