Commit 042d9ffc authored by Bruce Momjian's avatar Bruce Momjian

Run newly-configured perltidy script on Perl files.

Run on HEAD and 9.2.
parent d7c73484
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
# make sure we are in a sane environment. # make sure we are in a sane environment.
use DBI(); use DBI();
use DBD::Pg(); use DBD::Pg();
...@@ -10,7 +11,8 @@ use Getopt::Std; ...@@ -10,7 +11,8 @@ use Getopt::Std;
my %opt; my %opt;
getopts('d:b:s:veorauc', \%opt); getopts('d:b:s:veorauc', \%opt);
if ( !( scalar %opt && defined $opt{s} ) ) { if (!(scalar %opt && defined $opt{s}))
{
print <<EOT; print <<EOT;
Usage: Usage:
$0 -d DATABASE -s SECTIONS [-b NUMBER] [-v] [-e] [-o] [-r] [-a] [-u] $0 -d DATABASE -s SECTIONS [-b NUMBER] [-v] [-e] [-o] [-r] [-a] [-u]
...@@ -30,27 +32,37 @@ EOT ...@@ -30,27 +32,37 @@ EOT
} }
$opt{d} ||= '_int4'; $opt{d} ||= '_int4';
my $dbi=DBI->connect('DBI:Pg:dbname='.$opt{d}); my $dbi = DBI->connect('DBI:Pg:dbname=' . $opt{d});
my %table; my %table;
my @where; my @where;
$table{message}=1; $table{message} = 1;
if ( $opt{a} ) { if ($opt{a})
if ( $opt{r} ) { {
if ($opt{r})
{
push @where, "message.sections @ '{$opt{s}}'"; push @where, "message.sections @ '{$opt{s}}'";
} else { }
foreach my $sid ( split(/[,\s]+/, $opt{s} )) { else
{
foreach my $sid (split(/[,\s]+/, $opt{s}))
{
push @where, "message.mid = msp$sid.mid"; push @where, "message.mid = msp$sid.mid";
push @where, "msp$sid.sid = $sid"; push @where, "msp$sid.sid = $sid";
$table{"message_section_map msp$sid"}=1; $table{"message_section_map msp$sid"} = 1;
} }
} }
} else { }
if ( $opt{r} ) { else
{
if ($opt{r})
{
push @where, "message.sections && '{$opt{s}}'"; push @where, "message.sections && '{$opt{s}}'";
} else { }
else
{
$table{message_section_map} = 1; $table{message_section_map} = 1;
push @where, "message.mid = message_section_map.mid"; push @where, "message.mid = message_section_map.mid";
push @where, "message_section_map.sid in ($opt{s})"; push @where, "message_section_map.sid in ($opt{s})";
...@@ -58,48 +70,66 @@ if ( $opt{a} ) { ...@@ -58,48 +70,66 @@ if ( $opt{a} ) {
} }
my $outf; my $outf;
if ( $opt{c} ) { if ($opt{c})
$outf = ( $opt{u} ) ? 'count( distinct message.mid )' : 'count( message.mid )'; {
} else { $outf =
$outf = ( $opt{u} ) ? 'distinct( message.mid )' : 'message.mid'; ($opt{u}) ? 'count( distinct message.mid )' : 'count( message.mid )';
}
else
{
$outf = ($opt{u}) ? 'distinct( message.mid )' : 'message.mid';
} }
my $sql = "select $outf from ".join(', ', keys %table)." where ".join(' AND ', @where).';'; my $sql =
"select $outf from "
. join(', ', keys %table)
. " where "
. join(' AND ', @where) . ';';
if ( $opt{v} ) { if ($opt{v})
{
print "$sql\n"; print "$sql\n";
} }
if ( $opt{e} ) { if ($opt{e})
{
$dbi->do("explain $sql"); $dbi->do("explain $sql");
} }
my $t0 = [gettimeofday]; my $t0 = [gettimeofday];
my $count=0; my $count = 0;
my $b=$opt{b}; my $b = $opt{b};
$b||=1; $b ||= 1;
my @a; my @a;
foreach ( 1..$b ) { foreach (1 .. $b)
@a=exec_sql($dbi,$sql); {
$count=$#a; @a = exec_sql($dbi, $sql);
$count = $#a;
} }
my $elapsed = tv_interval ( $t0, [gettimeofday]); my $elapsed = tv_interval($t0, [gettimeofday]);
if ( $opt{o} ) { if ($opt{o})
foreach ( @a ) { {
foreach (@a)
{
print "$_->{mid}\t$_->{sections}\n"; print "$_->{mid}\t$_->{sections}\n";
} }
} }
print sprintf("total: %.02f sec; number: %d; for one: %.03f sec; found %d docs\n", $elapsed, $b, $elapsed/$b, $count+1 ); print sprintf(
$dbi -> disconnect; "total: %.02f sec; number: %d; for one: %.03f sec; found %d docs\n",
$elapsed, $b, $elapsed / $b,
$count + 1);
$dbi->disconnect;
sub exec_sql { sub exec_sql
my ($dbi, $sql, @keys) = @_; {
my $sth=$dbi->prepare($sql) || die; my ($dbi, $sql, @keys) = @_;
$sth->execute( @keys ) || die; my $sth = $dbi->prepare($sql) || die;
my $r; $sth->execute(@keys) || die;
my @row; my $r;
while ( defined ( $r=$sth->fetchrow_hashref ) ) { my @row;
push @row, $r; while (defined($r = $sth->fetchrow_hashref))
} {
$sth->finish; push @row, $r;
return @row; }
$sth->finish;
return @row;
} }
...@@ -15,28 +15,38 @@ create table message_section_map ( ...@@ -15,28 +15,38 @@ create table message_section_map (
EOT EOT
open(MSG,">message.tmp") || die; open(MSG, ">message.tmp") || die;
open(MAP,">message_section_map.tmp") || die; open(MAP, ">message_section_map.tmp") || die;
srand(1);
srand( 1 );
#foreach my $i ( 1..1778 ) { #foreach my $i ( 1..1778 ) {
#foreach my $i ( 1..3443 ) { #foreach my $i ( 1..3443 ) {
#foreach my $i ( 1..5000 ) { #foreach my $i ( 1..5000 ) {
#foreach my $i ( 1..29362 ) { #foreach my $i ( 1..29362 ) {
#foreach my $i ( 1..33331 ) { #foreach my $i ( 1..33331 ) {
#foreach my $i ( 1..83268 ) { #foreach my $i ( 1..83268 ) {
foreach my $i ( 1..200000 ) { foreach my $i (1 .. 200000)
{
my @sect; my @sect;
if ( rand() < 0.7 ) { if (rand() < 0.7)
$sect[0] = int( (rand()**4)*100 ); {
} else { $sect[0] = int((rand()**4) * 100);
}
else
{
my %hash; my %hash;
@sect = grep { $hash{$_}++; $hash{$_} <= 1 } map { int( (rand()**4)*100) } 0..( int(rand()*5) ); @sect =
grep { $hash{$_}++; $hash{$_} <= 1 }
map { int((rand()**4) * 100) } 0 .. (int(rand() * 5));
} }
if ( $#sect < 0 || rand() < 0.1 ) { if ($#sect < 0 || rand() < 0.1)
{
print MSG "$i\t\\N\n"; print MSG "$i\t\\N\n";
} else { }
print MSG "$i\t{".join(',',@sect)."}\n"; else
{
print MSG "$i\t{" . join(',', @sect) . "}\n";
map { print MAP "$i\t$_\n" } @sect; map { print MAP "$i\t$_\n" } @sect;
} }
} }
...@@ -64,12 +74,13 @@ EOT ...@@ -64,12 +74,13 @@ EOT
unlink 'message.tmp', 'message_section_map.tmp'; unlink 'message.tmp', 'message_section_map.tmp';
sub copytable { sub copytable
{
my $t = shift; my $t = shift;
print "COPY $t from stdin;\n"; print "COPY $t from stdin;\n";
open( FFF, "$t.tmp") || die; open(FFF, "$t.tmp") || die;
while(<FFF>) { print; } while (<FFF>) { print; }
close FFF; close FFF;
print "\\.\n"; print "\\.\n";
} }
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
$integer = '[+-]?[0-9]+'; $integer = '[+-]?[0-9]+';
$real = '[+-]?[0-9]+\.[0-9]+'; $real = '[+-]?[0-9]+\.[0-9]+';
$RANGE = '(\.\.)(\.)?'; $RANGE = '(\.\.)(\.)?';
$PLUMIN = q(\'\+\-\'); $PLUMIN = q(\'\+\-\');
$FLOAT = "(($integer)|($real))([eE]($integer))?"; $FLOAT = "(($integer)|($real))([eE]($integer))?";
$EXTENSION = '<|>|~'; $EXTENSION = '<|>|~';
$boundary = "($EXTENSION)?$FLOAT"; $boundary = "($EXTENSION)?$FLOAT";
$deviation = $FLOAT; $deviation = $FLOAT;
$rule_1 = $boundary . $PLUMIN . $deviation; $rule_1 = $boundary . $PLUMIN . $deviation;
...@@ -18,25 +18,33 @@ $rule_5 = $boundary; ...@@ -18,25 +18,33 @@ $rule_5 = $boundary;
print "$rule_5\n"; print "$rule_5\n";
while (<>) { while (<>)
# s/ +//g; {
if ( /^($rule_1)$/ ) {
print; # s/ +//g;
} if (/^($rule_1)$/)
elsif ( /^($rule_2)$/ ) { {
print; print;
} }
elsif ( /^($rule_3)$/ ) { elsif (/^($rule_2)$/)
print; {
} print;
elsif ( /^($rule_4)$/ ) { }
print; elsif (/^($rule_3)$/)
} {
elsif ( /^($rule_5)$/ ) { print;
print; }
} elsif (/^($rule_4)$/)
else { {
print STDERR "error in $_\n"; print;
} }
elsif (/^($rule_5)$/)
{
print;
}
else
{
print STDERR "error in $_\n";
}
} }
...@@ -2,19 +2,22 @@ ...@@ -2,19 +2,22 @@
# this script will sort any table with the segment data type in its last column # this script will sort any table with the segment data type in its last column
while (<>) { while (<>)
chomp; {
push @rows, $_; chomp;
push @rows, $_;
} }
foreach ( sort { foreach (
@ar = split("\t", $a); sort {
$valA = pop @ar; @ar = split("\t", $a);
$valA =~ s/[~<> ]+//g; $valA = pop @ar;
@ar = split("\t", $b); $valA =~ s/[~<> ]+//g;
$valB = pop @ar; @ar = split("\t", $b);
$valB =~ s/[~<> ]+//g; $valB = pop @ar;
$valA <=> $valB $valB =~ s/[~<> ]+//g;
} @rows ) { $valA <=> $valB
print "$_\n";; } @rows)
{
print "$_\n";
} }
...@@ -6,51 +6,54 @@ ...@@ -6,51 +6,54 @@
use warnings; use warnings;
use strict; use strict;
print "<!-- autogenerated from src/backend/utils/errcodes.txt, do not edit -->\n"; print
"<!-- autogenerated from src/backend/utils/errcodes.txt, do not edit -->\n";
open my $errcodes, $ARGV[0] or die; open my $errcodes, $ARGV[0] or die;
while (<$errcodes>) { while (<$errcodes>)
chomp; {
chomp;
# Skip comments # Skip comments
next if /^#/; next if /^#/;
next if /^\s*$/; next if /^\s*$/;
# Emit section headers # Emit section headers
if (/^Section:/) { if (/^Section:/)
{
# Remove the Section: string # Remove the Section: string
s/^Section: //; s/^Section: //;
# Escape dashes for SGML
s/-/&mdash;/;
# Wrap PostgreSQL in <productname/>
s/PostgreSQL/<productname>PostgreSQL<\/>/g;
print "\n\n"; # Escape dashes for SGML
print "<row>\n"; s/-/&mdash;/;
print "<entry spanname=\"span12\">";
print "<emphasis role=\"bold\">$_</></entry>\n"; # Wrap PostgreSQL in <productname/>
print "</row>\n"; s/PostgreSQL/<productname>PostgreSQL<\/>/g;
next; print "\n\n";
} print "<row>\n";
print "<entry spanname=\"span12\">";
print "<emphasis role=\"bold\">$_</></entry>\n";
print "</row>\n";
die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/; next;
}
(my $sqlstate, die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/;
my $type,
my $errcode_macro,
my $condition_name) = ($1, $2, $3, $4);
# Skip lines without PL/pgSQL condition names (my $sqlstate, my $type, my $errcode_macro, my $condition_name) =
next unless defined($condition_name); ($1, $2, $3, $4);
print "\n"; # Skip lines without PL/pgSQL condition names
print "<row>\n"; next unless defined($condition_name);
print "<entry><literal>$sqlstate</literal></entry>\n";
print "<entry><symbol>$condition_name</symbol></entry>\n"; print "\n";
print "</row>\n"; print "<row>\n";
print "<entry><literal>$sqlstate</literal></entry>\n";
print "<entry><symbol>$condition_name</symbol></entry>\n";
print "</row>\n";
} }
close $errcodes; close $errcodes;
...@@ -25,34 +25,41 @@ process_file($infile); ...@@ -25,34 +25,41 @@ process_file($infile);
exit 0; exit 0;
sub process_file { sub process_file
my $filename = shift; {
my $filename = shift;
local *FILE; # need a local filehandle so we can recurse local *FILE; # need a local filehandle so we can recurse
my $f = $srcdir . '/' . $filename; my $f = $srcdir . '/' . $filename;
open(FILE, $f) || die "could not read $f: $!\n"; open(FILE, $f) || die "could not read $f: $!\n";
while (<FILE>) { while (<FILE>)
# Recursively expand sub-files of the release notes {
if (m/^&(release-.*);$/) {
process_file($1 . ".sgml");
next;
}
# Remove <link ...> tags, which might span multiple lines # Recursively expand sub-files of the release notes
while (m/<link/) { if (m/^&(release-.*);$/)
if (s/<link\s+linkend[^>]*>//) { {
next; process_file($1 . ".sgml");
} next;
# incomplete tag, so slurp another line }
$_ .= <FILE>;
} # Remove <link ...> tags, which might span multiple lines
while (m/<link/)
{
if (s/<link\s+linkend[^>]*>//)
{
next;
}
# Remove </link> too # incomplete tag, so slurp another line
s|</link>||g; $_ .= <FILE>;
}
print; # Remove </link> too
} s|</link>||g;
close(FILE);
print;
}
close(FILE);
} }
...@@ -8,14 +8,18 @@ open PACK, $ARGV[1] or die; ...@@ -8,14 +8,18 @@ open PACK, $ARGV[1] or die;
my %feature_packages; my %feature_packages;
while (<PACK>) { while (<PACK>)
chomp; {
my ($fid, $pname) = split /\t/; chomp;
if ($feature_packages{$fid}) { my ($fid, $pname) = split /\t/;
$feature_packages{$fid} .= ", $pname"; if ($feature_packages{$fid})
} else { {
$feature_packages{$fid} = $pname; $feature_packages{$fid} .= ", $pname";
} }
else
{
$feature_packages{$fid} = $pname;
}
} }
close PACK; close PACK;
...@@ -24,33 +28,41 @@ open FEAT, $ARGV[2] or die; ...@@ -24,33 +28,41 @@ open FEAT, $ARGV[2] or die;
print "<tbody>\n"; print "<tbody>\n";
while (<FEAT>) { while (<FEAT>)
chomp; {
my ($feature_id, $feature_name, $subfeature_id, $subfeature_name, $is_supported, $comments) = split /\t/; chomp;
my ($feature_id, $feature_name, $subfeature_id,
$is_supported eq $yesno || next; $subfeature_name, $is_supported, $comments) = split /\t/;
$feature_name =~ s/</&lt;/g; $is_supported eq $yesno || next;
$feature_name =~ s/>/&gt;/g;
$subfeature_name =~ s/</&lt;/g; $feature_name =~ s/</&lt;/g;
$subfeature_name =~ s/>/&gt;/g; $feature_name =~ s/>/&gt;/g;
$subfeature_name =~ s/</&lt;/g;
print " <row>\n"; $subfeature_name =~ s/>/&gt;/g;
if ($subfeature_id) { print " <row>\n";
print " <entry>$feature_id-$subfeature_id</entry>\n";
} else { if ($subfeature_id)
print " <entry>$feature_id</entry>\n"; {
} print " <entry>$feature_id-$subfeature_id</entry>\n";
print " <entry>" . $feature_packages{$feature_id} . "</entry>\n"; }
if ($subfeature_id) { else
print " <entry>$subfeature_name</entry>\n"; {
} else { print " <entry>$feature_id</entry>\n";
print " <entry>$feature_name</entry>\n"; }
} print " <entry>" . $feature_packages{$feature_id} . "</entry>\n";
print " <entry>$comments</entry>\n"; if ($subfeature_id)
{
print " </row>\n"; print " <entry>$subfeature_name</entry>\n";
}
else
{
print " <entry>$feature_name</entry>\n";
}
print " <entry>$comments</entry>\n";
print " </row>\n";
} }
print "</tbody>\n"; print "</tbody>\n";
......
This diff is collapsed.
This diff is collapsed.
...@@ -19,29 +19,29 @@ use strict; ...@@ -19,29 +19,29 @@ use strict;
use warnings; use warnings;
# Collect arguments # Collect arguments
my $infile; # pg_proc.h my $infile; # pg_proc.h
my $output_path = ''; my $output_path = '';
while (@ARGV) while (@ARGV)
{ {
my $arg = shift @ARGV; my $arg = shift @ARGV;
if ($arg !~ /^-/) if ($arg !~ /^-/)
{ {
$infile = $arg; $infile = $arg;
} }
elsif ($arg =~ /^-o/) elsif ($arg =~ /^-o/)
{ {
$output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV; $output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV;
} }
else else
{ {
usage(); usage();
} }
} }
# Make sure output_path ends in a slash. # Make sure output_path ends in a slash.
if ($output_path ne '' && substr($output_path, -1) ne '/') if ($output_path ne '' && substr($output_path, -1) ne '/')
{ {
$output_path .= '/'; $output_path .= '/';
} }
# Read all the data from the include/catalog files. # Read all the data from the include/catalog files.
...@@ -50,48 +50,47 @@ my $catalogs = Catalog::Catalogs($infile); ...@@ -50,48 +50,47 @@ my $catalogs = Catalog::Catalogs($infile);
# Collect the raw data from pg_proc.h. # Collect the raw data from pg_proc.h.
my @fmgr = (); my @fmgr = ();
my @attnames; my @attnames;
foreach my $column ( @{ $catalogs->{pg_proc}->{columns} } ) foreach my $column (@{ $catalogs->{pg_proc}->{columns} })
{ {
push @attnames, keys %$column; push @attnames, keys %$column;
} }
my $data = $catalogs->{pg_proc}->{data}; my $data = $catalogs->{pg_proc}->{data};
foreach my $row (@$data) foreach my $row (@$data)
{ {
# To construct fmgroids.h and fmgrtab.c, we need to inspect some
# of the individual data fields. Just splitting on whitespace # To construct fmgroids.h and fmgrtab.c, we need to inspect some
# won't work, because some quoted fields might contain internal # of the individual data fields. Just splitting on whitespace
# whitespace. We handle this by folding them all to a simple # won't work, because some quoted fields might contain internal
# "xxx". Fortunately, this script doesn't need to look at any # whitespace. We handle this by folding them all to a simple
# fields that might need quoting, so this simple hack is # "xxx". Fortunately, this script doesn't need to look at any
# sufficient. # fields that might need quoting, so this simple hack is
$row->{bki_values} =~ s/"[^"]*"/"xxx"/g; # sufficient.
@{$row}{@attnames} = split /\s+/, $row->{bki_values}; $row->{bki_values} =~ s/"[^"]*"/"xxx"/g;
@{$row}{@attnames} = split /\s+/, $row->{bki_values};
# Select out just the rows for internal-language procedures.
# Note assumption here that INTERNALlanguageId is 12. # Select out just the rows for internal-language procedures.
next if $row->{prolang} ne '12'; # Note assumption here that INTERNALlanguageId is 12.
next if $row->{prolang} ne '12';
push @fmgr,
{ push @fmgr,
oid => $row->{oid}, { oid => $row->{oid},
strict => $row->{proisstrict}, strict => $row->{proisstrict},
retset => $row->{proretset}, retset => $row->{proretset},
nargs => $row->{pronargs}, nargs => $row->{pronargs},
prosrc => $row->{prosrc}, prosrc => $row->{prosrc}, };
};
# Hack to work around memory leak in some versions of Perl
# Hack to work around memory leak in some versions of Perl $row = undef;
$row = undef;
} }
# Emit headers for both files # Emit headers for both files
my $tmpext = ".tmp$$"; my $tmpext = ".tmp$$";
my $oidsfile = $output_path . 'fmgroids.h'; my $oidsfile = $output_path . 'fmgroids.h';
my $tabfile = $output_path . 'fmgrtab.c'; my $tabfile = $output_path . 'fmgrtab.c';
open H, '>', $oidsfile . $tmpext or die "Could not open $oidsfile$tmpext: $!"; open H, '>', $oidsfile . $tmpext or die "Could not open $oidsfile$tmpext: $!";
open T, '>', $tabfile . $tmpext or die "Could not open $tabfile$tmpext: $!"; open T, '>', $tabfile . $tmpext or die "Could not open $tabfile$tmpext: $!";
print H print H
qq|/*------------------------------------------------------------------------- qq|/*-------------------------------------------------------------------------
...@@ -160,12 +159,12 @@ qq|/*------------------------------------------------------------------------- ...@@ -160,12 +159,12 @@ qq|/*-------------------------------------------------------------------------
# Emit #define's and extern's -- only one per prosrc value # Emit #define's and extern's -- only one per prosrc value
my %seenit; my %seenit;
foreach my $s (sort {$a->{oid} <=> $b->{oid}} @fmgr) foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
{ {
next if $seenit{$s->{prosrc}}; next if $seenit{ $s->{prosrc} };
$seenit{$s->{prosrc}} = 1; $seenit{ $s->{prosrc} } = 1;
print H "#define F_" . uc $s->{prosrc} . " $s->{oid}\n"; print H "#define F_" . uc $s->{prosrc} . " $s->{oid}\n";
print T "extern Datum $s->{prosrc} (PG_FUNCTION_ARGS);\n"; print T "extern Datum $s->{prosrc} (PG_FUNCTION_ARGS);\n";
} }
# Create the fmgr_builtins table # Create the fmgr_builtins table
...@@ -173,10 +172,10 @@ print T "\nconst FmgrBuiltin fmgr_builtins[] = {\n"; ...@@ -173,10 +172,10 @@ print T "\nconst FmgrBuiltin fmgr_builtins[] = {\n";
my %bmap; my %bmap;
$bmap{'t'} = 'true'; $bmap{'t'} = 'true';
$bmap{'f'} = 'false'; $bmap{'f'} = 'false';
foreach my $s (sort {$a->{oid} <=> $b->{oid}} @fmgr) foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
{ {
print T print T
" { $s->{oid}, \"$s->{prosrc}\", $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, $s->{prosrc} },\n"; " { $s->{oid}, \"$s->{prosrc}\", $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, $s->{prosrc} },\n";
} }
# And add the file footers. # And add the file footers.
...@@ -198,11 +197,11 @@ close(T); ...@@ -198,11 +197,11 @@ close(T);
# Finally, rename the completed files into place. # Finally, rename the completed files into place.
Catalog::RenameTempFile($oidsfile, $tmpext); Catalog::RenameTempFile($oidsfile, $tmpext);
Catalog::RenameTempFile($tabfile, $tmpext); Catalog::RenameTempFile($tabfile, $tmpext);
sub usage sub usage
{ {
die <<EOM; die <<EOM;
Usage: perl -I [directory of Catalog.pm] Gen_fmgrtab.pl [path to pg_proc.h] Usage: perl -I [directory of Catalog.pm] Gen_fmgrtab.pl [path to pg_proc.h]
Gen_fmgrtab.pl generates fmgroids.h and fmgrtab.c from pg_proc.h Gen_fmgrtab.pl generates fmgroids.h and fmgrtab.c from pg_proc.h
......
...@@ -6,36 +6,41 @@ ...@@ -6,36 +6,41 @@
use warnings; use warnings;
use strict; use strict;
print "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n"; print
"/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
print "/* there is deliberately not an #ifndef ERRCODES_H here */\n"; print "/* there is deliberately not an #ifndef ERRCODES_H here */\n";
open my $errcodes, $ARGV[0] or die; open my $errcodes, $ARGV[0] or die;
while (<$errcodes>) { while (<$errcodes>)
chomp; {
chomp;
# Skip comments # Skip comments
next if /^#/; next if /^#/;
next if /^\s*$/; next if /^\s*$/;
# Emit a comment for each section header # Emit a comment for each section header
if (/^Section:(.*)/) { if (/^Section:(.*)/)
{
my $header = $1; my $header = $1;
$header =~ s/^\s+//; $header =~ s/^\s+//;
print "\n/* $header */\n"; print "\n/* $header */\n";
next; next;
} }
die "unable to parse errcodes.txt" unless /^([^\s]{5})\s+[EWS]\s+([^\s]+)/; die "unable to parse errcodes.txt"
unless /^([^\s]{5})\s+[EWS]\s+([^\s]+)/;
(my $sqlstate, my $errcode_macro) = ($1, $2); (my $sqlstate, my $errcode_macro) = ($1, $2);
# Split the sqlstate letters # Split the sqlstate letters
$sqlstate = join ",", split "", $sqlstate; $sqlstate = join ",", split "", $sqlstate;
# And quote them
$sqlstate =~ s/([^,])/'$1'/g;
print "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n"; # And quote them
$sqlstate =~ s/([^,])/'$1'/g;
print "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n";
} }
close $errcodes; close $errcodes;
...@@ -33,68 +33,82 @@ require "ucs2utf.pl"; ...@@ -33,68 +33,82 @@ require "ucs2utf.pl";
# #
$in_file = "BIG5.TXT"; $in_file = "BIG5.TXT";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
reset 'array'; reset 'array';
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $utf } ne "" ){ if ($array{$utf} ne "")
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; {
printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$array{ $utf } = $code; $array{$utf} = $code;
} }
} }
close( FILE ); close(FILE);
$in_file = "CP950.TXT"; $in_file = "CP950.TXT";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
# Pick only the ETEN extended characters in the range 0xf9d6 - 0xf9dc # Pick only the ETEN extended characters in the range 0xf9d6 - 0xf9dc
# from CP950.TXT # from CP950.TXT
if( $code >= 0x80 && $ucs >= 0x0080 && if ( $code >= 0x80
$code >= 0xf9d6 && $code <= 0xf9dc ){ && $ucs >= 0x0080
&& $code >= 0xf9d6
&& $code <= 0xf9dc)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $utf } ne "" ){ if ($array{$utf} ne "")
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; {
printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$array{ $utf } = $code; $array{$utf} = $code;
} }
} }
close( FILE ); close(FILE);
$file = lc("utf8_to_big5.map"); $file = lc("utf8_to_big5.map");
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_utf_to_local ULmapBIG5[ $count ] = {\n"; print FILE "static pg_utf_to_local ULmapBIG5[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$code = $array{ $index }; {
$code = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $code; printf FILE " {0x%04x, 0x%04x}\n", $index, $code;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $code; printf FILE " {0x%04x, 0x%04x},\n", $index, $code;
} }
} }
...@@ -107,67 +121,81 @@ close(FILE); ...@@ -107,67 +121,81 @@ close(FILE);
# #
$in_file = "BIG5.TXT"; $in_file = "BIG5.TXT";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
reset 'array'; reset 'array';
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $utf } ne "" ){ if ($array{$utf} ne "")
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; {
printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$array{ $code } = $utf; $array{$code} = $utf;
} }
} }
close( FILE ); close(FILE);
$in_file = "CP950.TXT"; $in_file = "CP950.TXT";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
# Pick only the ETEN extended characters in the range 0xf9d6 - 0xf9dc # Pick only the ETEN extended characters in the range 0xf9d6 - 0xf9dc
# from CP950.TXT # from CP950.TXT
if( $code >= 0x80 && $ucs >= 0x0080 && if ( $code >= 0x80
$code >= 0xf9d6 && $code <= 0xf9dc ){ && $ucs >= 0x0080
&& $code >= 0xf9d6
&& $code <= 0xf9dc)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $utf } ne "" ){ if ($array{$utf} ne "")
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; {
printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$array{ $code } = $utf; $array{$code} = $utf;
} }
} }
close( FILE ); close(FILE);
$file = lc("big5_to_utf8.map"); $file = lc("big5_to_utf8.map");
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_local_to_utf LUmapBIG5[ $count ] = {\n"; print FILE "static pg_local_to_utf LUmapBIG5[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$utf = $array{ $index }; {
$utf = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; printf FILE " {0x%04x, 0x%04x}\n", $index, $utf;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; printf FILE " {0x%04x, 0x%04x},\n", $index, $utf;
} }
} }
......
...@@ -22,43 +22,51 @@ require "ucs2utf.pl"; ...@@ -22,43 +22,51 @@ require "ucs2utf.pl";
$in_file = "GB2312.TXT"; $in_file = "GB2312.TXT";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $utf } ne "" ){ if ($array{$utf} ne "")
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; {
printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$array{ $utf } = ($code | 0x8080); $array{$utf} = ($code | 0x8080);
} }
} }
close( FILE ); close(FILE);
# #
# first, generate UTF8 --> EUC_CN table # first, generate UTF8 --> EUC_CN table
# #
$file = "utf8_to_euc_cn.map"; $file = "utf8_to_euc_cn.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_utf_to_local ULmapEUC_CN[ $count ] = {\n"; print FILE "static pg_utf_to_local ULmapEUC_CN[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$code = $array{ $index }; {
$code = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $code; printf FILE " {0x%04x, 0x%04x}\n", $index, $code;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $code; printf FILE " {0x%04x, 0x%04x},\n", $index, $code;
} }
} }
...@@ -71,39 +79,47 @@ close(FILE); ...@@ -71,39 +79,47 @@ close(FILE);
# #
reset 'array'; reset 'array';
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $code } ne "" ){ if ($array{$code} ne "")
printf STDERR "Warning: duplicate code: %04x\n",$ucs; {
printf STDERR "Warning: duplicate code: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$code |= 0x8080; $code |= 0x8080;
$array{ $code } = $utf; $array{$code} = $utf;
} }
} }
close( FILE ); close(FILE);
$file = "euc_cn_to_utf8.map"; $file = "euc_cn_to_utf8.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_local_to_utf LUmapEUC_CN[ $count ] = {\n"; print FILE "static pg_local_to_utf LUmapEUC_CN[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$utf = $array{ $index }; {
$utf = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; printf FILE " {0x%04x, 0x%04x}\n", $index, $utf;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; printf FILE " {0x%04x, 0x%04x},\n", $index, $utf;
} }
} }
......
...@@ -36,102 +36,118 @@ require "ucs2utf.pl"; ...@@ -36,102 +36,118 @@ require "ucs2utf.pl";
# #
$in_file = "JIS0201.TXT"; $in_file = "JIS0201.TXT";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
reset 'array'; reset 'array';
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $utf } ne "" ){ if ($array{$utf} ne "")
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; {
printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
# add single shift 2 # add single shift 2
$array{ $utf } = ($code | 0x8e00); $array{$utf} = ($code | 0x8e00);
} }
} }
close( FILE ); close(FILE);
# #
# JIS0208 # JIS0208
# #
$in_file = "JIS0208.TXT"; $in_file = "JIS0208.TXT";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $s, $c, $u, $rest ) = split; ($s, $c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $utf } ne "" ){ if ($array{$utf} ne "")
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; {
printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$array{ $utf } = ($code | 0x8080); $array{$utf} = ($code | 0x8080);
} }
} }
close( FILE ); close(FILE);
# #
# JIS0212 # JIS0212
# #
$in_file = "JIS0212.TXT"; $in_file = "JIS0212.TXT";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $utf } ne "" ){ if ($array{$utf} ne "")
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; {
printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$array{ $utf } = ($code | 0x8f8080); $array{$utf} = ($code | 0x8f8080);
} }
} }
close( FILE ); close(FILE);
# #
# first, generate UTF8 --> EUC_JP table # first, generate UTF8 --> EUC_JP table
# #
$file = "utf8_to_euc_jp.map"; $file = "utf8_to_euc_jp.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_utf_to_local ULmapEUC_JP[ $count ] = {\n"; print FILE "static pg_utf_to_local ULmapEUC_JP[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$code = $array{ $index }; {
$code = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $code; printf FILE " {0x%04x, 0x%04x}\n", $index, $code;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $code; printf FILE " {0x%04x, 0x%04x},\n", $index, $code;
} }
} }
...@@ -148,100 +164,116 @@ close(FILE); ...@@ -148,100 +164,116 @@ close(FILE);
# #
$in_file = "JIS0201.TXT"; $in_file = "JIS0201.TXT";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
reset 'array'; reset 'array';
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $code } ne "" ){ if ($array{$code} ne "")
printf STDERR "Warning: duplicate code: %04x\n",$ucs; {
printf STDERR "Warning: duplicate code: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
# add single shift 2 # add single shift 2
$code |= 0x8e00; $code |= 0x8e00;
$array{ $code } = $utf; $array{$code} = $utf;
} }
} }
close( FILE ); close(FILE);
# #
# JIS0208 # JIS0208
# #
$in_file = "JIS0208.TXT"; $in_file = "JIS0208.TXT";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $s, $c, $u, $rest ) = split; ($s, $c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $code } ne "" ){ if ($array{$code} ne "")
printf STDERR "Warning: duplicate code: %04x\n",$ucs; {
printf STDERR "Warning: duplicate code: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$code |= 0x8080; $code |= 0x8080;
$array{ $code } = $utf; $array{$code} = $utf;
} }
} }
close( FILE ); close(FILE);
# #
# JIS0212 # JIS0212
# #
$in_file = "JIS0212.TXT"; $in_file = "JIS0212.TXT";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $code } ne "" ){ if ($array{$code} ne "")
printf STDERR "Warning: duplicate code: %04x\n",$ucs; {
printf STDERR "Warning: duplicate code: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$code |= 0x8f8080; $code |= 0x8f8080;
$array{ $code } = $utf; $array{$code} = $utf;
} }
} }
close( FILE ); close(FILE);
$file = "euc_jp_to_utf8.map"; $file = "euc_jp_to_utf8.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_local_to_utf LUmapEUC_JP[ $count ] = {\n"; print FILE "static pg_local_to_utf LUmapEUC_JP[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$utf = $array{ $index }; {
$utf = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; printf FILE " {0x%04x, 0x%04x}\n", $index, $utf;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; printf FILE " {0x%04x, 0x%04x},\n", $index, $utf;
} }
} }
......
...@@ -22,43 +22,51 @@ require "ucs2utf.pl"; ...@@ -22,43 +22,51 @@ require "ucs2utf.pl";
$in_file = "KSX1001.TXT"; $in_file = "KSX1001.TXT";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $utf } ne "" ){ if ($array{$utf} ne "")
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; {
printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$array{ $utf } = ($code | 0x8080); $array{$utf} = ($code | 0x8080);
} }
} }
close( FILE ); close(FILE);
# #
# first, generate UTF8 --> EUC_KR table # first, generate UTF8 --> EUC_KR table
# #
$file = "utf8_to_euc_kr.map"; $file = "utf8_to_euc_kr.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_utf_to_local ULmapEUC_KR[ $count ] = {\n"; print FILE "static pg_utf_to_local ULmapEUC_KR[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$code = $array{ $index }; {
$code = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $code; printf FILE " {0x%04x, 0x%04x}\n", $index, $code;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $code; printf FILE " {0x%04x, 0x%04x},\n", $index, $code;
} }
} }
...@@ -71,39 +79,47 @@ close(FILE); ...@@ -71,39 +79,47 @@ close(FILE);
# #
reset 'array'; reset 'array';
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $code } ne "" ){ if ($array{$code} ne "")
printf STDERR "Warning: duplicate code: %04x\n",$ucs; {
printf STDERR "Warning: duplicate code: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$code |= 0x8080; $code |= 0x8080;
$array{ $code } = $utf; $array{$code} = $utf;
} }
} }
close( FILE ); close(FILE);
$file = "euc_kr_to_utf8.map"; $file = "euc_kr_to_utf8.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_local_to_utf LUmapEUC_KR[ $count ] = {\n"; print FILE "static pg_local_to_utf LUmapEUC_KR[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$utf = $array{ $index }; {
$utf = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; printf FILE " {0x%04x, 0x%04x}\n", $index, $utf;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; printf FILE " {0x%04x, 0x%04x},\n", $index, $utf;
} }
} }
......
...@@ -23,53 +23,66 @@ require "ucs2utf.pl"; ...@@ -23,53 +23,66 @@ require "ucs2utf.pl";
$in_file = "CNS11643.TXT"; $in_file = "CNS11643.TXT";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $utf } ne "" ){ if ($array{$utf} ne "")
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; {
printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$plane = ($code & 0x1f0000) >> 16; $plane = ($code & 0x1f0000) >> 16;
if ($plane > 16) { if ($plane > 16)
{
printf STDERR "Warning: invalid plane No.$plane. ignored\n"; printf STDERR "Warning: invalid plane No.$plane. ignored\n";
next; next;
} }
if ($plane == 1) { if ($plane == 1)
$array{ $utf } = (($code & 0xffff) | 0x8080); {
} else { $array{$utf} = (($code & 0xffff) | 0x8080);
$array{ $utf } = (0x8ea00000 + ($plane << 16)) | (($code & 0xffff) | 0x8080); }
else
{
$array{$utf} =
(0x8ea00000 + ($plane << 16)) | (($code & 0xffff) | 0x8080);
} }
} }
} }
close( FILE ); close(FILE);
# #
# first, generate UTF8 --> EUC_TW table # first, generate UTF8 --> EUC_TW table
# #
$file = "utf8_to_euc_tw.map"; $file = "utf8_to_euc_tw.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_utf_to_local ULmapEUC_TW[ $count ] = {\n"; print FILE "static pg_utf_to_local ULmapEUC_TW[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$code = $array{ $index }; {
$code = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $code; printf FILE " {0x%04x, 0x%04x}\n", $index, $code;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $code; printf FILE " {0x%04x, 0x%04x},\n", $index, $code;
} }
} }
...@@ -82,50 +95,60 @@ close(FILE); ...@@ -82,50 +95,60 @@ close(FILE);
# #
reset 'array'; reset 'array';
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $code } ne "" ){ if ($array{$code} ne "")
printf STDERR "Warning: duplicate code: %04x\n",$ucs; {
printf STDERR "Warning: duplicate code: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$plane = ($code & 0x1f0000) >> 16; $plane = ($code & 0x1f0000) >> 16;
if ($plane > 16) { if ($plane > 16)
{
printf STDERR "Warning: invalid plane No.$plane. ignored\n"; printf STDERR "Warning: invalid plane No.$plane. ignored\n";
next; next;
} }
if ($plane == 1) { if ($plane == 1)
{
$c = (($code & 0xffff) | 0x8080); $c = (($code & 0xffff) | 0x8080);
$array{ $c } = $utf; $array{$c} = $utf;
$count++; $count++;
} }
$c = (0x8ea00000 + ($plane << 16)) | (($code & 0xffff) | 0x8080); $c = (0x8ea00000 + ($plane << 16)) | (($code & 0xffff) | 0x8080);
$array{ $c } = $utf; $array{$c} = $utf;
} }
} }
close( FILE ); close(FILE);
$file = "euc_tw_to_utf8.map"; $file = "euc_tw_to_utf8.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_local_to_utf LUmapEUC_TW[ $count ] = {\n"; print FILE "static pg_local_to_utf LUmapEUC_TW[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$utf = $array{ $index }; {
$utf = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; printf FILE " {0x%04x, 0x%04x}\n", $index, $utf;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; printf FILE " {0x%04x, 0x%04x},\n", $index, $utf;
} }
} }
......
...@@ -18,28 +18,32 @@ require "ucs2utf.pl"; ...@@ -18,28 +18,32 @@ require "ucs2utf.pl";
$in_file = "ISO10646-GB18030.TXT"; $in_file = "ISO10646-GB18030.TXT";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $u, $c, $rest ) = split; ($u, $c, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $utf } ne "" ){ if ($array{$utf} ne "")
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; {
printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$array{ $utf } = $code; $array{$utf} = $code;
} }
} }
close( FILE ); close(FILE);
# #
...@@ -47,15 +51,19 @@ close( FILE ); ...@@ -47,15 +51,19 @@ close( FILE );
# #
$file = "utf8_to_gb18030.map"; $file = "utf8_to_gb18030.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_utf_to_local ULmapGB18030[ $count ] = {\n"; print FILE "static pg_utf_to_local ULmapGB18030[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$code = $array{ $index }; {
$code = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $code; printf FILE " {0x%04x, 0x%04x}\n", $index, $code;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $code; printf FILE " {0x%04x, 0x%04x},\n", $index, $code;
} }
} }
...@@ -69,38 +77,46 @@ close(FILE); ...@@ -69,38 +77,46 @@ close(FILE);
# #
reset 'array'; reset 'array';
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $u, $c, $rest ) = split; ($u, $c, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $code } ne "" ){ if ($array{$code} ne "")
printf STDERR "Warning: duplicate code: %04x\n",$ucs; {
printf STDERR "Warning: duplicate code: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$array{ $code } = $utf; $array{$code} = $utf;
} }
} }
close( FILE ); close(FILE);
$file = "gb18030_to_utf8.map"; $file = "gb18030_to_utf8.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_local_to_utf LUmapGB18030[ $count ] = {\n"; print FILE "static pg_local_to_utf LUmapGB18030[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$utf = $array{ $index }; {
$utf = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; printf FILE " {0x%04x, 0x%04x}\n", $index, $utf;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; printf FILE " {0x%04x, 0x%04x},\n", $index, $utf;
} }
} }
......
...@@ -13,65 +13,80 @@ require "ucs2utf.pl"; ...@@ -13,65 +13,80 @@ require "ucs2utf.pl";
$in_file = "sjis-0213-2004-std.txt"; $in_file = "sjis-0213-2004-std.txt";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
reset 'array'; reset 'array';
reset 'array1'; reset 'array1';
reset 'comment'; reset 'comment';
reset 'comment1'; reset 'comment1';
while($line = <FILE> ){ while ($line = <FILE>)
if ($line =~ /^0x(.*)[ \t]*U\+(.*)\+(.*)[ \t]*#(.*)$/) { {
$c = $1; if ($line =~ /^0x(.*)[ \t]*U\+(.*)\+(.*)[ \t]*#(.*)$/)
$u1 = $2; {
$u2 = $3; $c = $1;
$rest = "U+" . $u1 . "+" . $u2 . $4; $u1 = $2;
$code = hex($c); $u2 = $3;
$ucs = hex($u1); $rest = "U+" . $u1 . "+" . $u2 . $4;
$utf1 = &ucs2utf($ucs); $code = hex($c);
$ucs = hex($u2); $ucs = hex($u1);
$utf2 = &ucs2utf($ucs); $utf1 = &ucs2utf($ucs);
$str = sprintf "%08x%08x", $utf1, $utf2; $ucs = hex($u2);
$array1{ $str } = $code; $utf2 = &ucs2utf($ucs);
$comment1{ $str } = $rest; $str = sprintf "%08x%08x", $utf1, $utf2;
$array1{$str} = $code;
$comment1{$str} = $rest;
$count1++; $count1++;
next; next;
} elsif ($line =~ /^0x(.*)[ \t]*U\+(.*)[ \t]*#(.*)$/) { }
$c = $1; elsif ($line =~ /^0x(.*)[ \t]*U\+(.*)[ \t]*#(.*)$/)
$u = $2; {
$c = $1;
$u = $2;
$rest = "U+" . $u . $3; $rest = "U+" . $u . $3;
} else { }
else
{
next; next;
} }
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $utf } ne "" ){ if ($array{$utf} ne "")
printf STDERR "Warning: duplicate UTF8: %08x UCS: %04x Shift JIS: %04x\n",$utf, $ucs, $code; {
printf STDERR
"Warning: duplicate UTF8: %08x UCS: %04x Shift JIS: %04x\n", $utf,
$ucs, $code;
next; next;
} }
$count++; $count++;
$array{ $utf } = $code; $array{$utf} = $code;
$comment{ $code } = $rest; $comment{$code} = $rest;
} }
close( FILE ); close(FILE);
$file = "utf8_to_shift_jis_2004.map"; $file = "utf8_to_shift_jis_2004.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "/*\n"; print FILE "/*\n";
print FILE " * This file was generated by UCS_to_SHIFT_JIS_2004.pl\n"; print FILE " * This file was generated by UCS_to_SHIFT_JIS_2004.pl\n";
print FILE " */\n"; print FILE " */\n";
print FILE "static pg_utf_to_local ULmapSHIFT_JIS_2004[] = {\n"; print FILE "static pg_utf_to_local ULmapSHIFT_JIS_2004[] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$code = $array{ $index }; {
$code = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
printf FILE " {0x%08x, 0x%06x} /* %s */\n", $index, $code, $comment{ $code }; {
} else { printf FILE " {0x%08x, 0x%06x} /* %s */\n", $index, $code,
printf FILE " {0x%08x, 0x%06x}, /* %s */\n", $index, $code, $comment{ $code }; $comment{$code};
}
else
{
printf FILE " {0x%08x, 0x%06x}, /* %s */\n", $index, $code,
$comment{$code};
} }
} }
...@@ -79,19 +94,27 @@ print FILE "};\n"; ...@@ -79,19 +94,27 @@ print FILE "};\n";
close(FILE); close(FILE);
$file = "utf8_to_shift_jis_2004_combined.map"; $file = "utf8_to_shift_jis_2004_combined.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "/*\n"; print FILE "/*\n";
print FILE " * This file was generated by UCS_to_SHIFT_JIS_2004.pl\n"; print FILE " * This file was generated by UCS_to_SHIFT_JIS_2004.pl\n";
print FILE " */\n"; print FILE " */\n";
print FILE "static pg_utf_to_local_combined ULmapSHIFT_JIS_2004_combined[] = {\n"; print FILE
"static pg_utf_to_local_combined ULmapSHIFT_JIS_2004_combined[] = {\n";
for $index ( sort {$a cmp $b} keys( %array1 ) ){ for $index (sort { $a cmp $b } keys(%array1))
$code = $array1{ $index }; {
$code = $array1{$index};
$count1--; $count1--;
if( $count1 == 0 ){ if ($count1 == 0)
printf FILE " {0x%s, 0x%s, 0x%04x} /* %s */\n", substr($index, 0, 8), substr($index, 8, 8), $code, $comment1{ $index }; {
} else { printf FILE " {0x%s, 0x%s, 0x%04x} /* %s */\n", substr($index, 0, 8),
printf FILE " {0x%s, 0x%s, 0x%04x}, /* %s */\n", substr($index, 0, 8), substr($index, 8, 8), $code, $comment1{ $index }; substr($index, 8, 8), $code, $comment1{$index};
}
else
{
printf FILE " {0x%s, 0x%s, 0x%04x}, /* %s */\n",
substr($index, 0, 8), substr($index, 8, 8), $code,
$comment1{$index};
} }
} }
...@@ -102,66 +125,81 @@ close(FILE); ...@@ -102,66 +125,81 @@ close(FILE);
$in_file = "sjis-0213-2004-std.txt"; $in_file = "sjis-0213-2004-std.txt";
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
reset 'array'; reset 'array';
reset 'array1'; reset 'array1';
reset 'comment'; reset 'comment';
reset 'comment1'; reset 'comment1';
while($line = <FILE> ){ while ($line = <FILE>)
if ($line =~ /^0x(.*)[ \t]*U\+(.*)\+(.*)[ \t]*#(.*)$/) { {
$c = $1; if ($line =~ /^0x(.*)[ \t]*U\+(.*)\+(.*)[ \t]*#(.*)$/)
$u1 = $2; {
$u2 = $3; $c = $1;
$rest = "U+" . $u1 . "+" . $u2 . $4; $u1 = $2;
$code = hex($c); $u2 = $3;
$ucs = hex($u1); $rest = "U+" . $u1 . "+" . $u2 . $4;
$utf1 = &ucs2utf($ucs); $code = hex($c);
$ucs = hex($u2); $ucs = hex($u1);
$utf2 = &ucs2utf($ucs); $utf1 = &ucs2utf($ucs);
$str = sprintf "%08x%08x", $utf1, $utf2; $ucs = hex($u2);
$array1{ $code } = $str; $utf2 = &ucs2utf($ucs);
$comment1{ $code } = $rest; $str = sprintf "%08x%08x", $utf1, $utf2;
$array1{$code} = $str;
$comment1{$code} = $rest;
$count1++; $count1++;
next; next;
} elsif ($line =~ /^0x(.*)[ \t]*U\+(.*)[ \t]*#(.*)$/) { }
$c = $1; elsif ($line =~ /^0x(.*)[ \t]*U\+(.*)[ \t]*#(.*)$/)
$u = $2; {
$c = $1;
$u = $2;
$rest = "U+" . $u . $3; $rest = "U+" . $u . $3;
} else { }
else
{
next; next;
} }
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $code } ne "" ){ if ($array{$code} ne "")
printf STDERR "Warning: duplicate UTF-8: %08x UCS: %04x Shift JIS: %04x\n",$utf, $ucs, $code; {
printf STDERR "Previous value: UTF-8: %08x\n", $array{ $utf }; printf STDERR
"Warning: duplicate UTF-8: %08x UCS: %04x Shift JIS: %04x\n", $utf,
$ucs, $code;
printf STDERR "Previous value: UTF-8: %08x\n", $array{$utf};
next; next;
} }
$count++; $count++;
$array{ $code } = $utf; $array{$code} = $utf;
$comment{ $utf } = $rest; $comment{$utf} = $rest;
} }
close( FILE ); close(FILE);
$file = "shift_jis_2004_to_utf8.map"; $file = "shift_jis_2004_to_utf8.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "/*\n"; print FILE "/*\n";
print FILE " * This file was generated by UCS_to_SHIFTJIS_2004.pl\n"; print FILE " * This file was generated by UCS_to_SHIFTJIS_2004.pl\n";
print FILE " */\n"; print FILE " */\n";
print FILE "static pg_local_to_utf LUmapSHIFT_JIS_2004[] = {\n"; print FILE "static pg_local_to_utf LUmapSHIFT_JIS_2004[] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$code = $array{ $index }; {
$code = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
printf FILE " {0x%04x, 0x%08x} /* %s */\n", $index, $code, $comment{ $code }; {
} else { printf FILE " {0x%04x, 0x%08x} /* %s */\n", $index, $code,
printf FILE " {0x%04x, 0x%08x}, /* %s */\n", $index, $code, $comment{ $code }; $comment{$code};
}
else
{
printf FILE " {0x%04x, 0x%08x}, /* %s */\n", $index, $code,
$comment{$code};
} }
} }
...@@ -169,19 +207,26 @@ print FILE "};\n"; ...@@ -169,19 +207,26 @@ print FILE "};\n";
close(FILE); close(FILE);
$file = "shift_jis_2004_to_utf8_combined.map"; $file = "shift_jis_2004_to_utf8_combined.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "/*\n"; print FILE "/*\n";
print FILE " * This file was generated by UCS_to_SHIFT_JIS_2004.pl\n"; print FILE " * This file was generated by UCS_to_SHIFT_JIS_2004.pl\n";
print FILE " */\n"; print FILE " */\n";
print FILE "static pg_local_to_utf_combined LUmapSHIFT_JIS_2004_combined[] = {\n"; print FILE
"static pg_local_to_utf_combined LUmapSHIFT_JIS_2004_combined[] = {\n";
for $index ( sort {$a <=> $b} keys( %array1 ) ){ for $index (sort { $a <=> $b } keys(%array1))
$code = $array1{ $index }; {
$code = $array1{$index};
$count1--; $count1--;
if( $count1 == 0 ){ if ($count1 == 0)
printf FILE " {0x%04x, 0x%s, 0x%s} /* %s */\n", $index, substr($code, 0, 8), substr($code, 8, 8), $comment1{ $index }; {
} else { printf FILE " {0x%04x, 0x%s, 0x%s} /* %s */\n", $index,
printf FILE " {0x%04x, 0x%s, 0x%s}, /* %s */\n", $index, substr($code, 0, 8), substr($code, 8, 8), $comment1{ $index }; substr($code, 0, 8), substr($code, 8, 8), $comment1{$index};
}
else
{
printf FILE " {0x%04x, 0x%s, 0x%s}, /* %s */\n", $index,
substr($code, 0, 8), substr($code, 8, 8), $comment1{$index};
} }
} }
......
...@@ -22,60 +22,68 @@ require "ucs2utf.pl"; ...@@ -22,60 +22,68 @@ require "ucs2utf.pl";
# first generate UTF-8 --> SJIS table # first generate UTF-8 --> SJIS table
$in_file = "CP932.TXT"; $in_file = "CP932.TXT";
$count = 0; $count = 0;
open(FILE, $in_file) || die("cannot open $in_file");
open( FILE, $in_file ) || die( "cannot open $in_file" ); while (<FILE>)
{
while( <FILE> ){ chop;
chop; if (/^#/)
if( /^#/ ){ {
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
$utf = &ucs2utf($ucs); {
if((( $code >= 0xed40 ) $utf = &ucs2utf($ucs);
&& ( $code <= 0xeefc )) if ((($code >= 0xed40) && ($code <= 0xeefc))
|| (( $code >= 0x8754 ) || ( ($code >= 0x8754)
&&( $code <= 0x875d )) && ($code <= 0x875d))
|| ( $code == 0x878a ) || ($code == 0x878a)
|| ( $code == 0x8782 ) || ($code == 0x8782)
|| ( $code == 0x8784 ) || ($code == 0x8784)
|| ( $code == 0xfa5b ) || ($code == 0xfa5b)
|| ( $code == 0xfa54 ) || ($code == 0xfa54)
|| (( $code >= 0x8790 ) || ( ($code >= 0x8790)
&& ( $code <= 0x8792 )) && ($code <= 0x8792))
|| (( $code >= 0x8795 ) || ( ($code >= 0x8795)
&& ( $code <= 0x8797 )) && ($code <= 0x8797))
|| (( $code >= 0x879a ) || ( ($code >= 0x879a)
&& ( $code <= 0x879c ))) && ($code <= 0x879c)))
{ {
printf STDERR "Warning: duplicate UTF8 : UCS=0x%04x SJIS=0x%04x\n",$ucs,$code; printf STDERR
next; "Warning: duplicate UTF8 : UCS=0x%04x SJIS=0x%04x\n", $ucs,
} $code;
$count++; next;
$array{ $utf } = $code; }
} $count++;
$array{$utf} = $code;
}
} }
close( FILE ); close(FILE);
# #
# first, generate UTF8 --> SJIS table # first, generate UTF8 --> SJIS table
# #
$file = "utf8_to_sjis.map"; $file = "utf8_to_sjis.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_utf_to_local ULmapSJIS[ $count ] = {\n"; print FILE "static pg_utf_to_local ULmapSJIS[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$code = $array{ $index }; {
$code = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $code; printf FILE " {0x%04x, 0x%04x}\n", $index, $code;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $code; printf FILE " {0x%04x, 0x%04x},\n", $index, $code;
} }
} }
...@@ -87,37 +95,44 @@ close(FILE); ...@@ -87,37 +95,44 @@ close(FILE);
# then generate SJIS --> UTF8 table # then generate SJIS --> UTF8 table
# #
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
reset 'array'; reset 'array';
$count = 0; $count = 0;
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080 ){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
$count++; $count++;
$array{ $code } = $utf; $array{$code} = $utf;
} }
} }
close( FILE ); close(FILE);
$file = "sjis_to_utf8.map"; $file = "sjis_to_utf8.map";
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_local_to_utf LUmapSJIS[ $count ] = {\n"; print FILE "static pg_local_to_utf LUmapSJIS[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$utf = $array{ $index }; {
$utf = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; printf FILE " {0x%04x, 0x%04x}\n", $index, $utf;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; printf FILE " {0x%04x, 0x%04x},\n", $index, $utf;
} }
} }
......
...@@ -18,80 +18,88 @@ ...@@ -18,80 +18,88 @@
require "ucs2utf.pl"; require "ucs2utf.pl";
%filename = ( %filename = (
'WIN866' => 'CP866.TXT', 'WIN866' => 'CP866.TXT',
'WIN874' => 'CP874.TXT', 'WIN874' => 'CP874.TXT',
'WIN1250' => 'CP1250.TXT', 'WIN1250' => 'CP1250.TXT',
'WIN1251' => 'CP1251.TXT', 'WIN1251' => 'CP1251.TXT',
'WIN1252' => 'CP1252.TXT', 'WIN1252' => 'CP1252.TXT',
'WIN1253' => 'CP1253.TXT', 'WIN1253' => 'CP1253.TXT',
'WIN1254' => 'CP1254.TXT', 'WIN1254' => 'CP1254.TXT',
'WIN1255' => 'CP1255.TXT', 'WIN1255' => 'CP1255.TXT',
'WIN1256' => 'CP1256.TXT', 'WIN1256' => 'CP1256.TXT',
'WIN1257' => 'CP1257.TXT', 'WIN1257' => 'CP1257.TXT',
'WIN1258' => 'CP1258.TXT', 'WIN1258' => 'CP1258.TXT',
'ISO8859_2' => '8859-2.TXT', 'ISO8859_2' => '8859-2.TXT',
'ISO8859_3' => '8859-3.TXT', 'ISO8859_3' => '8859-3.TXT',
'ISO8859_4' => '8859-4.TXT', 'ISO8859_4' => '8859-4.TXT',
'ISO8859_5' => '8859-5.TXT', 'ISO8859_5' => '8859-5.TXT',
'ISO8859_6' => '8859-6.TXT', 'ISO8859_6' => '8859-6.TXT',
'ISO8859_7' => '8859-7.TXT', 'ISO8859_7' => '8859-7.TXT',
'ISO8859_8' => '8859-8.TXT', 'ISO8859_8' => '8859-8.TXT',
'ISO8859_9' => '8859-9.TXT', 'ISO8859_9' => '8859-9.TXT',
'ISO8859_10' => '8859-10.TXT', 'ISO8859_10' => '8859-10.TXT',
'ISO8859_13' => '8859-13.TXT', 'ISO8859_13' => '8859-13.TXT',
'ISO8859_14' => '8859-14.TXT', 'ISO8859_14' => '8859-14.TXT',
'ISO8859_15' => '8859-15.TXT', 'ISO8859_15' => '8859-15.TXT',
'ISO8859_16' => '8859-16.TXT', 'ISO8859_16' => '8859-16.TXT',
'KOI8R' => 'KOI8-R.TXT', 'KOI8R' => 'KOI8-R.TXT',
'KOI8U' => 'KOI8-U.TXT', 'KOI8U' => 'KOI8-U.TXT',
'GBK' => 'CP936.TXT', 'GBK' => 'CP936.TXT',
'UHC' => 'CP949.TXT', 'UHC' => 'CP949.TXT',
'JOHAB' => 'JOHAB.TXT', 'JOHAB' => 'JOHAB.TXT',);
);
@charsets = keys(filename); @charsets = keys(filename);
@charsets = @ARGV if scalar(@ARGV); @charsets = @ARGV if scalar(@ARGV);
foreach $charset (@charsets) { foreach $charset (@charsets)
{
# #
# first, generate UTF8-> charset table # first, generate UTF8-> charset table
# #
$in_file = $filename{$charset}; $in_file = $filename{$charset};
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
reset 'array'; reset 'array';
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if( $code >= 0x80 && $ucs >= 0x0080){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $utf } ne "" ){ if ($array{$utf} ne "")
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; {
printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$array{ $utf } = $code; $array{$utf} = $code;
} }
} }
close( FILE ); close(FILE);
$file = lc("utf8_to_${charset}.map"); $file = lc("utf8_to_${charset}.map");
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_utf_to_local ULmap${charset}[ $count ] = {\n"; print FILE "static pg_utf_to_local ULmap${charset}[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$code = $array{ $index }; {
$code = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $code; printf FILE " {0x%04x, 0x%04x}\n", $index, $code;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $code; printf FILE " {0x%04x, 0x%04x},\n", $index, $code;
} }
} }
...@@ -99,42 +107,50 @@ foreach $charset (@charsets) { ...@@ -99,42 +107,50 @@ foreach $charset (@charsets) {
print FILE "};\n"; print FILE "};\n";
close(FILE); close(FILE);
# #
# then generate character set code ->UTF8 table # then generate character set code ->UTF8 table
# #
open( FILE, $in_file ) || die( "cannot open $in_file" ); open(FILE, $in_file) || die("cannot open $in_file");
reset 'array'; reset 'array';
while( <FILE> ){ while (<FILE>)
{
chop; chop;
if( /^#/ ){ if (/^#/)
{
next; next;
} }
( $c, $u, $rest ) = split; ($c, $u, $rest) = split;
$ucs = hex($u); $ucs = hex($u);
$code = hex($c); $code = hex($c);
if($code >= 0x80 && $ucs >= 0x0080){ if ($code >= 0x80 && $ucs >= 0x0080)
{
$utf = &ucs2utf($ucs); $utf = &ucs2utf($ucs);
if( $array{ $code } ne "" ){ if ($array{$code} ne "")
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; {
printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs;
next; next;
} }
$count++; $count++;
$array{ $code } = $utf; $array{$code} = $utf;
} }
} }
close( FILE ); close(FILE);
$file = lc("${charset}_to_utf8.map"); $file = lc("${charset}_to_utf8.map");
open( FILE, "> $file" ) || die( "cannot open $file" ); open(FILE, "> $file") || die("cannot open $file");
print FILE "static pg_local_to_utf LUmap${charset}[ $count ] = {\n"; print FILE "static pg_local_to_utf LUmap${charset}[ $count ] = {\n";
for $index ( sort {$a <=> $b} keys( %array ) ){ for $index (sort { $a <=> $b } keys(%array))
$utf = $array{ $index }; {
$utf = $array{$index};
$count--; $count--;
if( $count == 0 ){ if ($count == 0)
{
printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; printf FILE " {0x%04x, 0x%04x}\n", $index, $utf;
} else { }
else
{
printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; printf FILE " {0x%04x, 0x%04x},\n", $index, $utf;
} }
} }
......
...@@ -4,24 +4,32 @@ ...@@ -4,24 +4,32 @@
# src/backend/utils/mb/Unicode/ucs2utf.pl # src/backend/utils/mb/Unicode/ucs2utf.pl
# convert UCS-4 to UTF-8 # convert UCS-4 to UTF-8
# #
sub ucs2utf { sub ucs2utf
local($ucs) = @_; {
local ($ucs) = @_;
local $utf; local $utf;
if ($ucs <= 0x007f) { if ($ucs <= 0x007f)
{
$utf = $ucs; $utf = $ucs;
} elsif ($ucs > 0x007f && $ucs <= 0x07ff) { }
elsif ($ucs > 0x007f && $ucs <= 0x07ff)
{
$utf = (($ucs & 0x003f) | 0x80) | ((($ucs >> 6) | 0xc0) << 8); $utf = (($ucs & 0x003f) | 0x80) | ((($ucs >> 6) | 0xc0) << 8);
} elsif ($ucs > 0x07ff && $ucs <= 0xffff) { }
$utf = ((($ucs >> 12) | 0xe0) << 16) | elsif ($ucs > 0x07ff && $ucs <= 0xffff)
(((($ucs & 0x0fc0) >> 6) | 0x80) << 8) | {
(($ucs & 0x003f) | 0x80); $utf =
} else { ((($ucs >> 12) | 0xe0) << 16) |
$utf = ((($ucs >> 18) | 0xf0) << 24) | (((($ucs & 0x0fc0) >> 6) | 0x80) << 8) | (($ucs & 0x003f) | 0x80);
(((($ucs & 0x3ffff) >> 12) | 0x80) << 16) | }
(((($ucs & 0x0fc0) >> 6) | 0x80) << 8) | else
(($ucs & 0x003f) | 0x80); {
} $utf =
return($utf); ((($ucs >> 18) | 0xf0) << 24) |
(((($ucs & 0x3ffff) >> 12) | 0x80) << 16) |
(((($ucs & 0x0fc0) >> 6) | 0x80) << 8) | (($ucs & 0x003f) | 0x80);
}
return ($utf);
} }
1; 1;
...@@ -32,16 +32,16 @@ my $CMPPARAMS; ...@@ -32,16 +32,16 @@ my $CMPPARAMS;
emit_qsort_boilerplate(); emit_qsort_boilerplate();
$SUFFIX = 'tuple'; $SUFFIX = 'tuple';
$EXTRAARGS = ', SortTupleComparator cmp_tuple, Tuplesortstate *state'; $EXTRAARGS = ', SortTupleComparator cmp_tuple, Tuplesortstate *state';
$EXTRAPARAMS = ', cmp_tuple, state'; $EXTRAPARAMS = ', cmp_tuple, state';
$CMPPARAMS = ', state'; $CMPPARAMS = ', state';
emit_qsort_implementation(); emit_qsort_implementation();
$SUFFIX = 'ssup'; $SUFFIX = 'ssup';
$EXTRAARGS = ', SortSupport ssup'; $EXTRAARGS = ', SortSupport ssup';
$EXTRAPARAMS = ', ssup'; $EXTRAPARAMS = ', ssup';
$CMPPARAMS = ', ssup'; $CMPPARAMS = ', ssup';
print <<'EOM'; print <<'EOM';
#define cmp_ssup(a, b, ssup) \ #define cmp_ssup(a, b, ssup) \
ApplySortComparator((a)->datum1, (a)->isnull1, \ ApplySortComparator((a)->datum1, (a)->isnull1, \
......
...@@ -22,15 +22,18 @@ ...@@ -22,15 +22,18 @@
use strict; use strict;
my $docdir = $ARGV[0] or die "$0: missing required argument: docdir\n"; my $docdir = $ARGV[0] or die "$0: missing required argument: docdir\n";
my $hfile = $ARGV[1] . '.h' or die "$0: missing required argument: output file\n"; my $hfile = $ARGV[1] . '.h'
or die "$0: missing required argument: output file\n";
my $cfile = $ARGV[1] . '.c'; my $cfile = $ARGV[1] . '.c';
my $hfilebasename; my $hfilebasename;
if ($hfile =~ m!.*/([^/]+)$!) { if ($hfile =~ m!.*/([^/]+)$!)
$hfilebasename = $1; {
$hfilebasename = $1;
} }
else { else
$hfilebasename = $hfile; {
$hfilebasename = $hfile;
} }
my $define = $hfilebasename; my $define = $hfilebasename;
...@@ -38,14 +41,13 @@ $define =~ tr/a-z/A-Z/; ...@@ -38,14 +41,13 @@ $define =~ tr/a-z/A-Z/;
$define =~ s/\W/_/g; $define =~ s/\W/_/g;
opendir(DIR, $docdir) opendir(DIR, $docdir)
or die "$0: could not open documentation source dir '$docdir': $!\n"; or die "$0: could not open documentation source dir '$docdir': $!\n";
open(HFILE, ">$hfile") open(HFILE, ">$hfile")
or die "$0: could not open output file '$hfile': $!\n"; or die "$0: could not open output file '$hfile': $!\n";
open(CFILE, ">$cfile") open(CFILE, ">$cfile")
or die "$0: could not open output file '$cfile': $!\n"; or die "$0: could not open output file '$cfile': $!\n";
print HFILE print HFILE "/*
"/*
* *** Do not change this file by hand. It is automatically * *** Do not change this file by hand. It is automatically
* *** generated from the DocBook documentation. * *** generated from the DocBook documentation.
* *
...@@ -72,8 +74,7 @@ struct _helpStruct ...@@ -72,8 +74,7 @@ struct _helpStruct
"; ";
print CFILE print CFILE "/*
"/*
* *** Do not change this file by hand. It is automatically * *** Do not change this file by hand. It is automatically
* *** generated from the DocBook documentation. * *** generated from the DocBook documentation.
* *
...@@ -90,71 +91,90 @@ my $maxlen = 0; ...@@ -90,71 +91,90 @@ my $maxlen = 0;
my %entries; my %entries;
foreach my $file (sort readdir DIR) { foreach my $file (sort readdir DIR)
my (@cmdnames, $cmddesc, $cmdsynopsis); {
$file =~ /\.sgml$/ or next; my (@cmdnames, $cmddesc, $cmdsynopsis);
$file =~ /\.sgml$/ or next;
open(FILE, "$docdir/$file") or next;
my $filecontent = join('', <FILE>); open(FILE, "$docdir/$file") or next;
close FILE; my $filecontent = join('', <FILE>);
close FILE;
# Ignore files that are not for SQL language statements
$filecontent =~ m!<refmiscinfo>\s*SQL - Language Statements\s*</refmiscinfo>!i # Ignore files that are not for SQL language statements
or next; $filecontent =~
m!<refmiscinfo>\s*SQL - Language Statements\s*</refmiscinfo>!i
# Collect multiple refnames or next;
LOOP: { $filecontent =~ m!\G.*?<refname>\s*([a-z ]+?)\s*</refname>!cgis and push @cmdnames, $1 and redo LOOP; }
$filecontent =~ m!<refpurpose>\s*(.+?)\s*</refpurpose>!is and $cmddesc = $1; # Collect multiple refnames
$filecontent =~ m!<synopsis>\s*(.+?)\s*</synopsis>!is and $cmdsynopsis = $1; LOOP:
{
if (@cmdnames && $cmddesc && $cmdsynopsis) { $filecontent =~ m!\G.*?<refname>\s*([a-z ]+?)\s*</refname>!cgis
s/\"/\\"/g foreach @cmdnames; and push @cmdnames, $1
and redo LOOP;
$cmddesc =~ s/<[^>]+>//g; }
$cmddesc =~ s/\s+/ /g; $filecontent =~ m!<refpurpose>\s*(.+?)\s*</refpurpose>!is
$cmddesc =~ s/\"/\\"/g; and $cmddesc = $1;
$filecontent =~ m!<synopsis>\s*(.+?)\s*</synopsis>!is
my @params = (); and $cmdsynopsis = $1;
my $nl_count = () = $cmdsynopsis =~ /\n/g; if (@cmdnames && $cmddesc && $cmdsynopsis)
{
$cmdsynopsis =~ m!</>! and die "$0:$file: null end tag not supported in synopsis\n"; s/\"/\\"/g foreach @cmdnames;
$cmdsynopsis =~ s/%/%%/g;
$cmddesc =~ s/<[^>]+>//g;
while ($cmdsynopsis =~ m!<(\w+)[^>]*>(.+?)</\1[^>]*>!) { $cmddesc =~ s/\s+/ /g;
my $match = $2; $cmddesc =~ s/\"/\\"/g;
$match =~ s/<[^>]+>//g;
$match =~ s/%%/%/g; my @params = ();
push @params, $match;
$cmdsynopsis =~ s!<(\w+)[^>]*>.+?</\1[^>]*>!%s!; my $nl_count = () = $cmdsynopsis =~ /\n/g;
}
$cmdsynopsis =~ s/\r?\n/\\n/g; $cmdsynopsis =~ m!</>!
$cmdsynopsis =~ s/\"/\\"/g; and die "$0:$file: null end tag not supported in synopsis\n";
$cmdsynopsis =~ s/%/%%/g;
foreach my $cmdname (@cmdnames) {
$entries{$cmdname} = { cmddesc => $cmddesc, cmdsynopsis => $cmdsynopsis, params => \@params, nl_count => $nl_count }; while ($cmdsynopsis =~ m!<(\w+)[^>]*>(.+?)</\1[^>]*>!)
$maxlen = ($maxlen >= length $cmdname) ? $maxlen : length $cmdname; {
my $match = $2;
$match =~ s/<[^>]+>//g;
$match =~ s/%%/%/g;
push @params, $match;
$cmdsynopsis =~ s!<(\w+)[^>]*>.+?</\1[^>]*>!%s!;
}
$cmdsynopsis =~ s/\r?\n/\\n/g;
$cmdsynopsis =~ s/\"/\\"/g;
foreach my $cmdname (@cmdnames)
{
$entries{$cmdname} = {
cmddesc => $cmddesc,
cmdsynopsis => $cmdsynopsis,
params => \@params,
nl_count => $nl_count };
$maxlen =
($maxlen >= length $cmdname) ? $maxlen : length $cmdname;
}
}
else
{
die "$0: parsing file '$file' failed (N='@cmdnames' D='$cmddesc')\n";
} }
}
else {
die "$0: parsing file '$file' failed (N='@cmdnames' D='$cmddesc')\n";
}
} }
foreach (sort keys %entries) { foreach (sort keys %entries)
my $prefix = "\t"x5 . ' '; {
my $id = $_; my $prefix = "\t" x 5 . ' ';
$id =~ s/ /_/g; my $id = $_;
my $synopsis = "\"$entries{$_}{cmdsynopsis}\""; $id =~ s/ /_/g;
$synopsis =~ s/\\n/\\n"\n$prefix"/g; my $synopsis = "\"$entries{$_}{cmdsynopsis}\"";
my @args = ("buf", $synopsis =~ s/\\n/\\n"\n$prefix"/g;
$synopsis, my @args =
map("_(\"$_\")", @{$entries{$_}{params}})); ("buf", $synopsis, map("_(\"$_\")", @{ $entries{$_}{params} }));
print HFILE "extern void sql_help_$id(PQExpBuffer buf);\n"; print HFILE "extern void sql_help_$id(PQExpBuffer buf);\n";
print CFILE "void print CFILE "void
sql_help_$id(PQExpBuffer buf) sql_help_$id(PQExpBuffer buf)
{ {
\tappendPQExpBuffer(".join(",\n$prefix", @args)."); \tappendPQExpBuffer(" . join(",\n$prefix", @args) . ");
} }
"; ";
...@@ -164,10 +184,11 @@ print HFILE " ...@@ -164,10 +184,11 @@ print HFILE "
static const struct _helpStruct QL_HELP[] = { static const struct _helpStruct QL_HELP[] = {
"; ";
foreach (sort keys %entries) { foreach (sort keys %entries)
my $id = $_; {
$id =~ s/ /_/g; my $id = $_;
print HFILE " { \"$_\", $id =~ s/ /_/g;
print HFILE " { \"$_\",
N_(\"$entries{$_}{cmddesc}\"), N_(\"$entries{$_}{cmddesc}\"),
sql_help_$id, sql_help_$id,
$entries{$_}{nl_count} }, $entries{$_}{nl_count} },
...@@ -180,7 +201,9 @@ print HFILE " ...@@ -180,7 +201,9 @@ print HFILE "
}; };
#define QL_HELP_COUNT ".scalar(keys %entries)." /* number of help items */ #define QL_HELP_COUNT "
. scalar(keys %entries)
. " /* number of help items */
#define QL_MAX_CMD_LEN $maxlen /* largest strlen(cmd) */ #define QL_MAX_CMD_LEN $maxlen /* largest strlen(cmd) */
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
# Copyright (c) 2009-2012, PostgreSQL Global Development Group # Copyright (c) 2009-2012, PostgreSQL Global Development Group
# #
# Written by Michael Meskes <meskes@postgresql.org> # Written by Michael Meskes <meskes@postgresql.org>
# Andy Colson <andy@squeakycode.net> # Andy Colson <andy@squeakycode.net>
# #
# Placed under the same license as PostgreSQL. # Placed under the same license as PostgreSQL.
# #
...@@ -25,7 +25,7 @@ if ($ARGV[0] eq '-v') ...@@ -25,7 +25,7 @@ if ($ARGV[0] eq '-v')
{ {
$verbose = shift; $verbose = shift;
} }
my $path = shift || '.'; my $path = shift || '.';
my $parser = shift || '../../../backend/parser/gram.y'; my $parser = shift || '../../../backend/parser/gram.y';
my $filename = $path . "/ecpg.addons"; my $filename = $path . "/ecpg.addons";
...@@ -37,32 +37,31 @@ if ($verbose) ...@@ -37,32 +37,31 @@ if ($verbose)
my %replace_line = ( my %replace_line = (
'ExecuteStmtEXECUTEnameexecute_param_clause' => 'ExecuteStmtEXECUTEnameexecute_param_clause' =>
'EXECUTE prepared_name execute_param_clause execute_rest', 'EXECUTE prepared_name execute_param_clause execute_rest',
'ExecuteStmtCREATEOptTempTABLEcreate_as_targetASEXECUTEnameexecute_param_clause' => 'ExecuteStmtCREATEOptTempTABLEcreate_as_targetASEXECUTEnameexecute_param_clause'
'CREATE OptTemp TABLE create_as_target AS EXECUTE prepared_name execute_param_clause', => 'CREATE OptTemp TABLE create_as_target AS EXECUTE prepared_name execute_param_clause',
'PrepareStmtPREPAREnameprep_type_clauseASPreparableStmt' => 'PrepareStmtPREPAREnameprep_type_clauseASPreparableStmt' =>
'PREPARE prepared_name prep_type_clause AS PreparableStmt' 'PREPARE prepared_name prep_type_clause AS PreparableStmt');
);
my $block = ''; my $block = '';
my $yaccmode = 0; my $yaccmode = 0;
my $brace_indent = 0; my $brace_indent = 0;
my (@arr, %found); my (@arr, %found);
my $comment = 0; my $comment = 0;
my $non_term_id = ''; my $non_term_id = '';
my $cc = 0; my $cc = 0;
open GRAM, $parser or die $!; open GRAM, $parser or die $!;
while (<GRAM>) while (<GRAM>)
{ {
if (/^%%/) if (/^%%/)
{ {
$yaccmode++; $yaccmode++;
} }
if ( $yaccmode != 1 ) if ($yaccmode != 1)
{ {
next; next;
} }
...@@ -80,50 +79,51 @@ while (<GRAM>) ...@@ -80,50 +79,51 @@ while (<GRAM>)
s|\*\/| */ |g; s|\*\/| */ |g;
# Now split the line into individual fields # Now split the line into individual fields
my $n = ( @arr = split( ' ' ) ); my $n = (@arr = split(' '));
# Go through each field in turn # Go through each field in turn
for ( my $fieldIndexer = 0 ; $fieldIndexer < $n ; $fieldIndexer++ ) for (my $fieldIndexer = 0; $fieldIndexer < $n; $fieldIndexer++)
{ {
if ( $arr[$fieldIndexer] eq '*/' && $comment ) if ($arr[$fieldIndexer] eq '*/' && $comment)
{ {
$comment = 0; $comment = 0;
next; next;
} }
elsif ($comment) elsif ($comment)
{ {
next; next;
} }
elsif ( $arr[$fieldIndexer] eq '/*' ) elsif ($arr[$fieldIndexer] eq '/*')
{ {
# start of a multiline comment # start of a multiline comment
$comment = 1; $comment = 1;
next; next;
} }
elsif ( $arr[$fieldIndexer] eq '//' ) elsif ($arr[$fieldIndexer] eq '//')
{ {
next; next;
} }
elsif ( $arr[$fieldIndexer] eq '}' ) elsif ($arr[$fieldIndexer] eq '}')
{ {
$brace_indent--; $brace_indent--;
next; next;
} }
elsif ( $arr[$fieldIndexer] eq '{' ) elsif ($arr[$fieldIndexer] eq '{')
{ {
$brace_indent++; $brace_indent++;
next; next;
} }
if ( $brace_indent > 0 ) if ($brace_indent > 0)
{ {
next; next;
} }
if ( $arr[$fieldIndexer] eq ';' || $arr[$fieldIndexer] eq '|' ) if ($arr[$fieldIndexer] eq ';' || $arr[$fieldIndexer] eq '|')
{ {
$block = $non_term_id . $block; $block = $non_term_id . $block;
if ( $replace_line{$block} ) if ($replace_line{$block})
{ {
$block = $non_term_id . $replace_line{$block}; $block = $non_term_id . $replace_line{$block};
$block =~ tr/ |//d; $block =~ tr/ |//d;
...@@ -132,13 +132,13 @@ while (<GRAM>) ...@@ -132,13 +132,13 @@ while (<GRAM>)
$cc++; $cc++;
$block = ''; $block = '';
} }
elsif ( ( $arr[$fieldIndexer] =~ '[A-Za-z0-9]+:' ) elsif (($arr[$fieldIndexer] =~ '[A-Za-z0-9]+:')
|| $arr[ $fieldIndexer + 1 ] eq ':' ) || $arr[ $fieldIndexer + 1 ] eq ':')
{ {
$non_term_id = $arr[$fieldIndexer]; $non_term_id = $arr[$fieldIndexer];
$non_term_id =~ tr/://d; $non_term_id =~ tr/://d;
} }
else else
{ {
$block = $block . $arr[$fieldIndexer]; $block = $block . $arr[$fieldIndexer];
} }
...@@ -155,16 +155,16 @@ my $ret = 0; ...@@ -155,16 +155,16 @@ my $ret = 0;
$cc = 0; $cc = 0;
open ECPG, $filename or die $!; open ECPG, $filename or die $!;
while (<ECPG>) while (<ECPG>)
{ {
if ( !/^ECPG:/ ) if (!/^ECPG:/)
{ {
next; next;
} }
my @Fld = split( ' ', $_, 3 ); my @Fld = split(' ', $_, 3);
$cc++; $cc++;
if ( not exists $found{ $Fld[1] } ) if (not exists $found{ $Fld[1] })
{ {
print $Fld[1], " is not used for building parser!\n"; print $Fld[1], " is not used for building parser!\n";
$ret = 1; $ret = 1;
......
This diff is collapsed.
...@@ -7,99 +7,113 @@ PostgreSQL::InServer::Util::bootstrap(); ...@@ -7,99 +7,113 @@ PostgreSQL::InServer::Util::bootstrap();
# globals # globals
sub ::is_array_ref { sub ::is_array_ref
{
return ref($_[0]) =~ m/^(?:PostgreSQL::InServer::)?ARRAY$/; return ref($_[0]) =~ m/^(?:PostgreSQL::InServer::)?ARRAY$/;
} }
sub ::encode_array_literal { sub ::encode_array_literal
{
my ($arg, $delim) = @_; my ($arg, $delim) = @_;
return $arg unless(::is_array_ref($arg)); return $arg unless (::is_array_ref($arg));
$delim = ', ' unless defined $delim; $delim = ', ' unless defined $delim;
my $res = ''; my $res = '';
foreach my $elem (@$arg) { foreach my $elem (@$arg)
{
$res .= $delim if length $res; $res .= $delim if length $res;
if (ref $elem) { if (ref $elem)
{
$res .= ::encode_array_literal($elem, $delim); $res .= ::encode_array_literal($elem, $delim);
} }
elsif (defined $elem) { elsif (defined $elem)
{
(my $str = $elem) =~ s/(["\\])/\\$1/g; (my $str = $elem) =~ s/(["\\])/\\$1/g;
$res .= qq("$str"); $res .= qq("$str");
} }
else { else
{
$res .= 'NULL'; $res .= 'NULL';
} }
} }
return qq({$res}); return qq({$res});
} }
sub ::encode_array_constructor { sub ::encode_array_constructor
{
my $arg = shift; my $arg = shift;
return ::quote_nullable($arg) unless ::is_array_ref($arg); return ::quote_nullable($arg) unless ::is_array_ref($arg);
my $res = join ", ", map { my $res = join ", ",
(ref $_) ? ::encode_array_constructor($_) map { (ref $_) ? ::encode_array_constructor($_) : ::quote_nullable($_) }
: ::quote_nullable($_) @$arg;
} @$arg;
return "ARRAY[$res]"; return "ARRAY[$res]";
} }
{ {
package PostgreSQL::InServer;
use strict;
use warnings;
sub plperl_warn {
(my $msg = shift) =~ s/\(eval \d+\) //g;
chomp $msg;
&::elog(&::WARNING, $msg);
}
$SIG{__WARN__} = \&plperl_warn;
sub plperl_die { package PostgreSQL::InServer;
(my $msg = shift) =~ s/\(eval \d+\) //g; use strict;
die $msg; use warnings;
}
$SIG{__DIE__} = \&plperl_die;
sub mkfuncsrc { sub plperl_warn
my ($name, $imports, $prolog, $src) = @_; {
(my $msg = shift) =~ s/\(eval \d+\) //g;
chomp $msg;
&::elog(&::WARNING, $msg);
}
$SIG{__WARN__} = \&plperl_warn;
my $BEGIN = join "\n", map { sub plperl_die
my $names = $imports->{$_} || []; {
"$_->import(qw(@$names));" (my $msg = shift) =~ s/\(eval \d+\) //g;
} sort keys %$imports; die $msg;
$BEGIN &&= "BEGIN { $BEGIN }"; }
$SIG{__DIE__} = \&plperl_die;
return qq[ package main; sub { $BEGIN $prolog $src } ]; sub mkfuncsrc
} {
my ($name, $imports, $prolog, $src) = @_;
sub mkfunc { my $BEGIN = join "\n", map {
no strict; # default to no strict for the eval my $names = $imports->{$_} || [];
no warnings; # default to no warnings for the eval "$_->import(qw(@$names));"
my $ret = eval(mkfuncsrc(@_)); } sort keys %$imports;
$@ =~ s/\(eval \d+\) //g if $@; $BEGIN &&= "BEGIN { $BEGIN }";
return $ret;
}
1; return qq[ package main; sub { $BEGIN $prolog $src } ];
}
sub mkfunc
{
no strict; # default to no strict for the eval
no warnings; # default to no warnings for the eval
my $ret = eval(mkfuncsrc(@_));
$@ =~ s/\(eval \d+\) //g if $@;
return $ret;
}
1;
} }
{ {
package PostgreSQL::InServer::ARRAY;
use strict;
use warnings;
use overload package PostgreSQL::InServer::ARRAY;
'""'=>\&to_str, use strict;
'@{}'=>\&to_arr; use warnings;
sub to_str { use overload
my $self = shift; '""' => \&to_str,
return ::encode_typed_literal($self->{'array'}, $self->{'typeoid'}); '@{}' => \&to_arr;
}
sub to_arr { sub to_str
return shift->{'array'}; {
} my $self = shift;
return ::encode_typed_literal($self->{'array'}, $self->{'typeoid'});
}
sub to_arr
{
return shift->{'array'};
}
1; 1;
} }
...@@ -5,54 +5,59 @@ use warnings; ...@@ -5,54 +5,59 @@ use warnings;
use Opcode qw(opset opset_to_ops opdesc); use Opcode qw(opset opset_to_ops opdesc);
my $plperl_opmask_h = shift my $plperl_opmask_h = shift
or die "Usage: $0 <output_filename.h>\n"; or die "Usage: $0 <output_filename.h>\n";
my $plperl_opmask_tmp = $plperl_opmask_h."tmp"; my $plperl_opmask_tmp = $plperl_opmask_h . "tmp";
END { unlink $plperl_opmask_tmp } END { unlink $plperl_opmask_tmp }
open my $fh, ">", "$plperl_opmask_tmp" open my $fh, ">", "$plperl_opmask_tmp"
or die "Could not write to $plperl_opmask_tmp: $!"; or die "Could not write to $plperl_opmask_tmp: $!";
printf $fh "#define PLPERL_SET_OPMASK(opmask) \\\n"; printf $fh "#define PLPERL_SET_OPMASK(opmask) \\\n";
printf $fh " memset(opmask, 1, MAXO);\t/* disable all */ \\\n"; printf $fh " memset(opmask, 1, MAXO);\t/* disable all */ \\\n";
printf $fh " /* then allow some... */ \\\n"; printf $fh " /* then allow some... */ \\\n";
my @allowed_ops = ( my @allowed_ops = (
# basic set of opcodes # basic set of opcodes
qw[:default :base_math !:base_io sort time], qw[:default :base_math !:base_io sort time],
# require is safe because we redirect the opcode # require is safe because we redirect the opcode
# entereval is safe as the opmask is now permanently set # entereval is safe as the opmask is now permanently set
# caller is safe because the entire interpreter is locked down # caller is safe because the entire interpreter is locked down
qw[require entereval caller], qw[require entereval caller],
# These are needed for utf8_heavy.pl: # These are needed for utf8_heavy.pl:
# dofile is safe because we redirect the opcode like require above # dofile is safe because we redirect the opcode like require above
# print is safe because the only writable filehandles are STDOUT & STDERR # print is safe because the only writable filehandles are STDOUT & STDERR
# prtf (printf) is safe as it's the same as print + sprintf # prtf (printf) is safe as it's the same as print + sprintf
qw[dofile print prtf], qw[dofile print prtf],
# Disallow these opcodes that are in the :base_orig optag # Disallow these opcodes that are in the :base_orig optag
# (included in :default) but aren't considered sufficiently safe # (included in :default) but aren't considered sufficiently safe
qw[!dbmopen !setpgrp !setpriority], qw[!dbmopen !setpgrp !setpriority],
# custom is not deemed a likely security risk as it can't be generated from
# perl so would only be seen if the DBA had chosen to load a module that # custom is not deemed a likely security risk as it can't be generated from
# used it. Even then it's unlikely to be seen because it's typically # perl so would only be seen if the DBA had chosen to load a module that
# generated by compiler plugins that operate after PL_op_mask checks. # used it. Even then it's unlikely to be seen because it's typically
# But we err on the side of caution and disable it # generated by compiler plugins that operate after PL_op_mask checks.
qw[!custom], # But we err on the side of caution and disable it
); qw[!custom],);
printf $fh " /* ALLOWED: @allowed_ops */ \\\n"; printf $fh " /* ALLOWED: @allowed_ops */ \\\n";
foreach my $opname (opset_to_ops(opset(@allowed_ops))) { foreach my $opname (opset_to_ops(opset(@allowed_ops)))
{
printf $fh qq{ opmask[OP_%-12s] = 0;\t/* %s */ \\\n}, printf $fh qq{ opmask[OP_%-12s] = 0;\t/* %s */ \\\n},
uc($opname), opdesc($opname); uc($opname), opdesc($opname);
} }
printf $fh " /* end */ \n"; printf $fh " /* end */ \n";
close $fh close $fh
or die "Error closing $plperl_opmask_tmp: $!"; or die "Error closing $plperl_opmask_tmp: $!";
rename $plperl_opmask_tmp, $plperl_opmask_h rename $plperl_opmask_tmp, $plperl_opmask_h
or die "Error renaming $plperl_opmask_tmp to $plperl_opmask_h: $!"; or die "Error renaming $plperl_opmask_tmp to $plperl_opmask_h: $!";
exit 0; exit 0;
...@@ -32,11 +32,10 @@ GetOptions( ...@@ -32,11 +32,10 @@ GetOptions(
'prefix=s' => \my $opt_prefix, 'prefix=s' => \my $opt_prefix,
'name=s' => \my $opt_name, 'name=s' => \my $opt_name,
'strip=s' => \my $opt_strip, 'strip=s' => \my $opt_strip,
'selftest!' => sub { exit selftest() }, 'selftest!' => sub { exit selftest() },) or exit 1;
) or exit 1;
die "No text files specified" die "No text files specified"
unless @ARGV; unless @ARGV;
print qq{ print qq{
/* /*
...@@ -45,17 +44,19 @@ print qq{ ...@@ -45,17 +44,19 @@ print qq{
*/ */
}; };
for my $src_file (@ARGV) { for my $src_file (@ARGV)
{
(my $macro = $src_file) =~ s/ .*? (\w+) (?:\.\w+) $/$1/x; (my $macro = $src_file) =~ s/ .*? (\w+) (?:\.\w+) $/$1/x;
open my $src_fh, $src_file # not 3-arg form open my $src_fh, $src_file # not 3-arg form
or die "Can't open $src_file: $!"; or die "Can't open $src_file: $!";
printf qq{#define %s%s \\\n}, printf qq{#define %s%s \\\n},
$opt_prefix || '', $opt_prefix || '',
($opt_name) ? $opt_name : uc $macro; ($opt_name) ? $opt_name : uc $macro;
while (<$src_fh>) { while (<$src_fh>)
{
chomp; chomp;
next if $opt_strip and m/$opt_strip/o; next if $opt_strip and m/$opt_strip/o;
...@@ -74,8 +75,9 @@ print "/* end */\n"; ...@@ -74,8 +75,9 @@ print "/* end */\n";
exit 0; exit 0;
sub selftest { sub selftest
my $tmp = "text2macro_tmp"; {
my $tmp = "text2macro_tmp";
my $string = q{a '' '\\'' "" "\\"" "\\\\" "\\\\n" b}; my $string = q{a '' '\\'' "" "\\"" "\\\\" "\\\\n" b};
open my $fh, ">$tmp.pl" or die; open my $fh, ">$tmp.pl" or die;
......
...@@ -6,35 +6,35 @@ ...@@ -6,35 +6,35 @@
use warnings; use warnings;
use strict; use strict;
print "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n"; print
"/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
print "/* there is deliberately not an #ifndef PLERRCODES_H here */\n"; print "/* there is deliberately not an #ifndef PLERRCODES_H here */\n";
open my $errcodes, $ARGV[0] or die; open my $errcodes, $ARGV[0] or die;
while (<$errcodes>) { while (<$errcodes>)
chomp; {
chomp;
# Skip comments # Skip comments
next if /^#/; next if /^#/;
next if /^\s*$/; next if /^\s*$/;
# Skip section headers # Skip section headers
next if /^Section:/; next if /^Section:/;
die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/; die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/;
(my $sqlstate, (my $sqlstate, my $type, my $errcode_macro, my $condition_name) =
my $type, ($1, $2, $3, $4);
my $errcode_macro,
my $condition_name) = ($1, $2, $3, $4);
# Skip non-errors # Skip non-errors
next unless $type eq 'E'; next unless $type eq 'E';
# Skip lines without PL/pgSQL condition names # Skip lines without PL/pgSQL condition names
next unless defined($condition_name); next unless defined($condition_name);
print "{\n\t\"$condition_name\", $errcode_macro\n},\n\n"; print "{\n\t\"$condition_name\", $errcode_macro\n},\n\n";
} }
close $errcodes; close $errcodes;
...@@ -6,39 +6,39 @@ ...@@ -6,39 +6,39 @@
use warnings; use warnings;
use strict; use strict;
print "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n"; print
"/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
print "/* there is deliberately not an #ifndef SPIEXCEPTIONS_H here */\n"; print "/* there is deliberately not an #ifndef SPIEXCEPTIONS_H here */\n";
open my $errcodes, $ARGV[0] or die; open my $errcodes, $ARGV[0] or die;
while (<$errcodes>) { while (<$errcodes>)
chomp; {
chomp;
# Skip comments # Skip comments
next if /^#/; next if /^#/;
next if /^\s*$/; next if /^\s*$/;
# Skip section headers # Skip section headers
next if /^Section:/; next if /^Section:/;
die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/; die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/;
(my $sqlstate, (my $sqlstate, my $type, my $errcode_macro, my $condition_name) =
my $type, ($1, $2, $3, $4);
my $errcode_macro,
my $condition_name) = ($1, $2, $3, $4);
# Skip non-errors # Skip non-errors
next unless $type eq 'E'; next unless $type eq 'E';
# Skip lines without PL/pgSQL condition names # Skip lines without PL/pgSQL condition names
next unless defined($condition_name); next unless defined($condition_name);
# Change some_error_condition to SomeErrorCondition # Change some_error_condition to SomeErrorCondition
$condition_name =~ s/([a-z])([^_]*)(?:_|$)/\u$1$2/g; $condition_name =~ s/([a-z])([^_]*)(?:_|$)/\u$1$2/g;
print "{ \"spiexceptions.$condition_name\", " . print "{ \"spiexceptions.$condition_name\", "
"\"$condition_name\", $errcode_macro },\n"; . "\"$condition_name\", $errcode_macro },\n";
} }
close $errcodes; close $errcodes;
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
use locale; use locale;
open(INFILE, "<$ARGV[0]"); open(INFILE, "<$ARGV[0]");
chop(my(@words) = <INFILE>); chop(my (@words) = <INFILE>);
close(INFILE); close(INFILE);
$"="\n"; $" = "\n";
my(@result) = sort @words; my (@result) = sort @words;
print "@result\n"; print "@result\n";
...@@ -10,9 +10,9 @@ $DBNAME = 'perftest'; ...@@ -10,9 +10,9 @@ $DBNAME = 'perftest';
# This describtion for all DBMS supported by test # This describtion for all DBMS supported by test
# DBMS_name => [FrontEnd, DestroyDB command, CreateDB command] # DBMS_name => [FrontEnd, DestroyDB command, CreateDB command]
%DBMS = ( %DBMS =
'pgsql' => ["psql -q -d $DBNAME", "destroydb $DBNAME", "createdb $DBNAME"] ('pgsql' =>
); [ "psql -q -d $DBNAME", "destroydb $DBNAME", "createdb $DBNAME" ]);
# Tests to run: test' script, test' description, ... # Tests to run: test' script, test' description, ...
# Test' script is in form # Test' script is in form
...@@ -34,30 +34,37 @@ $DBNAME = 'perftest'; ...@@ -34,30 +34,37 @@ $DBNAME = 'perftest';
# an idea of what can be done for features unsupported by an DBMS.) # an idea of what can be done for features unsupported by an DBMS.)
# #
@perftests = ( @perftests = (
# It speed up things
'connection.ntm', 'DB connection startup (no timing)', # It speed up things
# Just connection startup time (echo "" | psql ... - for PgSQL) 'connection.ntm', 'DB connection startup (no timing)',
'connection', 'DB connection startup',
'crtsimple.ntm', 'Create SIMPLE table (no timing)', # Just connection startup time (echo "" | psql ... - for PgSQL)
# 8192 inserts in single xaction 'connection', 'DB connection startup',
'inssimple T', '8192 INSERTs INTO SIMPLE (1 xact)', 'crtsimple.ntm', 'Create SIMPLE table (no timing)',
'drpsimple.ntm', 'Drop SIMPLE table (no timing)',
'crtsimple.ntm', 'Create SIMPLE table (no timing)', # 8192 inserts in single xaction
# 8192 inserts in 8192 xactions 'inssimple T', '8192 INSERTs INTO SIMPLE (1 xact)',
'inssimple', '8192 INSERTs INTO SIMPLE (8192 xacts)', 'drpsimple.ntm', 'Drop SIMPLE table (no timing)',
'vacuum.ntm', 'Vacuum (no timing)', 'crtsimple.ntm', 'Create SIMPLE table (no timing)',
# Fast (after table filled with data) index creation test
'crtsimpleidx', 'Create INDEX on SIMPLE', # 8192 inserts in 8192 xactions
'drpsimple.ntm', 'Drop SIMPLE table (no timing)', 'inssimple', '8192 INSERTs INTO SIMPLE (8192 xacts)',
'crtsimple.ntm', 'Create SIMPLE table (no timing)', 'vacuum.ntm', 'Vacuum (no timing)',
'crtsimpleidx.ntm', 'Create INDEX on SIMPLE (no timing)',
# 8192 inserts in single xaction into table with index # Fast (after table filled with data) index creation test
'inssimple T', '8192 INSERTs INTO SIMPLE with INDEX (1 xact)', 'crtsimpleidx', 'Create INDEX on SIMPLE',
# 8192 SELECT * FROM simple WHERE justint = <random_key> in single xaction 'drpsimple.ntm', 'Drop SIMPLE table (no timing)',
'slcsimple T', '8192 random INDEX scans on SIMPLE (1 xact)', 'crtsimple.ntm', 'Create SIMPLE table (no timing)',
# SELECT * FROM simple ORDER BY justint 'crtsimpleidx.ntm', 'Create INDEX on SIMPLE (no timing)',
'orbsimple', 'ORDER BY SIMPLE',
); # 8192 inserts in single xaction into table with index
'inssimple T', '8192 INSERTs INTO SIMPLE with INDEX (1 xact)',
# 8192 SELECT * FROM simple WHERE justint = <random_key> in single xaction
'slcsimple T', '8192 random INDEX scans on SIMPLE (1 xact)',
# SELECT * FROM simple ORDER BY justint
'orbsimple', 'ORDER BY SIMPLE',);
# #
# It seems that nothing below need to be changed # It seems that nothing below need to be changed
...@@ -66,72 +73,76 @@ $DBNAME = 'perftest'; ...@@ -66,72 +73,76 @@ $DBNAME = 'perftest';
$TestDBMS = $ARGV[0]; $TestDBMS = $ARGV[0];
die "Unsupported DBMS $TestDBMS\n" if !exists $DBMS{$TestDBMS}; die "Unsupported DBMS $TestDBMS\n" if !exists $DBMS{$TestDBMS};
$FrontEnd = $DBMS{$TestDBMS}[0]; $FrontEnd = $DBMS{$TestDBMS}[0];
$DestroyDB = $DBMS{$TestDBMS}[1]; $DestroyDB = $DBMS{$TestDBMS}[1];
$CreateDB = $DBMS{$TestDBMS}[2]; $CreateDB = $DBMS{$TestDBMS}[2];
print "(Re)create DataBase $DBNAME\n"; print "(Re)create DataBase $DBNAME\n";
`$DestroyDB`; # Destroy DB `$DestroyDB`; # Destroy DB
`$CreateDB`; # Create DB `$CreateDB`; # Create DB
$ResFile = "Results.$TestDBMS"; $ResFile = "Results.$TestDBMS";
$TmpFile = "Tmp.$TestDBMS"; $TmpFile = "Tmp.$TestDBMS";
open (SAVEOUT, ">&STDOUT"); open(SAVEOUT, ">&STDOUT");
open (STDOUT, ">/dev/null") or die; open(STDOUT, ">/dev/null") or die;
open (SAVEERR, ">&STDERR"); open(SAVEERR, ">&STDERR");
open (STDERR, ">$TmpFile") or die; open(STDERR, ">$TmpFile") or die;
select (STDERR); $| = 1; select(STDERR);
$| = 1;
for ($i = 0; $i <= $#perftests; $i++) for ($i = 0; $i <= $#perftests; $i++)
{ {
$test = $perftests[$i]; $test = $perftests[$i];
($test, $XACTBLOCK) = split (/ /, $test); ($test, $XACTBLOCK) = split(/ /, $test);
$runtest = $test; $runtest = $test;
if ( $test =~ /\.ntm/ ) if ($test =~ /\.ntm/)
{ {
# #
# No timing for this queries # No timing for this queries
# #
close (STDERR); # close $TmpFile close(STDERR); # close $TmpFile
open (STDERR, ">/dev/null") or die; open(STDERR, ">/dev/null") or die;
$runtest =~ s/\.ntm//; $runtest =~ s/\.ntm//;
} }
else else
{ {
close (STDOUT); close(STDOUT);
open(STDOUT, ">&SAVEOUT"); open(STDOUT, ">&SAVEOUT");
print STDOUT "\nRunning: $perftests[$i+1] ..."; print STDOUT "\nRunning: $perftests[$i+1] ...";
close (STDOUT); close(STDOUT);
open (STDOUT, ">/dev/null") or die; open(STDOUT, ">/dev/null") or die;
select (STDERR); $| = 1; select(STDERR);
$| = 1;
printf "$perftests[$i+1]: "; printf "$perftests[$i+1]: ";
} }
do "sqls/$runtest"; do "sqls/$runtest";
# Restore STDERR to $TmpFile # Restore STDERR to $TmpFile
if ( $test =~ /\.ntm/ ) if ($test =~ /\.ntm/)
{ {
close (STDERR); close(STDERR);
open (STDERR, ">>$TmpFile") or die; open(STDERR, ">>$TmpFile") or die;
} }
select (STDERR); $| = 1; select(STDERR);
$| = 1;
$i++; $i++;
} }
close (STDERR); close(STDERR);
open(STDERR, ">&SAVEERR"); open(STDERR, ">&SAVEERR");
open (TMPF, "<$TmpFile") or die; open(TMPF, "<$TmpFile") or die;
open (RESF, ">$ResFile") or die; open(RESF, ">$ResFile") or die;
while (<TMPF>) while (<TMPF>)
{ {
$str = $_; $str = $_;
($test, $rtime) = split (/:/, $str); ($test, $rtime) = split(/:/, $str);
($tmp, $rtime, $rest) = split (/[ ]+/, $rtime); ($tmp, $rtime, $rest) = split(/[ ]+/, $rtime);
print RESF "$test: $rtime\n"; print RESF "$test: $rtime\n";
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -17,7 +17,7 @@ use VCBuildProject; ...@@ -17,7 +17,7 @@ use VCBuildProject;
use MSBuildProject; use MSBuildProject;
our (@ISA, @EXPORT); our (@ISA, @EXPORT);
@ISA = qw(Exporter); @ISA = qw(Exporter);
@EXPORT = qw(CreateSolution CreateProject DetermineVisualStudioVersion); @EXPORT = qw(CreateSolution CreateProject DetermineVisualStudioVersion);
sub CreateSolution sub CreateSolution
...@@ -81,12 +81,12 @@ sub DetermineVisualStudioVersion ...@@ -81,12 +81,12 @@ sub DetermineVisualStudioVersion
if (!defined($nmakeVersion)) if (!defined($nmakeVersion))
{ {
# Determine version of nmake command, to set proper version of visual studio # Determine version of nmake command, to set proper version of visual studio
# we use nmake as it has existed for a long time and still exists in visual studio 2010 # we use nmake as it has existed for a long time and still exists in visual studio 2010
open(P,"nmake /? 2>&1 |") open(P, "nmake /? 2>&1 |")
|| croak || croak
"Unable to determine Visual Studio version: The nmake command wasn't found."; "Unable to determine Visual Studio version: The nmake command wasn't found.";
while(<P>) while (<P>)
{ {
chomp; chomp;
if (/(\d+)\.(\d+)\.\d+(\.\d+)?$/) if (/(\d+)\.(\d+)\.\d+(\.\d+)?$/)
...@@ -96,17 +96,17 @@ sub DetermineVisualStudioVersion ...@@ -96,17 +96,17 @@ sub DetermineVisualStudioVersion
} }
close(P); close(P);
} }
elsif($nmakeVersion =~ /(\d+)\.(\d+)\.\d+(\.\d+)?$/) elsif ($nmakeVersion =~ /(\d+)\.(\d+)\.\d+(\.\d+)?$/)
{ {
return _GetVisualStudioVersion($1, $2); return _GetVisualStudioVersion($1, $2);
} }
croak croak
"Unable to determine Visual Studio version: The nmake version could not be determined."; "Unable to determine Visual Studio version: The nmake version could not be determined.";
} }
sub _GetVisualStudioVersion sub _GetVisualStudioVersion
{ {
my($major, $minor) = @_; my ($major, $minor) = @_;
if ($major > 10) if ($major > 10)
{ {
carp carp
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -10,10 +10,13 @@ use warnings; ...@@ -10,10 +10,13 @@ use warnings;
use Mkvcbuild; use Mkvcbuild;
chdir('..\..\..') if (-d '..\msvc' && -d '..\..\..\src'); chdir('..\..\..') if (-d '..\msvc' && -d '..\..\..\src');
die 'Must run from root or msvc directory' unless (-d 'src\tools\msvc' && -d 'src'); die 'Must run from root or msvc directory'
unless (-d 'src\tools\msvc' && -d 'src');
die 'Could not find config_default.pl' unless (-f 'src/tools/msvc/config_default.pl'); die 'Could not find config_default.pl'
print "Warning: no config.pl found, using default.\n" unless (-f 'src/tools/msvc/config.pl'); unless (-f 'src/tools/msvc/config_default.pl');
print "Warning: no config.pl found, using default.\n"
unless (-f 'src/tools/msvc/config.pl');
our $config; our $config;
require 'src/tools/msvc/config_default.pl'; require 'src/tools/msvc/config_default.pl';
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment