summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2010-10-24 16:34:32 +0000
committerNorbert Preining <preining@logic.at>2010-10-24 16:34:32 +0000
commit80bf3d55d794628d8b084ac36b60ec3bcc3cc642 (patch)
tree70df5840b80dba01a0e9c188608450ded7ea1755 /Master
parentb874d7a17d2cb3d769e0fc2b9d70268aa81856ad (diff)
move the parse-texcatalogue-keywords file into tlpkg/bin, and add option
handling git-svn-id: svn://tug.org/texlive/trunk@20165 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rwxr-xr-xMaster/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";