Skip to content

Commit

Permalink
Merge pull request #286 from mknos/banner-getopt
Browse files Browse the repository at this point in the history
banner: switch to getopt
  • Loading branch information
briandfoy authored Oct 10, 2023
2 parents 517794c + 843ddd8 commit e8e58c1
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions bin/banner
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use strict;
require 5.004;

use File::Basename qw(basename);
use Getopt::Std qw(getopts);

use constant DWIDTH => 132;
use constant EX_SUCCESS => 0;
Expand All @@ -33,23 +34,15 @@ my @data_table;
# Pointers into @data_table for each ASCII char
my %ascii_to_table;

# options
my $width = DWIDTH;
while (@ARGV && $ARGV[0] =~ s/^-//) {
local $_ = shift;
if (s/^w//) {
if (length) { $width = $_ }
elsif (@ARGV) { $width = shift }
else { warn "$Program: illegal argument for -w option\n";
exit EX_FAILURE; }
if ($width =~ /[^0-9]/ || $width == 0) {
warn "$Program: illegal argument for -w option\n";
exit EX_FAILURE;
}
next;
my %opt;
getopts('w:', \%opt) or usage();
if (defined $opt{'w'}) {
if ($opt{'w'} =~ m/[^0-9]/ || $opt{'w'} == 0) {
warn "$Program: illegal argument for -w option\n";
exit EX_FAILURE;
}
warn "$Program: illegal option -- $_\n";
usage();
$width = $opt{'w'};
}

# scale characters to width
Expand Down

0 comments on commit e8e58c1

Please sign in to comment.