diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/catalog/Catalog.pm | 310 | ||||
-rw-r--r-- | src/backend/catalog/genbki.pl | 580 | ||||
-rw-r--r-- | src/backend/utils/Gen_fmgrtab.pl | 109 | ||||
-rw-r--r-- | src/backend/utils/generate-errcodes.pl | 35 | ||||
-rwxr-xr-x | src/backend/utils/mb/Unicode/UCS_to_BIG5.pl | 132 | ||||
-rwxr-xr-x | src/backend/utils/mb/Unicode/UCS_to_EUC_CN.pl | 76 | ||||
-rwxr-xr-x | src/backend/utils/mb/Unicode/UCS_to_EUC_JIS_2004.pl | 279 | ||||
-rwxr-xr-x | src/backend/utils/mb/Unicode/UCS_to_EUC_JP.pl | 172 | ||||
-rwxr-xr-x | src/backend/utils/mb/Unicode/UCS_to_EUC_KR.pl | 76 | ||||
-rwxr-xr-x | src/backend/utils/mb/Unicode/UCS_to_EUC_TW.pl | 97 | ||||
-rwxr-xr-x | src/backend/utils/mb/Unicode/UCS_to_GB18030.pl | 76 | ||||
-rwxr-xr-x | src/backend/utils/mb/Unicode/UCS_to_SHIFT_JIS_2004.pl | 211 | ||||
-rwxr-xr-x | src/backend/utils/mb/Unicode/UCS_to_SJIS.pl | 123 | ||||
-rw-r--r-- | src/backend/utils/mb/Unicode/UCS_to_most.pl | 142 | ||||
-rw-r--r-- | src/backend/utils/mb/Unicode/ucs2utf.pl | 38 | ||||
-rw-r--r-- | src/backend/utils/sort/gen_qsort_tuple.pl | 12 |
16 files changed, 1383 insertions, 1085 deletions
diff --git a/src/backend/catalog/Catalog.pm b/src/backend/catalog/Catalog.pm index 0be29e304e6..ebc02b50a9b 100644 --- a/src/backend/catalog/Catalog.pm +++ b/src/backend/catalog/Catalog.pm @@ -25,152 +25,160 @@ our @EXPORT_OK = qw(Catalogs RenameTempFile); # Returns a nested data structure describing the data in the headers. sub Catalogs { - my (%catalogs, $catname, $declaring_attributes, $most_recent); - $catalogs{names} = []; - - # There are a few types which are given one name in the C source, but a - # different name at the SQL level. These are enumerated here. - my %RENAME_ATTTYPE = ( - 'int16' => 'int2', - 'int32' => 'int4', - 'Oid' => 'oid', - 'NameData' => 'name', - 'TransactionId' => 'xid' - ); - - foreach my $input_file (@_) - { - my %catalog; - $catalog{columns} = []; - $catalog{data} = []; - - open(INPUT_FILE, '<', $input_file) || die "$input_file: $!"; - - # Scan the input file. - while (<INPUT_FILE>) - { - # Strip C-style comments. - s;/\*(.|\n)*\*/;;g; - if (m;/\*;) - { - # handle multi-line comments properly. - my $next_line = <INPUT_FILE>; - die "$input_file: ends within C-style comment\n" - if !defined $next_line; - $_ .= $next_line; - redo; - } - - # Strip useless whitespace and trailing semicolons. - chomp; - s/^\s+//; - s/;\s*$//; - s/\s+/ /g; - - # Push the data into the appropriate data structure. - if (/^DATA\(insert(\s+OID\s+=\s+(\d+))?\s+\(\s*(.*)\s*\)\s*\)$/) - { - push @{ $catalog{data} }, {oid => $2, bki_values => $3}; - } - elsif (/^DESCR\(\"(.*)\"\)$/) - { - $most_recent = $catalog{data}->[-1]; - # this tests if most recent line is not a DATA() statement - if (ref $most_recent ne 'HASH') - { - die "DESCR() does not apply to any catalog ($input_file)"; - } - if (!defined $most_recent->{oid}) - { - die "DESCR() does not apply to any oid ($input_file)"; - } - elsif ($1 ne '') - { - $most_recent->{descr} = $1; - } - } - elsif (/^SHDESCR\(\"(.*)\"\)$/) - { - $most_recent = $catalog{data}->[-1]; - # this tests if most recent line is not a DATA() statement - if (ref $most_recent ne 'HASH') - { - die "SHDESCR() does not apply to any catalog ($input_file)"; - } - if (!defined $most_recent->{oid}) - { - die "SHDESCR() does not apply to any oid ($input_file)"; - } - elsif ($1 ne '') - { - $most_recent->{shdescr} = $1; - } - } - elsif (/^DECLARE_TOAST\(\s*(\w+),\s*(\d+),\s*(\d+)\)/) - { - $catname = 'toasting'; - my ($toast_name, $toast_oid, $index_oid) = ($1, $2, $3); - push @{ $catalog{data} }, "declare toast $toast_oid $index_oid on $toast_name\n"; - } - elsif (/^DECLARE_(UNIQUE_)?INDEX\(\s*(\w+),\s*(\d+),\s*(.+)\)/) - { - $catname = 'indexing'; - my ($is_unique, $index_name, $index_oid, $using) = ($1, $2, $3, $4); - push @{ $catalog{data} }, - sprintf( - "declare %sindex %s %s %s\n", - $is_unique ? 'unique ' : '', - $index_name, $index_oid, $using - ); - } - elsif (/^BUILD_INDICES/) - { - push @{ $catalog{data} }, "build indices\n"; - } - elsif (/^CATALOG\(([^,]*),(\d+)\)/) - { - $catname = $1; - $catalog{relation_oid} = $2; - - # Store pg_* catalog names in the same order we receive them - push @{ $catalogs{names} }, $catname; - - $catalog{bootstrap} = /BKI_BOOTSTRAP/ ? ' bootstrap' : ''; - $catalog{shared_relation} = /BKI_SHARED_RELATION/ ? ' shared_relation' : ''; - $catalog{without_oids} = /BKI_WITHOUT_OIDS/ ? ' without_oids' : ''; - $catalog{rowtype_oid} = /BKI_ROWTYPE_OID\((\d+)\)/ ? " rowtype_oid $1" : ''; - $catalog{schema_macro} = /BKI_SCHEMA_MACRO/ ? 'True' : ''; - $declaring_attributes = 1; - } - elsif ($declaring_attributes) - { - next if (/^{|^$/); - next if (/^#/); - if (/^}/) - { - undef $declaring_attributes; - } - else - { - my ($atttype, $attname) = split /\s+/, $_; - die "parse error ($input_file)" unless $attname; - if (exists $RENAME_ATTTYPE{$atttype}) - { - $atttype = $RENAME_ATTTYPE{$atttype}; - } - if ($attname =~ /(.*)\[.*\]/) # array attribute - { - $attname = $1; - $atttype .= '[]'; # variable-length only - } - push @{ $catalog{columns} }, {$attname => $atttype}; - } - } - } - $catalogs{$catname} = \%catalog; - close INPUT_FILE; - } - return \%catalogs; + my (%catalogs, $catname, $declaring_attributes, $most_recent); + $catalogs{names} = []; + + # There are a few types which are given one name in the C source, but a + # different name at the SQL level. These are enumerated here. + my %RENAME_ATTTYPE = ( + 'int16' => 'int2', + 'int32' => 'int4', + 'Oid' => 'oid', + 'NameData' => 'name', + 'TransactionId' => 'xid'); + + foreach my $input_file (@_) + { + my %catalog; + $catalog{columns} = []; + $catalog{data} = []; + + open(INPUT_FILE, '<', $input_file) || die "$input_file: $!"; + + # Scan the input file. + while (<INPUT_FILE>) + { + + # Strip C-style comments. + s;/\*(.|\n)*\*/;;g; + if (m;/\*;) + { + + # handle multi-line comments properly. + my $next_line = <INPUT_FILE>; + die "$input_file: ends within C-style comment\n" + if !defined $next_line; + $_ .= $next_line; + redo; + } + + # Strip useless whitespace and trailing semicolons. + chomp; + s/^\s+//; + s/;\s*$//; + s/\s+/ /g; + + # Push the data into the appropriate data structure. + if (/^DATA\(insert(\s+OID\s+=\s+(\d+))?\s+\(\s*(.*)\s*\)\s*\)$/) + { + push @{ $catalog{data} }, { oid => $2, bki_values => $3 }; + } + elsif (/^DESCR\(\"(.*)\"\)$/) + { + $most_recent = $catalog{data}->[-1]; + + # this tests if most recent line is not a DATA() statement + if (ref $most_recent ne 'HASH') + { + die "DESCR() does not apply to any catalog ($input_file)"; + } + if (!defined $most_recent->{oid}) + { + die "DESCR() does not apply to any oid ($input_file)"; + } + elsif ($1 ne '') + { + $most_recent->{descr} = $1; + } + } + elsif (/^SHDESCR\(\"(.*)\"\)$/) + { + $most_recent = $catalog{data}->[-1]; + + # this tests if most recent line is not a DATA() statement + if (ref $most_recent ne 'HASH') + { + die + "SHDESCR() does not apply to any catalog ($input_file)"; + } + if (!defined $most_recent->{oid}) + { + die "SHDESCR() does not apply to any oid ($input_file)"; + } + elsif ($1 ne '') + { + $most_recent->{shdescr} = $1; + } + } + elsif (/^DECLARE_TOAST\(\s*(\w+),\s*(\d+),\s*(\d+)\)/) + { + $catname = 'toasting'; + my ($toast_name, $toast_oid, $index_oid) = ($1, $2, $3); + push @{ $catalog{data} }, + "declare toast $toast_oid $index_oid on $toast_name\n"; + } + elsif (/^DECLARE_(UNIQUE_)?INDEX\(\s*(\w+),\s*(\d+),\s*(.+)\)/) + { + $catname = 'indexing'; + my ($is_unique, $index_name, $index_oid, $using) = + ($1, $2, $3, $4); + push @{ $catalog{data} }, + sprintf( + "declare %sindex %s %s %s\n", + $is_unique ? 'unique ' : '', + $index_name, $index_oid, $using); + } + elsif (/^BUILD_INDICES/) + { + push @{ $catalog{data} }, "build indices\n"; + } + elsif (/^CATALOG\(([^,]*),(\d+)\)/) + { + $catname = $1; + $catalog{relation_oid} = $2; + + # Store pg_* catalog names in the same order we receive them + push @{ $catalogs{names} }, $catname; + + $catalog{bootstrap} = /BKI_BOOTSTRAP/ ? ' bootstrap' : ''; + $catalog{shared_relation} = + /BKI_SHARED_RELATION/ ? ' shared_relation' : ''; + $catalog{without_oids} = + /BKI_WITHOUT_OIDS/ ? ' without_oids' : ''; + $catalog{rowtype_oid} = + /BKI_ROWTYPE_OID\((\d+)\)/ ? " rowtype_oid $1" : ''; + $catalog{schema_macro} = /BKI_SCHEMA_MACRO/ ? 'True' : ''; + $declaring_attributes = 1; + } + elsif ($declaring_attributes) + { + next if (/^{|^$/); + next if (/^#/); + if (/^}/) + { + undef $declaring_attributes; + } + else + { + my ($atttype, $attname) = split /\s+/, $_; + die "parse error ($input_file)" unless $attname; + if (exists $RENAME_ATTTYPE{$atttype}) + { + $atttype = $RENAME_ATTTYPE{$atttype}; + } + if ($attname =~ /(.*)\[.*\]/) # array attribute + { + $attname = $1; + $atttype .= '[]'; # variable-length only + } + push @{ $catalog{columns} }, { $attname => $atttype }; + } + } + } + $catalogs{$catname} = \%catalog; + close INPUT_FILE; + } + return \%catalogs; } # Rename temporary files to final names. @@ -179,11 +187,11 @@ sub Catalogs # can't use the same temp files sub RenameTempFile { - my $final_name = shift; - my $extension = shift; - my $temp_name = $final_name . $extension; - print "Writing $final_name\n"; - rename($temp_name, $final_name) || die "rename: $temp_name: $!"; + my $final_name = shift; + my $extension = shift; + my $temp_name = $final_name . $extension; + print "Writing $final_name\n"; + rename($temp_name, $final_name) || die "rename: $temp_name: $!"; } 1; diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl index ebc4825cf47..5c910a93c12 100644 --- a/src/backend/catalog/genbki.pl +++ b/src/backend/catalog/genbki.pl @@ -27,44 +27,44 @@ my $major_version; # Process command line switches. while (@ARGV) { - my $arg = shift @ARGV; - if ($arg !~ /^-/) - { - push @input_files, $arg; - } - elsif ($arg =~ /^-o/) - { - $output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV; - } - elsif ($arg =~ /^-I/) - { - push @include_path, length($arg) > 2 ? substr($arg, 2) : shift @ARGV; - } - elsif ($arg =~ /^--set-version=(.*)$/) - { - $major_version = $1; - die "Version must be in format nn.nn.\n" - if !($major_version =~ /^\d+\.\d+$/); - } - else - { - usage(); - } + my $arg = shift @ARGV; + if ($arg !~ /^-/) + { + push @input_files, $arg; + } + elsif ($arg =~ /^-o/) + { + $output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV; + } + elsif ($arg =~ /^-I/) + { + push @include_path, length($arg) > 2 ? substr($arg, 2) : shift @ARGV; + } + elsif ($arg =~ /^--set-version=(.*)$/) + { + $major_version = $1; + die "Version must be in format nn.nn.\n" + if !($major_version =~ /^\d+\.\d+$/); + } + else + { + usage(); + } } # Sanity check arguments. -die "No input files.\n" if !@input_files; +die "No input files.\n" if !@input_files; die "No include path; you must specify -I at least once.\n" if !@include_path; die "--set-version must be specified.\n" if !defined $major_version; # Make sure output_path ends in a slash. if ($output_path ne '' && substr($output_path, -1) ne '/') { - $output_path .= '/'; + $output_path .= '/'; } # Open temp files -my $tmpext = ".tmp$$"; +my $tmpext = ".tmp$$"; my $bkifile = $output_path . 'postgres.bki'; open BKI, '>', $bkifile . $tmpext or die "can't open $bkifile$tmpext: $!"; @@ -86,8 +86,10 @@ open SHDESCR, '>', $shdescrfile . $tmpext # to handle those sorts of things is in initdb.c's bootstrap_template1().) # NB: make sure that the files used here are known to be part of the .bki # file's dependencies by src/backend/catalog/Makefile. -my $BOOTSTRAP_SUPERUSERID = find_defined_symbol('pg_authid.h', 'BOOTSTRAP_SUPERUSERID'); -my $PG_CATALOG_NAMESPACE = find_defined_symbol('pg_namespace.h', 'PG_CATALOG_NAMESPACE'); +my $BOOTSTRAP_SUPERUSERID = + find_defined_symbol('pg_authid.h', 'BOOTSTRAP_SUPERUSERID'); +my $PG_CATALOG_NAMESPACE = + find_defined_symbol('pg_namespace.h', 'PG_CATALOG_NAMESPACE'); # Read all the input header files into internal data structures my $catalogs = Catalog::Catalogs(@input_files); @@ -103,155 +105,164 @@ my @tables_needing_macros; our @types; # produce output, one catalog at a time -foreach my $catname ( @{ $catalogs->{names} } ) +foreach my $catname (@{ $catalogs->{names} }) { - # .bki CREATE command for this catalog - my $catalog = $catalogs->{$catname}; - print BKI "create $catname $catalog->{relation_oid}" - . $catalog->{shared_relation} - . $catalog->{bootstrap} - . $catalog->{without_oids} - . $catalog->{rowtype_oid}. "\n"; - - my %bki_attr; - my @attnames; - foreach my $column ( @{ $catalog->{columns} } ) - { - my ($attname, $atttype) = %$column; - $bki_attr{$attname} = $atttype; - push @attnames, $attname; - } - print BKI " (\n"; - print BKI join " ,\n", map(" $_ = $bki_attr{$_}", @attnames); - print BKI "\n )\n"; - - # open it, unless bootstrap case (create bootstrap does this automatically) - if ($catalog->{bootstrap} eq '') - { - print BKI "open $catname\n"; - } - - if (defined $catalog->{data}) - { - # Ordinary catalog with DATA line(s) - foreach my $row ( @{ $catalog->{data} } ) - { - # substitute constant values we acquired above - $row->{bki_values} =~ s/\bPGUID\b/$BOOTSTRAP_SUPERUSERID/g; - $row->{bki_values} =~ s/\bPGNSP\b/$PG_CATALOG_NAMESPACE/g; - - # Save pg_type info for pg_attribute processing below - if ($catname eq 'pg_type') - { - my %type; - $type{oid} = $row->{oid}; - @type{@attnames} = split /\s+/, $row->{bki_values}; - push @types, \%type; - } - - # Write to postgres.bki - my $oid = $row->{oid} ? "OID = $row->{oid} " : ''; - printf BKI "insert %s( %s)\n", $oid, $row->{bki_values}; - - # Write comments to postgres.description and postgres.shdescription - if (defined $row->{descr}) - { - printf DESCR "%s\t%s\t0\t%s\n", $row->{oid}, $catname, $row->{descr}; - } - if (defined $row->{shdescr}) - { - printf SHDESCR "%s\t%s\t%s\n", $row->{oid}, $catname, $row->{shdescr}; - } - } - } - if ($catname eq 'pg_attribute') - { - # For pg_attribute.h, we generate DATA entries ourselves. - # NB: pg_type.h must come before pg_attribute.h in the input list - # of catalog names, since we use info from pg_type.h here. - foreach my $table_name ( @{ $catalogs->{names} } ) - { - my $table = $catalogs->{$table_name}; - - # Currently, all bootstrapped relations also need schemapg.h - # entries, so skip if the relation isn't to be in schemapg.h. - next if $table->{schema_macro} ne 'True'; - - $schemapg_entries{$table_name} = []; - push @tables_needing_macros, $table_name; - my $is_bootstrap = $table->{bootstrap}; - - # Generate entries for user attributes. - my $attnum = 0; - my $priornotnull = 1; - my @user_attrs = @{ $table->{columns} }; - foreach my $attr (@user_attrs) - { - $attnum++; - my $row = emit_pgattr_row($table_name, $attr, $priornotnull); - $row->{attnum} = $attnum; - $row->{attstattarget} = '-1'; - $priornotnull &= ($row->{attnotnull} eq 't'); - - # If it's bootstrapped, put an entry in postgres.bki. - if ($is_bootstrap eq ' bootstrap') - { - bki_insert($row, @attnames); - } - - # Store schemapg entries for later. - $row = emit_schemapg_row($row, grep { $bki_attr{$_} eq 'bool' } @attnames); - push @{ $schemapg_entries{$table_name} }, - '{ ' . join(', ', grep { defined $_ } - map $row->{$_}, @attnames) . ' }'; - } - - # Generate entries for system attributes. - # We only need postgres.bki entries, not schemapg.h entries. - if ($is_bootstrap eq ' bootstrap') - { - $attnum = 0; - my @SYS_ATTRS = ( - {ctid => 'tid'}, - {oid => 'oid'}, - {xmin => 'xid'}, - {cmin => 'cid'}, - {xmax => 'xid'}, - {cmax => 'cid'}, - {tableoid => 'oid'} - ); - foreach my $attr (@SYS_ATTRS) - { - $attnum--; - my $row = emit_pgattr_row($table_name, $attr, 1); - $row->{attnum} = $attnum; - $row->{attstattarget} = '0'; - - # some catalogs don't have oids - next if $table->{without_oids} eq ' without_oids' && - $row->{attname} eq 'oid'; - - bki_insert($row, @attnames); - } - } - } - } - - print BKI "close $catname\n"; + + # .bki CREATE command for this catalog + my $catalog = $catalogs->{$catname}; + print BKI "create $catname $catalog->{relation_oid}" + . $catalog->{shared_relation} + . $catalog->{bootstrap} + . $catalog->{without_oids} + . $catalog->{rowtype_oid} . "\n"; + + my %bki_attr; + my @attnames; + foreach my $column (@{ $catalog->{columns} }) + { + my ($attname, $atttype) = %$column; + $bki_attr{$attname} = $atttype; + push @attnames, $attname; + } + print BKI " (\n"; + print BKI join " ,\n", map(" $_ = $bki_attr{$_}", @attnames); + print BKI "\n )\n"; + + # open it, unless bootstrap case (create bootstrap does this automatically) + if ($catalog->{bootstrap} eq '') + { + print BKI "open $catname\n"; + } + + if (defined $catalog->{data}) + { + + # Ordinary catalog with DATA line(s) + foreach my $row (@{ $catalog->{data} }) + { + + # substitute constant values we acquired above + $row->{bki_values} =~ s/\bPGUID\b/$BOOTSTRAP_SUPERUSERID/g; + $row->{bki_values} =~ s/\bPGNSP\b/$PG_CATALOG_NAMESPACE/g; + + # Save pg_type info for pg_attribute processing below + if ($catname eq 'pg_type') + { + my %type; + $type{oid} = $row->{oid}; + @type{@attnames} = split /\s+/, $row->{bki_values}; + push @types, \%type; + } + + # Write to postgres.bki + my $oid = $row->{oid} ? "OID = $row->{oid} " : ''; + printf BKI "insert %s( %s)\n", $oid, $row->{bki_values}; + + # Write comments to postgres.description and postgres.shdescription + if (defined $row->{descr}) + { + printf DESCR "%s\t%s\t0\t%s\n", $row->{oid}, $catname, + $row->{descr}; + } + if (defined $row->{shdescr}) + { + printf SHDESCR "%s\t%s\t%s\n", $row->{oid}, $catname, + $row->{shdescr}; + } + } + } + if ($catname eq 'pg_attribute') + { + + # For pg_attribute.h, we generate DATA entries ourselves. + # NB: pg_type.h must come before pg_attribute.h in the input list + # of catalog names, since we use info from pg_type.h here. + foreach my $table_name (@{ $catalogs->{names} }) + { + my $table = $catalogs->{$table_name}; + + # Currently, all bootstrapped relations also need schemapg.h + # entries, so skip if the relation isn't to be in schemapg.h. + next if $table->{schema_macro} ne 'True'; + + $schemapg_entries{$table_name} = []; + push @tables_needing_macros, $table_name; + my $is_bootstrap = $table->{bootstrap}; + + # Generate entries for user attributes. + my $attnum = 0; + my $priornotnull = 1; + my @user_attrs = @{ $table->{columns} }; + foreach my $attr (@user_attrs) + { + $attnum++; + my $row = emit_pgattr_row($table_name, $attr, $priornotnull); + $row->{attnum} = $attnum; + $row->{attstattarget} = '-1'; + $priornotnull &= ($row->{attnotnull} eq 't'); + + # If it's bootstrapped, put an entry in postgres.bki. + if ($is_bootstrap eq ' bootstrap') + { + bki_insert($row, @attnames); + } + + # Store schemapg entries for later. + $row = + emit_schemapg_row($row, + grep { $bki_attr{$_} eq 'bool' } @attnames); + push @{ $schemapg_entries{$table_name} }, '{ ' + . join( + ', ', grep { defined $_ } + map $row->{$_}, @attnames) . ' }'; + } + + # Generate entries for system attributes. + # We only need postgres.bki entries, not schemapg.h entries. + if ($is_bootstrap eq ' bootstrap') + { + $attnum = 0; + my @SYS_ATTRS = ( + { ctid => 'tid' }, + { oid => 'oid' }, + { xmin => 'xid' }, + { cmin => 'cid' }, + { xmax => 'xid' }, + { cmax => 'cid' }, + { tableoid => 'oid' }); + foreach my $attr (@SYS_ATTRS) + { + $attnum--; + my $row = emit_pgattr_row($table_name, $attr, 1); + $row->{attnum} = $attnum; + $row->{attstattarget} = '0'; + + # some catalogs don't have oids + next + if $table->{without_oids} eq ' without_oids' + && $row->{attname} eq 'oid'; + + bki_insert($row, @attnames); + } + } + } + } + + print BKI "close $catname\n"; } # Any information needed for the BKI that is not contained in a pg_*.h header # (i.e., not contained in a header with a CATALOG() statement) comes here # Write out declare toast/index statements -foreach my $declaration ( @{ $catalogs->{toasting}->{data} } ) +foreach my $declaration (@{ $catalogs->{toasting}->{data} }) { - print BKI $declaration; + print BKI $declaration; } -foreach my $declaration ( @{ $catalogs->{indexing}->{data} } ) +foreach my $declaration (@{ $catalogs->{indexing}->{data} }) { - print BKI $declaration; + print BKI $declaration; } @@ -283,9 +294,9 @@ EOM # Emit schemapg declarations foreach my $table_name (@tables_needing_macros) { - print SCHEMAPG "\n#define Schema_$table_name \\\n"; - print SCHEMAPG join ", \\\n", @{ $schemapg_entries{$table_name} }; - print SCHEMAPG "\n"; + print SCHEMAPG "\n#define Schema_$table_name \\\n"; + print SCHEMAPG join ", \\\n", @{ $schemapg_entries{$table_name} }; + print SCHEMAPG "\n"; } # Closing boilerplate for schemapg.h @@ -298,9 +309,9 @@ close DESCR; close SHDESCR; # Finally, rename the completed files into place. -Catalog::RenameTempFile($bkifile, $tmpext); -Catalog::RenameTempFile($schemafile, $tmpext); -Catalog::RenameTempFile($descrfile, $tmpext); +Catalog::RenameTempFile($bkifile, $tmpext); +Catalog::RenameTempFile($schemafile, $tmpext); +Catalog::RenameTempFile($descrfile, $tmpext); Catalog::RenameTempFile($shdescrfile, $tmpext); exit 0; @@ -314,137 +325,140 @@ exit 0; # columns were all not-null. sub emit_pgattr_row { - my ($table_name, $attr, $priornotnull) = @_; - my ($attname, $atttype) = %$attr; - my %row; - - $row{attrelid} = $catalogs->{$table_name}->{relation_oid}; - $row{attname} = $attname; - - # Adjust type name for arrays: foo[] becomes _foo - # so we can look it up in pg_type - if ($atttype =~ /(.+)\[\]$/) - { - $atttype = '_' . $1; - } - - # Copy the type data from pg_type, and add some type-dependent items - foreach my $type (@types) - { - if ( defined $type->{typname} && $type->{typname} eq $atttype ) - { - $row{atttypid} = $type->{oid}; - $row{attlen} = $type->{typlen}; - $row{attbyval} = $type->{typbyval}; - $row{attstorage} = $type->{typstorage}; - $row{attalign} = $type->{typalign}; - # set attndims if it's an array type - $row{attndims} = $type->{typcategory} eq 'A' ? '1' : '0'; - $row{attcollation} = $type->{typcollation}; - # attnotnull must be set true if the type is fixed-width and - # prior columns are too --- compare DefineAttr in bootstrap.c. - # oidvector and int2vector are also treated as not-nullable. - if ($priornotnull) - { - $row{attnotnull} = - $type->{typname} eq 'oidvector' ? 't' - : $type->{typname} eq 'int2vector' ? 't' - : $type->{typlen} eq 'NAMEDATALEN' ? 't' - : $type->{typlen} > 0 ? 't' : 'f'; - } - else - { - $row{attnotnull} = 'f'; - } - last; - } - } - - # Add in default values for pg_attribute - my %PGATTR_DEFAULTS = ( - attcacheoff => '-1', - atttypmod => '-1', - atthasdef => 'f', - attisdropped => 'f', - attislocal => 't', - attinhcount => '0', - attacl => '_null_', - attoptions => '_null_', - attfdwoptions => '_null_' - ); - return {%PGATTR_DEFAULTS, %row}; + my ($table_name, $attr, $priornotnull) = @_; + my ($attname, $atttype) = %$attr; + my %row; + + $row{attrelid} = $catalogs->{$table_name}->{relation_oid}; + $row{attname} = $attname; + + # Adjust type name for arrays: foo[] becomes _foo + # so we can look it up in pg_type + if ($atttype =~ /(.+)\[\]$/) + { + $atttype = '_' . $1; + } + + # Copy the type data from pg_type, and add some type-dependent items + foreach my $type (@types) + { + if (defined $type->{typname} && $type->{typname} eq $atttype) + { + $row{atttypid} = $type->{oid}; + $row{attlen} = $type->{typlen}; + $row{attbyval} = $type->{typbyval}; + $row{attstorage} = $type->{typstorage}; + $row{attalign} = $type->{typalign}; + + # set attndims if it's an array type + $row{attndims} = $type->{typcategory} eq 'A' ? '1' : '0'; + $row{attcollation} = $type->{typcollation}; + + # attnotnull must be set true if the type is fixed-width and + # prior columns are too --- compare DefineAttr in bootstrap.c. + # oidvector and int2vector are also treated as not-nullable. + if ($priornotnull) + { + $row{attnotnull} = + $type->{typname} eq 'oidvector' ? 't' + : $type->{typname} eq 'int2vector' ? 't' + : $type->{typlen} eq 'NAMEDATALEN' ? 't' + : $type->{typlen} > 0 ? 't' + : 'f'; + } + else + { + $row{attnotnull} = 'f'; + } + last; + } + } + + # Add in default values for pg_attribute + my %PGATTR_DEFAULTS = ( + attcacheoff => '-1', + atttypmod => '-1', + atthasdef => 'f', + attisdropped => 'f', + attislocal => 't', + attinhcount => '0', + attacl => '_null_', + attoptions => '_null_', + attfdwoptions => '_null_'); + return { %PGATTR_DEFAULTS, %row }; } # Write a pg_attribute entry to postgres.bki sub bki_insert { - my $row = shift; - my @attnames = @_; - my $oid = $row->{oid} ? "OID = $row->{oid} " : ''; - my $bki_values = join ' ', map $row->{$_}, @attnames; - printf BKI "insert %s( %s)\n", $oid, $bki_values; + my $row = shift; + my @attnames = @_; + my $oid = $row->{oid} ? "OID = $row->{oid} " : ''; + my $bki_values = join ' ', map $row->{$_}, @attnames; + printf BKI "insert %s( %s)\n", $oid, $bki_values; } # The field values of a Schema_pg_xxx declaration are similar, but not # quite identical, to the corresponding values in postgres.bki. sub emit_schemapg_row { - my $row = shift; - my @bool_attrs = @_; - - # Supply appropriate quoting for these fields. - $row->{attname} = q|{"| . $row->{attname} . q|"}|; - $row->{attstorage} = q|'| . $row->{attstorage} . q|'|; - $row->{attalign} = q|'| . $row->{attalign} . q|'|; - - # We don't emit initializers for the variable length fields at all. - # Only the fixed-size portions of the descriptors are ever used. - delete $row->{attacl}; - delete $row->{attoptions}; - delete $row->{attfdwoptions}; - - # Expand booleans from 'f'/'t' to 'false'/'true'. - # Some values might be other macros (eg FLOAT4PASSBYVAL), don't change. - foreach my $attr (@bool_attrs) - { - $row->{$attr} = - $row->{$attr} eq 't' ? 'true' - : $row->{$attr} eq 'f' ? 'false' - : $row->{$attr}; - } - return $row; + my $row = shift; + my @bool_attrs = @_; + + # Supply appropriate quoting for these fields. + $row->{attname} = q|{"| . $row->{attname} . q|"}|; + $row->{attstorage} = q|'| . $row->{attstorage} . q|'|; + $row->{attalign} = q|'| . $row->{attalign} . q|'|; + + # We don't emit initializers for the variable length fields at all. + # Only the fixed-size portions of the descriptors are ever used. + delete $row->{attacl}; + delete $row->{attoptions}; + delete $row->{attfdwoptions}; + + # Expand booleans from 'f'/'t' to 'false'/'true'. + # Some values might be other macros (eg FLOAT4PASSBYVAL), don't change. + foreach my $attr (@bool_attrs) + { + $row->{$attr} = + $row->{$attr} eq 't' ? 'true' + : $row->{$attr} eq 'f' ? 'false' + : $row->{$attr}; + } + return $row; } # Find a symbol defined in a particular header file and extract the value. sub find_defined_symbol { - my ($catalog_header, $symbol) = @_; - for my $path (@include_path) - { - # Make sure include path ends in a slash. - if (substr($path, -1) ne '/') - { - $path .= '/'; - } - my $file = $path . $catalog_header; - next if !-f $file; - open(FIND_DEFINED_SYMBOL, '<', $file) || die "$file: $!"; - while (<FIND_DEFINED_SYMBOL>) - { - if (/^#define\s+\Q$symbol\E\s+(\S+)/) - { - return $1; - } - } - close FIND_DEFINED_SYMBOL; - die "$file: no definition found for $symbol\n"; - } - die "$catalog_header: not found in any include directory\n"; + my ($catalog_header, $symbol) = @_; + for my $path (@include_path) + { + + # Make sure include path ends in a slash. + if (substr($path, -1) ne '/') + { + $path .= '/'; + } + my $file = $path . $catalog_header; + next if !-f $file; + open(FIND_DEFINED_SYMBOL, '<', $file) || die "$file: $!"; + while (<FIND_DEFINED_SYMBOL>) + { + if (/^#define\s+\Q$symbol\E\s+(\S+)/) + { + return $1; + } + } + close FIND_DEFINED_SYMBOL; + die "$file: no definition found for $symbol\n"; + } + die "$catalog_header: not found in any include directory\n"; } sub usage { - die <<EOM; + die <<EOM; Usage: genbki.pl [options] header... Options: diff --git a/src/backend/utils/Gen_fmgrtab.pl b/src/backend/utils/Gen_fmgrtab.pl index b75c3592fbc..cf560265325 100644 --- a/src/backend/utils/Gen_fmgrtab.pl +++ b/src/backend/utils/Gen_fmgrtab.pl @@ -19,29 +19,29 @@ use strict; use warnings; # Collect arguments -my $infile; # pg_proc.h +my $infile; # pg_proc.h my $output_path = ''; while (@ARGV) { - my $arg = shift @ARGV; - if ($arg !~ /^-/) - { - $infile = $arg; - } - elsif ($arg =~ /^-o/) - { - $output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV; - } - else - { - usage(); - } + my $arg = shift @ARGV; + if ($arg !~ /^-/) + { + $infile = $arg; + } + elsif ($arg =~ /^-o/) + { + $output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV; + } + else + { + usage(); + } } # Make sure output_path ends in a slash. if ($output_path ne '' && substr($output_path, -1) ne '/') { - $output_path .= '/'; + $output_path .= '/'; } # Read all the data from the include/catalog files. @@ -50,48 +50,47 @@ my $catalogs = Catalog::Catalogs($infile); # Collect the raw data from pg_proc.h. my @fmgr = (); 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}; 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 - # won't work, because some quoted fields might contain internal - # whitespace. We handle this by folding them all to a simple - # "xxx". Fortunately, this script doesn't need to look at any - # fields that might need quoting, so this simple hack is - # sufficient. - $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. - next if $row->{prolang} ne '12'; - - push @fmgr, - { - oid => $row->{oid}, - strict => $row->{proisstrict}, - retset => $row->{proretset}, - nargs => $row->{pronargs}, - prosrc => $row->{prosrc}, - }; - - # Hack to work around memory leak in some versions of Perl - $row = undef; + + # To construct fmgroids.h and fmgrtab.c, we need to inspect some + # of the individual data fields. Just splitting on whitespace + # won't work, because some quoted fields might contain internal + # whitespace. We handle this by folding them all to a simple + # "xxx". Fortunately, this script doesn't need to look at any + # fields that might need quoting, so this simple hack is + # sufficient. + $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. + next if $row->{prolang} ne '12'; + + push @fmgr, + { oid => $row->{oid}, + strict => $row->{proisstrict}, + retset => $row->{proretset}, + nargs => $row->{pronargs}, + prosrc => $row->{prosrc}, }; + + # Hack to work around memory leak in some versions of Perl + $row = undef; } # Emit headers for both files -my $tmpext = ".tmp$$"; +my $tmpext = ".tmp$$"; 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 T, '>', $tabfile . $tmpext or die "Could not open $tabfile$tmpext: $!"; +open T, '>', $tabfile . $tmpext or die "Could not open $tabfile$tmpext: $!"; print H qq|/*------------------------------------------------------------------------- @@ -160,12 +159,12 @@ qq|/*------------------------------------------------------------------------- # Emit #define's and extern's -- only one per prosrc value 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}}; - $seenit{$s->{prosrc}} = 1; - print H "#define F_" . uc $s->{prosrc} . " $s->{oid}\n"; - print T "extern Datum $s->{prosrc} (PG_FUNCTION_ARGS);\n"; + next if $seenit{ $s->{prosrc} }; + $seenit{ $s->{prosrc} } = 1; + print H "#define F_" . uc $s->{prosrc} . " $s->{oid}\n"; + print T "extern Datum $s->{prosrc} (PG_FUNCTION_ARGS);\n"; } # Create the fmgr_builtins table @@ -173,10 +172,10 @@ print T "\nconst FmgrBuiltin fmgr_builtins[] = {\n"; my %bmap; $bmap{'t'} = 'true'; $bmap{'f'} = 'false'; -foreach my $s (sort {$a->{oid} <=> $b->{oid}} @fmgr) +foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr) { - print T - " { $s->{oid}, \"$s->{prosrc}\", $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, $s->{prosrc} },\n"; + print T +" { $s->{oid}, \"$s->{prosrc}\", $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, $s->{prosrc} },\n"; } # And add the file footers. @@ -198,11 +197,11 @@ close(T); # Finally, rename the completed files into place. Catalog::RenameTempFile($oidsfile, $tmpext); -Catalog::RenameTempFile($tabfile, $tmpext); +Catalog::RenameTempFile($tabfile, $tmpext); sub usage { - die <<EOM; + die <<EOM; 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 diff --git a/src/backend/utils/generate-errcodes.pl b/src/backend/utils/generate-errcodes.pl index cb2b5fc35cb..ee76cef47ed 100644 --- a/src/backend/utils/generate-errcodes.pl +++ b/src/backend/utils/generate-errcodes.pl @@ -6,36 +6,41 @@ use warnings; 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"; open my $errcodes, $ARGV[0] or die; -while (<$errcodes>) { - chomp; +while (<$errcodes>) +{ + chomp; - # Skip comments - next if /^#/; - next if /^\s*$/; + # Skip comments + next if /^#/; + next if /^\s*$/; - # Emit a comment for each section header - if (/^Section:(.*)/) { + # Emit a comment for each section header + if (/^Section:(.*)/) + { my $header = $1; $header =~ s/^\s+//; print "\n/* $header */\n"; 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 - $sqlstate = join ",", split "", $sqlstate; - # And quote them - $sqlstate =~ s/([^,])/'$1'/g; + # Split the sqlstate letters + $sqlstate = join ",", split "", $sqlstate; - 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; diff --git a/src/backend/utils/mb/Unicode/UCS_to_BIG5.pl b/src/backend/utils/mb/Unicode/UCS_to_BIG5.pl index b41e79703be..06d924853f3 100755 --- a/src/backend/utils/mb/Unicode/UCS_to_BIG5.pl +++ b/src/backend/utils/mb/Unicode/UCS_to_BIG5.pl @@ -33,68 +33,82 @@ require "ucs2utf.pl"; # $in_file = "BIG5.TXT"; -open( FILE, $in_file ) || die( "cannot open $in_file" ); +open(FILE, $in_file) || die("cannot open $in_file"); reset 'array'; -while( <FILE> ){ +while (<FILE>) +{ chop; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $utf } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + if ($array{$utf} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; - $array{ $utf } = $code; + $array{$utf} = $code; } } -close( FILE ); +close(FILE); $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; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); # Pick only the ETEN extended characters in the range 0xf9d6 - 0xf9dc # from CP950.TXT - if( $code >= 0x80 && $ucs >= 0x0080 && - $code >= 0xf9d6 && $code <= 0xf9dc ){ + if ( $code >= 0x80 + && $ucs >= 0x0080 + && $code >= 0xf9d6 + && $code <= 0xf9dc) + { $utf = &ucs2utf($ucs); - if( $array{ $utf } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + if ($array{$utf} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; - $array{ $utf } = $code; + $array{$utf} = $code; } } -close( FILE ); +close(FILE); $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"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $code = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $code = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $code; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $code; } } @@ -107,67 +121,81 @@ close(FILE); # $in_file = "BIG5.TXT"; -open( FILE, $in_file ) || die( "cannot open $in_file" ); +open(FILE, $in_file) || die("cannot open $in_file"); reset 'array'; -while( <FILE> ){ +while (<FILE>) +{ chop; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $utf } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + if ($array{$utf} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; - $array{ $code } = $utf; + $array{$code} = $utf; } } -close( FILE ); +close(FILE); $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; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); # Pick only the ETEN extended characters in the range 0xf9d6 - 0xf9dc # from CP950.TXT - if( $code >= 0x80 && $ucs >= 0x0080 && - $code >= 0xf9d6 && $code <= 0xf9dc ){ + if ( $code >= 0x80 + && $ucs >= 0x0080 + && $code >= 0xf9d6 + && $code <= 0xf9dc) + { $utf = &ucs2utf($ucs); - if( $array{ $utf } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + if ($array{$utf} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; - $array{ $code } = $utf; + $array{$code} = $utf; } } -close( FILE ); +close(FILE); $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"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $utf = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $utf = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; } } diff --git a/src/backend/utils/mb/Unicode/UCS_to_EUC_CN.pl b/src/backend/utils/mb/Unicode/UCS_to_EUC_CN.pl index 0aa94c2b279..38c8ccd8806 100755 --- a/src/backend/utils/mb/Unicode/UCS_to_EUC_CN.pl +++ b/src/backend/utils/mb/Unicode/UCS_to_EUC_CN.pl @@ -22,43 +22,51 @@ require "ucs2utf.pl"; $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; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $utf } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + if ($array{$utf} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; - $array{ $utf } = ($code | 0x8080); + $array{$utf} = ($code | 0x8080); } } -close( FILE ); +close(FILE); # # first, generate UTF8 --> EUC_CN table # $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"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $code = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $code = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $code; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $code; } } @@ -71,39 +79,47 @@ close(FILE); # 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; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $code } ne "" ){ - printf STDERR "Warning: duplicate code: %04x\n",$ucs; + if ($array{$code} ne "") + { + printf STDERR "Warning: duplicate code: %04x\n", $ucs; next; } $count++; $code |= 0x8080; - $array{ $code } = $utf; + $array{$code} = $utf; } } -close( FILE ); +close(FILE); $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"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $utf = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $utf = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; } } diff --git a/src/backend/utils/mb/Unicode/UCS_to_EUC_JIS_2004.pl b/src/backend/utils/mb/Unicode/UCS_to_EUC_JIS_2004.pl index 797f825e336..b381aa65720 100755 --- a/src/backend/utils/mb/Unicode/UCS_to_EUC_JIS_2004.pl +++ b/src/backend/utils/mb/Unicode/UCS_to_EUC_JIS_2004.pl @@ -15,89 +15,110 @@ $TEST = 1; $in_file = "euc-jis-2004-std.txt"; -open( FILE, $in_file ) || die( "cannot open $in_file" ); +open(FILE, $in_file) || die("cannot open $in_file"); reset 'array'; reset 'array1'; reset 'comment'; reset 'comment1'; -while($line = <FILE> ){ - if ($line =~ /^0x(.*)[ \t]*U\+(.*)\+(.*)[ \t]*#(.*)$/) { - $c = $1; - $u1 = $2; - $u2 = $3; - $rest = "U+" . $u1 . "+" . $u2 . $4; - $code = hex($c); - $ucs = hex($u1); - $utf1 = &ucs2utf($ucs); - $ucs = hex($u2); - $utf2 = &ucs2utf($ucs); - $str = sprintf "%08x%08x", $utf1, $utf2; - $array1{ $str } = $code; - $comment1{ $str } = $rest; +while ($line = <FILE>) +{ + if ($line =~ /^0x(.*)[ \t]*U\+(.*)\+(.*)[ \t]*#(.*)$/) + { + $c = $1; + $u1 = $2; + $u2 = $3; + $rest = "U+" . $u1 . "+" . $u2 . $4; + $code = hex($c); + $ucs = hex($u1); + $utf1 = &ucs2utf($ucs); + $ucs = hex($u2); + $utf2 = &ucs2utf($ucs); + $str = sprintf "%08x%08x", $utf1, $utf2; + $array1{$str} = $code; + $comment1{$str} = $rest; $count1++; next; - } elsif ($line =~ /^0x(.*)[ \t]*U\+(.*)[ \t]*#(.*)$/) { - $c = $1; - $u = $2; + } + elsif ($line =~ /^0x(.*)[ \t]*U\+(.*)[ \t]*#(.*)$/) + { + $c = $1; + $u = $2; $rest = "U+" . $u . $3; - } else { + } + else + { next; } - $ucs = hex($u); + $ucs = hex($u); $code = hex($c); - $utf = &ucs2utf($ucs); - if( $array{ $utf } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + $utf = &ucs2utf($ucs); + if ($array{$utf} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; - $array{ $utf } = $code; - $comment{ $code } = $rest; + $array{$utf} = $code; + $comment{$code} = $rest; } -close( FILE ); +close(FILE); $file = "utf8_to_euc_jis_2004.map"; -open( FILE, "> $file" ) || die( "cannot open $file" ); +open(FILE, "> $file") || die("cannot open $file"); print FILE "/*\n"; print FILE " * This file was generated by UCS_to_EUC_JIS_2004.pl\n"; print FILE " */\n"; print FILE "static pg_utf_to_local ULmapEUC_JIS_2004[] = {\n"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $code = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $code = $array{$index}; $count--; - 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, $comment{ $code }; + 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, + $comment{$code}; } } print FILE "};\n"; close(FILE); -if ($TEST == 1) { +if ($TEST == 1) +{ $file1 = "utf8.data"; $file2 = "euc_jis_2004.data"; - open( FILE1, "> $file1" ) || die( "cannot open $file1" ); - open( FILE2, "> $file2" ) || die( "cannot open $file2" ); - - for $index ( sort {$a <=> $b} keys( %array ) ){ - $code = $array{ $index }; - if ($code > 0x00 && $code != 0x09 && $code != 0x0a && $code != 0x0d && - $code != 0x5c && - ($code < 0x80 || - ($code >= 0x8ea1 && $code <= 0x8efe) || - ($code >= 0x8fa1a1 && $code <= 0x8ffefe) || - ($code >= 0xa1a1 && $code <= 0x8fefe))) { - for ($i = 3; $i >= 0; $i--) { - $s = $i * 8; + open(FILE1, "> $file1") || die("cannot open $file1"); + open(FILE2, "> $file2") || die("cannot open $file2"); + + for $index (sort { $a <=> $b } keys(%array)) + { + $code = $array{$index}; + if ( $code > 0x00 + && $code != 0x09 + && $code != 0x0a + && $code != 0x0d + && $code != 0x5c + && ( $code < 0x80 + || ($code >= 0x8ea1 && $code <= 0x8efe) + || ($code >= 0x8fa1a1 && $code <= 0x8ffefe) + || ($code >= 0xa1a1 && $code <= 0x8fefe))) + { + for ($i = 3; $i >= 0; $i--) + { + $s = $i * 8; $mask = 0xff << $s; - print FILE1 pack("C", ($index & $mask) >> $s) if $index & $mask; + print FILE1 pack("C", ($index & $mask) >> $s) + if $index & $mask; print FILE2 pack("C", ($code & $mask) >> $s) if $code & $mask; } print FILE1 "\n"; @@ -107,46 +128,62 @@ if ($TEST == 1) { } $file = "utf8_to_euc_jis_2004_combined.map"; -open( FILE, "> $file" ) || die( "cannot open $file" ); +open(FILE, "> $file") || die("cannot open $file"); print FILE "/*\n"; print FILE " * This file was generated by UCS_to_EUC_JIS_2004.pl\n"; print FILE " */\n"; -print FILE "static pg_utf_to_local_combined ULmapEUC_JIS_2004_combined[] = {\n"; +print FILE + "static pg_utf_to_local_combined ULmapEUC_JIS_2004_combined[] = {\n"; -for $index ( sort {$a cmp $b} keys( %array1 ) ){ - $code = $array1{ $index }; +for $index (sort { $a cmp $b } keys(%array1)) +{ + $code = $array1{$index}; $count1--; - if( $count1 == 0 ){ - printf FILE " {0x%s, 0x%s, 0x%06x} /* %s */\n", substr($index, 0, 8), substr($index, 8, 8), $code, $comment1{ $index }; - } else { - printf FILE " {0x%s, 0x%s, 0x%06x}, /* %s */\n", substr($index, 0, 8), substr($index, 8, 8), $code, $comment1{ $index }; + if ($count1 == 0) + { + printf FILE " {0x%s, 0x%s, 0x%06x} /* %s */\n", substr($index, 0, 8), + substr($index, 8, 8), $code, $comment1{$index}; + } + else + { + printf FILE " {0x%s, 0x%s, 0x%06x}, /* %s */\n", + substr($index, 0, 8), substr($index, 8, 8), $code, + $comment1{$index}; } } print FILE "};\n"; close(FILE); -if ($TEST == 1) { - for $index ( sort {$a cmp $b} keys( %array1 ) ){ - $code = $array1{ $index }; - if ($code > 0x00 && $code != 0x09 && $code != 0x0a && $code != 0x0d && - $code != 0x5c && - ($code < 0x80 || - ($code >= 0x8ea1 && $code <= 0x8efe) || - ($code >= 0x8fa1a1 && $code <= 0x8ffefe) || - ($code >= 0xa1a1 && $code <= 0x8fefe))) { +if ($TEST == 1) +{ + for $index (sort { $a cmp $b } keys(%array1)) + { + $code = $array1{$index}; + if ( $code > 0x00 + && $code != 0x09 + && $code != 0x0a + && $code != 0x0d + && $code != 0x5c + && ( $code < 0x80 + || ($code >= 0x8ea1 && $code <= 0x8efe) + || ($code >= 0x8fa1a1 && $code <= 0x8ffefe) + || ($code >= 0xa1a1 && $code <= 0x8fefe))) + { $v1 = hex(substr($index, 0, 8)); $v2 = hex(substr($index, 8, 8)); - for ($i = 3; $i >= 0; $i--) { - $s = $i * 8; + for ($i = 3; $i >= 0; $i--) + { + $s = $i * 8; $mask = 0xff << $s; - print FILE1 pack("C", ($v1 & $mask) >> $s) if $v1 & $mask; + print FILE1 pack("C", ($v1 & $mask) >> $s) if $v1 & $mask; print FILE2 pack("C", ($code & $mask) >> $s) if $code & $mask; } - for ($i = 3; $i >= 0; $i--) { - $s = $i * 8; + for ($i = 3; $i >= 0; $i--) + { + $s = $i * 8; $mask = 0xff << $s; print FILE1 pack("C", ($v2 & $mask) >> $s) if $v2 & $mask; } @@ -162,65 +199,78 @@ if ($TEST == 1) { $in_file = "euc-jis-2004-std.txt"; -open( FILE, $in_file ) || die( "cannot open $in_file" ); +open(FILE, $in_file) || die("cannot open $in_file"); reset 'array'; reset 'array1'; reset 'comment'; reset 'comment1'; -while($line = <FILE> ){ - if ($line =~ /^0x(.*)[ \t]*U\+(.*)\+(.*)[ \t]*#(.*)$/) { - $c = $1; - $u1 = $2; - $u2 = $3; - $rest = "U+" . $u1 . "+" . $u2 . $4; - $code = hex($c); - $ucs = hex($u1); - $utf1 = &ucs2utf($ucs); - $ucs = hex($u2); - $utf2 = &ucs2utf($ucs); - $str = sprintf "%08x%08x", $utf1, $utf2; - $array1{ $code } = $str; - $comment1{ $code } = $rest; +while ($line = <FILE>) +{ + if ($line =~ /^0x(.*)[ \t]*U\+(.*)\+(.*)[ \t]*#(.*)$/) + { + $c = $1; + $u1 = $2; + $u2 = $3; + $rest = "U+" . $u1 . "+" . $u2 . $4; + $code = hex($c); + $ucs = hex($u1); + $utf1 = &ucs2utf($ucs); + $ucs = hex($u2); + $utf2 = &ucs2utf($ucs); + $str = sprintf "%08x%08x", $utf1, $utf2; + $array1{$code} = $str; + $comment1{$code} = $rest; $count1++; next; - } elsif ($line =~ /^0x(.*)[ \t]*U\+(.*)[ \t]*#(.*)$/) { - $c = $1; - $u = $2; + } + elsif ($line =~ /^0x(.*)[ \t]*U\+(.*)[ \t]*#(.*)$/) + { + $c = $1; + $u = $2; $rest = "U+" . $u . $3; - } else { + } + else + { next; } - $ucs = hex($u); + $ucs = hex($u); $code = hex($c); - $utf = &ucs2utf($ucs); - if( $array{ $code } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + $utf = &ucs2utf($ucs); + if ($array{$code} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; - $array{ $code } = $utf; - $comment{ $utf } = $rest; + $array{$code} = $utf; + $comment{$utf} = $rest; } -close( FILE ); +close(FILE); $file = "euc_jis_2004_to_utf8.map"; -open( FILE, "> $file" ) || die( "cannot open $file" ); +open(FILE, "> $file") || die("cannot open $file"); print FILE "/*\n"; print FILE " * This file was generated by UCS_to_EUC_JIS_2004.pl\n"; print FILE " */\n"; print FILE "static pg_local_to_utf LUmapEUC_JIS_2004[] = {\n"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $code = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $code = $array{$index}; $count--; - if( $count == 0 ){ - printf FILE " {0x%06x, 0x%08x} /* %s */\n", $index, $code, $comment{ $code }; - } else { - printf FILE " {0x%06x, 0x%08x}, /* %s */\n", $index, $code, $comment{ $code }; + if ($count == 0) + { + printf FILE " {0x%06x, 0x%08x} /* %s */\n", $index, $code, + $comment{$code}; + } + else + { + printf FILE " {0x%06x, 0x%08x}, /* %s */\n", $index, $code, + $comment{$code}; } } @@ -228,19 +278,26 @@ print FILE "};\n"; close(FILE); $file = "euc_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 " * This file was generated by UCS_to_EUC_JIS_2004.pl\n"; print FILE " */\n"; -print FILE "static pg_local_to_utf_combined LUmapEUC_JIS_2004_combined[] = {\n"; +print FILE + "static pg_local_to_utf_combined LUmapEUC_JIS_2004_combined[] = {\n"; -for $index ( sort {$a <=> $b} keys( %array1 ) ){ - $code = $array1{ $index }; +for $index (sort { $a <=> $b } keys(%array1)) +{ + $code = $array1{$index}; $count1--; - if( $count1 == 0 ){ - printf FILE " {0x%06x, 0x%s, 0x%s} /* %s */\n", $index, substr($code, 0, 8), substr($code, 8, 8), $comment1{ $index }; - } else { - printf FILE " {0x%06x, 0x%s, 0x%s}, /* %s */\n", $index, substr($code, 0, 8), substr($code, 8, 8), $comment1{ $index }; + if ($count1 == 0) + { + printf FILE " {0x%06x, 0x%s, 0x%s} /* %s */\n", $index, + substr($code, 0, 8), substr($code, 8, 8), $comment1{$index}; + } + else + { + printf FILE " {0x%06x, 0x%s, 0x%s}, /* %s */\n", $index, + substr($code, 0, 8), substr($code, 8, 8), $comment1{$index}; } } diff --git a/src/backend/utils/mb/Unicode/UCS_to_EUC_JP.pl b/src/backend/utils/mb/Unicode/UCS_to_EUC_JP.pl index 7c1292e3b8a..54632f168fd 100755 --- a/src/backend/utils/mb/Unicode/UCS_to_EUC_JP.pl +++ b/src/backend/utils/mb/Unicode/UCS_to_EUC_JP.pl @@ -36,102 +36,118 @@ require "ucs2utf.pl"; # $in_file = "JIS0201.TXT"; -open( FILE, $in_file ) || die( "cannot open $in_file" ); +open(FILE, $in_file) || die("cannot open $in_file"); reset 'array'; -while( <FILE> ){ +while (<FILE>) +{ chop; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $utf } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + if ($array{$utf} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; # add single shift 2 - $array{ $utf } = ($code | 0x8e00); + $array{$utf} = ($code | 0x8e00); } } -close( FILE ); +close(FILE); # # JIS0208 # $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; - if( /^#/ ){ + if (/^#/) + { next; } - ( $s, $c, $u, $rest ) = split; - $ucs = hex($u); + ($s, $c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $utf } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + if ($array{$utf} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; - $array{ $utf } = ($code | 0x8080); + $array{$utf} = ($code | 0x8080); } } -close( FILE ); +close(FILE); # # JIS0212 # $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; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $utf } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + if ($array{$utf} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; - $array{ $utf } = ($code | 0x8f8080); + $array{$utf} = ($code | 0x8f8080); } } -close( FILE ); +close(FILE); # # first, generate UTF8 --> EUC_JP table # $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"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $code = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $code = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $code; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $code; } } @@ -148,100 +164,116 @@ close(FILE); # $in_file = "JIS0201.TXT"; -open( FILE, $in_file ) || die( "cannot open $in_file" ); +open(FILE, $in_file) || die("cannot open $in_file"); reset 'array'; -while( <FILE> ){ +while (<FILE>) +{ chop; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $code } ne "" ){ - printf STDERR "Warning: duplicate code: %04x\n",$ucs; + if ($array{$code} ne "") + { + printf STDERR "Warning: duplicate code: %04x\n", $ucs; next; } $count++; # add single shift 2 $code |= 0x8e00; - $array{ $code } = $utf; + $array{$code} = $utf; } } -close( FILE ); +close(FILE); # # JIS0208 # $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; - if( /^#/ ){ + if (/^#/) + { next; } - ( $s, $c, $u, $rest ) = split; - $ucs = hex($u); + ($s, $c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $code } ne "" ){ - printf STDERR "Warning: duplicate code: %04x\n",$ucs; + if ($array{$code} ne "") + { + printf STDERR "Warning: duplicate code: %04x\n", $ucs; next; } $count++; $code |= 0x8080; - $array{ $code } = $utf; + $array{$code} = $utf; } } -close( FILE ); +close(FILE); # # JIS0212 # $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; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $code } ne "" ){ - printf STDERR "Warning: duplicate code: %04x\n",$ucs; + if ($array{$code} ne "") + { + printf STDERR "Warning: duplicate code: %04x\n", $ucs; next; } $count++; $code |= 0x8f8080; - $array{ $code } = $utf; + $array{$code} = $utf; } } -close( FILE ); +close(FILE); $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"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $utf = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $utf = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; } } diff --git a/src/backend/utils/mb/Unicode/UCS_to_EUC_KR.pl b/src/backend/utils/mb/Unicode/UCS_to_EUC_KR.pl index 6825f5339ac..d0b22fcceb6 100755 --- a/src/backend/utils/mb/Unicode/UCS_to_EUC_KR.pl +++ b/src/backend/utils/mb/Unicode/UCS_to_EUC_KR.pl @@ -22,43 +22,51 @@ require "ucs2utf.pl"; $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; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $utf } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + if ($array{$utf} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; - $array{ $utf } = ($code | 0x8080); + $array{$utf} = ($code | 0x8080); } } -close( FILE ); +close(FILE); # # first, generate UTF8 --> EUC_KR table # $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"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $code = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $code = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $code; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $code; } } @@ -71,39 +79,47 @@ close(FILE); # 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; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $code } ne "" ){ - printf STDERR "Warning: duplicate code: %04x\n",$ucs; + if ($array{$code} ne "") + { + printf STDERR "Warning: duplicate code: %04x\n", $ucs; next; } $count++; $code |= 0x8080; - $array{ $code } = $utf; + $array{$code} = $utf; } } -close( FILE ); +close(FILE); $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"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $utf = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $utf = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; } } diff --git a/src/backend/utils/mb/Unicode/UCS_to_EUC_TW.pl b/src/backend/utils/mb/Unicode/UCS_to_EUC_TW.pl index dc406dc16c7..45cee78ed85 100755 --- a/src/backend/utils/mb/Unicode/UCS_to_EUC_TW.pl +++ b/src/backend/utils/mb/Unicode/UCS_to_EUC_TW.pl @@ -23,53 +23,66 @@ require "ucs2utf.pl"; $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; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $utf } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + if ($array{$utf} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; $plane = ($code & 0x1f0000) >> 16; - if ($plane > 16) { + if ($plane > 16) + { printf STDERR "Warning: invalid plane No.$plane. ignored\n"; next; } - if ($plane == 1) { - $array{ $utf } = (($code & 0xffff) | 0x8080); - } else { - $array{ $utf } = (0x8ea00000 + ($plane << 16)) | (($code & 0xffff) | 0x8080); + if ($plane == 1) + { + $array{$utf} = (($code & 0xffff) | 0x8080); + } + else + { + $array{$utf} = + (0x8ea00000 + ($plane << 16)) | (($code & 0xffff) | 0x8080); } } } -close( FILE ); +close(FILE); # # first, generate UTF8 --> EUC_TW table # $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"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $code = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $code = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $code; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $code; } } @@ -82,50 +95,60 @@ close(FILE); # 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; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $code } ne "" ){ - printf STDERR "Warning: duplicate code: %04x\n",$ucs; + if ($array{$code} ne "") + { + printf STDERR "Warning: duplicate code: %04x\n", $ucs; next; } $count++; $plane = ($code & 0x1f0000) >> 16; - if ($plane > 16) { + if ($plane > 16) + { printf STDERR "Warning: invalid plane No.$plane. ignored\n"; next; } - if ($plane == 1) { + if ($plane == 1) + { $c = (($code & 0xffff) | 0x8080); - $array{ $c } = $utf; + $array{$c} = $utf; $count++; } $c = (0x8ea00000 + ($plane << 16)) | (($code & 0xffff) | 0x8080); - $array{ $c } = $utf; + $array{$c} = $utf; } } -close( FILE ); +close(FILE); $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"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $utf = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $utf = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; } } diff --git a/src/backend/utils/mb/Unicode/UCS_to_GB18030.pl b/src/backend/utils/mb/Unicode/UCS_to_GB18030.pl index 636a9620bd9..ef5dd81de75 100755 --- a/src/backend/utils/mb/Unicode/UCS_to_GB18030.pl +++ b/src/backend/utils/mb/Unicode/UCS_to_GB18030.pl @@ -18,28 +18,32 @@ require "ucs2utf.pl"; $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; - if( /^#/ ){ + if (/^#/) + { next; } - ( $u, $c, $rest ) = split; - $ucs = hex($u); + ($u, $c, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $utf } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + if ($array{$utf} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; - $array{ $utf } = $code; + $array{$utf} = $code; } } -close( FILE ); +close(FILE); # @@ -47,15 +51,19 @@ close( FILE ); # $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"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $code = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $code = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $code; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $code; } } @@ -69,38 +77,46 @@ close(FILE); # 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; - if( /^#/ ){ + if (/^#/) + { next; } - ( $u, $c, $rest ) = split; - $ucs = hex($u); + ($u, $c, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $code } ne "" ){ - printf STDERR "Warning: duplicate code: %04x\n",$ucs; + if ($array{$code} ne "") + { + printf STDERR "Warning: duplicate code: %04x\n", $ucs; next; } $count++; - $array{ $code } = $utf; + $array{$code} = $utf; } } -close( FILE ); +close(FILE); $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"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $utf = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $utf = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; } } diff --git a/src/backend/utils/mb/Unicode/UCS_to_SHIFT_JIS_2004.pl b/src/backend/utils/mb/Unicode/UCS_to_SHIFT_JIS_2004.pl index b16cdb3321b..40735ed7e2e 100755 --- a/src/backend/utils/mb/Unicode/UCS_to_SHIFT_JIS_2004.pl +++ b/src/backend/utils/mb/Unicode/UCS_to_SHIFT_JIS_2004.pl @@ -13,65 +13,80 @@ require "ucs2utf.pl"; $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 'array1'; reset 'comment'; reset 'comment1'; -while($line = <FILE> ){ - if ($line =~ /^0x(.*)[ \t]*U\+(.*)\+(.*)[ \t]*#(.*)$/) { - $c = $1; - $u1 = $2; - $u2 = $3; - $rest = "U+" . $u1 . "+" . $u2 . $4; - $code = hex($c); - $ucs = hex($u1); - $utf1 = &ucs2utf($ucs); - $ucs = hex($u2); - $utf2 = &ucs2utf($ucs); - $str = sprintf "%08x%08x", $utf1, $utf2; - $array1{ $str } = $code; - $comment1{ $str } = $rest; +while ($line = <FILE>) +{ + if ($line =~ /^0x(.*)[ \t]*U\+(.*)\+(.*)[ \t]*#(.*)$/) + { + $c = $1; + $u1 = $2; + $u2 = $3; + $rest = "U+" . $u1 . "+" . $u2 . $4; + $code = hex($c); + $ucs = hex($u1); + $utf1 = &ucs2utf($ucs); + $ucs = hex($u2); + $utf2 = &ucs2utf($ucs); + $str = sprintf "%08x%08x", $utf1, $utf2; + $array1{$str} = $code; + $comment1{$str} = $rest; $count1++; next; - } elsif ($line =~ /^0x(.*)[ \t]*U\+(.*)[ \t]*#(.*)$/) { - $c = $1; - $u = $2; + } + elsif ($line =~ /^0x(.*)[ \t]*U\+(.*)[ \t]*#(.*)$/) + { + $c = $1; + $u = $2; $rest = "U+" . $u . $3; - } else { + } + else + { next; } - $ucs = hex($u); + $ucs = hex($u); $code = hex($c); - $utf = &ucs2utf($ucs); - if( $array{ $utf } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %08x UCS: %04x Shift JIS: %04x\n",$utf, $ucs, $code; + $utf = &ucs2utf($ucs); + if ($array{$utf} ne "") + { + printf STDERR + "Warning: duplicate UTF8: %08x UCS: %04x Shift JIS: %04x\n", $utf, + $ucs, $code; next; } $count++; - $array{ $utf } = $code; - $comment{ $code } = $rest; + $array{$utf} = $code; + $comment{$code} = $rest; } -close( FILE ); +close(FILE); $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 " * This file was generated by UCS_to_SHIFT_JIS_2004.pl\n"; print FILE " */\n"; print FILE "static pg_utf_to_local ULmapSHIFT_JIS_2004[] = {\n"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $code = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $code = $array{$index}; $count--; - 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, $comment{ $code }; + 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, + $comment{$code}; } } @@ -79,19 +94,27 @@ print FILE "};\n"; close(FILE); $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 " * This file was generated by UCS_to_SHIFT_JIS_2004.pl\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 ) ){ - $code = $array1{ $index }; +for $index (sort { $a cmp $b } keys(%array1)) +{ + $code = $array1{$index}; $count1--; - 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), substr($index, 8, 8), $code, $comment1{ $index }; + 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), substr($index, 8, 8), $code, + $comment1{$index}; } } @@ -102,66 +125,81 @@ close(FILE); $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 'array1'; reset 'comment'; reset 'comment1'; -while($line = <FILE> ){ - if ($line =~ /^0x(.*)[ \t]*U\+(.*)\+(.*)[ \t]*#(.*)$/) { - $c = $1; - $u1 = $2; - $u2 = $3; - $rest = "U+" . $u1 . "+" . $u2 . $4; - $code = hex($c); - $ucs = hex($u1); - $utf1 = &ucs2utf($ucs); - $ucs = hex($u2); - $utf2 = &ucs2utf($ucs); - $str = sprintf "%08x%08x", $utf1, $utf2; - $array1{ $code } = $str; - $comment1{ $code } = $rest; +while ($line = <FILE>) +{ + if ($line =~ /^0x(.*)[ \t]*U\+(.*)\+(.*)[ \t]*#(.*)$/) + { + $c = $1; + $u1 = $2; + $u2 = $3; + $rest = "U+" . $u1 . "+" . $u2 . $4; + $code = hex($c); + $ucs = hex($u1); + $utf1 = &ucs2utf($ucs); + $ucs = hex($u2); + $utf2 = &ucs2utf($ucs); + $str = sprintf "%08x%08x", $utf1, $utf2; + $array1{$code} = $str; + $comment1{$code} = $rest; $count1++; next; - } elsif ($line =~ /^0x(.*)[ \t]*U\+(.*)[ \t]*#(.*)$/) { - $c = $1; - $u = $2; + } + elsif ($line =~ /^0x(.*)[ \t]*U\+(.*)[ \t]*#(.*)$/) + { + $c = $1; + $u = $2; $rest = "U+" . $u . $3; - } else { + } + else + { next; } - $ucs = hex($u); + $ucs = hex($u); $code = hex($c); - $utf = &ucs2utf($ucs); - 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 }; + $utf = &ucs2utf($ucs); + 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}; next; } $count++; - $array{ $code } = $utf; - $comment{ $utf } = $rest; + $array{$code} = $utf; + $comment{$utf} = $rest; } -close( FILE ); +close(FILE); $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 " * This file was generated by UCS_to_SHIFTJIS_2004.pl\n"; print FILE " */\n"; print FILE "static pg_local_to_utf LUmapSHIFT_JIS_2004[] = {\n"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $code = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $code = $array{$index}; $count--; - 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, $comment{ $code }; + 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, + $comment{$code}; } } @@ -169,19 +207,26 @@ print FILE "};\n"; close(FILE); $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 " * This file was generated by UCS_to_SHIFT_JIS_2004.pl\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 ) ){ - $code = $array1{ $index }; +for $index (sort { $a <=> $b } keys(%array1)) +{ + $code = $array1{$index}; $count1--; - 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, substr($code, 0, 8), substr($code, 8, 8), $comment1{ $index }; + 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, + substr($code, 0, 8), substr($code, 8, 8), $comment1{$index}; } } diff --git a/src/backend/utils/mb/Unicode/UCS_to_SJIS.pl b/src/backend/utils/mb/Unicode/UCS_to_SJIS.pl index 510350e6b53..f93ca7af302 100755 --- a/src/backend/utils/mb/Unicode/UCS_to_SJIS.pl +++ b/src/backend/utils/mb/Unicode/UCS_to_SJIS.pl @@ -22,60 +22,68 @@ require "ucs2utf.pl"; # first generate UTF-8 --> SJIS table $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> ){ - chop; - if( /^#/ ){ - next; - } - ( $c, $u, $rest ) = split; - $ucs = hex($u); - $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ - $utf = &ucs2utf($ucs); - if((( $code >= 0xed40 ) - && ( $code <= 0xeefc )) - || (( $code >= 0x8754 ) - &&( $code <= 0x875d )) - || ( $code == 0x878a ) - || ( $code == 0x8782 ) - || ( $code == 0x8784 ) - || ( $code == 0xfa5b ) - || ( $code == 0xfa54 ) - || (( $code >= 0x8790 ) - && ( $code <= 0x8792 )) - || (( $code >= 0x8795 ) - && ( $code <= 0x8797 )) - || (( $code >= 0x879a ) - && ( $code <= 0x879c ))) - { - printf STDERR "Warning: duplicate UTF8 : UCS=0x%04x SJIS=0x%04x\n",$ucs,$code; - next; - } - $count++; - $array{ $utf } = $code; - } +while (<FILE>) +{ + chop; + if (/^#/) + { + next; + } + ($c, $u, $rest) = split; + $ucs = hex($u); + $code = hex($c); + if ($code >= 0x80 && $ucs >= 0x0080) + { + $utf = &ucs2utf($ucs); + if ((($code >= 0xed40) && ($code <= 0xeefc)) + || ( ($code >= 0x8754) + && ($code <= 0x875d)) + || ($code == 0x878a) + || ($code == 0x8782) + || ($code == 0x8784) + || ($code == 0xfa5b) + || ($code == 0xfa54) + || ( ($code >= 0x8790) + && ($code <= 0x8792)) + || ( ($code >= 0x8795) + && ($code <= 0x8797)) + || ( ($code >= 0x879a) + && ($code <= 0x879c))) + { + printf STDERR + "Warning: duplicate UTF8 : UCS=0x%04x SJIS=0x%04x\n", $ucs, + $code; + next; + } + $count++; + $array{$utf} = $code; + } } -close( FILE ); +close(FILE); # # first, generate UTF8 --> SJIS table # $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"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $code = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $code = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $code; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $code; } } @@ -87,37 +95,44 @@ close(FILE); # 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'; $count = 0; -while( <FILE> ){ +while (<FILE>) +{ chop; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080 ){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); $count++; - $array{ $code } = $utf; + $array{$code} = $utf; } } -close( FILE ); +close(FILE); $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"; -for $index ( sort {$a <=> $b} keys( %array ) ){ - $utf = $array{ $index }; +for $index (sort { $a <=> $b } keys(%array)) +{ + $utf = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; } } diff --git a/src/backend/utils/mb/Unicode/UCS_to_most.pl b/src/backend/utils/mb/Unicode/UCS_to_most.pl index b67c7943e63..bd031f79a06 100644 --- a/src/backend/utils/mb/Unicode/UCS_to_most.pl +++ b/src/backend/utils/mb/Unicode/UCS_to_most.pl @@ -18,80 +18,88 @@ require "ucs2utf.pl"; %filename = ( - 'WIN866' => 'CP866.TXT', - 'WIN874' => 'CP874.TXT', - 'WIN1250' => 'CP1250.TXT', - 'WIN1251' => 'CP1251.TXT', - 'WIN1252' => 'CP1252.TXT', - 'WIN1253' => 'CP1253.TXT', - 'WIN1254' => 'CP1254.TXT', - 'WIN1255' => 'CP1255.TXT', - 'WIN1256' => 'CP1256.TXT', - 'WIN1257' => 'CP1257.TXT', - 'WIN1258' => 'CP1258.TXT', - 'ISO8859_2' => '8859-2.TXT', - 'ISO8859_3' => '8859-3.TXT', - 'ISO8859_4' => '8859-4.TXT', - 'ISO8859_5' => '8859-5.TXT', - 'ISO8859_6' => '8859-6.TXT', - 'ISO8859_7' => '8859-7.TXT', - 'ISO8859_8' => '8859-8.TXT', - 'ISO8859_9' => '8859-9.TXT', + 'WIN866' => 'CP866.TXT', + 'WIN874' => 'CP874.TXT', + 'WIN1250' => 'CP1250.TXT', + 'WIN1251' => 'CP1251.TXT', + 'WIN1252' => 'CP1252.TXT', + 'WIN1253' => 'CP1253.TXT', + 'WIN1254' => 'CP1254.TXT', + 'WIN1255' => 'CP1255.TXT', + 'WIN1256' => 'CP1256.TXT', + 'WIN1257' => 'CP1257.TXT', + 'WIN1258' => 'CP1258.TXT', + 'ISO8859_2' => '8859-2.TXT', + 'ISO8859_3' => '8859-3.TXT', + 'ISO8859_4' => '8859-4.TXT', + 'ISO8859_5' => '8859-5.TXT', + 'ISO8859_6' => '8859-6.TXT', + 'ISO8859_7' => '8859-7.TXT', + 'ISO8859_8' => '8859-8.TXT', + 'ISO8859_9' => '8859-9.TXT', 'ISO8859_10' => '8859-10.TXT', 'ISO8859_13' => '8859-13.TXT', 'ISO8859_14' => '8859-14.TXT', 'ISO8859_15' => '8859-15.TXT', 'ISO8859_16' => '8859-16.TXT', - 'KOI8R' => 'KOI8-R.TXT', - 'KOI8U' => 'KOI8-U.TXT', - 'GBK' => 'CP936.TXT', - 'UHC' => 'CP949.TXT', - 'JOHAB' => 'JOHAB.TXT', -); + 'KOI8R' => 'KOI8-R.TXT', + 'KOI8U' => 'KOI8-U.TXT', + 'GBK' => 'CP936.TXT', + 'UHC' => 'CP949.TXT', + 'JOHAB' => 'JOHAB.TXT',); @charsets = keys(filename); @charsets = @ARGV if scalar(@ARGV); -foreach $charset (@charsets) { +foreach $charset (@charsets) +{ -# -# first, generate UTF8-> charset table -# - $in_file = $filename{$charset}; + # + # first, generate UTF8-> charset table + # + $in_file = $filename{$charset}; - open( FILE, $in_file ) || die( "cannot open $in_file" ); + open(FILE, $in_file) || die("cannot open $in_file"); reset 'array'; - while( <FILE> ){ + while (<FILE>) + { chop; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if( $code >= 0x80 && $ucs >= 0x0080){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $utf } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + if ($array{$utf} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; - $array{ $utf } = $code; + $array{$utf} = $code; } } - close( FILE ); + close(FILE); $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"; - for $index ( sort {$a <=> $b} keys( %array ) ){ - $code = $array{ $index }; + for $index (sort { $a <=> $b } keys(%array)) + { + $code = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $code; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $code; } } @@ -99,42 +107,50 @@ foreach $charset (@charsets) { print FILE "};\n"; close(FILE); -# -# then generate character set code ->UTF8 table -# - open( FILE, $in_file ) || die( "cannot open $in_file" ); + # + # then generate character set code ->UTF8 table + # + open(FILE, $in_file) || die("cannot open $in_file"); reset 'array'; - while( <FILE> ){ + while (<FILE>) + { chop; - if( /^#/ ){ + if (/^#/) + { next; } - ( $c, $u, $rest ) = split; - $ucs = hex($u); + ($c, $u, $rest) = split; + $ucs = hex($u); $code = hex($c); - if($code >= 0x80 && $ucs >= 0x0080){ + if ($code >= 0x80 && $ucs >= 0x0080) + { $utf = &ucs2utf($ucs); - if( $array{ $code } ne "" ){ - printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs; + if ($array{$code} ne "") + { + printf STDERR "Warning: duplicate UTF8: %04x\n", $ucs; next; } $count++; - $array{ $code } = $utf; + $array{$code} = $utf; } } - close( FILE ); + close(FILE); $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"; - for $index ( sort {$a <=> $b} keys( %array ) ){ - $utf = $array{ $index }; + for $index (sort { $a <=> $b } keys(%array)) + { + $utf = $array{$index}; $count--; - if( $count == 0 ){ + if ($count == 0) + { printf FILE " {0x%04x, 0x%04x}\n", $index, $utf; - } else { + } + else + { printf FILE " {0x%04x, 0x%04x},\n", $index, $utf; } } diff --git a/src/backend/utils/mb/Unicode/ucs2utf.pl b/src/backend/utils/mb/Unicode/ucs2utf.pl index 083dd8ac06b..48d2b69616a 100644 --- a/src/backend/utils/mb/Unicode/ucs2utf.pl +++ b/src/backend/utils/mb/Unicode/ucs2utf.pl @@ -4,24 +4,32 @@ # src/backend/utils/mb/Unicode/ucs2utf.pl # convert UCS-4 to UTF-8 # -sub ucs2utf { - local($ucs) = @_; +sub ucs2utf +{ + local ($ucs) = @_; local $utf; - if ($ucs <= 0x007f) { + if ($ucs <= 0x007f) + { $utf = $ucs; - } elsif ($ucs > 0x007f && $ucs <= 0x07ff) { + } + elsif ($ucs > 0x007f && $ucs <= 0x07ff) + { $utf = (($ucs & 0x003f) | 0x80) | ((($ucs >> 6) | 0xc0) << 8); - } elsif ($ucs > 0x07ff && $ucs <= 0xffff) { - $utf = ((($ucs >> 12) | 0xe0) << 16) | - (((($ucs & 0x0fc0) >> 6) | 0x80) << 8) | - (($ucs & 0x003f) | 0x80); - } else { - $utf = ((($ucs >> 18) | 0xf0) << 24) | - (((($ucs & 0x3ffff) >> 12) | 0x80) << 16) | - (((($ucs & 0x0fc0) >> 6) | 0x80) << 8) | - (($ucs & 0x003f) | 0x80); - } - return($utf); + } + elsif ($ucs > 0x07ff && $ucs <= 0xffff) + { + $utf = + ((($ucs >> 12) | 0xe0) << 16) | + (((($ucs & 0x0fc0) >> 6) | 0x80) << 8) | (($ucs & 0x003f) | 0x80); + } + else + { + $utf = + ((($ucs >> 18) | 0xf0) << 24) | + (((($ucs & 0x3ffff) >> 12) | 0x80) << 16) | + (((($ucs & 0x0fc0) >> 6) | 0x80) << 8) | (($ucs & 0x003f) | 0x80); + } + return ($utf); } 1; diff --git a/src/backend/utils/sort/gen_qsort_tuple.pl b/src/backend/utils/sort/gen_qsort_tuple.pl index 40d55488f1a..18dd751b382 100644 --- a/src/backend/utils/sort/gen_qsort_tuple.pl +++ b/src/backend/utils/sort/gen_qsort_tuple.pl @@ -32,16 +32,16 @@ my $CMPPARAMS; emit_qsort_boilerplate(); -$SUFFIX = 'tuple'; -$EXTRAARGS = ', SortTupleComparator cmp_tuple, Tuplesortstate *state'; +$SUFFIX = 'tuple'; +$EXTRAARGS = ', SortTupleComparator cmp_tuple, Tuplesortstate *state'; $EXTRAPARAMS = ', cmp_tuple, state'; -$CMPPARAMS = ', state'; +$CMPPARAMS = ', state'; emit_qsort_implementation(); -$SUFFIX = 'ssup'; -$EXTRAARGS = ', SortSupport ssup'; +$SUFFIX = 'ssup'; +$EXTRAARGS = ', SortSupport ssup'; $EXTRAPARAMS = ', ssup'; -$CMPPARAMS = ', ssup'; +$CMPPARAMS = ', ssup'; print <<'EOM'; #define cmp_ssup(a, b, ssup) \ ApplySortComparator((a)->datum1, (a)->isnull1, \ |