3 #=======================================================================
5 # File ID: 04048b4a-284a-11e5-8465-000df06acc56
7 # Search for hexadecimal or decimal numbers in files or streams.
10 # ©opyleft 2015– Ø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 #=======================================================================
36 $progname =~ s/^.*\/(.*?)$/$1/;
37 our $VERSION = '0.1.0';
39 Getopt
::Long
::Configure
('bundling');
42 'decimal|d' => \
$Opt{'decimal'},
43 'help|h' => \
$Opt{'help'},
44 'ignore-case|i' => \
$Opt{'ignore-case'},
45 'length|l=s' => \
$Opt{'length'},
46 'quiet|q+' => \
$Opt{'quiet'},
47 'unique|u' => \
$Opt{'unique'},
48 'verbose|v+' => \
$Opt{'verbose'},
49 'version' => \
$Opt{'version'},
51 ) || die("$progname: Option error. Use -h for help.\n");
78 $Opt{'verbose'} -= $Opt{'quiet'};
79 $Opt{'help'} && usage
(0);
80 if ($Opt{'version'}) {
94 my $l = $Opt{'length'};
95 if ($l =~ /^(\d+)$/) {
98 } elsif ($l =~ /^(\d+)-$/) {
100 } elsif ($l =~ /^-(\d+)$/) {
102 } elsif ($l =~ /^(\d+)-(\d+)$/) {
105 } elsif ($l =~ /^([0-9a-z])+$/) {
106 my $val = $size{"$Opt{'length'}"};
111 warn("$progname: $l: Unknown length unit\n");
115 msg
(3, "minlen = '$minlen', maxlen = '$maxlen'");
120 $Opt{'ignore-case'} && ($exp .= 'A-F');
121 $Opt{'decimal'} || ($exp .= 'a-f');
122 while (my $line = <>) {
128 length($str) < $minlen && ($do_print = 0);
129 $maxlen && length($str) > $maxlen && ($do_print = 0);
131 $Opt{'unique'} && $uniq{"$str"} && ($do_print = 0);
132 $do_print && print("$str\n");
144 for my $f (keys %size) {
145 push(@arr, "$f ($size{$f})");
147 return(join(', ', sort(@arr)));
152 # Print program version {{{
153 print("$progname $VERSION\n");
159 # Send the help message to stdout {{{
162 if ($Opt{'verbose'}) {
166 $Text::Wrap
::columns
= 72;
167 my $unit_str = wrap
(' ' x
6, ' ' x
6, unit_list
());
170 Usage: $progname [options] [file [files [...]]]
177 Limit search to decimal (0-9) digits.
179 Also include hexadecimal digits with upper case (A-F).
181 List only values of length X where X can be:
183 Each printed value must be exactly X characters wide
187 No longer than X characters
189 Minimal and maximum length
191 A list of predefined sizes can also be specified. Current list:
194 Be more quiet. Can be repeated to increase silence.
196 Don't print any value more than once.
198 Increase level of verbosity. Can be repeated.
200 Print version information.
208 # Print a status message to stderr based on verbosity level {{{
209 my ($verbose_level, $Txt) = @_;
211 if ($Opt{'verbose'} >= $verbose_level) {
212 print(STDERR
"$progname: $Txt\n");
220 # This program is free software; you can redistribute it and/or modify
221 # it under the terms of the GNU General Public License as published by
222 # the Free Software Foundation; either version 2 of the License, or (at
223 # your option) any later version.
225 # This program is distributed in the hope that it will be useful, but
226 # WITHOUT ANY WARRANTY; without even the implied warranty of
227 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
228 # See the GNU General Public License for more details.
230 # You should have received a copy of the GNU General Public License
231 # along with this program.
232 # If not, see L<http://www.gnu.org/licenses/>.
234 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :