#!/usr/bin/perl use FindBin; use lib "$FindBin::Bin/../lib"; use lib "$FindBin::Bin/../../Parse-Binary/lib"; # XXX - use encoding 'utf8' cannot be used as it interferes with code parsing # resulting in inconsistent utf8 flag on all of the @ARGV! #use encoding 'utf8'; #utf8::upgrade($_) for @ARGV; # XXX black, black voodoo magic use File::Basename; use Parse::AFP; use Encode::IBM; use Encode::Guess; use Getopt::Std; binmode(STDIN, ':utf8'); binmode(STDOUT, ':utf8'); $Encode::Guess::NoUTFAutoGuess = 1; use vars qw/$opt_e/; getopts('e:'); Encode::Guess->set_suspects(split(/\s*,\s*/, ($opt_e || 'cp500,ibm-835'))); =head1 NAME adpdump.pl - Dump IBM AFP data to HTML =head1 SYNOPSIS # Defaults to "cp500, ibm-835" encoding % afpdump.pl input.afp > output.html # For Big5-encoded AFPs % afpdump -e cp437,ibm-947 big5.afp > output.html =cut my %desc; foreach my $type qw( Record Triplet PTX/ControlSequence ) { require "Parse/AFP/$type.pm"; open my $fh, $INC{"Parse/AFP/$type.pm"} or die $!; while (<$fh>) { /'([A-Z][:\w]+)',\s+#\s?(.+)/ or next; $desc{$1} = $2; } } sub Header (); sub Parse::AFP::PTX::TRN::ENCODING () { 'Guess' }; die "Usage: $0 [ -e codepage1,codepage2... ] file.afp > file.html\n" unless @ARGV; $SIG{__WARN__} = sub { use Carp; Carp::cluck(@_) }; $SIG{__DIE__} = sub { use Carp; Carp::confess(@_) }; my $input = shift; my $afp = Parse::AFP->new($input, { lazy => 1 }); $input = basename($input); print Header(); print "