aboutsummaryrefslogtreecommitdiff
path: root/doc/src/sgml/generate-errcodes-table.pl
blob: 5d0ccffadd9610efdf838bbacd24a6132d19c27d (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl
#
# Generate the errcodes-table.sgml file from errcodes.txt
# Copyright (c) 2000-2011, PostgreSQL Global Development Group

use warnings;
use strict;

print "<!-- autogenerated from src/backend/utils/errcodes.txt, do not edit -->\n";

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

while (<$errcodes>) {
    chomp;

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

    # Emit section headers
    if (/^Section:/) {

	# Remove the Section: string
	s/^Section: //;
	# Escape dashes for SGML
	s/-/&mdash;/;
	# Wrap PostgreSQL in <productname/>
	s/PostgreSQL/<productname>PostgreSQL<\/>/g;

	print "\n\n";
	print "<row>\n";
	print "<entry spanname=\"span13\">";
	print "<emphasis role=\"bold\">$_</></entry>\n";
	print "</row>\n";

	next;
    }

    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 lines without PL/pgSQL condition names
    next unless defined($condition_name);

    my $meaning = $condition_name;
    # Remove underscores
    $meaning =~ s/_/ /g;
    # And capitalize
    $meaning =~ tr/[a-z]/[A-Z]/;

    print "\n";
    print "<row>\n";
    print "<entry><literal>$sqlstate</literal></entry>\n";
    print "<entry>$meaning</entry>\n";
    print "<entry>$condition_name</entry>\n";
    print "</row>\n";
}

close $errcodes;