doc: 1-byte varlena headers can be used for user PLAIN storage
[pgsql.git] / src / backend / utils / generate-errcodes.pl
blob34d0f25c2335d95d4962cc15b065ce3775135764
1 #!/usr/bin/perl
3 # Generate the errcodes.h header from errcodes.txt
4 # Copyright (c) 2000-2023, PostgreSQL Global Development Group
6 use strict;
7 use warnings;
8 use Getopt::Long;
10 my $outfile = '';
12 GetOptions('outfile=s' => \$outfile) or die "$0: wrong arguments";
14 open my $errcodes, '<', $ARGV[0]
15 or die "$0: could not open input file '$ARGV[0]': $!\n";
17 my $outfh;
18 if ($outfile)
20 open $outfh, '>', $outfile
21 or die "$0: could not open output file '$outfile': $!\n";
23 else
25 $outfh = *STDOUT;
28 print $outfh
29 "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
30 print $outfh "/* there is deliberately not an #ifndef ERRCODES_H here */\n";
33 while (<$errcodes>)
35 chomp;
37 # Skip comments
38 next if /^#/;
39 next if /^\s*$/;
41 # Emit a comment for each section header
42 if (/^Section:(.*)/)
44 my $header = $1;
45 $header =~ s/^\s+//;
46 print $outfh "\n/* $header */\n";
47 next;
50 die "unable to parse errcodes.txt"
51 unless /^([^\s]{5})\s+[EWS]\s+([^\s]+)/;
53 (my $sqlstate, my $errcode_macro) = ($1, $2);
55 # Split the sqlstate letters
56 $sqlstate = join ",", split "", $sqlstate;
58 # And quote them
59 $sqlstate =~ s/([^,])/'$1'/g;
61 print $outfh "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n";
64 close $errcodes;
65 close $outfh if ($outfile);