mktar: Use `wc` instead of `du` in summary message
[sunny256-utils.git] / sumdup
blob6ca9effc6e472b8434a5b9c3fee70746f9b4c527
1 #!/usr/bin/env perl
3 #=======================================================================
4 # sumdup
5 # File ID: f8b42aae-f743-11dd-b0d8-000475e441b9
7 # Search for duplicates in MD5 and SHA1 files.
9 # Character set: UTF-8
10 # ©opyleft 2008– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
15 use strict;
16 use warnings;
17 use Getopt::Long;
19 local $| = 1;
21 our %Opt = (
23 'help' => 0,
24 'quiet' => 0,
25 'verbose' => 0,
26 'version' => 0,
30 our $progname = $0;
31 $progname =~ s/^.*\/(.*?)$/$1/;
32 our $VERSION = '0.1.0';
34 Getopt::Long::Configure('bundling');
35 GetOptions(
37 'help|h' => \$Opt{'help'},
38 'quiet|q+' => \$Opt{'quiet'},
39 'verbose|v+' => \$Opt{'verbose'},
40 'version' => \$Opt{'version'},
42 ) || die("$progname: Option error. Use -h for help.\n");
44 $Opt{'verbose'} -= $Opt{'quiet'};
45 $Opt{'help'} && usage(0);
46 if ($Opt{'version'}) {
47 print_version();
48 exit(0);
51 exit(main());
53 sub main {
54 # {{{
55 my $Retval = 0;
57 my ($Last, $Curr) = ("", "");
58 my ($Line, $last_line) = ("", "");
59 my $first_printed = 0;
61 while (<>) {
62 chomp($Line = $_);
63 /^([[:xdigit:]]+)/ && ($Curr = $1);
64 if ($Curr eq $Last) {
65 if (!$first_printed) {
66 print("\n$last_line\n");
67 $first_printed = 1;
69 print("$Line\n");
70 } else {
71 $first_printed = 0;
73 $Last = $Curr;
74 $last_line = $Line;
77 return $Retval;
78 # }}}
79 } # main()
81 sub print_version {
82 # Print program version {{{
83 print("$progname $VERSION\n");
84 return;
85 # }}}
86 } # print_version()
88 sub usage {
89 # Send the help message to stdout {{{
90 my $Retval = shift;
92 if ($Opt{'verbose'}) {
93 print("\n");
94 print_version();
96 print(<<"END");
98 Find duplicates in MD5 and SHA1 files. Input has to be sorted.
100 Usage: $progname [options] [file [files [...]]]
102 Options:
104 -h, --help
105 Show this help.
106 -q, --quiet
107 Be more quiet. Can be repeated to increase silence.
108 -v, --verbose
109 Increase level of verbosity. Can be repeated.
110 --version
111 Print version information.
114 exit($Retval);
115 # }}}
116 } # usage()
118 sub msg {
119 # Print a status message to stderr based on verbosity level {{{
120 my ($verbose_level, $Txt) = @_;
122 if ($Opt{'verbose'} >= $verbose_level) {
123 print(STDERR "$progname: $Txt\n");
125 return;
126 # }}}
127 } # msg()
129 __END__
131 # This program is free software; you can redistribute it and/or modify
132 # it under the terms of the GNU General Public License as published by
133 # the Free Software Foundation; either version 2 of the License, or (at
134 # your option) any later version.
136 # This program is distributed in the hope that it will be useful, but
137 # WITHOUT ANY WARRANTY; without even the implied warranty of
138 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
139 # See the GNU General Public License for more details.
141 # You should have received a copy of the GNU General Public License
142 # along with this program.
143 # If not, see L<http://www.gnu.org/licenses/>.
145 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :