Debian Codegraph @

Ref_Data/eslect_fixed.cdump_ref

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