54f3416f78112bf93908c84370d5750a086884cb
[platform/upstream/automake.git] / lib / Automake / General.pm
1 # Copyright (C) 2001, 2003  Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2, or (at your option)
6 # any later version.
7
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 # 02110-1301, USA.
17
18 package Automake::General;
19
20 use 5.005;
21 use strict;
22 use Exporter;
23 use File::Basename;
24
25 use vars qw (@ISA @EXPORT);
26
27 @ISA = qw (Exporter);
28 @EXPORT = qw (&uniq $me);
29
30 # Variable we share with the main package.  Be sure to have a single
31 # copy of them: using `my' together with multiple inclusion of this
32 # package would introduce several copies.
33 use vars qw ($me);
34 $me = basename ($0);
35
36 # END
37 # ---
38 # Exit nonzero whenever closing STDOUT fails.
39 sub END
40 {
41   # This is required if the code might send any output to stdout
42   # E.g., even --version or --help.  So it's best to do it unconditionally.
43   if (! close STDOUT)
44     {
45       print STDERR "$me: closing standard output: $!\n";
46       $? = 74; # EX_IOERR
47       return;
48     }
49 }
50
51
52 # @RES
53 # uniq (@LIST)
54 # ------------
55 # Return LIST with no duplicates.
56 sub uniq (@)
57 {
58    my @res = ();
59    my %seen = ();
60    foreach my $item (@_)
61      {
62        if (! exists $seen{$item})
63          {
64            $seen{$item} = 1;
65            push (@res, $item);
66          }
67      }
68    return wantarray ? @res : "@res";
69 }
70
71
72 1; # for require
73
74 ### Setup "GNU" style for perl-mode and cperl-mode.
75 ## Local Variables:
76 ## perl-indent-level: 2
77 ## perl-continued-statement-offset: 2
78 ## perl-continued-brace-offset: 0
79 ## perl-brace-offset: 0
80 ## perl-brace-imaginary-offset: 0
81 ## perl-label-offset: -2
82 ## cperl-indent-level: 2
83 ## cperl-brace-offset: 0
84 ## cperl-continued-brace-offset: 0
85 ## cperl-label-offset: -2
86 ## cperl-extra-newline-before-brace: t
87 ## cperl-merge-trailing-else: nil
88 ## cperl-continued-statement-offset: 2
89 ## End: