| 1 | #!/usr/local/bin/perl | ||
| 2 | use FindBin; | ||
| 3 | use lib "$FindBin::Bin/../lib"; | ||
| 4 | use lib "$FindBin::Bin/../../Parse-Binary/lib"; | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use DBI; | ||
| 8 | use DBD::SQLite; | ||
| 9 | use Data::Dumper; | ||
| 10 | use Parse::AFP; | ||
| 11 | use Getopt::Long; | ||
| 12 | use File::Glob 'bsd_glob'; | ||
| 13 | |||
| 14 | my %CodePages = ( | ||
| 15 | 947 => { | ||
| 16 | FillChar => "\xA1\x40", | ||
| 17 | FirstChar => "\xA4\x40", | ||
| 18 | CharPattern => qr{ | ||
| 19 | ( | ||
| 20 | [\x81-\xA0\xC7-\xC8\xFA-\xFE]. # UDC range 1 | ||
| 21 | | | ||
| 22 | \xC6[\xA1-\xFE] # UDC range 2 | ||
| 23 | ) | ||
| 24 | | | ||
| 25 | ([\x00-\x7f]) # Single Byte | ||
| 26 | | | ||
| 27 | (..) # Double Byte | ||
| 28 | }x, | ||
| 29 | NoUDC => qr{^ | ||
| 30 | (?: | ||
| 31 | [\x00-\x7f]+ | ||
| 32 | | | ||
| 33 | (?:[\xA1-\xC5\xC9-\xF9].)+ | ||
| 34 | | | ||
| 35 | (?:\xC6[^\xA1-\xFE])+ | ||
| 36 | )* | ||
| 37 | $}x, | ||
| 38 | }, | ||
| 39 | 835 => { | ||
| 40 | FillChar => "\x40\x40", | ||
| 41 | FirstChar => "\x4C\x41", | ||
| 42 | CharPattern => qr{ | ||
| 43 | ([\x92-\xFE].) # UDC | ||
| 44 | | | ||
| 45 | ((?!)) # Single Byte | ||
| 46 | | | ||
| 47 | ([\x40-\x91].) # Double Byte | ||
| 48 | }x, | ||
| 49 | NeedDBCSPattern => 1, | ||
| 50 | NoUDC => qr{^[^\x92-\xFE]*$}x, | ||
| 51 | }, | ||
| 52 | ); | ||
| 53 | |||
| 54 | my ($dbcs_pattern, @db); | ||
| 55 | my $codepage = 947; | ||
| 56 | my $dir = 'udcdir'; | ||
| 57 | my $adjust; | ||
| 58 | |||
| 59 | our $input; | ||
| 60 | our $output = 'fixed.afp'; | ||
| 61 | |||
| 62 | GetOptions( | ||
| 63 | 'i|input:s' => \$input, | ||
| 64 | 'f|fontdb:s@' => \@db, | ||
| 65 | 'o|output:s' => \$output, | ||
| 66 | 'u|udcdir:s' => \$dir, | ||
| 67 | 'd|dbcs-pattern:s' => \$dbcs_pattern, | ||
| 68 | 'c|codepage:i' => \$codepage, | ||
| 69 | 'a|adjust' => \$adjust, | ||
| 70 | ); | ||
| 71 | |||
| 72 | $input ||= shift; | ||
| 73 | @db = sort grep /\.f?db$/i, map { (-d $_) ? bsd_glob("$_/*") : $_ } (@db ? @db : 'fonts.db'); | ||
| 74 | |||
| 75 | die "Usage: $0 [-a] [-c 947|835] -d dbcs_pattern -i input.afp -o output.afp -f fonts.db\n" | ||
| 76 | if !@db or grep !defined, $input, $output; | ||
| 77 | |||
| 78 | $CodePages{$codepage} or die "Unknown codepage: $codepage"; | ||
| 79 | |||
| 80 | our ($FillChar, $FirstChar, $CharPattern, $NeedDBCSPattern, $NoUDC) | ||
| 81 | = @{$CodePages{$codepage}}{qw( FillChar FirstChar CharPattern NeedDBCSPattern NoUDC )}; | ||
| 82 | |||
| 83 | die "Need DBCS Pattern with -d for this codepage" | ||
| 84 | if $NeedDBCSPattern and !$dbcs_pattern; | ||
| 85 | |||
| 86 | my (%FontToId, %IdToFont); | ||
| 87 | |||
| 88 | ########################################################################## | ||
| 89 | |||
| 90 | no warnings qw(once numeric); | ||
| 91 | |||
| 92 | my %errors; | ||
| 93 | my $db = shift(@db); | ||
| 94 | die "No such database: $db" unless -e $db; | ||
| 95 | my $dbh = DBI->connect( | ||
| 96 | "dbi:SQLite:dbname=$db", '', '', { | ||
| 97 | PrintError => 0, | ||
| 98 | HandleError => sub { $errors{$_[0]}++ }, | ||
| 99 | } | ||
| 100 | ) or die $DBI::errstr; | ||
| 101 | my $fonts = $dbh->selectall_hashref("SELECT * FROM Fonts", 'FontName') or die $dbh->errstr; | ||
| 102 | |||
| 103 | foreach my $idx (0..$#db) { | ||
| 104 | my $filename = $dbh->quote($db[$idx]); | ||
| 105 | $dbh->do("ATTACH DATABASE $filename AS DB$idx") or die $dbh->errstr; | ||
| 106 | my $more_fonts = $dbh->selectall_hashref("SELECT * FROM Fonts", 'FontName') or die $dbh->errstr; | ||
| 107 | %$fonts = (%$fonts, %$more_fonts); | ||
| 108 | } | ||
| 109 | |||
| 110 | ########################################################################## | ||
| 111 | |||
| 112 | # SPLIT! | ||
| 113 | # | ||
| 114 | udcsplit::run(); | ||
| 115 | |||
| 116 | ########################################################################## | ||
| 117 | |||
| 118 | sub udc4pca { | ||
| 119 | my ($in, $out) = @_; | ||
| 120 | my $afp = Parse::AFP->new($in, {lazy => 1, output_file => $out}); | ||
| 121 | $afp->callback_members([qw( MCF1 MCF PGD PTX EMO EPG * )]); | ||
| 122 | } | ||
| 123 | |||
| 124 | ########################################################################## | ||
| 125 | |||
| 126 | my @UDC; | ||
| 127 | sub __ { | ||
| 128 | $_[0]->done; | ||
| 129 | } | ||
| 130 | |||
| 131 | my ($x, $y); | ||
| 132 | my ($XUnit, $YUnit, $XPageSize, $YPageSize); | ||
| 133 | sub PGD { | ||
| 134 | my $rec = shift; | ||
| 135 | $XUnit = $rec->XLUnitsperUnitBase; | ||
| 136 | $YUnit = $rec->YLUnitsperUnitBase; | ||
| 137 | $XPageSize = $rec->XPageSize; | ||
| 138 | $YPageSize = $rec->YPageSize; | ||
| 139 | $rec->done; | ||
| 140 | $x = $y = 0; | ||
| 141 | } | ||
| 142 | |||
| 143 | sub MCF1 { | ||
| 144 | my $rec = shift; | ||
| 145 | my $font_e = substr($rec->CodedFontName, 2, 4); | ||
| 146 | my $font_eid = $rec->CodedFontLocalId; | ||
| 147 | $FontToId{$font_e} = $font_eid; | ||
| 148 | $IdToFont{$font_eid} = $font_e; | ||
| 149 | $rec->done; | ||
| 150 | } | ||
| 151 | |||
| 152 | sub MCF { | ||
| 153 | my $rec = shift; | ||
| 154 | $rec->callback_members(['MCF::DataGroup']); | ||
| 155 | $rec->done; | ||
| 156 | } | ||
| 157 | |||
| 158 | sub MCF_DataGroup { | ||
| 159 | my $data_group = shift; | ||
| 160 | $data_group->callback_members(['Triplet::FQN', 'Triplet::RLI']); | ||
| 161 | } | ||
| 162 | |||
| 163 | { | ||
| 164 | my $font_e; | ||
| 165 | |||
| 166 | sub Triplet_FQN { | ||
| 167 | my $fqn = shift; | ||
| 168 | $font_e = $fqn->Data; | ||
| 169 | } | ||
| 170 | |||
| 171 | sub Triplet_RLI { | ||
| 172 | my $rli = shift; | ||
| 173 | my $font_eid = $rli->Data; | ||
| 174 | $FontToId{$font_e} = $font_eid; | ||
| 175 | $IdToFont{$font_eid} = $font_e; | ||
| 176 | } | ||
| 177 | } | ||
| 178 | |||
| 179 | sub PTX { | ||
| 180 | my ($rec, $buf) = @_; | ||
| 181 | my $font_eid; | ||
| 182 | |||
| 183 | # Now iterate over $$buf. | ||
| 184 | my $pos = 11; | ||
| 185 | my $len = length($$buf); | ||
| 186 | |||
| 187 | while ($pos < $len) { | ||
| 188 | my ($size, $code) = unpack("x${pos}CC", $$buf); | ||
| 189 | $size or do { | ||
| 190 | open my $fh, '>:raw', 'buf.afp'; | ||
| 191 | print $fh $$buf; | ||
| 192 | close $fh; | ||
| 193 | die "Incorrect parsing: $pos\n"; | ||
| 194 | }; | ||
| 195 | |||
| 196 | if ($code == 0xDA or $code == 0xDB) { | ||
| 197 | if (substr($$buf, $pos + 2, $size - 2) !~ $NoUDC) { | ||
| 198 | $rec->callback_members([map "PTX::$_", qw( | ||
| 199 | SIM SBI STO SCFL AMI AMB RMI RMB BLN TRN | ||
| 200 | )], \$font_eid); | ||
| 201 | $rec->refresh; | ||
| 202 | last; | ||
| 203 | } | ||
| 204 | } | ||
| 205 | |||
| 206 | $pos += $size; | ||
| 207 | } | ||
| 208 | |||
| 209 | $rec->done; | ||
| 210 | } | ||
| 211 | |||
| 212 | sub PTX_AMI { | ||
| 213 | my $rec = shift; | ||
| 214 | $x = $rec->Data; | ||
| 215 | } | ||
| 216 | |||
| 217 | sub PTX_AMB { | ||
| 218 | my $rec = shift; | ||
| 219 | $y = $rec->Data; | ||
| 220 | } | ||
| 221 | |||
| 222 | sub PTX_RMI { | ||
| 223 | my $rec = shift; | ||
| 224 | $x += $rec->Data; | ||
| 225 | } | ||
| 226 | |||
| 227 | sub PTX_RMB { | ||
| 228 | my $rec = shift; | ||
| 229 | $y += $rec->Data; | ||
| 230 | } | ||
| 231 | |||
| 232 | my $InlineMargin; | ||
| 233 | sub PTX_SIM { | ||
| 234 | my $rec = shift; | ||
| 235 | $InlineMargin = $rec->Data; | ||
| 236 | } | ||
| 237 | |||
| 238 | my $BaselineIncrement; | ||
| 239 | sub PTX_SBI { | ||
| 240 | my $rec = shift; | ||
| 241 | $BaselineIncrement = $rec->Data; | ||
| 242 | } | ||
| 243 | |||
| 244 | sub PTX_BLN { | ||
| 245 | my $rec = shift; | ||
| 246 | $x = $InlineMargin; | ||
| 247 | $y += $BaselineIncrement; | ||
| 248 | } | ||
| 249 | |||
| 250 | my ($XOrientation, $YOrientation); | ||
| 251 | sub PTX_STO { | ||
| 252 | my $rec = shift; | ||
| 253 | $XOrientation = $rec->Orientation; | ||
| 254 | $YOrientation = $rec->WrapDirection; | ||
| 255 | } | ||
| 256 | |||
| 257 | sub PTX_SCFL { | ||
| 258 | my ($dat, $font_ref) = @_; | ||
| 259 | $$font_ref = $dat->Data; | ||
| 260 | } | ||
| 261 | |||
| 262 | my %Increment; | ||
| 263 | sub PTX_TRN { | ||
| 264 | my ($dat, $font_ref) = @_; | ||
| 265 | |||
| 266 | my $font_eid = $$font_ref; | ||
| 267 | my $font_name = $IdToFont{$font_eid}; | ||
| 268 | $font_name =~ s/^X\d/X0/; | ||
| 269 | |||
| 270 | my $string = $dat->Data; | ||
| 271 | my $data = ''; | ||
| 272 | |||
| 273 | # if $font_name is single byte... | ||
| 274 | # simply add increments together without parsing UDC | ||
| 275 | if ($dbcs_pattern and $font_name !~ /$dbcs_pattern/o) { | ||
| 276 | $Increment{$font_name} ||= { @{ | ||
| 277 | $dbh->selectcol_arrayref( | ||
| 278 | "SELECT Character, Increment FROM $font_name", | ||
| 279 | { Columns=>[1, 2] } | ||
| 280 | ) || [] } }; | ||
| 281 | $x += $Increment{$font_name}{$_} | ||
| 282 | or die "Cannot find char ".unpack('(H2)*', $_)." in $font_name" | ||
| 283 | foreach split(//, $string); | ||
| 284 | return; | ||
| 285 | } | ||
| 286 | |||
| 287 | # my $dbcs_space_char = "\xFA\x40"; | ||
| 288 | |||
| 289 | while ($string =~ /$CharPattern/go) { | ||
| 290 | # ... calculate position, add to fonts to write ... | ||
| 291 | if ( $1 || $3 ) { | ||
| 292 | $Increment{$font_name} ||= { @{ | ||
| 293 | $dbh->selectcol_arrayref( | ||
| 294 | "SELECT Character, Increment FROM $font_name", | ||
| 295 | { Columns => [1, 2] } | ||
| 296 | ) || [] } }; | ||
| 297 | } | ||
| 298 | |||
| 299 | if (defined $1) { | ||
| 300 | push @UDC, { | ||
| 301 | X => $x, | ||
| 302 | Y => $y, | ||
| 303 | Character => $1, | ||
| 304 | FontName => $font_name | ||
| 305 | }; | ||
| 306 | $data .= $FillChar; | ||
| 307 | $x += $Increment{$font_name}{$1}; | ||
| 308 | } | ||
| 309 | elsif (defined $2) { | ||
| 310 | # single byte | ||
| 311 | $Increment{$font_name} ||= { @{ | ||
| 312 | $dbh->selectcol_arrayref( | ||
| 313 | "SELECT Character, Increment FROM $font_name", | ||
| 314 | { Columns=>[1, 2] } | ||
| 315 | ) || [] } }; | ||
| 316 | $x += $Increment{$font_name}{$2} | ||
| 317 | or die "Cannot find char ".unpack('(H2)*', $2)." in $font_name"; | ||
| 318 | $data .= $2; | ||
| 319 | #print $font_name, "=", $x, "\n"; | ||
| 320 | } | ||
| 321 | else { | ||
| 322 | $data .= $3; | ||
| 323 | $x += $Increment{$font_name}{$3} || $Increment{$font_name}{$FirstChar}; | ||
| 324 | } | ||
| 325 | } | ||
| 326 | $dat->{struct}{Data} = $data; | ||
| 327 | } | ||
| 328 | |||
| 329 | BEGIN { *EMO = *EPG; } | ||
| 330 | |||
| 331 | sub EPG { | ||
| 332 | my $rec = shift; | ||
| 333 | |||
| 334 | if (!@UDC) { | ||
| 335 | $rec->done; | ||
| 336 | return; | ||
| 337 | } | ||
| 338 | |||
| 339 | # ... write out the actual BII..IOC..IID..ICP..IRD..EII images ... | ||
| 340 | #print "Writing out Bitmap...\n" if @UDC; | ||
| 341 | |||
| 342 | # Construct: | ||
| 343 | $rec->spawn_obj( | ||
| 344 | Class => 'BII', | ||
| 345 | Data => 'UDCImage', | ||
| 346 | )->write; | ||
| 347 | |||
| 348 | $rec->spawn_obj( | ||
| 349 | Class => 'IOC', | ||
| 350 | ConstantData1 => ("00" x 8), | ||
| 351 | ConstantData2 => ("FF" x 2), | ||
| 352 | Reserved1 => '00', | ||
| 353 | Reserved2 => '00', | ||
| 354 | XMap => '03e8', | ||
| 355 | XOffset => 0, | ||
| 356 | XOrientation => $XOrientation, | ||
| 357 | YMap => '03e8', | ||
| 358 | YOffset => 0, | ||
| 359 | YOrientation => $YOrientation, | ||
| 360 | )->write; | ||
| 361 | |||
| 362 | my %res = @{$dbh->selectcol_arrayref( | ||
| 363 | "SELECT FontName, Resolution FROM Fonts", { Columns => [1,2] } | ||
| 364 | )}; | ||
| 365 | my $name = $UDC[0]{FontName}; | ||
| 366 | $name =~ s/\s//g; | ||
| 367 | my $res = $res{$name}; | ||
| 368 | |||
| 369 | $rec->spawn_obj( | ||
| 370 | Class => 'IID', | ||
| 371 | Color => '0008', | ||
| 372 | ConstantData1 => '000009600960000000000000', | ||
| 373 | ConstantData2 => '000000002D00', | ||
| 374 | ConstantData3 => '00', | ||
| 375 | XBase => '00', | ||
| 376 | XCellSizeDefault => 0, | ||
| 377 | XSize => 0, | ||
| 378 | XUnits => $res, | ||
| 379 | YBase => '00', | ||
| 380 | YCellSizeDefault => 0, | ||
| 381 | YSize => 0, | ||
| 382 | YUnits => $res, | ||
| 383 | )->write; | ||
| 384 | |||
| 385 | foreach my $char (@UDC) { | ||
| 386 | my $sth = $dbh->prepare("SELECT * FROM $char->{FontName} WHERE Character = ?") or next; | ||
| 387 | $sth->execute($char->{Character}); | ||
| 388 | |||
| 389 | my $row = $sth->fetchrow_hashref or next; | ||
| 390 | |||
| 391 | my ($X, $Y) = @{$char}{qw( X Y )}; | ||
| 392 | $X += $row->{ASpace}; | ||
| 393 | |||
| 394 | my $oset = $row->{BaseOffset}; | ||
| 395 | $oset = int($oset * 3 / 4) if $adjust; | ||
| 396 | $Y -= $oset; | ||
| 397 | |||
| 398 | if ($YOrientation eq '5a00') { | ||
| 399 | ($X, $Y) = ($XPageSize - $Y, $X); | ||
| 400 | } | ||
| 401 | |||
| 402 | $rec->spawn_obj( | ||
| 403 | Class => 'ICP', | ||
| 404 | XCellOffset => $X, | ||
| 405 | XCellSize => $row->{Width}, | ||
| 406 | XFillSize => $row->{Width}, | ||
| 407 | YCellOffset => $Y, | ||
| 408 | YCellSize => $row->{Height}, | ||
| 409 | YFillSize => $row->{Height}, | ||
| 410 | )->write; | ||
| 411 | $rec->spawn_obj( | ||
| 412 | Class => 'IRD', | ||
| 413 | ImageData => $row->{Bitmap}, | ||
| 414 | )->write; | ||
| 415 | } | ||
| 416 | |||
| 417 | $rec->spawn_obj( | ||
| 418 | Class => 'EII', | ||
| 419 | Data => 'UDCImage', | ||
| 420 | )->write; | ||
| 421 | |||
| 422 | @UDC = (); | ||
| 423 | $rec->done; | ||
| 424 | } | ||
| 425 | |||
| 426 | 1; | ||
| 427 | |||
| 428 | package udcsplit; | ||
| 429 | |||
| 430 | my ($has_udc, $name, $prev, $has_BNG, $PTX_cnt); | ||
| 431 | my ($itmp, $otmp, $ifh, $ofh, $ipos, $opos); | ||
| 432 | |||
| 433 | use strict; | ||
| 434 | |||
| 435 | sub run { | ||
| 436 | *Parse::AFP::Record::new = sub { | ||
| 437 | my ($self, $buf, $attr) = @_; | ||
| 438 | if (substr($$buf, 3, 3) eq "\xD3\xEE\x9B") { return bless($buf, 'PTX'); } | ||
| 439 | # if (substr($$buf, 3, 3) eq "\xD3\xA8\xAD") { return bless($buf, 'BNG'); } | ||
| 440 | if (substr($$buf, 3, 3) eq "\xD3\xA8\xAF") { return bless($buf, 'BPG'); } | ||
| 441 | if (substr($$buf, 3, 3) eq "\xD3\xA8\xDF") { return bless($buf, 'BMO'); } | ||
| 442 | return $self->Parse::Binary::new($buf, $attr); | ||
| 443 | }; | ||
| 444 | |||
| 445 | *PTX::done = sub { return }; | ||
| 446 | *BPG::done = sub { return }; | ||
| 447 | *BMO::done = sub { return }; | ||
| 448 | *PTX::callback = sub { udcsplit::PTX($_[0]) }; | ||
| 449 | *BPG::callback = sub { udcsplit::BPG($_[0]) }; | ||
| 450 | *BMO::callback = sub { udcsplit::BMO($_[0]) }; | ||
| 451 | |||
| 452 | $name = $prev = 0; | ||
| 453 | $ipos = $opos = 0; | ||
| 454 | ($itmp, $otmp) = ("input-$$.afp", "output-$$.afp"); | ||
| 455 | |||
| 456 | my $afp = Parse::AFP->new($main::input, { lazy => 1, output_file => $main::output }); | ||
| 457 | ($ifh, $ofh) = @{$afp}{qw( input output )}; | ||
| 458 | |||
| 459 | $afp->callback_members([qw( BMO BPG PTX * )]); | ||
| 460 | begin_page(0); | ||
| 461 | } | ||
| 462 | |||
| 463 | sub begin_page { | ||
| 464 | $prev = $name; $name++; | ||
| 465 | |||
| 466 | my $pos = tell($ifh) - $_[0]; | ||
| 467 | udc4pca($pos) if $has_udc; | ||
| 468 | $has_udc = 0; | ||
| 469 | |||
| 470 | $ipos = $pos; | ||
| 471 | $opos = tell($ofh); | ||
| 472 | # print "ipos is now $ipos; opos is now $opos\n"; | ||
| 473 | } | ||
| 474 | |||
| 475 | sub udc4pca { | ||
| 476 | if (my $pid = fork) { | ||
| 477 | waitpid($pid, 0); | ||
| 478 | ($? == 0) or die $?; | ||
| 479 | print STDERR '.'; | ||
| 480 | } | ||
| 481 | else { | ||
| 482 | close $ifh; | ||
| 483 | close $ofh; | ||
| 484 | |||
| 485 | my $size = ($_[0] - $ipos); | ||
| 486 | |||
| 487 | open my $nfh, '<:raw', $main::input or die $!; | ||
| 488 | seek $nfh, $ipos, 0; | ||
| 489 | |||
| 490 | open my $fh, '>:raw', $itmp or die $!; | ||
| 491 | |||
| 492 | { | ||
| 493 | local $/ = \$size; | ||
| 494 | print $fh scalar <$nfh>; | ||
| 495 | } | ||
| 496 | close $fh; | ||
| 497 | |||
| 498 | no warnings 'redefine'; | ||
| 499 | *Parse::AFP::Record::new = \&Parse::Binary::new; | ||
| 500 | undef &PTX::callback; | ||
| 501 | undef &PTX::done; | ||
| 502 | |||
| 503 | main::udc4pca($itmp => $otmp); | ||
| 504 | exit; | ||
| 505 | } | ||
| 506 | |||
| 507 | seek $ofh, $opos, 0; | ||
| 508 | open my $fh, '<:raw', $otmp or die $!; | ||
| 509 | local $/ = \32768; | ||
| 510 | while (<$fh>) { | ||
| 511 | print $ofh $_; | ||
| 512 | } | ||
| 513 | close $fh; | ||
| 514 | |||
| 515 | unlink ("input-$$.afp", "output-$$.afp"); | ||
| 516 | } | ||
| 517 | |||
| 518 | sub BNG { | ||
| 519 | $has_BNG = 1; | ||
| 520 | begin_page(length ${$_[0]}); | ||
| 521 | $_[0]->done; | ||
| 522 | } | ||
| 523 | |||
| 524 | BEGIN { *BMO = *BPG; } | ||
| 525 | |||
| 526 | sub BPG { | ||
| 527 | begin_page(length ${$_[0]}); | ||
| 528 | $_[0]->done; | ||
| 529 | } | ||
| 530 | |||
| 531 | sub PTX { | ||
| 532 | my $rec = my $buf = shift; | ||
| 533 | |||
| 534 | return $rec->done if $has_udc; | ||
| 535 | |||
| 536 | # Now iterate over $$buf. | ||
| 537 | my $pos = 11; | ||
| 538 | my $len = length($$buf); | ||
| 539 | |||
| 540 | while ($pos < $len) { | ||
| 541 | my ($size, $code) = unpack("x${pos}CC", $$buf); | ||
| 542 | |||
| 543 | $size or do { | ||
| 544 | open my $fh, '>:raw', 'buf.afp'; | ||
| 545 | print $fh $$buf; | ||
| 546 | close $fh; | ||
| 547 | die "Wrong parsing: $pos\n"; | ||
| 548 | }; | ||
| 549 | |||
| 550 | if ($code == 0xDA or $code == 0xDB) { | ||
| 551 | if ( substr($$buf, $pos + 2, $size - 2) !~ /$main::NoUDC/o) { | ||
| 552 | $has_udc = 1; | ||
| 553 | last; | ||
| 554 | } | ||
| 555 | } | ||
| 556 | |||
| 557 | $pos += $size; | ||
| 558 | } | ||
| 559 | |||
| 560 | $rec->done; | ||
| 561 | } | ||
| 562 | |||
| 563 | sub __ { $_[0]->done } | ||
| 564 | |||
| 565 | 1; |