diff options
Diffstat (limited to 'Master/tlpkg/TeXLive/TLUtils.pm')
-rw-r--r-- | Master/tlpkg/TeXLive/TLUtils.pm | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/Master/tlpkg/TeXLive/TLUtils.pm b/Master/tlpkg/TeXLive/TLUtils.pm new file mode 100644 index 00000000000..f07c4588ed5 --- /dev/null +++ b/Master/tlpkg/TeXLive/TLUtils.pm @@ -0,0 +1,136 @@ +# +# TeXLive::TLUtils.pm +# common functions for TeX Live Infrastructure +# Copyright 2007 Norbert Preining +# +# based on Fabrice Popineau's FileUtils.pm +# +# This file is licensed under the GNU General Public Licence version 2 +# or any later version + +package TeXLive::TLUtils; + +=pod +=head1 NAME + +TeXLive::TLUtils - utilities used in the TeX Live Infrastructure Modules + +=head1 SYNOPSIS + + use TeXLive::TLUtils; + + TeXLive::TLUtils::sort_uniq(@list); + TeXLive::TLUtils::push_uniq(\@list, @items); + TeXLive::TLUtils::member($item, @list); + TeXLive::TLUtils::debug($string); + +=head1 DESCRIPTION + +=cut + +use File::Basename; + +BEGIN { + use Exporter (); + use Cwd; + use File::Path; + use vars qw( @ISA @EXPORT_OK ); + @ISA = qw(Exporter); + @EXPORT_OK = qw( + &sort_uniq + &push_uniq + ); +} + +=pod + +The C<sort_uniq> function sorts the given array and throws away multiple +occurrences of elements. It returns a sorted and unified array. + +=cut + +sub sort_uniq { + my (@l) = @_; + my ($e, $f, @r); + $f = ""; + @l = sort(@l); + foreach $e (@l) { + if ($e ne $f) { + $f = $e; + push @r, $e; + } + } + return @r; +} + +=pod + +The C<push_uniq> function pushes the last elements on the list referenced +by the first argument. + +=cut + +sub push_uniq { + local (*l, @le) = @_; + my ($e); + foreach $e (@le) { + if (! &member($e, @l)) { + push @l, $e; + } + } +} + +=pod + +The C<member> function returns true if the the first argument is contained +in the list of the remaining arguments. + +=cut + +sub member { + my ($e, @l) = @_; + my ($f); + foreach $f (@l) { + if ($e eq $f) { + return 1; + } + } + return 0; +} + +=pod + +The C<debug> function echos the argument string to STDERR in case that +the global varialbe C<opt_debug> is set. + +=cut + +sub debug { + print STDERR @_ if ($::opt_debug); +} + +1; + +=pod + +=head1 AUTHORS AND COPYRIGHT + +This module and its documentation was written by +Norbert Preining <F<preining@logic.at>> for the TeX Live distribution and both +are licensed under the GNU General Public License Version 2 or later. + +=head1 SEE ALSO + +The modules L<TeXLive::TLPSRC>, L<TeXLive::TLPOBJ>, +L<TeXLive::TLPDB>, L<TeXLive::TLTREE>, and the +document L<Perl-API.txt> and the specification in the TeX Live +repository trunk/Master/tlpkg/doc/. + +=cut + +### Local Variables: +### perl-indent-level: 4 +### tab-width: 4 +### indent-tabs-mode: t +### End: +# vim:set tabstop=4: # |