~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to src/pl/plpython/generate-spiexceptions.pl

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
#
 
3
# Generate the spiexceptions.h header from errcodes.txt
 
4
# Copyright (c) 2000-2011, PostgreSQL Global Development Group
 
5
 
 
6
use warnings;
 
7
use strict;
 
8
 
 
9
print "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
 
10
print "/* there is deliberately not an #ifndef SPIEXCEPTIONS_H here */\n";
 
11
 
 
12
open my $errcodes, $ARGV[0] or die;
 
13
 
 
14
while (<$errcodes>) {
 
15
    chomp;
 
16
 
 
17
    # Skip comments
 
18
    next if /^#/;
 
19
    next if /^\s*$/;
 
20
 
 
21
    # Skip section headers
 
22
    next if /^Section:/;
 
23
 
 
24
    die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/;
 
25
 
 
26
    (my $sqlstate,
 
27
     my $type,
 
28
     my $errcode_macro,
 
29
     my $condition_name) = ($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
    # Change some_error_condition to SomeErrorCondition
 
38
    $condition_name =~ s/([a-z])([^_]*)(?:_|$)/\u$1$2/g;
 
39
 
 
40
    print "{ \"spiexceptions.$condition_name\", " .
 
41
        "\"$condition_name\", $errcode_macro },\n";
 
42
}
 
43
 
 
44
close $errcodes;