]> granicus.if.org Git - postgresql/blob - doc/src/sgml/generate-errcodes-table.pl
Trim trailing whitespace
[postgresql] / doc / src / sgml / generate-errcodes-table.pl
1 #!/usr/bin/perl
2 #
3 # Generate the errcodes-table.sgml file from errcodes.txt
4 # Copyright (c) 2000-2017, PostgreSQL Global Development Group
5
6 use warnings;
7 use strict;
8
9 print
10   "<!-- autogenerated from src/backend/utils/errcodes.txt, do not edit -->\n";
11
12 open my $errcodes, '<', $ARGV[0] or die;
13
14 while (<$errcodes>)
15 {
16         chomp;
17
18         # Skip comments
19         next if /^#/;
20         next if /^\s*$/;
21
22         # Emit section headers
23         if (/^Section:/)
24         {
25
26                 # Remove the Section: string
27                 s/^Section: //;
28
29                 # Escape dashes for SGML
30                 s/-/&mdash;/;
31
32                 # Wrap PostgreSQL in <productname/>
33                 s/PostgreSQL/<productname>PostgreSQL<\/>/g;
34
35                 print "\n\n";
36                 print "<row>\n";
37                 print "<entry spanname=\"span12\">";
38                 print "<emphasis role=\"bold\">$_</></entry>\n";
39                 print "</row>\n";
40
41                 next;
42         }
43
44         die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/;
45
46         (my $sqlstate, my $type, my $errcode_macro, my $condition_name) =
47           ($1, $2, $3, $4);
48
49         # Skip lines without PL/pgSQL condition names
50         next unless defined($condition_name);
51
52         print "\n";
53         print "<row>\n";
54         print "<entry><literal>$sqlstate</literal></entry>\n";
55         print "<entry><symbol>$condition_name</symbol></entry>\n";
56         print "</row>\n";
57 }
58
59 close $errcodes;