General.pm 2.1 KB

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