Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

banner: switch to getopt #286

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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