1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# $Id$
# TeXLive::TLUtils.pm
# common functions for TeX Live Infrastructure
#
# Copyright 2007 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.
#
# ideas from Fabrice Popineau's FileUtils.pm.
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 {
# can't we use $l as a reference, and then use my? later ...
local (*l, @le) = @_;
foreach my $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 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/.
=head1 AUTHORS AND COPYRIGHT
This script and its documentation were written for the TeX Live
distribution (L<http://tug.org/texlive>) and both are licensed under the
GNU General Public License Version 2 or later.
=cut
### Local Variables:
### perl-indent-level: 2
### tab-width: 2
### indent-tabs-mode: nil
### End:
# vim:set tabstop=2 expandtab: #
|