3 # Generate the errcodes.h header from errcodes.txt
4 # Copyright (c) 2000-2023, PostgreSQL Global Development Group
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";
20 open $outfh, '>', $outfile
21 or die "$0: could not open output file '$outfile': $!\n";
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";
41 # Emit a comment for each section header
46 print $outfh "\n/* $header */\n";
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;
59 $sqlstate =~ s/([^,])/'$1'/g;
61 print $outfh "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n";
65 close $outfh if ($outfile);