📄 mktbl.pl
字号:
{ $tbl = \@FromSpeedTbl; $direction = " UCS -> $CCSName"; $bytes = $FromSpeedBytes; if ($Source) { print OUTFILE"/* * 16-bit UCS -> $CCSName speed-optimized table ($FromSpeedBytes bytes). * $Separator */#if defined ($GuardFromUCS) \\ && !($GuardSize)static _CONST __uint16_t${VarFromUCSSpeed}\[] ={"; } } else { Err "Internal script error Output16bitSpeed()\n"; } printf "Output%s 16-bit%s%s table (%d bytes).\n", $e, $direction, $optimiz, $bytes if $Verbose; # OUTPUT HEADING BLOCK (ALWAYS 16 BIT) if ($Source) { my $count = 0; print OUTFILE "\t/* Heading Block */"; for (my $i = 0, my $br = 0; $i < 256; $br = ++$i % 8) { print OUTFILE "\n\t" unless $br; if (defined $tbl->[0]->[$i]) { printf OUTFILE "0x%.4X,", $tbl->[0]->[$i]; } else { print OUTFILE "$MacroInvBlock,"; } } } else { print OUTFILE pack($endian, defined $_ ? $_ : $InvBlock) foreach @{$tbl->[0]}; } # OUTPUT OTHER BLOCKS if ($Source) { my $index = 256; for (my $blk = 1; $blk <= $#$tbl; $blk++) { next unless defined $tbl->[$blk]; printf OUTFILE "\n\t/* Block $blk, Array index 0x%.4X */", $index; $index += 256; for (my $i = 0, my $br = 0; $i < 256; $br = ++$i % 8) { print OUTFILE "\n\t" unless $br; my $code = $tbl->[$blk]->[$i]; print OUTFILE defined $code ? ($code == $TmpLost ? $MacroLostCode : sprintf "0x%.4X", $code) : $MacroInvCode, ","; } } } else { for (my $blk = 1; $blk <= $#$tbl; $blk++) { next unless defined $tbl->[$blk]; for (my $i = 0, my $br = 0; $i < 256; $br = ++$i % 8) { my $code = $tbl->[$blk]->[$i]; print OUTFILE pack($endian, defined $code ? ($code == $TmpLost ? $LostCode : $code) : $InvCode); } } } if ($Source) { if ($_[0] eq "to_ucs") { print OUTFILE"};#endif /* $GuardToUCS && !$GuardSize */"; } else { print OUTFILE"};#endif /* $GuardFromUCS && !$GuardSize */"; } }}# =============================================================================## Output 16bit Size-optimized table. Output table's source code if $Source# and table's binary data if !$Source.# # Parameter 1: # "to_ucs" - Output "to_ucs" table.# "from_ucs" - Output "from_ucs" table.# Parameter 2: Not used when sources are output. Output BE binary if 'n' and# LE binary if 'v'.## =============================================================================sub OutputSize($;$){ my $endian = $_[1]; my $tbl; my ($direction, $optimiz, $e, $bytes); $optimiz = $Bits == 16 ? " size-optimized" : ""; $e = $endian ? ($endian eq 'n' ? " Big Endian" : " Little Endian") : ""; if ($_[0] eq "to_ucs") { $tbl = \@ToSizeTbl; $direction = " $CCSName -> UCS"; $bytes = $ToSizeBytes; if ($Source) { print OUTFILE"/* * 16-bit $CCSName -> UCS size-optimized table ($ToSizeBytes bytes). * $Separator */#if defined ($GuardToUCS) \\ && ($GuardSize)static _CONST __uint16_t${VarToUCSSize}\[] ={"; } } elsif ($_[0] eq "from_ucs") { $tbl = \@FromSizeTbl; $direction = " UCS -> $CCSName"; $bytes = $FromSizeBytes; if ($Source) { print OUTFILE"/* * 16-bit UCS -> $CCSName size-optimized table ($FromSizeBytes bytes). * $Separator */#if defined ($GuardFromUCS) \\ && ($GuardSize)static _CONST __uint16_t${VarFromUCSSize}\[] ={"; } } else { Err "Internal script error Output16bitSize()\n"; } printf "Output%s 16-bit%s%s table (%d bytes).\n", $e, $direction, $optimiz, $bytes if $Verbose; # OUTPUT FIRST 3 ELEMENTS if ($Source) { printf OUTFILE "\t0x%.4X, /* Ranges number */\n", $tbl->[0]; printf OUTFILE "\t0x%.4X, /* Unranged codes number */\n", $tbl->[1]; printf OUTFILE "\t0x%.4X, /* First unranged code index */\n", $tbl->[2]; } else { printf OUTFILE pack $endian, $tbl->[0]; printf OUTFILE pack $endian, $tbl->[1]; printf OUTFILE pack $endian, $tbl->[2]; } my $idx = 0; # OUTPUT RANGES if ($Source) { print OUTFILE "\t/* Ranges list: first code, last Code, array index. */\n"; for (my $range = 0; $range <= $#{$tbl->[3]}; $range++) { printf OUTFILE "\t/* Array index: 0x%.4X */ 0x%.4X, 0x%.4X, 0x%.4X,\n", $idx += 3, $tbl->[3]->[$range]->[0], $tbl->[3]->[$range]->[1], $tbl->[3]->[$range]->[2]; } } else { for (my $range = 0; $range <= $#{$tbl->[3]}; $range++) { print OUTFILE pack($endian, $tbl->[3]->[$range]->[0]), pack($endian, $tbl->[3]->[$range]->[1]), pack($endian, $tbl->[3]->[$range]->[2]); } } $idx += 3; # OUTPUT RANGES CONTENT if ($Source) { print OUTFILE "\t/* Ranges content */"; for (my $range = 0; $range <= $#{$tbl->[3]}; $range++) { printf OUTFILE "\n\t/* Range 0x%.4X - 0x%.4X, array index: 0x%.4X */", $tbl->[3]->[$range]->[0], $tbl->[3]->[$range]->[1], $idx; $idx += $tbl->[3]->[$range]->[1] - $tbl->[3]->[$range]->[0] + 1; for (my $elt = 0, my $br = 0; $elt <= $#{$tbl->[4]->[$range]}; $br = ++$elt % 8) { print OUTFILE "\n\t" unless $br; if (defined $tbl->[4]->[$range]->[$elt]) { if ($tbl->[4]->[$range]->[$elt] != $TmpLost) { printf OUTFILE "0x%.4X,", $tbl->[4]->[$range]->[$elt]; } else { print OUTFILE "$MacroLostCode,"; } } else { print OUTFILE "$MacroInvCode,"; } } } } else { for (my $range = 0; $range <= $#{$tbl->[3]}; $range++) { for (my $elt = 0; $elt <= $#{$tbl->[4]->[$range]}; $elt++) { if (defined $tbl->[4]->[$range]->[$elt]) { if ($tbl->[4]->[$range]->[$elt] != $TmpLost) { print OUTFILE pack $endian, $tbl->[4]->[$range]->[$elt]; } else { print OUTFILE pack $endian, $LostCode; } } else { print OUTFILE pack $endian, $InvCode; } } } } # OUTPUT UNRANGED CODES if ($Source) { printf OUTFILE "\n\t/* Unranged codes (%d codes) */", $#{$tbl->[4]} + 1; for (my $i = 0; $i <= $#{$tbl->[5]}; $i++) { printf OUTFILE "\n\t/* Array index: 0x%.4X */ 0x%.4X,0x%.4X,", $idx, $tbl->[5]->[$i]->[0], $tbl->[5]->[$i]->[1]; } } else { for (my $i = 0; $i <= $#{$tbl->[5]}; $i++) { print OUTFILE pack($endian, $tbl->[5]->[$i]->[0]), pack($endian, $tbl->[5]->[$i]->[1]); } } if ($Source) { if ($_[0] eq "to_ucs") { print OUTFILE"};#endif /* $GuardToUCS && $GuardSize */"; } else { print OUTFILE"};#endif /* $GuardFromUCS && $GuardSize */"; } }}# =============================================================================## Parse command line options## =============================================================================sub ProcessOptions(){ my $help_opt = 'h'; # Print help option my $input_opt = 'i'; # Input file name option my $output_opt = 'o'; # Output file name option my $source_opt = 'S'; # Generate C source file option my $enc_opt = 'N'; # Encoding name my $plane_opt = 'p'; # Plane number my $verbose_opt = 'v'; # Verbose output my $ccscol_opt = 'x'; # Encoding's column number my $ucscol_opt = 'y'; # UCS column number my $nosize_opt = 'l'; # Don't generate size-optimized tables my $nospeed_opt = 'b'; # Don't generate speed-optimized tables my $nobe_opt = 'B'; # Don't generate big-endian tables my $nole_opt = 'L'; # Don't generate big-endian tables my $noto_opt = 't'; # Don't generate "to_ucs" table my $nofrom_opt = 'f'; # Don't generate "from_ucs" table my %args; # Command line arguments found by getopts() my $getopts_string = "$help_opt$source_opt$enc_opt:$verbose_opt$input_opt:$output_opt:$plane_opt:" . "$nosize_opt$nospeed_opt$nobe_opt$nole_opt$noto_opt$nofrom_opt$ccscol_opt:" . "$ucscol_opt:"; getopts($getopts_string, \%args) || Err "getopts() failed: $!.\n", 1; # Print usage rules and exit. if ($args{$help_opt}) { print<<ENDUsage: -$help_opt - this help message; -$input_opt - input file name (required); -$output_opt - output file name; -$enc_opt - CCS or encoding name; -$plane_opt - plane number (high 16 bits) to use (in hex); -$source_opt - generate C source file; -$nospeed_opt - don't generate speed-optimized tables (binary files only); -$nosize_opt - don't generate size-optimized tables (binary files only); -$nobe_opt - don't generate Big Endian tables (binary files only); -$nole_opt - don't generate Little Endian tables (binary files only); -$noto_opt - don't generate "to_ucs" table; -$nofrom_opt - don't generate "from_ucs" table; -$ccscol_opt - encoding's column number; -$ucscol_opt - UCS column number; -$verbose_opt - verbose output.If output file name isn't specified, <infile>.c (for sources) or<infile>.cct (for binaries) is assumed.If encoding name isn't specified <infile> is assumed.<infile> is normalized (small letters, "-" are substituted by "_") input filename base (no extension). For example, for Koi8-r.txt input file, <infile>is koi8_r. END; exit 0; } $Verbose = $args{$verbose_opt}; $Source = $args{$source_opt}; $NoSpeed = $args{$nospeed_opt}; $NoSize = $args{$nosize_opt}; $NoBE = $args{$nobe_opt}; $NoLE = $args{$nole_opt}; $NoFrom = $args{$nofrom_opt}; $NoTo = $args{$noto_opt}; $CCSCol = $args{$ccscol_opt}; $UCSCol = $args{$ucscol_opt}; $Plane = $args{$plane_opt}; $InFile = $args{$input_opt}; $OutFile = $args{$output_opt}; $CCSName = $args{$enc_opt}; Err "Error: input file isn't defined. Use -$help_opt for help.\n", 1 unless $InFile; unless ($OutFile) { # Construct output file name $OutFile = $InFile; $OutFile =~ s/(.*\/)*([0-9a-zA-Z-_]*)(\..*)$/\L$2/; $OutFile =~ tr/-/_/; if ($Source) { $OutFile = "$OutFile.c"; } else { $OutFile = "$OutFile.cct" } } unless ($CCSName) { # Construct CCS name $CCSName = $InFile; $CCSName =~ s/(.*\/)*([0-9a-zA-Z-_]*)(\..*)$/\L$2/; $CCSName =~ tr/-/_/; } Err "-$nosize_opt option can't be used with -$nospeed_opt option " . "simultaniously.\n", 1 if $NoSpeed && $NoSize; Err "-$nobe_opt option can't be used with -$nole_opt option " . "simultaniously.\n", 1 if $NoBE && $NoLE; Err "-$noto_opt option can't be used with -$nofrom_opt option" . "simultaniously.\n", 1 if $NoTo && $NoFrom; Err "-$nosize_opt, -$nospeed_opt, -$nobe_opt -$nole_opt " . "-$noto_opt and -$nofrom_opt " . "options can't be used with -$source_opt option.\n" . "Source code always contains both speed- and size-optimized " . "tables in System Endian. Use -$help_opt for help.\n", 1 if $Source and $NoSpeed || $NoSize || $NoBE || $NoLE || $NoTo || $NoFrom; if (!$CCSCol && !$UCSCol) { $CCSCol = 0; $UCSCol = 1; } elsif ($CCSCol && $UCSCol) { Err "Column number should be >= 0\n", 1 if ($CCSCol <= 0 or $UCSCol <= 0); $CCSCol -= 1; $UCSCol -= 1; } else { Err "Please, define both CCS and UCS column numbers\n", 1; } if ($Verbose) { print "Use $InFile file for input.\n", "Use $OutFile file for output.\n", "Use $CCSName as CCS name.\n"; print "Generate C source file.\n" if $Source; print "Generate binary file.\n" if !$Source; printf "Use plane N 0x%.4X.\n", hex $Plane if defined $Plane; printf "Use column N $CCSCol for $CCSName.\n"; printf "Use column N $UCSCol for UCS.\n"; print "Don't generate size-optimized tables.\n" if $NoSize; print "Don't generate speed-optimized tables.\n" if $NoSpeed; print "Don't generate big-endian tables.\n" if $NoBE; print "Don't generate little-endian tables.\n" if $NoLE; print "Don't generate \"to_ucs\" table.\n" if $NoTo; print "Don't generate \"from_ucs\" table.\n" if $NoFrom; } return;}# =============================================================================## Print error message, close all and exit## Parameter 1: error message# Parameter 2: don't delete output file if > 1## =============================================================================sub Err($;$){ print STDERR "$_[0]"; close INFILE; close OUTFILE; unlink $OutFile unless $_[1]; exit 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -