1#!/usr/bin/perl 2# 3# Generate the plerrcodes.h header from errcodes.txt 4# Copyright (c) 2000-2021, PostgreSQL Global Development Group 5 6use strict; 7use warnings; 8 9print 10 "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n"; 11print "/* there is deliberately not an #ifndef PLERRCODES_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 # Skip section headers 24 next if /^Section:/; 25 26 die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/; 27 28 (my $sqlstate, my $type, my $errcode_macro, my $condition_name) = 29 ($1, $2, $3, $4); 30 31 # Skip non-errors 32 next unless $type eq 'E'; 33 34 # Skip lines without PL/pgSQL condition names 35 next unless defined($condition_name); 36 37 print "\n{\n\t\"$condition_name\", $errcode_macro\n},\n"; 38} 39 40close $errcodes; 41