3 #=======================================================================
5 # File ID: 7028de4a-f744-11dd-a3ac-000475e441b9
7 # Pads all integers read from stdin with zeros so they all have the same
10 # Character set: UTF-8
11 # ©opyleft 2008– Øyvind A. Holm <sunny@sunbase.org>
12 # License: GNU General Public License version 2 or later, see end of
13 # file for legal stuff.
14 #=======================================================================
34 $progname =~ s/^.*\/(.*?)$/$1/;
35 our $VERSION = '0.1.1';
37 Getopt
::Long
::Configure
('bundling');
40 'help|h' => \
$Opt{'help'},
41 'hex|x' => \
$Opt{'hex'},
42 'quiet|q+' => \
$Opt{'quiet'},
43 'size|s=i' => \
$Opt{'size'},
44 'verbose|v+' => \
$Opt{'verbose'},
45 'version' => \
$Opt{'version'},
47 ) || die("$progname: Option error. Use -h for help.\n");
49 $Opt{'verbose'} -= $Opt{'quiet'};
50 $Opt{'help'} && usage
(0);
51 if ($Opt{'version'}) {
66 my $DIGITS = $Opt{'hex'} ?
'0-9A-Fa-f' : '0-9';
71 $Line =~ s/([$DIGITS]+)/check_max($1)/ge;
74 for my $Curr (@Array) {
75 $Curr =~ s/([$DIGITS]+)/pad_number($1)/ge;
86 if (length($Str) > $max_length) {
87 $max_length = $Opt{'size'} ?
$Opt{'size'} : length($Str);
96 return $Num if ($max_length <= length($Num));
97 return('0' x
($max_length - length($Num)) . $Num);
102 # Print program version {{{
103 print("$progname $VERSION\n");
109 # Send the help message to stdout {{{
112 if ($Opt{'verbose'}) {
118 Usage: $progname [options] [file [files [...]]]
120 Pads all integers read from stdin with zeros so they all have the same
121 length. I.e.: 1 5 12 156 1024 = 0001 0005 0012 0156 1024.
128 Be more quiet. Can be repeated to increase silence.
130 Instead of padding to the size of the largest number, pad to a width
133 Increase level of verbosity. Can be repeated.
135 Include hexadecimal digits a-f and A-F.
137 Print version information.
145 # Print a status message to stderr based on verbosity level {{{
146 my ($verbose_level, $Txt) = @_;
148 if ($Opt{'verbose'} >= $verbose_level) {
149 print(STDERR
"$progname: $Txt\n");
157 # This program is free software; you can redistribute it and/or modify
158 # it under the terms of the GNU General Public License as published by
159 # the Free Software Foundation; either version 2 of the License, or (at
160 # your option) any later version.
162 # This program is distributed in the hope that it will be useful, but
163 # WITHOUT ANY WARRANTY; without even the implied warranty of
164 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
165 # See the GNU General Public License for more details.
167 # You should have received a copy of the GNU General Public License
168 # along with this program.
169 # If not, see L<http://www.gnu.org/licenses/>.
171 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :