1
2
3
4
5
6
7
8
9
10
11 edm: proc;
12
13
14
15
16
17
18
19
20
21
22 %include set_wakeup_table_info;
23 %include access_mode_values;
24 %include terminate_file;
25
26 dcl 1 swt aligned static like swt_info;
27 dcl iox_$modes entry (ptr, char (*), char (*), fixed bin (35));
28 dcl iox_$user_io ptr ext;
29 dcl error_table_$bad_mode fixed bin (35) ext;
30 dcl waketable_is_set bit (1) init (""b);
31
32 dcl readysw bit (1) aligned init ("0"b);
33 dcl cv_dec_check_ entry (char (*)aligned, fixed bin (35)) returns (fixed bin);
34 dcl (M, N) fixed bin (21);
35 dcl ready ext entry;
36
37 dcl 1 edata aligned,
38 2 upper,
39 3 fptr ptr,
40 3 indf fixed bin (21) init (0),
41 3 iflag bit (1) aligned init ("1"b),
42 3 csize1 fixed bin (24) init (0),
43 3 pad1 fixed bin,
44 2 tptr ptr,
45 2 indt fixed bin (21) init (0),
46 2 eof_ bit (1) aligned init ("0"b),
47 2 changed bit (1) aligned init ("0"b),
48 2 lngth fixed bin (17) init (0),
49 2 curlino fixed bin (21) init (1),
50 2 isok fixed bin (17) init (0);
51 dcl line char (152) aligned;
52
53 dcl 1 Edata_pi like edata aligned;
54
55 dcl pi_allowed bit (1) aligned init ("0"b);
56
57 dcl Line_pi char (152) aligned;
58
59 dcl 1 move_data aligned,
60 2 (x1, x2, xlen, y1, y2, ylen) fixed bin (21);
61
62 dcl did_move bit (1) aligned init ("0"b);
63
64 dcl buffer char (152) aligned;
65 dcl bufp ptr;
66 dcl sptr ptr init (null),
67
68 orig_ptr ptr;
69
70 dcl b168cu char (168) unal based;
71 dcl b32cu char (32) unal based;
72
73 dcl scanlen fixed bin (17);
74
75 dcl (g_lines, g_chars, mg_lines, mg_chars) fixed bin (21);
76
77 dcl (mc_skip, mc_chars) fixed bin (21);
78 dcl chunk fixed bin (21) init (512);
79 dcl (bkover, cgscanlen, xxxx, tnx) fixed bin (21);
80
81 dcl (bklen, nbk, nxlen) fixed bin (21);
82
83 dcl printing fixed bin;
84 dcl locating fixed bin;
85
86 dcl locstring char (152) aligned init ("
87 ");
88 dcl (loclen, locend) fixed bin;
89 dcl skipblank fixed bin;
90 dcl where_found fixed bin;
91 dcl locp pointer;
92 dcl trick_ptr ptr;
93 dcl me char (4) static aligned init ("edm ");
94 dcl active fixed bin static init (0);
95
96 dcl status bit (72) aligned,
97 (m, ij, ii) fixed bin (21),
98 error_message char (33) aligned init ("Line too long. Max length is 152.") static,
99 string char (262144) aligned based,
100 arg char (lname) based (np) unaligned,
101 xarg char (lprinam) based (np) unal,
102 (error_table_$noentry, error_table_$noarg) fixed bin (35) ext,
103 error_table_$no_w_permission fixed bin(35) ext static,
104 (iox_$user_input, iox_$user_output) ptr ext,
105 code fixed bin (35),
106 type fixed bin (2),
107 (edct, num_err, cm1) fixed bin (17),
108 (i, j, k, n) fixed bin (21),
109 l fixed bin (17),
110 sw_pi bit (1) aligned init ("0"b),
111 gotlino fixed bin (21),
112 prc fixed bin (17),
113 count fixed bin (17),
114 (lname, lprinam) fixed bin (17),
115 located bit (1),
116 temp1 bit (1),
117 brief bit (1),
118 break char (1) aligned,
119 cwd char (1) aligned,
120 (rrs init ("^N"), brs init ("^O"), nl init ("
121 ")) char (1) aligned static,
122 saveflag fixed bin (17),
123 tlin char (152),
124 olin char (456) aligned,
125
126 int_lab label init (pedit);
127 dcl np ptr;
128
129 dcl (ptr1 init (null),
130 ptr2) int static ptr;
131
132 dcl
133 iox_$get_line entry (ptr, ptr, fixed bin (17), fixed bin (17), fixed bin (35)),
134 hcs_$truncate_seg entry (ptr, fixed bin (21), fixed bin (35)),
135 cu_$cp entry (ptr, fixed bin (17), fixed bin (35)),
136 hcs_$make_seg entry (char (*), char (*), char (*), fixed bin (5), ptr, fixed bin (35)),
137 cu_$arg_ptr entry (fixed bin (17), ptr, fixed bin (17), fixed bin (35)),
138 (com_err_, command_query_) entry options (variable),
139 iox_$control entry (ptr, char (*) aligned, ptr, fixed bin (35)),
140 ioa_ entry options (variable),
141 initiate_file_ entry (char(*), char(*), bit(*), ptr, fixed bin(24), fixed bin(35)),
142 terminate_file_ entry (ptr, fixed bin(24), bit(*), fixed bin(35)),
143 expand_pathname_ entry (char(*), char(*), char(*), fixed bin(35)),
144 check_entryname_ entry (char (*), fixed bin (35)),
145 hcs_$status_mins entry (ptr, fixed bin (2), fixed bin (24), fixed bin (35)),
146 iox_$put_chars entry (ptr, ptr, fixed bin (17), fixed bin (35));
147
148 dcl segsize fixed bin (21);
149 dcl merge_bc fixed bin (24);
150
151 dcl (cleanup, program_interrupt) condition;
152
153 dcl (addr, divide, fixed, index, min, mod, null, reverse, substr, unspec, verify) builtin;
154
155 dcl 1 query_info static aligned,
156 2 version fixed bin init (2),
157 2 yes_no bit (1) unal init ("1"b),
158 2 suppress_name bit (1) unal init ("0"b),
159 2 status fixed bin init (0),
160 2 query fixed bin init (0);
161
162 dcl answer char (4) varying;
163
164 dcl com_line char (cm1) aligned based (bufp);
165 dcl (dnp, enp) ptr;
166
167 dcl (ename, enameo) char (32),
168 (dirname, dirnameo) char (168);
169
170 dcl pad_count fixed bin;
171
172
173
174 lname = 0;
175 brief = "0"b;
176 prc = 152;
177
178 bufp = addr (buffer);
179
180
181
182 Edata_pi.changed = "0"b;
183
184 if ptr1 = null then do;
185 call hcs_$make_seg ("", "temp1_", "", 1010b, ptr1, code);
186 call hcs_$make_seg ("", "temp2_", "", 1010b, ptr2, code);
187 end;
188 else if active ^= 0 then do;
189 call command_query_ (addr (query_info), answer, me,
190 "Pending work in previous invocation will be lost if you proceed;^/do you wish to proceed?");
191 if answer ^= "yes" then go to return;
192 else go to truncate_temp;
193 end;
194 else do;
195 truncate_temp: call clean;
196 end;
197
198 active = active + 1;
199
200
201
202 on cleanup call clean;
203
204
205
206
207 call cu_$arg_ptr (1, np, lname, code);
208 if code ^= 0 then if code = error_table_$noarg then go to finput;
209 else do;
210 call com_err_ (code, me);
211 go to exit;
212 end;
213
214 if lname = 0 then go to finput;
215
216
217
218 call expand_pathname_ (arg, dirnameo, enameo, code);
219 if code ^= 0 then do;
220
221 call com_err_ (code, me, "^a", arg);
222 go to exit;
223 end;
224
225
226
227 call check_entryname_ (enameo, code);
228 if code ^= 0 then do;
229 call com_err_ (code, me, "^a", enameo);
230 goto exit;
231 end;
232
233 call initiate_file_ (dirnameo, enameo, RW_ACCESS, sptr, edata.csize1, code);
234
235
236
237 if sptr = null then do;
238 if code = error_table_$no_w_permission then do;
239 call initiate_file_ (dirnameo, enameo, R_ACCESS, sptr, edata.csize1, code);
240 if sptr ^= null then goto have_seg_ptr;
241 end;
242 if code = error_table_$noentry then do;
243 call ioa_ ("Segment not found.");
244 orig_ptr = null;
245 go to finput;
246 end;
247 else do;
248 dnp = addr (dirnameo);
249 enp = addr (enameo);
250 call COM_DE;
251 go to exit;
252 end;
253 end;
254
255 have_seg_ptr:
256 edata.csize1 = divide (edata.csize1, 9, 24, 0);
257 if edata.csize1 ^= 0 then if substr (sptr -> string, edata.csize1, 1) ^= nl
258 then call com_err_ (0, me, "Warning
259
260
261
262
263 edata.fptr, orig_ptr = sptr;
264 edata.tptr = ptr1;
265 edata.iflag = "0"b;
266 on program_interrupt call interrupt;
267 sw_pi = "1"b; note
268
269 pedit:
270 call SAVE;
271 call ioa_ ("Edit.");
272 next:
273
274
275
276
277
278
279
280 call iox_$get_line (iox_$user_input, bufp, prc, count, code);
281 cm1 = count - 1;
282 if cm1 = 0 then go to next;
283
284 call SAVE;
285 if substr (buffer, 1, 1) = "E" then go to callms;
286
287 i = verify (substr (buffer, 2, count - 1), " ");
288 if i = 0 then i = 152;
289
290 if substr (buffer, 1, 1) = "w" then do;
291 edct = i;
292 go to wsave;
293 end;
294
295 num_err = 0;
296
297 if cm1 = 1
298 then go to got_num_1;
299
300 n = 0;
301
302
303
304 num_err = num_err + 1;
305
306 num_loop: j = fixed (unspec (substr (buffer, i + 1, 1)), 9) - 110000b ;
307 if j<0 then go to got_num;
308 if j>9 then go to got_num;
309 n = 10 * n + j;
310 i = i + 1;
311 if i<count-1 then go to num_loop;
312 num_err = 0;
313 got_num: if n = 0 then
314 got_num_1: n = 1;
315
316 edct = i - 1 + verify (substr (buffer, i+1, count - i), " ");
317 cwd = substr (buffer, 1, 1);
318
319 if cwd = "i" then go to insert;
320 if cwd = "r" then go to retype;
321 if cwd = "l" then go to locate;
322 if cwd = "p" then go to print;
323 if cwd = "n" then go to nexlin;
324 if cwd = "-" then go to backup;
325 if cwd = "c" then go to change;
326 if cwd = "d" then go to dellin;
327 if cwd = "t" then go to top;
328 if cwd = "b" then go to bottom;
329 if cwd = "f" then go to find;
330 if cwd = "s" then go to change;
331 if cwd = "v" then go to veron;
332
333
334
335 if cwd = "k" then go to veroff;
336 if cwd = "." then do;
337 if cm1 = 1 then go to pinput;
338 go to request_err;
339 end;
340 if cwd = "=" then go to equals;
341 if cwd = "," then go to comment_init;
342
343 if count >= 3
344 then if substr (buffer, 1, 2) = "qf"
345 then go to q_force;
346
347 if cwd = "q" then go to quit;
348
349 if count >= 6
350 then if substr (buffer, 1, 5) = "merge"
351 then go to insert_file;
352
353 if count >= 5 then
354 if substr (buffer, 1, 4) = "move" then
355 go to move_;
356
357 if count >= 8
358 then if substr (buffer, 1, 7) = "upwrite"
359 then go to save_top;
360
361 if count >= 9
362 then if substr (buffer, 1, 8) = "updelete"
363 then go to delete_top_init;
364
365 call com_err_ (0, me, "Not a request: ^a", com_line);
366 reset_io:
367 call iox_$control (iox_$user_input, "resetread", null (), code);
368 go to next;
369 numeric_err:
370 call com_err_ (0, me, "Non-numeric characters in numeric argument: ^a", com_line);
371 go to reset_io;
372 request_err:
373 call com_err_ (0, me, "Text follows logical end of request, request ignored: ^a", com_line);
374 go to reset_io;
375
376
377
378
379 veron: if cm1 ^= 1 then go to request_err;
380 else do;
381 brief = "0"b;
382 go to next;
383 end;
384
385 veroff: if cm1 ^= 1 then go to request_err;
386 else do;
387 brief = "1"b;
388 go to next;
389 end;
390
391
392
393 finput: edata.fptr = ptr1; edata.tptr = ptr2;
394 call SAVE;
395 if ^sw_pi then do;
396 on program_interrupt call interrupt;
397 sw_pi = "1"b;
398 end;
399 pinput: call ioa_ ("Input.");
400 call INPUT;
401 go to pedit;
402
403
404
405 comment_init:
406 if cm1 ^= 1 then go to request_err;
407
408 comment: if edata.eof_ then go to eof;
409 if edata.lngth = 1 then go to cnoline;
410 if edata.lngth = 0 then go to cnoline;
411 call iox_$put_chars (iox_$user_output, addr (line), edata.lngth-1, code);
412 call iox_$get_line (iox_$user_input, bufp, prc, count, code);
413 if count = 2 then
414 if substr (buffer, 1, 1) = "." then go to pedit;
415 if count > 1 then do;
416 edata.changed = "1"b;
417 edata.isok = -1;
418 end;
419 substr (line, edata.lngth, count) = substr (buffer, 1, count);
420 edata.lngth = edata.lngth + count - 1;
421 cnoline: call PUT;
422 call GET;
423 go to comment;
424
425
426
427
428 equals: if cm1 ^= 1 then go to request_err;
429 if edata.curlino = -1 then do;
430 call GET_LINO;
431 GET_LINO: proc;
432 if edata.isok ^= -1 then trick_ptr = edata.fptr;
433 else trick_ptr = edata.tptr;
434 i = 1;
435 k = edata.indt;
436 do gotlino = 1 by 1 while (k ^= 0);
437 k = index (substr (trick_ptr -> string, i, edata.indt-i), nl);
438 i = i + k;
439 end;
440 if edata.indt = 0 then if edata.indf ^= 0 then gotlino = 1;
441 end GET_LINO;
442 edata.curlino = gotlino;
443 end;
444 else do;
445 gotlino = edata.curlino;
446 if gotlino = 0 then gotlino = 1;
447 end;
448 call ioa_ ("^d", gotlino);
449 go to next;
450
451
452
453
454 dellin: if num_err ^= 0 then go to numeric_err;
455 if edata.eof_ then go to eof;
456 if edata.lngth ^= 0 then do;
457 edata.changed = "1"b;
458 edata.isok = -1;
459 edata.lngth = 0;
460 end;
461 if n - 1 > 0 then do;
462 mg_lines = n-1;
463 mg_chars = edata.csize1 - edata.indf;
464 call GET_LINES;
465 if g_chars = 0 then g_chars = mg_chars;
466 if g_chars ^= 0 then do;
467 edata.changed = "1"b;
468 edata.isok = -1;
469 end;
470 if g_lines ^= mg_lines then do;
471 edata.indf = edata.csize1;
472 edata.eof_ = "1"b;
473 go to eof;
474 end;
475 else edata.indf = edata.indf + g_chars;
476 end;
477 go to next;
478
479
480
481 insert: call PUT;
482 retype:
483 if substr (buffer, 2, 1) = " " then skipblank = 1;else skipblank = 0;
484 edata.lngth = count - skipblank - 1;
485 if edata.lngth ^= 0 then
486 substr (line, 1, edata.lngth) = substr (buffer, skipblank + 2, edata.lngth);
487 edata.changed = "1"b;
488 edata.eof_ = "0"b;
489 edata.isok = -1;
490 go to next;
491
492
493
494
495 nexlin: printing = 0;go to NPSET;
496 print: printing = 1;
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515 NPSET:
516 if num_err ^= 0 then go to numeric_err;
517 if printing ^= 0 then do;
518 if n = 1 then go to NPFIN;
519 else do;
520 if edata.eof_ then go to eof;
521 n = n - 1;
522 call PRINT_CURLINE;
523 end;
524 end;
525
526 call PUT;
527 mg_lines = n - 1;
528 tnx = edata.csize1 - edata.indf;
529 g_chars = 0;
530 g_lines = 0;
531 NPLOOP:
532 mg_lines = mg_lines - g_lines;
533 if mg_lines = 0 then go to NPGET;
534 mg_chars = min (chunk, tnx);
535 if mg_chars = 0 then go to NPGET;
536
537 call GET_LINES;
538 if g_chars = 0 then g_chars = mg_chars;
539 if printing ^= 0 then
540 call iox_$put_chars (iox_$user_output, addr (substr (edata.fptr -> string, edata.indf+1, 1)), (g_chars), code);
541 call MOVE_CHARS;
542 tnx = tnx - g_chars;
543 go to NPLOOP;
544
545 NPGET: call GET;
546 NPFIN:
547 if edata.eof_ then go to eof;
548 else if printing ^= 0 then call PRINT_CURLINE;
549 else if ^brief then call PRINT_CURLINE;
550 go to next;
551
552
553
554
555 find: locating = 0; go to FLSET;
556 locate: locating = 1;
557
558
559
560
561
562
563
564
565
566
567 FLSET:
568 if count ^= 2 then do;
569 if substr (buffer, 2, 1) = " " then skipblank = 1; else skipblank = 0;
570 locend = count - 1 - skipblank;
571
572 substr (locstring, 2, locend - 1)
573 = substr (buffer, 2 + skipblank, locend - 1);
574 end;
575 else if locend = 1 then go to incmplt;
576
577 locp = addr (substr (locstring, 1 + locating, 1));
578 loclen = locend - locating;
579
580 call FIND_LOCATE;
581 if where_found = 0 then do;
582 call com_err_ (0, me, "Search failed.");
583 go to reset_io;
584 end;
585
586 if where_found = 1 then do;
587 call PUT;
588 if k ^= 0 then do;
589 g_chars = k;
590 edata.curlino = -1;
591 call MOVE_CHARS;
592 end;
593 end;
594 else do;
595 edata.curlino = -1;
596 if edata.isok ^= -1 then do;
597 edata.indf, edata.indt = k;
598 go to FLFIN;
599 end;
600 bkover = edata.indt - k;
601 if edata.fptr ^= orig_ptr then
602 if bkover + edata.lngth < edata.indf then
603 if bkover < edata.csize1 - edata.indf + k
604 then do;
605 call COPY_BACK;
606 go to FLFIN;
607 end;
608 call COPY;
609 call SWITCH;
610 g_chars = k;
611 call MOVE_CHARS;
612 end;
613 FLFIN:
614 call GET;
615 if ^brief then call PRINT_CURLINE;
616 go to next;
617
618
619
620
621 change:
622 located = "0"b;
623 if edct = cm1
624 then do;
625 incmplt: call com_err_ (0, me, "Incomplete request: ^a", com_line);
626 go to reset_io;
627 end;
628 break = substr (buffer, edct + 1, 1);
629 i = index (substr (buffer, edct+2, count-edct-2), break);
630 if i = 0 then go to incmplt;
631 j = index (substr (buffer, i+edct+2, count-edct-i-2), break);
632 if j = 0 then j = count-i-edct-1;
633 else if (edct + i + j + 2) ^= count
634 then go to request_err;
635
636 if edata.lngth = 0 then go to chnoline;
637 ch1: temp1 = "0"b;
638 m, ij, l = 1;
639
640 if i = 1 then do;
641 ij = j + edata.lngth -1;
642 if ij > 152 then do;
643 LONG_ERROR:
644 call com_err_ (0, me, "Change would result in too long a line. Max length is 152. Request ignored:^/ ^a",
645 com_line);
646 go to reset_io;
647 end;
648 temp1, located = "1"b;
649 if j ^= 1 then substr (tlin, 1, j-1) = substr (buffer, edct+i+2, j-1);
650 substr (tlin, j, edata.lngth) = substr (line, 1, edata.lngth);
651 if ^brief then do;
652 substr (olin, 1, 1) = rrs;
653 if j ^= 1 then substr (olin, 2, j-1) = substr (buffer, edct+i+2, j-1);
654 substr (olin, j+1, 1) = brs;
655 substr (olin, j+2, edata.lngth) = substr (line, 1, edata.lngth);
656 l = j + edata.lngth +1;
657 end;
658 end;
659 else do;
660 ch2: if edata.lngth = m then k = 0;
661 else k = index (substr (line, m, edata.lngth-m), substr (buffer, edct+2, i-1));
662 if k ^= 0 then do;
663 if (ij+k-2) > 152 then go to LONG_ERROR;
664 if k ^= 1 then substr (tlin, ij, k-1) = substr (line, m, k-1);
665 if j ^= 1 then substr (tlin, ij+k-1, j-1) = substr (buffer, edct+i+2, j-1);
666 if ^brief then do;
667 if k ^= 1 then substr (olin, l, k-1) = substr (line, m, k-1);
668 substr (olin, l+k-1, 1) = rrs;
669 if j ^= 1 then substr (olin, l+k, j-1) = substr (buffer, edct+i+2, j-1);
670 substr (olin, l+k+j-1, 1) = brs;
671 l = l + k + j;
672 end;
673 m = m + k + i - 2;
674 ij = ij + k + j - 2;
675 temp1, located = "1"b;
676 go to ch2;
677 end;
678 ii = ij + edata.lngth - m;
679 if ii > 152 then go to LONG_ERROR;
680 if temp1 then do;
681 if edata.lngth-m+1 ^= 0 then
682 substr (tlin, ij, edata.lngth-m+1) = substr (line, m, edata.lngth-m+1);
683 ij = ii;
684 if ^brief then do;
685 if edata.lngth-m+1 ^= 0 then
686 substr (olin, l, edata.lngth-m+1) = substr (line, m, edata.lngth-m+1);
687 l = l + edata.lngth - m;
688 end;
689 end;
690 end;
691 if temp1 then do;
692 substr (line, 1, ij) = substr (tlin, 1, ij);
693 edata.lngth = ij;
694 edata.changed = "1"b;
695 edata.isok = -1;
696 if ^brief then call iox_$put_chars (iox_$user_output, addr (olin), l, code);
697 end;
698 chnoline: if n = 1 then do;
699 if ^located then do;
700 call com_err_ (0, me, "Substitution failed.");
701 go to reset_io;
702 end;
703 go to next;
704 end;
705 n = n-1;
706 call PUT;
707
708 if ^temp1 then do;
709
710 CGLOOP:
711 if n > 1 then
712 if edata.csize1 - edata.indf > 0 then do;
713 cgscanlen = min (edata.csize1 - edata.indf, chunk);
714 xxxx = index (substr (edata.fptr -> string, edata.indf + 1, cgscanlen), substr (buffer, edct +2, i -1));
715 if xxxx ^= 0 then mg_chars = xxxx;
716 else mg_chars = cgscanlen;
717 mg_lines = n - 1;
718
719 call GET_LINES;
720 if g_chars = 0 then
721 if xxxx ^= 0 then
722 go to CGGET;
723 call MOVE_CHARS;
724
725 n = n - g_lines;
726 if xxxx = 0 then go to CGLOOP;
727 end;
728 end;
729 CGGET:
730 call GET;
731 if edata.eof_ then go to eof;
732 go to ch1;
733
734
735
736
737 quit:
738 if cm1 ^= 1 then go to request_err;
739
740 if edata.changed then do;
741 call command_query_ (addr (query_info), answer, me,
742 "Changes to text since last ""w"" request will be lost if you quit;^/do you wish to quit?");
743 if answer ^= "yes" then go to pedit;
744 end;
745
746 q_force: if cm1 > 2 then go to request_err;
747 call clean;
748 exit: active = 0;
749 go to return;
750
751
752
753
754 top:
755 if cm1 ^= 1 then go to request_err;
756
757 if edata.isok >= 0 then do;
758 edata.indt, edata.indf = 0;
759 go to TSET;
760 end;
761 if edata.indf >= edata.indt + edata.lngth
762 then if edata.indt < edata.csize1 - edata.indt
763 then if edata.fptr ^= orig_ptr
764 then do;
765 bkover = edata.indt;
766 call COPY_BACK;
767 TSET: edata.lngth = 0;
768 edata.eof_ = "0"b;
769 edata.curlino = 1;
770 go to next;
771 end;
772
773 call COPY;
774 call SWITCH;
775 edata.curlino = 1;
776 go to next;
777
778
779
780 bottom:
781 if cm1 ^= 1 then go to request_err;
782 edata.curlino = -1;
783
784 call COPY;
785 edata.lngth = 0;
786 go to pinput;
787
788
789
790
791
792 backup:
793 if num_err ^= 0 then go to numeric_err;
794
795 edata.eof_ = "0"b;
796 scanlen = edata.indt - 1;
797
798 if edata.curlino ^= -1 then do;
799 if edata.curlino <= n then do;
800 bklen = 0;
801 scanlen = -1;
802 nbk = edata.curlino - 1;
803 go to BKDO;
804 end;
805 end;
806
807 if edata.isok ^= -1
808 then trick_ptr = edata.fptr;
809 else trick_ptr = edata.tptr;
810
811 do nbk = 0 to n - 1;
812 if scanlen <= 0 then do;
813 bklen = scanlen + 1;
814 if bklen = 0 then go to BKDO;
815 end;
816 else do;
817 bklen = index (reverse (substr
818 (trick_ptr -> string, 1, scanlen)), nl);
819 if bklen = 0 then bklen = scanlen + 1;
820 end;
821 scanlen = scanlen - bklen;
822 end;
823 BKDO: note
824 g_chars = scanlen + 1;
825 bkover = edata.indt - g_chars;
826
827 if edata.isok >= 0 then do;
828 edata.indt, edata.indf = g_chars;
829 go to BKFIN;
830 end;
831
832 if edata.fptr ^= orig_ptr
833 then if edata.indf >= bkover + edata.lngth
834 then if edata.csize1 - edata.indf + edata.indt - bkover > bkover
835 then do;
836 call COPY_BACK;
837 go to BKFIN;
838 end;
839
840 call COPY;
841 call SWITCH;
842 call MOVE_CHARS;
843 BKFIN:
844 if bklen = 0 then edata.lngth = 0;
845 else call GET;
846 if Edata_pi.curlino ^= -1 then do;
847 edata.curlino = Edata_pi.curlino - nbk;
848 end;
849 if ^brief then call PRINT_CURLINE;
850 go to next;
851
852
853
854
855
856 move_:
857
858 if count = 5 then go to incmplt;
859
860 i = 4;
861 call GET_NUM;
862 M = N;
863
864 i = i + j;
865 if i = count - 1 then N = 1;
866 else do;
867 call GET_NUM;
868 if j ^= count - i - 1 then go to request_err;
869 end;
870
871
872
873
874 if edata.curlino = -1 then do;
875 call GET_LINO;
876 edata.curlino = gotlino;
877 end;
878
879 if M <= edata.curlino then
880 if M+N > edata.curlino then do;
881 call com_err_ (0b, me, "Text overlaps current line.");
882 go to reset_io;
883 end;
884
885 Edata_pi.isok = -1;
886 call CHECK_ORIG;
887
888 if edata.curlino > M then do;
889
890
891
892
893
894 i = GET_BLOCK (edata.tptr, 0, edata.indt, M-1);
895 j = GET_BLOCK (edata.tptr, i, edata.indt - i, N);
896 k = edata.indt - i - j;
897
898 substr (edata.tptr -> string, edata.indt+edata.lngth+1, edata.csize1- edata.indf)
899 = substr (edata.fptr -> string, edata.indf+1, edata.csize1-edata.indf);
900 move_data.x1 = edata.indf;
901 move_data.x2 = edata.indt + edata.lngth;
902 move_data.xlen = edata.csize1 - edata.indf;
903 move_data.y1, move_data.y2, move_data.ylen = 0; note
904 did_move = "1"b;
905
906
907
908 if edata.isok < 0 then
909 substr (edata.fptr -> string, 1, i) = substr (edata.tptr -> string, 1, i);
910 substr (edata.fptr -> string, i+1, k) = substr (edata.tptr -> string, i+j+1, k);
911 substr (edata.fptr -> string, i+k+1, edata.lngth) = substr (line, 1, edata.lngth);
912 substr (edata.fptr -> string, edata.lngth+i+k+1, j) = substr (edata.tptr -> string, i+1, j);
913
914 edata.indt, edata.indf = i+j+k+edata.lngth;
915 edata.csize1 = edata.indf + move_data.xlen;
916 edata.fptr = Edata_pi.tptr;
917 edata.tptr = Edata_pi.fptr;
918 end;
919 else do;
920
921
922
923
924
925
926
927
928
929
930
931
932
933 note
934 note
935
936
937
938 i = GET_BLOCK (edata.fptr, edata.indf, edata.csize1-edata.indf, M-edata.curlino-min (1, edata.lngth));
939 if i < 0 then do;
940 nonesuch:
941 call com_err_ (0, me, "Specified lines do not exist.");
942 go to reset_io;
943 end;
944 if edata.csize1 - edata.indf - i <= 0 then go to nonesuch;
945 j = GET_BLOCK (edata.fptr, edata.indf+i, edata.csize1-edata.indf-i, N);
946 if j < 0 then do;
947 j = edata.csize1 - edata.indf - i;
948 edata.curlino = -1;
949 end;
950 else edata.curlino = edata.curlino + N;
951 substr (edata.tptr -> string, edata.indt+1, edata.lngth)
952 = substr (line, 1, edata.lngth);
953 edata.indt = edata.indt + edata.lngth;
954
955 move_data.y1 = edata.indf + i;
956 move_data.y2 = edata.indt;
957 move_data.ylen = j;
958
959 move_data.x2 = edata.indt + j;
960 k = edata.csize1 - edata.indf - i - j;
961 if i < 2 * k then do;
962
963 move_data.x1 = edata.indf;
964 move_data.xlen = i;
965 edata.indf = edata.indf + j;
966 i = 0;
967 end;
968
969 else do;
970 move_data.x1 = edata.indf + i + j;
971 move_data.xlen = k;
972 edata.csize1 = edata.csize1 - j;
973 end;
974
975
976 substr (edata.tptr -> string, move_data.x2 + 1, move_data.xlen)
977 = substr (edata.fptr -> string, move_data.x1 + 1, move_data.xlen);
978 substr (edata.tptr -> string, move_data.y2 + 1, move_data.ylen)
979 = substr (edata.fptr -> string, move_data.y1 + 1, move_data.ylen);
980 did_move = "1"b;
981
982
983
984 substr (edata.fptr -> string, edata.indf + i + 1, move_data.xlen)
985 = substr (edata.tptr -> string, move_data.x2 + 1, move_data.xlen);
986
987 edata.indt = move_data.y2 + move_data.ylen;
988
989 end;
990
991
992
993 if edata.curlino ^= -1 then
994 if edata.lngth ^= 0 then
995 edata.curlino = edata.curlino + 1;
996 edata.isok = -1;
997 edata.lngth = 0;
998 edata.changed = "1"b;
999 go to next;
1000
1001
1002
1003
1004
1005 wsave:
1006 saveflag = 0;
1007 go to scan_path;
1008
1009
1010
1011 delete_top_init:
1012 if cm1 ^= 8
1013 then go to request_err;
1014
1015 delete_top:
1016 edata.indt = 0;
1017 edata.changed = "1"b;
1018 edata.isok = -1;
1019 edata.curlino = 1;
1020 go to next;
1021
1022
1023
1024 save_top:
1025 saveflag = 2;
1026 edct = 7;
1027 go to long_scan;
1028
1029
1030
1031 insert_file:
1032 saveflag = 3;
1033 edct = 5;
1034 go to long_scan;
1035
1036 ret_insert:
1037 call initiate_file_ (dirname, ename, RW_ACCESS, sptr, merge_bc, code);
1038 if sptr = null
1039 then do;
1040 call initiate_file_ (dirname, ename, R_ACCESS, sptr, merge_bc, code);
1041 if sptr = null then go to new_error;
1042 end;
1043
1044 ret_insert_default:
1045 segsize = divide (merge_bc+ 8, 9, 21, 0);
1046 call PUT;
1047 edata.lngth = 0;
1048 if segsize ^= 0 then do;
1049 substr (edata.tptr -> string, edata.indt + 1, segsize)
1050 = substr (sptr -> string, 1, segsize);
1051 edata.indt = edata.indt + segsize;
1052 edata.changed = "1"b;
1053 edata.isok = -1;
1054 edata.curlino = -1;
1055 end;
1056 go to next;
1057
1058
1059
1060 long_scan:
1061 edct = edct - 1 + verify (substr (buffer, edct + 1, count - edct), " ");
1062
1063
1064
1065
1066
1067
1068 scan_path:
1069 lprinam = cm1 - edct;
1070
1071 if (lname + lprinam) = 0 then do;
1072 call com_err_ (0, me, "No segment name given in ^a request.", com_line);
1073 go to reset_io;
1074 end;
1075 if lprinam ^= 0 then do;
1076 np = addr (substr (buffer, edct + 1, 1));
1077 call expand_pathname_ (substr (buffer, edct+1, lprinam), dirname, ename, code);
1078 if code ^= 0 then do;
1079 badname: call com_err_ (code, me, "^a", xarg);
1080 go to reset_io;
1081 end;
1082 call check_entryname_ (ename, code);
1083 if code ^= 0 then go to badname;
1084 if saveflag = 3 then go to ret_insert;
1085 else do;
1086 call hcs_$make_seg (dirname, ename, "", 01010b, sptr, code);
1087 if sptr = null then go to new_error;
1088 end;
1089 end;
1090 else do;
1091 sptr = orig_ptr;
1092 if sptr = null then do;
1093 if saveflag = 3 then do;
1094 call com_err_ (0, me, "No default segment for merge request.");
1095 go to reset_io;
1096 end;
1097 else do;
1098 call hcs_$make_seg (dirnameo, enameo, "", 01010b, sptr, code);
1099 if sptr = null then go to error;
1100 end;
1101 end;
1102 else if saveflag = 3 then do;
1103 call hcs_$status_mins (sptr, type, merge_bc, code);
1104 if code ^= 0 then go to error;
1105 else go to ret_insert_default;
1106 end;
1107 end;
1108
1109 edata.curlino = -1;
1110
1111 if saveflag = 0 then do;
1112 i = edata.indt;
1113 call COPY; note
1114 end;
1115 else do;
1116 i = 0;
1117 if sptr = edata.fptr then
1118 call CHECK_ORIG;
1119 end;
1120
1121 if edata.indt > i then substr (sptr -> string, i + 1, edata.indt - i) =
1122 substr (edata.tptr -> string, i + 1, edata.indt - i);
1123
1124 if i > 0 then substr (sptr -> string, 1, i) =
1125 substr (edata.tptr -> string, 1, i);
1126
1127 call terminate_file_ (sptr, edata.indt*9, TERM_FILE_TRUNC_BC, code);
1128 if code ^= 0 then go to test_error;
1129
1130 if saveflag = 2 then go to delete_top;
1131 edata.changed = "0"b;
1132 Edata_pi.changed = "0"b;
1133 if edata.isok >= 0 then edata.isok = edata.indt;
1134
1135
1136 go to next;
1137
1138
1139
1140 callms:
1141 substr (buffer, 1, 1) = " ";
1142 call cu_$cp (addr (buffer), count, code);
1143 if active = 0
1144 then call com_err_ (0, me, "Working buffers have been destroyed.");
1145 active = active + 1;
1146 go to pedit;
1147
1148
1149
1150 eof: call ioa_ ("EOF");
1151 go to next;
1152
1153
1154
1155 test_error: if lprinam = 0 then do;
1156 error: dnp = addr (dirnameo);
1157 enp = addr (enameo);
1158 end;
1159 else do;
1160 new_error: dnp = addr (dirname);
1161 enp = addr (ename);
1162 end;
1163 call COM_DE;
1164 go to reset_io;
1165
1166
1167
1168 return: return;
1169
1170
1171
1172
1173
1174
1175 FIND_LOCATE: proc;
1176
1177 dcl lptr ptr;
1178 dcl indl fixed bin (21);
1179 dcl lscan fixed bin (21);
1180 lptr = edata.fptr;
1181 indl = edata.indf;
1182 lscan = edata.csize1 - edata.indf;
1183 where_found = 1;
1184 FLLOOP:
1185 if locating = 0 then do;
1186 if substr (lptr -> string, indl + 1, loclen - 1)
1187 = substr (locp -> string, 2, loclen - 1) then do;
1188 i = 0;
1189 go to FLGOT;
1190 end;
1191 end;
1192 i = index (substr (lptr -> string, indl + 1, lscan), substr (locp -> string, 1, loclen));
1193 if i = 0 then do;
1194 if where_found = 1 then do;
1195 where_found = -1;
1196
1197 if edata.isok ^= -1
1198 then lptr = edata.fptr;
1199 else lptr = edata.tptr;
1200
1201 indl = 0;
1202 lscan = edata.indt;
1203 go to FLLOOP;
1204 end;
1205 else do;
1206 where_found = 0;
1207 return;
1208 end;
1209 end;
1210 FLGOT:
1211 if locating = 1 then do;
1212 k = index (reverse (substr (lptr -> string, indl + 1, i)), nl);
1213 if k ^= 0 then k = i - k + 1;
1214 end;
1215 else do;
1216 k = i;
1217 end;
1218
1219 end FIND_LOCATE;
1220
1221
1222
1223 CHECK_ORIG: proc;
1224
1225 if edata.fptr = orig_ptr
1226 then do;
1227 edata.fptr = ptr2; note
1228 substr (edata.fptr -> string, 1, edata.csize1)
1229 = substr (orig_ptr -> string, 1, edata.csize1);
1230 Edata_pi.fptr = ptr2;
1231 end;
1232
1233 end CHECK_ORIG;
1234
1235 GET_BLOCK: proc (xp, xo, xc, xl) returns (fixed bin (21));
1236
1237 dcl xp ptr;
1238 dcl xo fixed bin (21);
1239 dcl xc fixed bin (21);
1240 dcl xl fixed bin (21);
1241 dcl xx fixed bin (21);
1242
1243 dcl (i, j, k) fixed bin (21);
1244
1245 if xl = 0 then return (0);
1246
1247 xx = 0;
1248
1249 i = 0;
1250
1251 do while (i < xl & xc-xx>0);
1252 j = index (substr (xp -> string, xo+xx+1, xc-xx), nl);
1253
1254 if j = 0 then xx = xc;
1255 else xx = xx + j;
1256 i = i + 1;
1257
1258 end;
1259
1260 if i < xl then return (-1);
1261 else return (xx);
1262
1263 end GET_BLOCK;
1264
1265 GET_NUM: proc;
1266 i = i + verify (substr (buffer, i + 1, count - i), " ") -1;
1267 j = index (substr (buffer, i+1, count-i), " ") -1;
1268 if j < 0 then j = count - i - 1;
1269 N = cv_dec_check_ (substr (buffer, i+1, j), code);
1270 if code ^= 0 then go to numeric_err;
1271 if N < 0 then go to numeric_err;
1272 if N = 0 then go to nonesuch;
1273 end GET_NUM;
1274
1275
1276
1277 clean: proc;
1278
1279
1280
1281
1282
1283
1284
1285 dcl code fixed bin (35);
1286 call hcs_$truncate_seg (ptr1, 0, code);
1287 call hcs_$truncate_seg (ptr2, 0, code);
1288 if sptr ^= null then call terminate_file_ (sptr, 0, TERM_FILE_TERM, code);
1289 active = 0;
1290
1291 end clean;
1292
1293
1294 interrupt: proc;
1295
1296
1297 Note
1298
1299
1300
1301
1302
1303
1304
1305
1306 note
1307
1308
1309
1310
1311 if pi_allowed then do;
1312 edata = Edata_pi;
1313 if edata.lngth ^= 0 then
1314 substr (line, 1, edata.lngth) = substr (Line_pi, 1, edata.lngth);
1315 if did_move then do;
1316 if move_data.xlen > 0 then
1317 substr (edata.fptr -> string, move_data.x1 +1, move_data.xlen)
1318 = substr (edata.tptr -> string, move_data.x2 +1, move_data.xlen);
1319
1320 if move_data.ylen > 0 then
1321 substr (edata.fptr -> string, move_data.y1 +1, move_data.ylen)
1322 = substr (edata.tptr -> string, move_data.y2 +1, move_data.ylen);
1323 did_move = ""b;
1324 end;
1325 end;
1326
1327 go to int_lab;
1328 end interrupt;
1329
1330 COM_DE: proc;
1331
1332 call com_err_ (code, me, "^a>^a", dnp -> b168cu, enp -> b32cu);
1333
1334 end COM_DE;
1335
1336
1337
1338
1339
1340 COPY: proc;
1341
1342 call PUT;
1343 edata.lngth = 0;
1344 if ^edata.iflag then do;
1345 ij = edata.csize1 - edata.indf;
1346 if ij > 0 then do;
1347 if edata.isok >= 0 then do;
1348 mc_chars = edata.csize1 - edata.isok;
1349 edata.isok = edata.isok + mc_chars;
1350 end;
1351 else mc_chars = ij;
1352 mc_skip = ij - mc_chars;
1353
1354 if mc_chars > 0 then
1355 substr (edata.tptr -> string, edata.indt + mc_skip + 1, mc_chars)
1356 = substr (edata.fptr -> string, edata.indf + mc_skip + 1, mc_chars);
1357
1358 edata.indt = edata.indt + ij;
1359 edata.indf = edata.indf + ij;
1360 end;
1361 end;
1362
1363 end COPY;
1364
1365 COPY_BACK: proc;
1366
1367 if edata.lngth ^= 0 then do;
1368 edata.indf = edata.indf - edata.lngth;
1369 substr (edata.fptr -> string, edata.indf + 1, edata.lngth)
1370 = substr (line, 1, edata.lngth);
1371 end;
1372
1373 if bkover > 0 then do;
1374 edata.indf = edata.indf - bkover;
1375 edata.indt = edata.indt - bkover;
1376 substr (edata.fptr -> string, edata.indf + 1, bkover)
1377 = substr (edata.tptr -> string, edata.indt + 1, bkover);
1378 end;
1379
1380 end COPY_BACK;
1381
1382
1383 SWITCH: proc;
1384 if edata.tptr = ptr1 then
1385 do;
1386 edata.tptr = ptr2;
1387 edata.fptr = ptr1;
1388 end; else
1389 do;
1390 edata.tptr = ptr1;
1391 edata.fptr = ptr2;
1392 end;
1393 edata.csize1 = edata.indt;
1394 edata.isok, edata.lngth, edata.indt, edata.indf = 0;
1395 edata.iflag, edata.eof_ = "0"b;
1396 return;
1397 end SWITCH;
1398
1399 PRINT_CURLINE: proc;
1400
1401 if edata.lngth = 0 then call ioa_ ("No line.");
1402 else call iox_$put_chars (iox_$user_output, addr (line), edata.lngth, code);
1403
1404 end PRINT_CURLINE;
1405
1406
1407 GET_LINES: proc;
1408 g_chars = 0;
1409 g_lines = 0;
1410 GLOOP:
1411 nxlen = index (substr
1412 (edata.fptr -> string, edata.indf + 1 + g_chars, mg_chars - g_chars), nl);
1413 if nxlen ^= 0 then do;
1414 g_chars = g_chars + nxlen;
1415 g_lines = g_lines + 1;
1416 if g_lines < mg_lines then go to GLOOP;
1417 end;
1418
1419 end GET_LINES;
1420
1421 MOVE_CHARS: proc;
1422
1423 if g_chars ^= 0 then do;
1424 if edata.isok >= 0 then do;
1425 mc_chars = edata.indf + g_chars - edata.isok;
1426 if mc_chars < 0 then mc_chars = 0;
1427 else edata.isok = edata.isok + mc_chars;
1428 end;
1429 else mc_chars = g_chars;
1430
1431 mc_skip = g_chars - mc_chars;
1432
1433 if mc_chars >0 then
1434 substr (edata.tptr -> string, edata.indt + mc_skip + 1, mc_chars)
1435 = substr (edata.fptr -> string, edata.indf + mc_skip + 1, mc_chars);
1436 edata.indt = edata.indt + g_chars;
1437 edata.indf = edata.indf + g_chars;
1438 end;
1439
1440 if edata.curlino ^= -1 then do;
1441 edata.curlino = edata.curlino + g_lines;
1442 end;
1443
1444 end MOVE_CHARS;
1445
1446 INPUT: proc;
1447
1448 if ^waketable_is_set then do;
1449 unspec (swt) = ""b;
1450 swt.version = swt_info_version_1;
1451 swt.new_table.wake_map (46) = "1"b;
1452 call iox_$control (iox_$user_io, "set_wakeup_table", addr (swt), code);
1453 waketable_is_set = "1"b;
1454 end;
1455 call iox_$modes (iox_$user_io, "wake_tbl", "", (0));
1456 input: call iox_$get_line (iox_$user_input, bufp, prc, count, code);
1457 if count = 2 then
1458 if substr (buffer, 1, 1) = "." then do;
1459 call iox_$modes (iox_$user_io, "^wake_tbl", "", code);
1460 return;
1461 end;
1462 call PUT;
1463 edata.changed = "1"b;
1464 edata.isok = -1;
1465 edata.eof_ = "0"b;
1466 edata.lngth = count;
1467 substr (line, 1, edata.lngth) = substr (buffer, 1, edata.lngth);
1468 go to input;
1469
1470 end INPUT;
1471
1472
1473 PUT: proc;
1474
1475 if edata.lngth ^= 0 then do;
1476 if edata.curlino ^= -1 then do;
1477 if index (substr (line, 1, edata.lngth), nl) ^= edata.lngth
1478 then edata.curlino = -1;
1479 else edata.curlino = edata.curlino + 1;
1480 end;
1481 if edata.indt >= edata.isok then do;
1482 substr (edata.tptr -> string, edata.indt+1, edata.lngth)
1483 = substr (line, 1, edata.lngth);
1484 end;
1485 edata.indt = edata.indt + edata.lngth;
1486 if edata.isok >= 0 then
1487 if edata.isok < edata.indt then
1488 edata.isok = edata.indt;
1489 end;
1490 return;
1491 end PUT;
1492
1493 GET: proc;
1494
1495 scanlen = edata.csize1 - edata.indf;
1496 if scanlen = 0 then do;
1497 edata.eof_ = "1"b;
1498 edata.lngth = 0;
1499 return;
1500 end;
1501 else if scanlen > 152 then scanlen = 152;
1502
1503 edata.eof_ = "0"b;
1504
1505 edata.lngth = index (substr (edata.fptr -> string, edata.indf + 1, scanlen), nl);
1506
1507 if edata.lngth = 0 then do;
1508 edata.lngth = min (151, scanlen);
1509 if scanlen = 152 then
1510 call com_err_ (0, me, error_message);
1511 end;
1512
1513 substr (line, 1, edata.lngth) = substr (edata.fptr -> string, edata.indf + 1, edata.lngth);
1514 edata.indf = edata.indf + edata.lngth;
1515
1516 end GET;
1517
1518
1519
1520
1521 SAVE: proc;
1522 pi_allowed = ""b;
1523
1524 Edata_pi = edata;
1525 substr (Line_pi, 1, edata.lngth) = substr (line, 1, edata.lngth);
1526 did_move = ""b;
1527
1528
1529
1530 pi_allowed = "1"b;
1531
1532 end SAVE;
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613 end edm;