fix
[libpgclient.git] / errcodes.pl
blob7cc7c3b2b7005315d4435e75b625e70fadfbacf8
1 #!/usr/bin/perl
3 # Generate the errcodes.h header from errcodes.txt
4 # Copyright (c) 2000-2019, PostgreSQL Global Development Group
5 # patched by Brian B.
7 use warnings;
8 use strict;
10 print "#ifndef __PGERRCODES_H__\n";
11 print "#define __PGERRCODES_H__\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 print "#define $errcode_macro \"$sqlstate\"\n";
40 print "\n#endif\n";
42 close $errcodes;