diff options
Diffstat (limited to 'Master')
-rwxr-xr-x | Master/tlpkg/bin/parse-texcatalogue-keywords (renamed from Master/tlpkg/dev/keyword-search/parse-texcatalogue-keywords) | 64 |
1 files changed, 48 insertions, 16 deletions
diff --git a/Master/tlpkg/dev/keyword-search/parse-texcatalogue-keywords b/Master/tlpkg/bin/parse-texcatalogue-keywords index 25cb5617a45..ab15297b196 100755 --- a/Master/tlpkg/dev/keyword-search/parse-texcatalogue-keywords +++ b/Master/tlpkg/bin/parse-texcatalogue-keywords @@ -7,29 +7,63 @@ # This file is licensed under the GNU General Public License version 2 # or any later version. -$^W = 1; -use strict; +BEGIN { + $^W = 1; + chomp ($mydir = `dirname $0`); + unshift (@INC, "$mydir/.."); +} +use strict; use XML::Parser; use XML::XPath; use XML::XPath::XMLParser; use Text::Unidecode; use Data::Dumper; +use Getopt::Long; +use TeXLive::TLUtils; + +my %taxonomy; my $tcfile; -if (@ARGV) { - $tcfile = shift @ARGV; -} else { - $tcfile = "texcatalogue.xml"; -} +my $output; +my $help = 0; -my %taxonomy; +TeXLive::TLUtils::process_logging_options(); +GetOptions( + "input|catalogue=s" => \$tcfile, + "output=s" => \$output, + "help|?" => \$help) or pod2usage(1); +pod2usage(-exitstatus => 0, -verbose => 2) if $help; -parse_texcatalogue($tcfile); +my $progname = TeXLive::TLUtils::basename($0); + +exit (&main()); + + +sub main +{ + my $io; + if (!defined($tcfile)) { + $io = \*STDIN; + } else { + if (! -f $tcfile) { + die "$progname: argument to --input is not a file: $!.\n"; + } + open($io, "<", $tcfile) or die "Cannot open input file $tcfile: $!"; + } + parse_texcatalogue($io); + $Data::Dumper::Indent = 1; + + my $out; + if (!defined($output)) { + $out = \*STDOUT; + } else { + open($out, ">$output") or die "Cannot open $output for writing: $!"; + } + print $out Data::Dumper->Dump([\%taxonomy], ["taxonomy"]), $/; +} -$Data::Dumper::Indent = 1; -print Data::Dumper->Dump([\%taxonomy], ["taxonomy"]), $/; # how to read in!!! @@ -52,16 +86,14 @@ print Data::Dumper->Dump([\%taxonomy], ["taxonomy"]), $/; ##### only subs from here ########## sub parse_texcatalogue { - my $tcfile = shift; + my $io = shift; my $_parser = XML::Parser->new( ErrorContext => 2, ParseParamEnt => 1, NoLWP => 1 ); - my $io; - open($io, "<", $tcfile) or die "Cannot open texcatalogue.xml: $!"; my $parser = new XML::XPath->new(ioref => $io, parser => $_parser) || - die "Failed to parse texcatalogue.xml: $!"; + die "Failed to parse input file $tcfile: $!"; # format of the data # $taxonomy{'by-package'}{'keyword'}{$package} = [ $kwi, $kwii,...]; @@ -148,7 +180,7 @@ sub print_keywords { my $kw_pkg = shift; for my $k (keys %$kw_pkg) { my @pkgl = @{$kw_pkg->{$k}}; - if (defined(@pkgl)) { + if (@pkgl) { print "keyword = $k\n package = @pkgl\n"; } else { print "keyword = $k\n package = NO PACKAGE FOUND!\n"; |