Author: turnstep
Date: Sat May 24 18:39:04 2008
New Revision: 11306

Modified:
   DBD-Pg/trunk/types.c
   DBD-Pg/trunk/types.h

Log:
Cleanup of embedded Perl script in types.c


Modified: DBD-Pg/trunk/types.c
==============================================================================
--- DBD-Pg/trunk/types.c        (original)
+++ DBD-Pg/trunk/types.c        Sat May 24 18:39:04 2008
@@ -10,11 +10,10 @@
 */
 
 /*
-        Please do not edit the C portions of this file directly. 
-        It is automatically generated by the enclosed Perl script.
+    Please do not edit the C portions of this file directly. 
+    It is automatically generated by the enclosed Perl script.
 */
 
-
 #include "Pg.h"
 
 static sql_type_info_t pg_types[] = {
@@ -353,14 +352,16 @@
 /*
 #!perl
 
-## Autogenerate all type information and populate types.c and types.h
+## Autogenerate all type information and populate 
+## all files referenceing type information.
 
 ## You should only run this if you are developing DBD::Pg and 
 ## understand what this script does
 
 ## Usage: perl -x $0 "path-to-pgsql-source"
 
-use strict; use warnings; use Data::Dumper;
+use strict;
+use warnings;
 
 my $arg = shift || die "Usage: $0 path-to-pgsql-source\n";
 
@@ -368,15 +369,15 @@
 
 my $file = "$arg/src/include/catalog/pg_type.h";
 
-open(F, $file) or die qq{Could not open file "$file": $!\n};
+open my $fh, '<', $file or die qq{Could not open file "$file": $!\n};
 my $maxlen = 1;
 my %pgtype;
 my $thisname = 0;
-while(<F>) {
+while(<$fh>) {
        s/FLOAT8PASSBYVAL/t/;
        s/FLOAT4PASSBYVAL/t/;
        if (/^DATA\(insert OID\s+=\s+(\d+)\s+\(\s+(\S+)\s+\S+ 
\S+\s+\S+\s+[t|f]\s+. ([tf]) \\(\d+) (\d+)\s+(\d+) (\d+) (\S+) (\S+) (\S+) 
(\S+)/o) {
-               my 
($oid,$name,$typedef,$delim,$typrelid,$typelem,$typarray,$tin,$tout,$bin,$bout) 
= 
+               my 
($oid,$name,$typedef,$delim,$typrelid,$typelem,$typarray,$tin,$tout,$bin,$bout) 
=
                        ($1,$2,$3,chr(oct($4)),$5,$6,$7,$8,$9,$10,$11);
                die "Duplicated OID $oid!: $_\n" if exists $pgtype{$oid};
                $pgtype{$name} = {
@@ -387,10 +388,10 @@
                        binin   => $bin,
                        binout  => $bout,
                        quote   => 'quote_string',
-            dequote => 'dequote_string',
+                       dequote => 'dequote_string',
                        define  => 'PG_' . uc($name),
                        sql     => 0,
-            sqlc    => 0,
+                       sqlc    => 0,
                        svtype  => 0,
                };
                length($name) > $maxlen and $maxlen = length($name);
@@ -405,33 +406,33 @@
        }
        elsif (/^DATA/) {
                die "Bad line at $. ->$_\n";
-   }
+       }
 }
-close(F);
+close $fh or die qq{Could not close "$file": $!\n};
 
 my ($oldfh,$newfh);
 
 ## Rewrite types.h
-$file = "types.h";
+$file = 'types.h';
 open $newfh, '>', "$file.tmp" or die qq{Could not create "$file.tmp": $!\n};
 
-print $newfh '/' . qq{*
-       Do not edit this file directly - it is generated by types.c
-*} . qq{/
+my $slashstar = '/' . '*';
+my $starslash = '*' . '/';
+print $newfh qq{$slashstar\nDo not edit this file directly - it is generated 
by types.c\n$starslash
 
 typedef struct sql_type_info {
-       int         type_id;
+       int     type_id;
        char*   type_name;
-    char    array_delimeter;
-    char*   arrayout;
-       char*   (*quote)();
-       void    (*dequote)();
-       union   {
+       char    array_delimeter;
+       char*   arrayout;
+       char*   (*quote)();
+       void    (*dequote)();
+       union   {
                        int pg;
                        int sql;
        } type;
-       bool    bind_ok;
-    int     svtype;
+       bool    bind_ok;
+       int     svtype;
 } sql_type_info_t;
 
 sql_type_info_t* pg_type_data(int);
@@ -448,7 +449,7 @@
 }
 
 print $newfh "\n";
-close $newfh;
+close $newfh or die qq{Could not close "$file.tmp": $!\n};
 system("mv $file.tmp $file");
 print "Wrote $file\n";
 
@@ -465,9 +466,9 @@
                        for (sort { $pgtype{$a}{define} cmp $pgtype{$b}{define} 
} keys %pgtype) {
                                printf $newfh "\t%-${maxlen}s = 
$pgtype{$_}{oid}\n", $pgtype{$_}{define};
                        }
-                       printf $newfh "\n\t%-${maxlen}s = 1\n", "PG_ASYNC";
-                       printf $newfh "\t%-${maxlen}s = 2\n", 
"PG_OLDQUERY_CANCEL";
-                       printf $newfh "\t%-${maxlen}s = 4\n\n", 
"PG_OLDQUERY_WAIT";
+                       printf $newfh "\n\t%-${maxlen}s = 1\n", 'PG_ASYNC';
+                       printf $newfh "\t%-${maxlen}s = 2\n", 
'PG_OLDQUERY_CANCEL';
+                       printf $newfh "\t%-${maxlen}s = 4\n\n", 
'PG_OLDQUERY_WAIT';
                        next;
                }
        }
@@ -477,8 +478,8 @@
        }
        print $newfh $_;
 }
-close $newfh;
-close $oldfh;
+close $newfh or die qq{Could not close "$file.tmp": $!\n};
+close $oldfh  or die qq{Could not close "$file": $!\n};
 system("mv $file.tmp $file");
 print "Wrote $file\n";
 
@@ -495,7 +496,7 @@
                        print $newfh $_;
                        $step = 0;
                        for (sort { $pgtype{$a}{define} cmp $pgtype{$b}{define} 
} keys %pgtype) {
-                               printf $newfh "%s$pgtype{$_}{define}", 
!($step++ % 5) ? "\n\t\t\t" : " ";
+                               printf $newfh "%s$pgtype{$_}{define}", 
!($step++ % 5) ? "\n\t\t\t" : ' ';
                        }
                        print $newfh "\n";
                        $step = 1;
@@ -511,12 +512,12 @@
                        print $newfh $_;
                        $step = 0;
                        for (sort { $pgtype{$a}{define} cmp $pgtype{$b}{define} 
} keys %pgtype) {
-                               printf $newfh "%s$pgtype{$_}{define}", 
!($step++ % 6) ? "\n" : " ";
+                               printf $newfh "%s$pgtype{$_}{define}", 
!($step++ % 6) ? "\n" : ' ';
                        }
-                       print $newfh "\n\n";                    
+                       print $newfh "\n\n";
                        $step = 3;
                        next;
-                 }
+               }
        }
        elsif (3 == $step) {
                next unless /sticky/;
@@ -524,8 +525,8 @@
        }
        print $newfh $_;
 }
-close $newfh;
-close $oldfh;
+close $newfh or die qq{Could not close "$file.tmp": $!\n};
+close $oldfh or die qq{Could not close "$file": $!\n};
 system("mv $file.tmp $file");
 print "Wrote $file\n";
 
@@ -548,8 +549,8 @@
        }
        print $newfh $_;
 }
-close $newfh;
-close $oldfh;
+close $newfh or die qq{Could not close "$file.tmp": $!\n};
+close $oldfh or die qq{Could not close "$file": $!\n};
 system("mv $file.tmp $file");
 print "Wrote $file\n";
 
@@ -576,31 +577,31 @@
        }
        print $newfh $_;
 }
-close $newfh;
-close $oldfh;
+close $newfh or die qq{Could not close "$file.tmp": $!\n};
+close $oldfh or die qq{Could not close "$file": $!\n};
 system("mv $file.tmp $file");
 print "Wrote $file\n";
 
 
 ## Rewrite types.c
-$file = "types.c";
+$file = 'types.c';
 open $newfh, '>', "$file.tmp" or die qq{Could not write to "$file.tmp": $!\n};
 
-print $newfh 
-'/' . q{*
+print $newfh qq{$slashstar
 
-   $Id$
+   \$Id: types.c 11297 2008-05-20 21:52:34Z turnstep \$
 
    Copyright (c) 2003-2008 Greg Sabino Mullane and others: see the Changes file
    
    You may distribute under the terms of either the GNU General Public
    License or the Artistic License, as specified in the Perl README file.
 
-*} . "/\n\n/" . qq{*
-        Please do not edit the C portions of this file directly. 
-        It is automatically generated by the enclosed Perl script.
-*} . qq{/
+$starslash
 
+$slashstar
+    Please do not edit the C portions of this file directly. 
+    It is automatically generated by the enclosed Perl script.
+$starslash
 
 #include "Pg.h"
 
@@ -622,7 +623,7 @@
        $pgtype{$name}{svtype}  = $svtype;
        ## For arrays, we want to echo the base svtype
        if ($svtype and exists $pgtype{"_$name"} and $pgtype{"_$name"}{textin} 
=~ /array/) {
-        $pgtype{"_$name"}{svtype} = $svtype;
+               $pgtype{"_$name"}{svtype} = $svtype;
        }
 }
 
@@ -636,7 +637,7 @@
 for my $name (sort {$a cmp $b } keys %pgtype) {
        my $t = $pgtype{$name};
        my ($sqltype,$quote,$dequote) = (0,0,0);
-       (my $sql = $t->{sql}) =~ s#^(\w+).*#$1#;
+       (my $sql = $t->{sql}) =~ s{^(\w+).*}{$1};
 
        printf $newfh qq! {%-*s,%-*s,'%s',%-18s,%-12s,%-14s,\{%s\},%d,%d\},\n!,
                $maxlen, $t->{define}, $maxlen-2, "\"$name\"", $t->{delim}, 
"\"$t->{textout}\"", $t->{quote}, $t->{dequote}, $sql, 1, $t->{svtype};
@@ -645,7 +646,7 @@
 
 print $newfh "\};\n\n";
 
-print $newfh 
+print $newfh
 "sql_type_info_t* pg_type_data(int sql_type)
 {
 \tdTHX;
@@ -687,7 +688,7 @@
 1 while <DATA> !~ /!perl/;
 print $newfh "#!perl\n";
 while (<DATA>) { print $newfh $_; }
-close($newfh);
+close($newfh) or die qq{Could not close "$file.tmp": $!\n};
 system("mv $file.tmp $file");
 print "Wrote $file\n";
 
@@ -746,4 +747,3 @@
 __END__
 
 */
-

Modified: DBD-Pg/trunk/types.h
==============================================================================
--- DBD-Pg/trunk/types.h        (original)
+++ DBD-Pg/trunk/types.h        Sat May 24 18:39:04 2008
@@ -1,20 +1,20 @@
 /*
-       Do not edit this file directly - it is generated by types.c
+Do not edit this file directly - it is generated by types.c
 */
 
 typedef struct sql_type_info {
-       int         type_id;
+       int     type_id;
        char*   type_name;
-    char    array_delimeter;
-    char*   arrayout;
-       char*   (*quote)();
-       void    (*dequote)();
-       union   {
+       char    array_delimeter;
+       char*   arrayout;
+       char*   (*quote)();
+       void    (*dequote)();
+       union   {
                        int pg;
                        int sql;
        } type;
-       bool    bind_ok;
-    int     svtype;
+       bool    bind_ok;
+       int     svtype;
 } sql_type_info_t;
 
 sql_type_info_t* pg_type_data(int);

Reply via email to