1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 ask_: proc (prompt, ans);
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 note
75
76
77
78
79
80
81
82
83 NOTE
84
85
86
87
88
89
90
91
92
93 dcl (addr, index, length, min, rtrim, substr) builtin;
94
95 dcl (line char (128) aligned,
96 empty bit (1) init ("1"b),
97 i fixed bin init (1),
98 nchr fixed bin (21),
99 prompt_len fixed bin,
100 blank char (1) init (" ") aligned,
101 NL char (1) aligned init ("
102 "),
103 tab char (1) init (" ") aligned) int static;
104
105 dcl prompt char (*),
106 ans char (*),
107 flag fixed bin,
108 int fixed bin,
109 flo float bin;
110
111 dcl (start, j, tdg) fixed bin,
112 arglistp ptr,
113 ftm float bin (63),
114 fpm float bin (63),
115 oldi fixed bin,
116 fracsw bit (1) aligned,
117 tf char (4) aligned,
118 (flosw, intsw, linesw, csw, nsw, ynsw, nfsw, prmsw) bit (1) aligned init ("0"b);
119
120 dcl 1 ll aligned based (addr (line)),
121 2 ch (0: 127) char (1) unaligned;
122
123 dcl ioa_$nnl entry options (variable),
124 cu_$arg_list_ptr entry (ptr),
125 iox_$put_chars entry (ptr, ptr, fixed bin(21), fixed bin(35)),
126 iox_$get_line entry (ptr, ptr, fixed bin(21), fixed bin(21), fixed bin(35)),
127 iox_$user_input ptr ext static,
128 iox_$user_output ptr ext static,
129 ioa_$general_rs entry (ptr, fixed bin, fixed bin, char (*) aligned, fixed bin,
130 bit (1) aligned, bit (1) aligned);
131
132 dcl NL_HT_SP char (3) internal static options (constant) init ("
133 ");
134
135 dcl code fixed bin (35);
136
137
138
139 go to join;
140
141 ask_c: entry (ans, flag);
142
143 csw = "1"b;
144 go to join;
145
146 ask_int: entry (prompt, int);
147
148 intsw = "1"b;
149 go to join;
150
151 ask_cint: entry (int, flag);
152
153 intsw, csw = "1"b;
154 go to join;
155
156 ask_flo: entry (prompt, flo);
157
158 flosw = "1"b;
159 go to join;
160
161 ask_cflo: entry (flo, flag);
162
163 flosw, csw = "1"b;
164 go to join;
165
166 ask_line: entry (prompt, ans);
167
168 linesw = "1"b;
169 go to join;
170
171 ask_cline: entry (ans, flag);
172
173 linesw, csw = "1"b;
174 go to join;
175
176 ask_n: entry (ans, flag);
177
178 csw, nsw = "1"b;
179 go to join;
180
181 ask_nint: entry (int, flag);
182
183 csw, intsw, nsw = "1"b;
184 go to join;
185
186 ask_nflo: entry (flo, flag);
187
188 csw, nsw, flosw = "1"b;
189 go to join;
190
191 ask_nline: entry (ans, flag);
192
193 csw, nsw, linesw = "1"b;
194 go to join;
195
196 ask_prompt: entry (prompt);
197
198 empty, prmsw = "1"b;
199 go to join;
200
201 ask_yn: entry (prompt, ans);
202
203 ynsw = "1"b;
204 go to join;
205
206 ask_cyn: entry (ans, flag);
207
208 csw, ynsw = "1"b;
209 go to join;
210
211 ask_nyn: entry (ans, flag);
212
213 csw, nsw, ynsw = "1"b;
214 go to join;
215
216 ask_nf: entry (prompt, ans);
217
218 nfsw = "1"b;
219 go to join;
220
221 ask_cnf: entry (ans, flag);
222
223 csw, nfsw = "1"b;
224 go to join;
225
226 ask_nnf: entry (ans, flag);
227
228 csw, nsw, nfsw = "1"b;
229 go to join;
230
231
232
233 join: if empty then do;
234 mt: if csw then do;
235 flag = 0;
236 return;
237 end;
238 read: prompt_len = 120;
239 if prmsw then j = 2;
240 else j = 3;
241 call cu_$arg_list_ptr (arglistp);
242 call ioa_$general_rs (arglistp, 1, j, line, prompt_len, "1"b, "0"b);
243 nchr = prompt_len;
244 call iox_$put_chars (iox_$user_output, addr (line), nchr, code);
245 reread:
246 line = "";
247 nchr = 0;
248 call iox_$get_line (iox_$user_input, addr (line), 128, nchr, code);
249 nchr = length (rtrim (substr (line, 1, nchr), NL_HT_SP));
250 if nchr = 0 then go to read;
251 empty = "0"b;
252 i = 0;
253 if prmsw then return;
254 end;
255 oldi = i;
256
257 findb: if ch (i) ^= tab then if ch (i) ^= blank then go to first;
258 i = i + 1;
259 if i >= nchr then go to mt;
260 go to findb;
261
262 first: start = i;
263 if linesw then do;
264 ans = substr (line, start+1, nchr-i);
265 if ^nsw then empty = "1"b;
266 go to exit;
267 end;
268 finde: if ch (i) = blank then go to last;
269 if ch (i) = tab then go to last;
270 i = i + 1;
271 if i >= nchr then go to last;
272 go to finde;
273
274 last: if intsw then go to do_num;
275 if flosw then do;
276 do_num: fracsw = "0"b;
277 fpm = 1.0e0;
278 ftm = 0.0e0;
279 if ch (start) = "$" then start = start + 1;
280 if ch (start) = "-" then start = start + 1;
281
282 do j = start to i-1;
283 if ch (j) = "," then;
284 else if ch (j) = "." then fracsw = "1"b;
285 else do;
286 tdg = index ("0123456789", ch (j)) - 1;
287 if tdg < 0 then do;
288 badd: if csw then do;
289 fail: flag = -1;
290 i = oldi;
291 return;
292 end;
293 call ioa_$nnl ("""^a"" non-numeric. Please retype: ",
294 substr (line, start+1, i-start));
295 go to reread;
296 end;
297 if fracsw then do;
298 fpm = fpm * 10.0e0;
299 ftm = ftm + tdg/fpm;
300 end;
301 else ftm = 10.0e0*ftm + tdg;
302 end;
303 end;
304 if ch (start-1) = "-" then ftm = -ftm;
305 if intsw then int = ftm;
306 else flo = ftm;
307 end;
308 else if ynsw then do;
309 tf = substr (line, start+1, i-start);
310 if tf = "yes" | tf = "y" then do;
311 ans = "yes";
312 go to oky;
313 end;
314 else if tf = "no" | tf = "n" then do;
315 ans = "no";
316 go to oky;
317 end;
318 if csw then go to fail;
319 call ioa_$nnl ("""^a"" is not ""yes"" or ""no"". Please retype: ", substr (line, start+1, i-start));
320 go to reread;
321 end;
322 else if nfsw then do;
323 tf = substr (line, start+1, i-start);
324 if tf = "on" then do;
325 ans = "on";
326 goto oky;
327 end;
328 else if tf = "off" then do;
329 ans = "off";
330 goto oky;
331 end;
332 if csw then go to fail;
333 call ioa_$nnl ("""^a"" is not ""on"" or ""off"". Please retype: ", substr (line, start+1, i-start));
334 go to reread;
335 end;
336 else ans = substr (line, start+1, i-start);
337 oky:
338
339 exit: if csw then flag = 1;
340 if nsw then i = oldi;
341 else if i >= nchr then empty = "1"b;
342 return;
343
344
345
346 ask_clr: entry;
347
348 empty = "1"b;
349 return;
350
351
352
353 ask_setline: entry (input);
354
355 dcl input char (*);
356
357 line = input;
358 nchr = min (length (input), 128);
359 i = 0;
360 do while (nchr > 0);
361 if ch (nchr) ^= blank then if ch (nchr) ^= tab then if ch (nchr) ^= NL then go to sltx;
362 nchr = nchr - 1;
363 end;
364 sltx: if nchr > 0 then empty = "0"b;
365
366 end ask_;