| 1 |
|
| 2 |
|
| 3 |
# Code generated by Shell::POSIX::Select v0.09, by tim(AT)TeachMePerl.com |
| 4 |
# NOTA BENE: Line 1 of this segment must start with {, so user can LABEL it |
| 5 |
{ # **** NEW WRAPPER SCOPE FOR SELECTLOOP #1 **** |
| 6 |
$Shell::POSIX::Select::DEBUG > 1 and 1 == 1 and |
| 7 |
warn "LINE NUMBER FOR START OF USER CODE_BLOCK IS: ", __LINE__, "\n"; |
| 8 |
_SEL_LOOP1: { # **** NEW SCOPE FOR SELECTLOOP #1 **** |
| 9 |
|
| 10 |
# critical for values's contents to be resolved in user's scope |
| 11 |
local @Shell::POSIX::Select::looplist=(@ARGV); |
| 12 |
local $Shell::POSIX::Select::num_values=@Shell::POSIX::Select::looplist; |
| 13 |
|
| 14 |
$Shell::POSIX::Select::DEBUG > 4 and do { |
| 15 |
warn "ARRAY VALUES ARE: @Shell::POSIX::Select::looplist\n"; |
| 16 |
warn "NUM VALUES is $Shell::POSIX::Select::num_values\n"; |
| 17 |
warn "user-program debug level is $Shell::POSIX::Select::U_WARN\n"; |
| 18 |
}; |
| 19 |
; # NO DECLARATION OF LOOP-VAR REQUESTED # loop-var declaration appears here |
| 20 |
|
| 21 |
; |
| 22 |
local ( |
| 23 |
$Shell::POSIX::Select::Prompt[1], |
| 24 |
$Shell::POSIX::Select::menu |
| 25 |
) = |
| 26 |
Shell::POSIX::Select::make_menu( |
| 27 |
$Shell::POSIX::Select::Heading || "", |
| 28 |
$Shell::POSIX::Select::Prompt || "" , # Might be overridden in make_menu |
| 29 |
@Shell::POSIX::Select::looplist |
| 30 |
); |
| 31 |
|
| 32 |
# no point in prompting a pipe! |
| 33 |
local $Shell::POSIX::Select::do_prompt[1] = (-t) ? 1 : 0 ; |
| 34 |
0 > 2 and warn "do_prompt is $Shell::POSIX::Select::do_prompt[1]\n"; |
| 35 |
if ( defined $Shell::POSIX::Select::menu ) { # No list, no iterations! |
| 36 |
while (1) { # for repeating prompt for selections |
| 37 |
# localize, so I don't have to reset for |
| 38 |
# outer loop on exit from inner |
| 39 |
local ($Reply); |
| 40 |
while (1) { # for validating user's input |
| 41 |
local $Shell::POSIX::Select::bad = 0; |
| 42 |
|
| 43 |
# local decl suppresses newline on prompt when -l switch turned on |
| 44 |
{ |
| 45 |
local $\; |
| 46 |
if ($Shell::POSIX::Select::do_prompt[1]) { |
| 47 |
|
| 48 |
# When transferring from INNER to OUTER loop, |
| 49 |
# extra NL before prompt is visually desirable |
| 50 |
|
| 51 |
if ( $Shell::POSIX::Select::_extra_nl) { |
| 52 |
print STDERR "\n\n"; |
| 53 |
$Shell::POSIX::Select::_extra_nl=0; |
| 54 |
} |
| 55 |
print STDERR |
| 56 |
"$Shell::POSIX::Select::menu\n$Shell::POSIX::Select::Prompt[1] "; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
# $Shell::POSIX::Select::do_prompt=0; |
| 61 |
# constant prompting depends on style |
| 62 |
$Shell::POSIX::Select::do_prompt[1]= 0; |
| 63 |
|
| 64 |
if ( $Shell::POSIX::Select::dump_data ) { |
| 65 |
$Reply = undef; |
| 66 |
# dump filtered source for comparison against expected |
| 67 |
print STDERR "copacetic |
| 68 |
"; # ensure some output, and flush pending |
| 69 |
exit 222; # code for graceful, expected, early exit |
| 70 |
} |
| 71 |
else { |
| 72 |
# $^W=0; |
| 73 |
# warn "Waiting for input"; |
| 74 |
$Eof=0; |
| 75 |
$Reply = <STDIN>; |
| 76 |
# warn "Got input"; |
| 77 |
# $^W=1; |
| 78 |
|
| 79 |
if ( !defined( $Reply ) ) { |
| 80 |
defined "" and "" ne "" and print STDERR ""; |
| 81 |
|
| 82 |
# need to undef loop var; user may check it! |
| 83 |
undef $var[0]; |
| 84 |
|
| 85 |
# last Shell::POSIX::Select::_SEL_LOOP1; # Syntax error! |
| 86 |
# If returning to outer loop, show the prompt for it |
| 87 |
# warn "User hit ^D"; |
| 88 |
if ( 1 > 1 and -t ) { # reset prompting for outer loop |
| 89 |
$Shell::POSIX::Select::do_prompt[1-1] = 1; $Shell::POSIX::Select::_extra_nl=1; |
| 90 |
} |
| 91 |
0 > 2 and warn "Lasting out of _SEL_LOOP1\n"; |
| 92 |
$Eof=1; |
| 93 |
last _SEL_LOOP1; |
| 94 |
} |
| 95 |
!defined $Reply and die "REPLY accessed, while undefined"; |
| 96 |
chomp $Reply; |
| 97 |
|
| 98 |
# undo emboldening of user input |
| 99 |
defined "" and "" ne "" and print STDERR ""; |
| 100 |
|
| 101 |
#print STDERR "$Shell::POSIX::Select::menu\n$Shell::POSIX::Select::Prompt "; |
| 102 |
if ( $Reply eq "" ) { # interpreted as re-print menu request |
| 103 |
# Empty input is legit, means redisplay menu |
| 104 |
$Shell::POSIX::Select::U_WARN > 1 and warn "\tINPUT IS: empty\n"; |
| 105 |
$Shell::POSIX::Select::bad = $Shell::POSIX::Select::do_prompt[1] = 1; |
| 106 |
} |
| 107 |
elsif ( $Reply =~ /\D/ ) { # shouldn't be any non-digit! |
| 108 |
$Shell::POSIX::Select::U_WARN > 0 |
| 109 |
and warn "\tINPUT CONTAINS NON-DIGIT: '$Reply'\n"; |
| 110 |
$Shell::POSIX::Select::bad = 1; # Korn and Bash shell just ignore this case |
| 111 |
} |
| 112 |
elsif ( $Reply < 1 or $Reply > $Shell::POSIX::Select::num_values ) { |
| 113 |
$Shell::POSIX::Select::U_WARN > 0 |
| 114 |
and warn |
| 115 |
"\t'$Reply' IS NOT IN RANGE: 1 - $Shell::POSIX::Select::num_values\n"; |
| 116 |
$Shell::POSIX::Select::bad = 1; # Korn and Bash shell just ignore this case |
| 117 |
} |
| 118 |
|
| 119 |
# warn "BAD is now: $Shell::POSIX::Select::bad"; |
| 120 |
$Shell::POSIX::Select::bad or |
| 121 |
0 > 2 and warn "About to last out of Reply Validator Loop |
| 122 |
"; |
| 123 |
$Shell::POSIX::Select::bad or last; # REPLY VALIDATOR EXITED HERE |
| 124 |
} # if for validating user input |
| 125 |
} # infinite while for validating user input |
| 126 |
|
| 127 |
$var[0] = $Shell::POSIX::Select::looplist[$Reply - 1]; # set users' variable |
| 128 |
|
| 129 |
# USER'S LOOP-BLOCK BELOW |
| 130 |
print "$var[0]\n";; |
| 131 |
|
| 132 |
# USER'S LOOP-BLOCK ABOVE |
| 133 |
# Making sure there's colon (maybe |
| 134 |
# even two) after codestring above, |
| 135 |
# in case user omitted after last |
| 136 |
# statement in block. I might add |
| 137 |
# another statement below it someday! |
| 138 |
0 > 2 and warn "At end of prompt-repeating loop |
| 139 |
"; |
| 140 |
} # infinite while for repeating collection of selections |
| 141 |
0 and warn "BEYOND end of prompt-repeating loop |
| 142 |
"; |
| 143 |
} # endif (defined $Shell::POSIX::Select::menu) |
| 144 |
else { |
| 145 |
$Shell::POSIX::Select::DEBUG > 0 and warn "Shell::POSIX::Select: Select Loop #1 has no list, so no iterations\n"; |
| 146 |
|
| 147 |
if ( $Shell::POSIX::Select::dump_data ) { |
| 148 |
$Reply = undef; |
| 149 |
# dump filtered source for comparison against expected |
| 150 |
print STDERR "copacetic |
| 151 |
"; # ensure some output, and flush pending |
| 152 |
exit 222; # code for graceful, expected, early exit |
| 153 |
} |
| 154 |
} |
| 155 |
# return omitted above, to get last expression's value |
| 156 |
# returned automatically, just like shell's version |
| 157 |
|
| 158 |
|
| 159 |
} # **** END NEW SCOPE FOR SELECTLOOP #1 **** |
| 160 |
} # **** END WRAPPER SCOPE FOR SELECTLOOP #1 **** |
| 161 |
# vi:ts=2 sw=2: |
| 162 |
|