3 #=======================================================================
5 # File ID: 3ced9aa2-f744-11dd-9353-000475e441b9
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 #=======================================================================
33 $progname =~ s/^.*\/(.*?)$/$1/;
34 our $VERSION = '0.1.0';
36 Getopt
::Long
::Configure
('bundling');
39 'decimal|d' => \
$Opt{'decimal'},
40 'help|h' => \
$Opt{'help'},
41 'quiet|q+' => \
$Opt{'quiet'},
42 'unicode|u' => \
$Opt{'unicode'},
43 'verbose|v+' => \
$Opt{'verbose'},
44 'version' => \
$Opt{'version'},
46 ) || die("$progname: Option error. Use -h for help.\n");
48 $Opt{'verbose'} -= $Opt{'quiet'};
49 $Opt{'help'} && usage
(0);
50 if ($Opt{'version'}) {
55 my $print_str = $Opt{'decimal'} ?
"%u" : "%02x";
66 warn("$progname: $ARGV[0]: Unknown command line argument\n");
70 if ($Opt{'unicode'}) {
71 binmode(STDIN
, ':utf8');
75 s/(.)/print_byte(ord($1))/gse;
92 printf("$spc$print_str", $val);
100 # Print program version {{{
101 print("$progname $VERSION\n");
107 # Send the help message to stdout {{{
110 if ($Opt{'verbose'}) {
116 Usage: $progname [options]
121 Use decimal (10 base) output instead of hex.
125 Be more quiet. Can be repeated to increase silence.
127 Output Unicode values instead of bytes when reading UTF-8. For
128 example, when reading the character U+2620, output "2620" instead of
129 "e2 98 a0" when this option is used. Likewise, when combined with
130 --decimal, output "9760" instead of "226 152 160".
132 Increase level of verbosity. Can be repeated.
134 Print version information.
142 # Print a status message to stderr based on verbosity level {{{
143 my ($verbose_level, $Txt) = @_;
145 if ($Opt{'verbose'} >= $verbose_level) {
146 print(STDERR
"$progname: $Txt\n");
154 # This program is free software; you can redistribute it and/or modify
155 # it under the terms of the GNU General Public License as published by
156 # the Free Software Foundation; either version 2 of the License, or (at
157 # your option) any later version.
159 # This program is distributed in the hope that it will be useful, but
160 # WITHOUT ANY WARRANTY; without even the implied warranty of
161 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
162 # See the GNU General Public License for more details.
164 # You should have received a copy of the GNU General Public License
165 # along with this program.
166 # If not, see L<http://www.gnu.org/licenses/>.
168 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :