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