Update copyright for 2022
[pgsql.git] / src / backend / utils / generate-errcodes.pl
blob5727ff76cc3040e0eb10495735b99d6af8af2dd5
1 #!/usr/bin/perl
3 # Generate the errcodes.h header from errcodes.txt
4 # Copyright (c) 2000-2022, PostgreSQL Global Development Group
6 use strict;
7 use warnings;
9 print
10 "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
11 print "/* there is deliberately not an #ifndef ERRCODES_H here */\n";
13 open my $errcodes, '<', $ARGV[0] or die;
15 while (<$errcodes>)
17 chomp;
19 # Skip comments
20 next if /^#/;
21 next if /^\s*$/;
23 # Emit a comment for each section header
24 if (/^Section:(.*)/)
26 my $header = $1;
27 $header =~ s/^\s+//;
28 print "\n/* $header */\n";
29 next;
32 die "unable to parse errcodes.txt"
33 unless /^([^\s]{5})\s+[EWS]\s+([^\s]+)/;
35 (my $sqlstate, my $errcode_macro) = ($1, $2);
37 # Split the sqlstate letters
38 $sqlstate = join ",", split "", $sqlstate;
40 # And quote them
41 $sqlstate =~ s/([^,])/'$1'/g;
43 print "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n";
46 close $errcodes;