1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 debug
17
18 debug
19
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 %page;
74
75 ihtest:
76 proc options(variable);
77
78 dcl code fixed bin(35);
79
80 dcl 1 lei aligned like line_editor_info;
81 dcl lei_buffer char(lei.line_length) based(addr(lei.input_buffer));
82
83 dcl (FALSE init("0"b), TRUE init("1"b)) bit(1) aligned int static options(constant);
84 dcl NL char(1) int static options(constant) init("
85 ");
86 dcl PROC char(6) int static options(constant) init("ihtest");
87
88 dcl com_err_ entry() options(variable);
89 dcl cu_$arg_count entry (fixed bin, fixed bin(35));
90 dcl cu_$arg_ptr entry (fixed bin, ptr, fixed bin(21), fixed bin(35));
91 dcl input_history_$ih_forward_search entry (ptr, fixed bin(35));
92 dcl input_history_$ih_next_line entry (ptr, fixed bin(35));
93 dcl input_history_$ih_previous_line entry (ptr, fixed bin(35));
94 dcl input_history_$ih_reverse_search entry (ptr, fixed bin(35));
95 dcl input_history_$test_iocb_dict_clear entry (ptr);
96 dcl input_history_$test_iocb_dict_display entry();
97 dcl input_history_$test_iocb_dict_get entry (ptr) returns(ptr);
98 dcl input_history_$validate_attach_options entry (char(*), char(*), (*) char(*) var, fixed bin(35));
99 dcl ioa_ entry() options(variable);
100 dcl (iox_$user_input, iox_$user_io) ptr ext static;
101
102 dcl (error_table_$bad_opt,
103 error_table_$no_iocb,
104 video_et_$wsys_not_invoked
105 ) fixed bin(35) ext static;
106
107 dcl (addr, binary, null, substr, verify, unspec) builtin;
108 %page;
109
110
111
112
113
114
115 dcl operation char(40) var;
116 dcl operationI fixed bin;
117 dcl operationsN fixed bin;
118 dcl optionP ptr, optionL fixed bin(21), option char(optionL) based(optionP);
119 dcl repetitionCount fixed bin;
120
121 call cu_$arg_count (operationsN, code);
122
123 OPERATION_LOOP:
124 do operationI = 0 to operationsN;
125 repetitionCount = 1;
126
127 if operationI = 0 then do;
128 if operationsN = 0 then go to PREVIOUS_LINE_REQ;
129 else go to NEXT_OPERATION;
130 end;
131
132 call cu_$arg_ptr (operationI, optionP, optionL, code);
133 if option = "-clear" | option = "-c" then go to CLEAR_REQ;
134 if option = "-display" | option = "-disp" | option = "-d" then go to DISPLAY_REQ;
135 if option = "-next" | option = "-n" then go to NEXT_LINE_REQ;
136 if option = "-previous" | option = "-prev" | option = "-p" then go to PREVIOUS_LINE_REQ;
137 if option = "-reverse_search" | option = "-reverse" | option = "-rev" | option = "-r" then go to REVERSE_SEARCH_REQ;
138 if option = "-search" | option = "-srch" | option = "-s" then go to FORWARD_SEARCH_REQ;
139 if verify(option, "+-0123456789") = 0 then do;
140 repetitionCount = binary(option,17);
141 if repetitionCount < 0 then do;
142 repetitionCount = -repetitionCount;
143 go to PREVIOUS_LINE_REQ;
144 end;
145 else if repetitionCount > 0 then go to NEXT_LINE_REQ;
146 end;
147 call com_err_ (error_table_$bad_opt, PROC, option);
148 return;
149 %page;
150
151 PREVIOUS_LINE_REQ:
152 operation = "ih_previous_line";
153 call setup_request(operation, "^P" , repetitionCount, lei);
154 call input_history_$ih_previous_line (addr(lei), code);
155 go to END_REQUEST;
156
157 NEXT_LINE_REQ:
158 operation = "ih_next_line";
159 call setup_request(operation, "^N" , repetitionCount, lei);
160 call input_history_$ih_next_line (addr(lei), code);
161 go to END_REQUEST;
162
163 REVERSE_SEARCH_REQ:
164 operation = "ih_reverse_search";
165 call setup_request(operation, "^R" , repetitionCount, lei);
166 call input_history_$ih_reverse_search (addr(lei), code);
167 go to END_REQUEST;
168
169 FORWARD_SEARCH_REQ:
170 operation = "ih_forward_search";
171 call setup_request(operation, "^S" , repetitionCount, lei);
172 call input_history_$ih_forward_search (addr(lei), code);
173 go to END_REQUEST;
174
175 END_REQUEST:
176 if code ^= 0 then do;
177 if code = error_table_$no_iocb then do;
178 call com_err_ (code, PROC, "lei.iocb_ptr: ^p (^a) not found in iocb_dict.",
179 lei.iocb_ptr, lei.iocb_ptr->iocb.name);
180 call input_history_$test_iocb_dict_display();
181 end;
182 if code = video_et_$wsys_not_invoked then
183 call com_err_ (code, PROC, "Must use 'wdc invoke' to test input_history_.");
184 return;
185 end;
186
187 call ioa_ ("^a AFTER ^a [editor line: ^p (^d chars), cursor index: ^d^[, break: ^a^;^s^]]: ^a^12x'^a'",
188 NL, operation, addr(lei.input_buffer), lei.line_length, lei.cursor_index,
189 lei.break_given, interpret_break(lei.new_break_character), NL, lei_buffer);
190
191 DISPLAY_REQ:
192 operation = "input_history_$test_iocb_dict_display";
193 call input_history_$test_iocb_dict_display();
194 go to NEXT_OPERATION;
195
196 CLEAR_REQ:
197 operation = "input_history_$test_iocb_dict_clear";
198 ihDataP = input_history_$test_iocb_dict_get (iox_$user_io);
199 if ihDataP ^= null then do;
200 call input_history_$test_iocb_dict_clear (iox_$user_io);
201 free ihData in (ihArea);
202 end;
203
204 NEXT_OPERATION:
205 call ioa_("");
206 end OPERATION_LOOP;
207 return;
208
209 %page;
210 setup_request:
211 proc (op, keySeq, repetitionCount, lei);
212
213 dcl op char(40) var;
214 dcl keySeq char(4) var;
215 dcl repetitionCount fixed bin;
216 dcl 1 lei aligned like line_editor_info;
217 dcl lei_buffer char(lei.line_length) based(addr(lei.input_buffer));
218
219
220
221
222
223
224
225
226
227
228 dcl attach_options (1) char(20) var init("user_i/o");
229 dcl code fixed bin(35);
230
231 ihDataP = input_history_$test_iocb_dict_get (iox_$user_io);
232 if ihDataP = null then do;
233 call input_history_$validate_attach_options (PROC, "user_i/o", attach_options, code);
234
235 if code ^= 0 then return;
236 end;
237
238 if lei.version ^= line_editor_info_version_3 then do;
239 lei.version = line_editor_info_version_3;
240 lei.iocb_ptr = iox_$user_io -> iocb.actual_iocb_ptr;
241 unspec(lei.flags) = FALSE;
242 lei.flags.numarg_given = TRUE;
243 lei.flags.break_given = FALSE;
244 lei.user_data_ptr = null();
245 lei.cursor_index = 7;
246 lei.line_length = 11;
247 lei.input_buffer = "CURSOR_here";
248 lei.redisplay = redisplayBuffer;
249 lei.new_break_character = "";
250 lei.pad2 = "";
251 end;
252 lei.repetition_count = repetitionCount;
253 lei.key_sequence = keySeq;
254
255 call ioa_ ("BEFORE ^a [editor line: ^p (^d chars), cursor index: ^d]: ^a^12x'^a'",
256 op, addr(lei.input_buffer), lei.line_length, lei.cursor_index, NL, lei_buffer);
257
258 end setup_request;
259 %page;
260
261 interpret_break:
262 proc (break) returns(char(16) var);
263
264 dcl break char(1);
265
266
267 dcl AT char(1) int static options(constant) init("@");
268 dcl BEL char(1) int static options(constant) init("^G");
269 dcl CTL char(1) int static options(constant) init("^");
270 dcl DEL char(1) int static options(constant) init("^?");
271 dcl HT char(1) int static options(constant) init(" ");
272 dcl NL char(1) int static options(constant) init("
273 ");
274 dcl NUL char(1) int static options(constant) init("^@");
275 dcl PND char(1) int static options(constant) init("#");
276 dcl SP char(1) int static options(constant) init(" ");
277
278 if break = NUL then return (CTL || AT);
279 if break < SP then return (CTL || substr(collate(),(rank(break)+1+rank(AT)),1));
280 if break < DEL then return (substr(collate(),(rank(break)+1),1));
281 if break = DEL then return ("DEL");
282 if rank(break) < 256 then
283 return ("Meta-" || interpret_break(substr(collate(),(rank(break)+1-128),1)));
284 if rank(break) >= 256 then return ("BAD-" || ltrim(char(rank(break))));
285
286 end interpret_break;
287 %page;
288
289 redisplayBuffer:
290 proc (leiP);
291
292
293
294
295 dcl leiP ptr;
296 dcl 1 lei aligned like line_editor_info based(leiP);
297 dcl lei_buffer char(lei.line_length) based(addr(lei.input_buffer));
298
299 dcl (cursorI, lineI) fixed bin;
300 dcl ignoreCode fixed bin(35);
301
302 call window_$get_cursor_position (lei.iocb_ptr, lineI, cursorI, code);
303 call window_$position_cursor (lei.iocb_ptr, lineI, 1, ignoreCode);
304 call window_$overwrite_text (lei.iocb_ptr, lei_buffer, ignoreCode);
305 call window_$clear_to_end_of_line (lei.iocb_ptr, ignoreCode);
306 call window_$position_cursor (lei.iocb_ptr, lineI, (lei.cursor_index), ignoreCode);
307 call window_$sync (lei.iocb_ptr, ignoreCode);
308
309 end redisplayBuffer;
310
311 %page;
312 %include input_history_data;
313
314 dcl ihArea area based(get_system_free_area_());
315
316
317
318
319 dcl get_system_free_area_ entry() returns(ptr);
320
321 %page;
322 %include iocb;
323 %page;
324 %include window_dcls;
325 %page;
326 %include window_line_editor;
327 end ihtest;