From 9884b82724a9a0425a4a0361304567f4b2b83f74 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Tue, 19 Oct 2010 17:58:46 +0000 Subject: first start on supporting tlmgr search --taxonomy git-svn-id: svn://tug.org/texlive/trunk@20142 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf/scripts/texlive/tlmgr.pl | 97 ++++++++++++++++++++++++++++++----- 1 file changed, 84 insertions(+), 13 deletions(-) (limited to 'Master') diff --git a/Master/texmf/scripts/texlive/tlmgr.pl b/Master/texmf/scripts/texlive/tlmgr.pl index 7a8411dced5..9c3cf4a4583 100755 --- a/Master/texmf/scripts/texlive/tlmgr.pl +++ b/Master/texmf/scripts/texlive/tlmgr.pl @@ -165,7 +165,8 @@ sub main { "force" => 1 }, "search" => { "global" => 1, "word" => 1, - "file" => 1 }, + "file" => 1, + "taxonomy" => 1 }, "show" => { "list" => 1 }, "uninstall" => { "force" => 1 }, "update" => { "no-depends" => 1, @@ -1124,15 +1125,42 @@ sub action_path { # SEARCH # +sub load_taxonomy_datafile { + init_local_db(); + my $taxonomy; + my $fpath = $localtlpdb->root . "/texmf/scripts/texlive/tc-dump"; + if (! -r $fpath) { + tlwarn("tlmgr: taxonomy file $fpath not readable.\n"); + return; + } + my $foo = `cat $fpath`; + no strict "vars"; + # the no strict "vars" is *ABSOLUT* necessary otherwise the file is not + # evaluated, no idea why! + eval "$foo"; + use strict "vars"; + return $taxonomy; +} + sub action_search { my $r = shift @ARGV; my $ret = ""; my $tlpdb; + my $taxonomy; # if (!defined($r) || !$r) { tlwarn("tlmgr: nothing to search for.\n"); return; } + if ($opts{"extended"}) { + tlwarn("tlmgr: sorry, extended searching not implemented by now.\n"); + return; + } + # check the arguments + if (exists($opts{"file"}) && exists($opts{"taxonomy"})) { + tlwarn("tlmgr: please specify only one thing to search for!\n"); + return; + } init_local_db(); if ($opts{"global"}) { init_tlmedia(); @@ -1140,6 +1168,13 @@ sub action_search { } else { $tlpdb = $localtlpdb; } + if ($opts{"taxonomy"}) { + $taxonomy = load_taxonomy_datafile(); + if (!defined($taxonomy)) { + tlwarn("tlmgr: Cannot load taxonomy file, searching for taxonomies not supported.\n"); + return; + } + } foreach my $pkg ($tlpdb->list_packages) { my $tlp = $tlpdb->get_package($pkg); if ($opts{"file"}) { @@ -1156,16 +1191,32 @@ sub action_search { } } else { next if ($pkg =~ m/\./); - my $t = $tlpdb->get_package($pkg)->shortdesc; - $t |= ""; - my $lt = $tlpdb->get_package($pkg)->longdesc; - $lt |= ""; + # the other searching is done together + my $t = ""; + if ($opts{"taxonomy"}) { + $t = "$t" . join('\n', @{$taxonomy->{'by-package'}{'keyword'}{$pkg}}) + if (defined($taxonomy->{'by-package'}{'keyword'}{$pkg})); + $t = "$t$taxonomy->{'by-package'}{'primary'}{$pkg}\n" + if (defined($taxonomy->{'by-package'}{'primary'}{$pkg})); + $t = "$t$taxonomy->{'by-package'}{'secondary'}{$pkg}\n" + if (defined($taxonomy->{'by-package'}{'secondary'}{$pkg})); + $t = "$t" . join('\n', @{$taxonomy->{'by-package'}{'function'}{$pkg}}) + if (defined($taxonomy->{'by-package'}{'function'}{$pkg})); + } else { + $t = "$pkg\n"; + $t = "$t" . $tlp->shortdesc . "\n" + if (defined($tlp->shortdesc)); + $t = "$t" . $tlp->longdesc . "\n" + if (defined($tlp->longdesc)); + } + my $shortdesc = $tlp->shortdesc; + $shortdesc |= ""; my $pat = $r; if ($opts{"word"}) { $pat = '\W' . $r . '\W'; } - if (($pkg =~ m/$pat/) || ($t =~ m/$pat/) || ($lt =~ m/$pat/)) { - $ret .= " $pkg - $t\n"; + if ($t =~ m/$pat/) { + $ret .= " $pkg - " . $shortdesc . "\n"; } } } @@ -5371,17 +5422,19 @@ Print the TeX Live identifier for the detected platform C<--print-arch> is a synonym. -=head2 search [I