Repository navigation
Expand file tree
/
Copy pathET.Mod
More file actions
1539 lines (1413 loc) · 52.1 KB
/
Copy pathET.Mod
File metadata and controls
1539 lines (1413 loc) · 52.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* OBERON System 3, Release 2.3.
Copyright 1999 ETH Zürich Institute for Computer Systems,
ETH Center, CH-8092 Zürich. e-mail: oberon@inf.ethz.ch.
This module may be used under the conditions of the general Oberon
System 3 license contract. The full text can be downloaded from
"ftp://ftp.inf.ethz.ch/pub/software/Oberon/System3/license.txt;A"
Under the license terms stated it is in particular (a) prohibited to modify
the interface of this module in any way that disagrees with the style
or content of the system and (b) requested to provide all conversions
of the source code to another platform with the name OBERON. *)
MODULE ET; (** portable *) (* uh, Wed, 30-Jun-1993 *)
IMPORT Display, Texts, TextFrames, Viewers, Files, Input, MenuViewers, Oberon, Objects, Fonts;
CONST
AsciiTemp = "ET.XXX.Tmp"; (* temporary used file *)
ErrorsText = "OberonErrors.Text"; (* text for conversion error number to error message *)
PopupText = "ET.Popup.Menu"; (* commands for standard popup menus *)
LogFile = "ET.Name.Log"; (* register names of stored files *)
UserMenu = "System.Close System.Copy System.Grow ET.Move ET.Search ET.Replace ET.Store";
SysMenu = "System.Close System.Copy System.Grow ET.Store";
LogMenu = "ET.Clear ET.Locate ET.Error ET.Search ET.Store";
UserAscii = "System.Close System.Copy System.Grow ET.Move ET.Search ET.Replace ET.StoreAscii";
SysAscii = "System.Close System.Copy System.Grow ET.StoreAscii";
Err = -1; (* scanner *)
CR = 0DX; TAB = 09X; SPACE = " "; LF = 0AX; DEL = 07FX; Quote = 22X;
LtArrow = 0C4X; RtArrow = 0C3X;
ML = 2; MM = 1; MR = 0;
Fnt = 0; Colr = 1; Voff = 2;
MinSplitHeight = 40; MaxPatLen = 128; BufLen = 64;
FG = Display.FG;
TYPE
Frame = Display.Frame;
Object = Objects.Object;
ObjMsg = Objects.ObjMsg;
UpdateMsg = Texts.UpdateMsg;
SelectMsg = Oberon.SelectMsg;
Handler = Objects.Handler;
FocMsg = RECORD (Display.FrameMsg)
V: Viewers.Viewer;
END;
BackRdr = RECORD
text: Texts.Text;
buf: ARRAY BufLen OF CHAR;
begPos: LONGINT;
last, next: INTEGER;
beg: BOOLEAN
END;
MenuStr = ARRAY 255 OF CHAR;
VAR
tW, WL: Texts.Writer;
popup: Texts.Text; (* name of popup text *)
para: Texts.Text; (* parameter text for Call *)
log: RECORD f: Files.File; r: Files.Rider END; (* for names of stored texts *)
sPat: ARRAY MaxPatLen OF CHAR; (* search pattern [read only] *)
sDv: ARRAY MaxPatLen + 1 OF INTEGER; (* displacement vector for search pattern *)
sPatLen: INTEGER; (* number of valid characters in sPat [read only] *)
rBuf: Texts.Buffer; (* replace buffer [read only] *)
lTime: LONGINT; (* most recent time for sPat and/or rBuf *)
inFnt: Fonts.Font; (* input font *)
inColor: SHORTINT; (* input color *)
menuAvail: BOOLEAN; (* true if modul Menu is available *)
filter: BOOLEAN; (* filter compiler warnings *)
mStr: ARRAY 6 OF MenuStr; (* menu strings: 0=user / 1=system / 2=log / 3=userascii / 4=systemascii *)
sX, sY: INTEGER; (* saved coordinates for new viewer [used in Marker and ExchangeMenu] *)
ii: INTEGER;
PROCEDURE Min(i, j: LONGINT): LONGINT;
BEGIN
IF i < j THEN RETURN i ELSE RETURN j END
END Min;
PROCEDURE Max(i, j: LONGINT): LONGINT;
BEGIN
IF i > j THEN RETURN i ELSE RETURN j END
END Max;
PROCEDURE OpenScanner(VAR S: Texts.Scanner; text: Texts.Text; pos: LONGINT);
BEGIN
S.line := 0;
IF text = NIL THEN S.class := Err
ELSE Texts.OpenReader(S, text, pos); Texts.Read(S, S.nextCh); S.class := Texts.Inval
END
END OpenScanner;
PROCEDURE ScanName(DX: INTEGER; VAR X, Y: INTEGER; VAR S: Texts.Scanner);
VAR text: Texts.Text; beg, end, time: LONGINT;
BEGIN
IF DX = Oberon.SystemTrack(DX) THEN Oberon.AllocateSystemViewer(DX, X, Y)
ELSE Oberon.AllocateUserViewer(DX, X, Y)
END;
OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); IF S.class = Err THEN RETURN END; (* ### *)
Texts.Scan(S);
IF (S.class = Texts.Char) & (S.c = "^") OR (S.line > 0) THEN (* check for selection *)
text := NIL; time := 0; Oberon.GetSelection(text, beg, end, time);
IF (text = NIL) OR (time <= 0) THEN S.class := Texts.Inval; RETURN END; (* ### *)
OpenScanner(S, text, beg); Texts.Scan(S)
END;
IF S.class = Texts.Int THEN (* option y coordinate *)
IF (Display.Bottom + Viewers.minH <= S.i) & (S.i <= Display.Height) THEN X := DX; Y := SHORT(S.i) END;
Texts.Scan(S)
END
END ScanName;
PROCEDURE ViewerName(V : Viewers.Viewer; VAR S: Texts.Scanner);
(* return first name of viewer text *)
BEGIN
S.class := Texts.Inval;
IF (V IS MenuViewers.Viewer) & (V.dsc IS TextFrames.Frame) THEN
OpenScanner(S, V.dsc(TextFrames.Frame).text, 0); Texts.Scan(S)
END
END ViewerName;
PROCEDURE ScanPara(VAR S: Texts.Scanner);
VAR text: Texts.Text; beg, end, time: LONGINT;
BEGIN
OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); IF S.class = Err THEN RETURN END; (* ### *)
Texts.Scan(S);
IF (S.class = Texts.Char) & (S.c = "^") OR (S.line > 0) THEN (* check for selection *)
text := NIL; time := 0; Oberon.GetSelection(text, beg, end, time);
IF (text = NIL) OR (time <= 0) THEN S.class := Texts.Inval; RETURN END; (* ### *)
OpenScanner(S, text, beg); Texts.Scan(S)
END
END ScanPara;
PROCEDURE ScanQuote(VAR S: Texts.Scanner; VAR s: ARRAY OF CHAR);
VAR i: INTEGER;
BEGIN
i := 0;
WHILE (S.nextCh # Quote) & (S.nextCh # CR) & ~ S.eot DO Texts.Read(S, S.nextCh) END;
IF S.nextCh = Quote THEN
i := 0; Texts.Read(S, S.nextCh);
WHILE (S.nextCh # Quote) & (S.nextCh # CR) & ~ S.eot DO
IF i < LEN(s) THEN s[i] := S.nextCh; INC(i) END;
Texts.Read(S, S.nextCh)
END;
IF S.nextCh = Quote THEN Texts.Read(S, S.nextCh) END
END;
IF i < LEN(s) THEN s[i] := 0X ELSE s[LEN(s)-1] := 0X END
END ScanQuote;
PROCEDURE FocusViewer(): Viewers.Viewer;
VAR M: FocMsg;
BEGIN
M.V := NIL; M.F := NIL; Display.Broadcast(M);
IF M.V = NIL THEN M.V := Oberon.MarkedViewer() END;
RETURN M.V
END FocusViewer;
PROCEDURE SetFocus(V: Viewers.Viewer);
BEGIN Oberon.Defocus
END SetFocus;
PROCEDURE Defocus(tF: TextFrames.Frame);
BEGIN Oberon.Defocus
END Defocus;
PROCEDURE GetSelData(tF: TextFrames.Frame; VAR text: Texts.Text; VAR beg, end, time: LONGINT);
VAR M: SelectMsg; (* gets correct selection data of textframe tF *)
BEGIN
M.time := -1; M.id := Display.get; TextFrames.GetSelection(tF, M);
text := M.text; beg := M.beg; end := M.end; time := M.time
END GetSelData;
PROCEDURE GetSelFrame(VAR F: TextFrames.Frame);
VAR M: Oberon.SelectMsg;
BEGIN
M.id := Oberon.get; M.F := NIL;
M.time := -1; M.sel := NIL; M.text := NIL;
Display.Broadcast(M);
IF (M.time >= 0) & (M.text # NIL) & (M.sel # NIL) & (M.sel IS TextFrames.Frame) THEN
F := M.sel(TextFrames.Frame)
ELSE F := NIL
END
END GetSelFrame;
PROCEDURE ReaderFnt(VAR R: Texts.Reader): Fonts.Font;
BEGIN RETURN R.lib(Fonts.Font)
END ReaderFnt;
PROCEDURE AdjustFont(VAR W: Texts.Writer; VAR R: Texts.Reader);
BEGIN
IF W.lib # R.lib THEN Texts.SetFont(tW, R.lib) END
END AdjustFont;
PROCEDURE SetDefFont(VAR W: Texts.Writer);
BEGIN
IF W.lib # Fonts.Default THEN Texts.SetFont(W, Fonts.Default) END
END SetDefFont;
(*-v2-
PROCEDURE FocusViewer(): Viewers.Viewer;
BEGIN
RETURN Oberon.FocusViewer
END FocusViewer;
PROCEDURE SetFocus(V: Viewers.Viewer);
BEGIN
IF Oberon.FocusViewer # V THEN Oberon.PassFocus(V) END
END SetFocus;
PROCEDURE Defocus(tF: TextFrames.Frame);
VAR M: Oberon.InputMsg;
BEGIN
IF tF # NIL THEN SetFocus(Viewers.This(tF.X, tF.Y))
ELSE
M.id := Oberon.defocus; Oberon.FocusViewer.handle(Oberon.FocusViewer, M)
END
END Defocus;
PROCEDURE GetSelData(tF: TextFrames.Frame; VAR text: Texts.Text; VAR beg, end, time: LONGINT);
BEGIN
text := NIL; time := -1;
TextFrames.GetSelection(tF, text, beg, end, time)
END GetSelData;
PROCEDURE GetSelFrame(VAR F: TextFrames.Frame);
VAR time: LONGINT; V: Viewers.Viewer; X: INTEGER; f: TextFrames.Frame;
BEGIN
time := -1; X := 0; F := NIL;
WHILE X < Display.Width DO V := Viewers.This(X, 0);
WHILE V.state > 1 DO
IF (V.dsc # NIL) & (V.dsc.next # NIL) & (V.dsc.next IS TextFrames.Frame) THEN
f := V.dsc.next(TextFrames.Frame);
IF (f.sel > 0) & (f.time > time) THEN F := f; time := f.time END
END;
V := Viewers.Next(V)
END;
X := X + V.W
END
END GetSelFrame;
PROCEDURE ReaderFnt(VAR R: Texts.Reader): Fonts.Font;
BEGIN RETURN R.fnt
END ReaderFnt;
PROCEDURE AdjustFont(VAR W: Texts.Writer; VAR R: Texts.Reader);
BEGIN
IF W.fnt # R.fnt THEN Texts.SetFont(tW, R.fnt) END
END AdjustFont;
PROCEDURE SetDefFont(VAR W: Texts.Writer);
BEGIN
IF W.fnt # Fonts.Default THEN Texts.SetFont(W, Fonts.Default) END
END SetDefFont;
-v-*)
PROCEDURE LinesOf(tF: TextFrames.Frame): INTEGER;
BEGIN
RETURN (tF.H - tF.top - tF.bot) DIV tF.lsp
END LinesOf;
PROCEDURE OpenBackRdr(VAR bR: BackRdr; text: Texts.Text; pos: LONGINT);
VAR R: Texts.Reader; i: INTEGER; ch: CHAR;
BEGIN
bR.text := text; bR.beg := FALSE; bR.next := BufLen - 1;
IF pos >= BufLen THEN
bR.begPos := pos - BufLen; i := 0; Texts.OpenReader(R, text, bR.begPos)
ELSE
(*
i := 0; WHILE i < (BufLen - pos) DO bR.buf[i] := 0X; INC(i) END;
*)
i := SHORT(BufLen - pos);
bR.begPos := -i; Texts.OpenReader(R, text, 0)
END;
bR.last := i; Texts.Read(R, ch);
WHILE i < BufLen DO bR.buf[i] := ch; INC(i); Texts.Read(R, ch) END
END OpenBackRdr;
PROCEDURE BackRead(VAR bR: BackRdr; VAR ch: CHAR);
BEGIN
IF bR.next >= bR.last THEN
ch := bR.buf[bR.next]; DEC(bR.next); bR.beg := FALSE
ELSIF (bR.next = -1) & (bR.begPos > 0) THEN
OpenBackRdr(bR, bR.text, bR.begPos); BackRead(bR, ch)
ELSE ch := 0X; bR.beg := TRUE
END
END BackRead;
PROCEDURE RPos(VAR bR: BackRdr): LONGINT;
BEGIN
IF bR.next >= 0 THEN RETURN bR.begPos + bR.next + 1
ELSE RETURN bR.begPos
END
END RPos;
PROCEDURE LinesUp(text: Texts.Text; pos: LONGINT; nbr: INTEGER): LONGINT;
(* returns the start position of nbr lines above line containing pos *)
VAR bR: BackRdr; l: INTEGER; ch: CHAR;
BEGIN
OpenBackRdr(bR, text, pos); l := 0;
REPEAT
BackRead(bR, ch);
IF ch = CR THEN INC(l) END
UNTIL bR.beg OR (l > nbr);
pos := RPos(bR); IF ~ bR.beg THEN INC(pos) END; (* RPos(bR) = pos of CR *)
RETURN pos
END LinesUp;
PROCEDURE RemoveMarks(tF : TextFrames.Frame);
BEGIN
TextFrames.RemoveSelection(tF); TextFrames.RemoveCaret(tF);
Oberon.RemoveMarks(tF.X, tF.Y, tF.W, tF.H)
END RemoveMarks;
PROCEDURE ShowPos(tF: TextFrames.Frame; pos: LONGINT);
VAR org, lines: LONGINT;
BEGIN
IF (pos < TextFrames.Pos(tF, tF.X , tF.Y + tF.H)) OR (TextFrames.Pos(tF, tF.X + tF.W, tF.Y) < pos) THEN
lines := LinesOf(tF);
IF lines > 4 THEN org := LinesUp(tF.text, pos, 4)
ELSE org := LinesUp(tF.text, pos, 1)
END;
TextFrames.Show(tF, org)
END
END ShowPos;
PROCEDURE SendTabs(tF: TextFrames.Frame; VAR M: Oberon.InputMsg);
VAR tR: Texts.Reader; ch: CHAR; pos: LONGINT; T: Texts.Text;
BEGIN
T := tF.text;
pos := LinesUp(T, tF.carloc.pos, 1);
Texts.OpenReader(tR, T, pos); Texts.Read(tR, ch);
WHILE ~ tR.eot & ((ch = TAB) OR (ch = SPACE)) DO
M.ch := ch; TextFrames.Handle(tF, M); Texts.Read(tR, ch)
END
END SendTabs;
PROCEDURE ScrollFrame(tF: TextFrames.Frame; X, Y: INTEGER; keys: SET);
VAR mm, mr, ml: BOOLEAN; pos: LONGINT; lPos: INTEGER;
BEGIN
ml := FALSE; mm := FALSE; mr := FALSE;
IF keys = {ML} THEN
TextFrames.TrackLine(tF, X, Y, pos, keys);
IF MM IN keys THEN mm := TRUE END;
IF MR IN keys THEN mr := TRUE END;
IF mm OR mr THEN RETURN END;
Oberon.FadeCursor(Oberon.Mouse); RemoveMarks(tF);
TextFrames.Show(tF, pos) (* scroll distance up *)
ELSIF keys = {MM} THEN
WHILE keys # {} DO
Input.Mouse(keys, X, Y); Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, X, Y);
IF ML IN keys THEN ml := TRUE END;
IF MR IN keys THEN mr := TRUE END
END;
IF ml & mr THEN RETURN END;
Oberon.FadeCursor(Oberon.Mouse); RemoveMarks(tF);
IF mr THEN TextFrames.Show(tF, 0) (* scroll to begin *)
ELSIF ml THEN (* scroll to end *)
lPos := LinesOf(tF);
IF lPos > 1 THEN TextFrames.Show(tF, LinesUp(tF.text, tF.text.len, lPos - 1)) END
ELSE (* relative positioning *)
pos := (tF.text.len DIV tF.H) * (tF.Y + tF.H - Y);
IF pos < 0 THEN pos := 0 END;
IF tF.org # pos THEN TextFrames.Show(tF, pos) END
END
ELSIF keys = {MR} THEN mr := TRUE;
TextFrames.TrackLine(tF, X, Y, pos, keys); (* beginning of new bottom line *)
IF MM IN keys THEN mm := TRUE END;
IF ML IN keys THEN ml := TRUE END;
IF ml OR mm THEN RETURN END; (* ### *)
Oberon.FadeCursor(Oberon.Mouse); RemoveMarks(tF);
lPos := LinesOf(tF);
IF lPos > 1 THEN TextFrames.Show(tF, LinesUp(tF.text, pos, lPos - 1)) END
END
END ScrollFrame;
PROCEDURE DisplayMenu(tF: TextFrames.Frame; X, Y: INTEGER; text: Texts.Text; pos: LONGINT);
VAR cmd: ARRAY 32 OF CHAR; res: INTEGER;
BEGIN
IF menuAvail THEN
cmd := "Menu.ShowCmd";
Oberon.Par.text := text; Oberon.Par.pos := pos;
Oberon.Par.vwr := Viewers.This(X, Y); Oberon.Par.frame := Oberon.Par.vwr.dsc;
Oberon.Call(cmd, Oberon.Par, FALSE, res);
menuAvail := (res = 0)
END
END DisplayMenu;
PROCEDURE TrackedMM(tF: TextFrames.Frame; X, Y: INTEGER; keys: SET): BOOLEAN;
VAR R: Texts.Reader; bR: BackRdr; T: Texts.Text; ch: CHAR;
BEGIN
T := tF.text;
Texts.OpenReader(R, T, TextFrames.Pos(tF, X, Y)); Texts.Read(R, ch);
IF (ch = CR) OR (ch = TAB) OR (ch = SPACE) OR (ch = 0X) THEN
IF (popup # NIL) & menuAvail THEN DisplayMenu(tF, X, Y, popup, 0); RETURN menuAvail
ELSE RETURN FALSE
END
ELSE
OpenBackRdr(bR, T, Texts.Pos(R)); BackRead(bR, ch);
WHILE ~bR.beg & (ch # "^") & ~ ((ch = CR) OR (ch = TAB) OR (ch = SPACE) OR (ch = 0X)) DO BackRead(bR, ch) END;
IF (ch = "^") & menuAvail THEN
DisplayMenu(tF, X, Y, T, RPos(bR) + 1); RETURN menuAvail
ELSE RETURN FALSE
END
END
END TrackedMM;
PROCEDURE right(F: Frame; nbr: SHORTINT);
VAR tF: TextFrames.Frame; text: Texts.Text; R: Texts.Reader; ch, dh: CHAR;
beg, end, time, fLine, lLine: LONGINT; nr: SHORTINT;
BEGIN
IF F = NIL THEN GetSelFrame(tF) ELSIF F IS TextFrames.Frame THEN tF := F(TextFrames.Frame) ELSE tF := NIL END;
IF (tF # NIL) & (tF.sel > 0) THEN
GetSelData(tF, text, beg, end, time);
IF (text # NIL) & (time > 0) THEN
fLine := LinesUp(text, beg, 0); lLine := LinesUp(text, end - 1, 0);
Texts.OpenReader(R, text, fLine); Texts.Read(R, ch); AdjustFont(tW, R);
IF (ch # SPACE) & (ch # TAB) THEN ch := TAB END;
nr := nbr; WHILE nr > 0 DO Texts.Write(tW, ch); DEC(nr); INC(end) END; Texts.Insert(text, lLine, tW.buf);
WHILE fLine # lLine DO
lLine := LinesUp(text, lLine - 1, 0);
Texts.OpenReader(R, text, lLine); Texts.Read(R, dh); AdjustFont(tW, R);
nr := nbr; WHILE nr > 0 DO Texts.Write(tW, ch); DEC(nr); INC(end) END; Texts.Insert(text, lLine, tW.buf)
END;
TextFrames.SetSelection(tF, beg, end)
END;
Texts.SetFont(tW, Fonts.Default)
END
END right;
PROCEDURE Right*;
(* idents last current selected text to right by a tabulator *)
BEGIN
IF (Oberon.Par.vwr # NIL) & (Oberon.Par.frame = Oberon.Par.vwr.dsc) THEN
right(Oberon.Par.vwr.dsc.next, 1)
ELSE right(NIL, 1)
END
END Right;
PROCEDURE IsCh(T: Texts.Text; pos: LONGINT): BOOLEAN;
(* tests if character in text T at position pos is a tabulator or space *)
VAR R: Texts.Reader; ch: CHAR;
BEGIN
Texts.OpenReader(R, T, pos); Texts.Read(R, ch);
RETURN (ch = SPACE) OR (ch = TAB)
END IsCh;
PROCEDURE left(F: Frame; nbr: SHORTINT);
VAR tF: TextFrames.Frame; text: Texts.Text;
beg, end, time, fLine, lLine: LONGINT; nr: SHORTINT;
BEGIN
IF F = NIL THEN GetSelFrame(tF) ELSIF F IS TextFrames.Frame THEN tF := F(TextFrames.Frame) ELSE tF := NIL END;
IF (tF # NIL) & (tF.sel > 0) THEN
GetSelData(tF, text, beg, end, time);
IF (text # NIL) & (time > 0) THEN
fLine := LinesUp(text, beg, 0); lLine := LinesUp(text, end - 1, 0);
nr := nbr; WHILE (nr > 0) & IsCh(text, lLine) DO Texts.Delete(text, lLine, lLine + 1); DEC(nr); DEC(end) END;
WHILE fLine # lLine DO
lLine := LinesUp(text, lLine - 1, 0);
nr := nbr; WHILE (nr > 0) & IsCh(text, lLine) DO Texts.Delete(text, lLine, lLine + 1); DEC(nr); DEC(end) END
END;
TextFrames.SetSelection(tF, beg, end)
END
END
END left;
PROCEDURE Left*;
(* idents last current selected text to left *)
BEGIN
IF (Oberon.Par.vwr # NIL) & (Oberon.Par.frame = Oberon.Par.vwr.dsc) THEN
left(Oberon.Par.vwr.dsc.next, 1)
ELSE left(NIL, 1)
END
END Left;
PROCEDURE SetInFnt(tF: TextFrames.Frame; VAR inFnt: Fonts.Font; VAR inCol: SHORTINT);
VAR R: Texts.Reader; ch: CHAR;
BEGIN
IF (tF.car > 0) & (tF.text.len > 0) THEN
Texts.OpenReader(R, tF.text, tF.carloc.pos);
Texts.Read(R, ch);
IF R.eot & (tF.carloc.pos > 0) THEN
Texts.OpenReader(R, tF.text, tF.carloc.pos-1); Texts.Read(R, ch)
END;
IF ~ R.eot THEN inFnt := ReaderFnt(R); inCol := R.col END
ELSE inFnt := NIL; inCol := -1
END
END SetInFnt;
PROCEDURE PredSelFrame(tF: TextFrames.Frame): TextFrames.Frame;
VAR V: Viewers.Viewer; f: TextFrames.Frame;
BEGIN
f := NIL; V := Viewers.This(tF.X, tF.Y); V := V.next(Viewers.Viewer);
IF (V.dsc # NIL) & (V.dsc.next # NIL) & (V.dsc.next IS TextFrames.Frame) THEN
f := V.dsc.next(TextFrames.Frame);
IF (f.text = tF.text) & (f.sel > 0) THEN (* skip *) ELSE f := NIL END
END;
RETURN f
END PredSelFrame;
PROCEDURE PreHandleMR(tF: TextFrames.Frame; VAR X, Y: INTEGER; keys: SET);
VAR V: Viewers.Viewer; pF: TextFrames.Frame; newPos, endPos: LONGINT;
BEGIN
IF (X >= tF.X + Min(tF.left, TextFrames.barW)) THEN (* not in scrollbar *)
pF := PredSelFrame(tF);
IF pF # NIL THEN
newPos := TextFrames.Pos(tF, X, Y); endPos := TextFrames.Pos(pF, pF.X + pF.W, pF.Y) + 1;
IF (pF.selend.pos < newPos) & (endPos <= newPos) & (pF.selbeg.pos <= tF.org) THEN
TextFrames.SetSelection(pF, pF.selbeg.pos, endPos);
X := tF.X + tF.left; Y := tF.Y + tF.H - 1; (* to start selection at frame origin *)
ELSE
TextFrames.RemoveSelection(pF)
END
END
END
END PreHandleMR;
PROCEDURE GetSelection(tF: TextFrames.Frame; VAR M: SelectMsg; VAR handled: BOOLEAN);
VAR pF: TextFrames.Frame;
BEGIN
handled := (tF.sel > 0) & (tF.time > M.time);
IF handled THEN
GetSelData(tF, M.text, M.beg, M.end, M.time);
pF := PredSelFrame(tF);
IF (pF # NIL) & (pF.time < M.time) & (pF.selbeg.pos < M.end) THEN (* enlarge selection *)
M.beg := pF.selbeg.pos
END
END
END GetSelection;
PROCEDURE MarkMenu(F: Frame; updT: Texts.Text);
VAR R: Texts.Reader; V: Viewers.Viewer; T: Texts.Text; ch: CHAR;
BEGIN V := Viewers.This(F.X, F.Y);
IF (V IS MenuViewers.Viewer) & (V.dsc IS TextFrames.Frame) THEN
T := V.dsc(TextFrames.Frame).text;
IF T # updT THEN
IF T.len > 0 THEN Texts.OpenReader(R, T, T.len - 1); Texts.Read(R, ch) ELSE ch := 0X END;
IF ch # "!" THEN Texts.WriteString(WL, " !"); Texts.Append(T, WL.buf) END
END
END
END MarkMenu;
PROCEDURE UnMarkMenu(F: Frame);
VAR R: Texts.Reader; V: Viewers.Viewer; T: Texts.Text; ch: CHAR;
BEGIN V := Viewers.This(F.X, F.Y);
IF (V IS MenuViewers.Viewer) & (V.dsc IS TextFrames.Frame) THEN T := V.dsc(TextFrames.Frame).text;
IF T.len > 0 THEN Texts.OpenReader(R, T, T.len - 1); Texts.Read(R, ch) ELSE ch := 0X END;
IF ch = "!" THEN Texts.Delete(T, T.len - 2, T.len) END
END
END UnMarkMenu;
PROCEDURE IsWarning(VAR M: UpdateMsg): BOOLEAN;
VAR S: Texts.Scanner;
BEGIN
Texts.OpenScanner(S, M.text, M.beg); Texts.Scan(S);
IF (S.class = Texts.Name) & (S.s = "pos") THEN Texts.Scan(S); Texts.Scan(S) END;
RETURN (S.class = Texts.Name) & (S.s = "warning")
END IsWarning;
PROCEDURE TextProcessor(tF: TextFrames.Frame; VAR M: UpdateMsg);
VAR scroll: BOOLEAN; lUp, pos: LONGINT;
BEGIN
scroll := FALSE;
IF tF.text = Oberon.Log THEN
IF (tF.car = 0) & (M.beg = M.end) THEN
IF filter & IsWarning(M) THEN
tF.text := NIL; Texts.Delete(M.text, M.beg, M.beg+M.len);
tF.text := M.text; RETURN (* ### *)
END;
scroll := TRUE
END
ELSE MarkMenu (tF, tF.text)
END;
TextFrames.Handle(tF, M);
IF scroll THEN
lUp := LinesOf(tF) - 1;
IF lUp > 0 THEN
pos := LinesUp(tF.text, tF.text.len, SHORT(lUp));
IF pos > tF.org THEN TextFrames.Show(tF, pos) END
END
END
END TextProcessor;
PROCEDURE Handle*(F: Object; VAR M: ObjMsg);
VAR tF: TextFrames.Frame; handled, ml: BOOLEAN; T: Texts.Text;
BEGIN
tF := F(TextFrames.Frame);
T := tF.text; IF T = NIL THEN RETURN END; (* ### *)
handled := FALSE;
IF M IS Oberon.InputMsg THEN
WITH M: Oberon.InputMsg DO
IF (M.id = Oberon.consume) & (tF.car > 0) THEN
IF inFnt # NIL THEN M.fnt := inFnt; M.col := inColor END; (* adjust input font *)
IF M.ch = CR THEN
TextFrames.Handle(F, M); handled := TRUE;
SendTabs(tF, M)
ELSIF M.ch = LF THEN
M.ch := CR; TextFrames.Handle(F, M); handled := TRUE; M.ch := LF (* restore msg *)
ELSIF (M.ch = LtArrow) THEN
IF (tF.carloc.pos > 0) THEN
TextFrames.RemoveCaret(tF); TextFrames.SetCaret(tF, tF.carloc.pos - 1)
END;
handled := TRUE
ELSIF (M.ch = RtArrow) THEN
IF (tF.carloc.pos < T.len) THEN
TextFrames.RemoveCaret(tF); TextFrames.SetCaret(tF, tF.carloc.pos + 1)
END;
handled := TRUE
END
ELSIF M.id = Oberon.track THEN
IF tF.Y <= M.Y THEN
IF M.X >= tF.X + Min(tF.left, TextFrames.barW) THEN (* not in scrollbar *)
IF M.keys = {MM} THEN handled := TrackedMM(tF, M.X, M.Y, M.keys)
ELSE
IF M.keys = {MR} THEN PreHandleMR(tF, M.X, M.Y, M.keys) END;
ml := M.keys = {ML}; handled := TRUE; TextFrames.Handle(F, M);
IF ml THEN SetInFnt(tF, inFnt, inColor) END
END
ELSIF tF.left > TextFrames.barW THEN (* scrollbar exisiting *)
Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, M.X, M.Y); handled := TRUE;
IF M.keys # {} THEN ScrollFrame(tF, M.X, M.Y, M.keys) END
END
END
END (* IF M.id = ... *)
END (* WITH M: ... *)
ELSIF M IS UpdateMsg THEN
WITH M: UpdateMsg DO
IF M.text = T THEN TextProcessor(tF, M); handled := TRUE END
END;
ELSIF M IS SelectMsg THEN
GetSelection(tF, M(SelectMsg), handled);
IF handled THEN M(SelectMsg).sel := tF ELSE handled := TRUE END
ELSIF M IS FocMsg THEN
IF tF.car = 1 THEN M(FocMsg).V := Viewers.This(tF.X, tF.Y) END
END;
IF ~ handled THEN TextFrames.Handle(F, M) END
END Handle;
PROCEDURE AsciiText(IN name: ARRAY OF CHAR): Texts.Text;
VAR text: Texts.Text; res: INTEGER; ch, pch: CHAR;
f, g : Files.File; Rf, Rg : Files.Rider;
BEGIN
f := Files.Old(name);
IF f # NIL THEN g := Files.New(AsciiTemp);
Files.Set(Rf, f, 0); Files.Set(Rg, g, 0); Files.ReadChar(Rf, ch); pch := 0X;
WHILE ~Rf.eof DO
IF (ch = LF) & (pch # CR) THEN Files.WriteChar(Rg, CR) (* unix *)
ELSIF (ch # LF) & (ch # 1AX) THEN Files.WriteChar(Rg, ch)
END;
pch := ch; Files.ReadChar(Rf, ch)
END;
Files.Register(g);
text := TextFrames.Text(AsciiTemp);
Files.Delete(AsciiTemp, res)
ELSE text := TextFrames.Text("")
END;
RETURN text
END AsciiText;
PROCEDURE NewMF(IN mTitle: ARRAY OF CHAR; typ: INTEGER; VAR menuH: INTEGER): TextFrames.Frame;
VAR F: TextFrames.Frame;
BEGIN
menuH := TextFrames.menuH;
F := TextFrames.NewMenu(mTitle, mStr[typ]);
F.handle := Handle;
RETURN F
END NewMF;
PROCEDURE NewETF(text: Texts.Text; org: LONGINT): TextFrames.Frame;
VAR F: TextFrames.Frame;
BEGIN
F := TextFrames.NewText(text, org);
F.handle := Handle;
RETURN F
END NewETF;
PROCEDURE OpenViewer(text: Texts.Text; IN title: ARRAY OF CHAR; pos: LONGINT;
X, Y: INTEGER; kind: SHORTINT): Viewers.Viewer;
VAR mF: TextFrames.Frame; menuH: INTEGER;
BEGIN
IF text = NIL THEN text := TextFrames.Text("") END;
mF := NewMF(title, kind, menuH);
RETURN MenuViewers.New(mF, NewETF(text, pos), menuH, X, Y)
END OpenViewer;
PROCEDURE New*;
VAR V: Viewers.Viewer; X, Y: INTEGER;
BEGIN
Oberon.AllocateUserViewer(Oberon.UserTrack(Oberon.Par.vwr.X), X, Y);
V := OpenViewer(NIL, "ET.New", 0, X, Y, 0)
END New;
PROCEDURE NewSys*;
VAR V: Viewers.Viewer; X, Y: INTEGER;
BEGIN
Oberon.AllocateSystemViewer(Oberon.SystemTrack(Oberon.Par.vwr.X), X, Y);
V := OpenViewer(NIL, "ET.NewSys", 0, X, Y, 1)
END NewSys;
PROCEDURE Open*;
VAR V: Viewers.Viewer; X, Y: INTEGER; text: Texts.Text; S: Texts.Scanner;
BEGIN
ScanName(Oberon.UserTrack(Oberon.Par.vwr.X), X, Y, S);
IF S.class = Texts.Name THEN text := TextFrames.Text(S.s); V := OpenViewer(text, S.s, 0, X, Y, 0)
ELSE text := NIL; V := OpenViewer(text, "ET.Open", 0, X, Y, 0)
END
END Open;
PROCEDURE OpenSys*;
VAR V: Viewers.Viewer; X, Y: INTEGER; text: Texts.Text; S: Texts.Scanner;
BEGIN
ScanName(Oberon.SystemTrack(Oberon.Par.vwr.X), X, Y, S);
IF S.class = Texts.Name THEN text := TextFrames.Text(S.s); V := OpenViewer(text, S.s, 0, X, Y, 1)
ELSE text := NIL; V := OpenViewer(text, "ET.OpenSys", 0, X, Y, 1)
END
END OpenSys;
PROCEDURE OpenAscii*;
VAR V: Viewers.Viewer; X, Y: INTEGER; S: Texts.Scanner;
BEGIN
ScanName(Oberon.UserTrack(Oberon.Par.vwr.X), X, Y, S);
IF S.class = Texts.Name THEN V := OpenViewer(AsciiText(S.s), S.s, 0, X, Y, 3)
ELSE V := OpenViewer(TextFrames.Text(""), "ET.OpenAscii", 0, X, Y, 3)
END
END OpenAscii;
PROCEDURE OpenSysAscii*;
VAR V: Viewers.Viewer; X, Y: INTEGER; S: Texts.Scanner;
BEGIN
ScanName(Oberon.SystemTrack(Oberon.Par.vwr.X), X, Y, S);
IF S.class = Texts.Name THEN V := OpenViewer(AsciiText(S.s), S.s, 0, X, Y, 4)
ELSE V := OpenViewer(TextFrames.Text(""), "ET.OpenSysAscii", 0, X, Y, 4)
END
END OpenSysAscii;
PROCEDURE CalcDispVec(time: LONGINT);
VAR i, j, d: INTEGER;
BEGIN
lTime := time;
i := 1; d := 1; (* calculate displacement vector *)
WHILE i <= sPatLen DO
j := 0; WHILE (j + d < sPatLen) & (sPat[j] = sPat[j + d]) DO INC(j) END;
WHILE i <= j + d DO sDv[i] := d; INC(i) END;
INC(d)
END
END CalcDispVec;
PROCEDURE SPatFound(tF: TextFrames.Frame; text: Texts.Text; VAR pos:LONGINT): BOOLEAN;
(* searches the next position for the search pattern sPat begining at position pos *)
(* in the text text; resturns result accordingly *)
VAR R: Texts.Reader; l: LONGINT; i: INTEGER; ch: CHAR;
BEGIN
IF sPatLen > 0 THEN
IF tF # NIL THEN TextFrames.Mark(tF, -1) END;
Texts.OpenReader(R, text, pos); Texts.Read(R, ch); INC(pos);
l := text.len; i := 0;
WHILE (i # sPatLen) & (pos <= l) DO
IF ch = sPat[i] THEN
INC(i); IF i < sPatLen THEN Texts.Read(R, ch); INC(pos) END
ELSIF i = 0 THEN Texts.Read(R, ch); INC(pos)
ELSE DEC(i, sDv[i])
END
END;
IF tF # NIL THEN TextFrames.Mark(tF, 1) END
ELSE i := -1
END;
RETURN i = sPatLen (* pattern found *)
END SPatFound;
PROCEDURE Show*;
(** specification needed: "text.pattern"; loads the text text, searches the pattern *)
(** pattern and shows it in a viewer *)
VAR text: Texts.Text; S: Texts.Scanner; V: Viewers.Viewer;
X, Y, i, j, M: INTEGER; pos, beg, end: LONGINT; name: ARRAY 35 OF CHAR;
BEGIN
ScanName(Oberon.UserTrack(Oberon.Par.vwr.X), X, Y, S);
IF S.class # Texts.Name THEN RETURN END; (* ### *)
i := -1; j := 0;
WHILE S.s[j] # 0X DO
IF S.s[j] = "." THEN i := j END;
name[j] := S.s[j]; INC(j)
END;
IF i = -1 THEN i := j; name[i] := "." END;
name[i+1] := "M"; name[i+2] := "o"; name[i+3] := "d"; name[i+4] := 0X;
text := TextFrames.Text(name);
j := i+1; M := 0;
WHILE (M # MaxPatLen) & (S.s[j] # 0X) DO sPat[M] := S.s[j]; INC(j); INC(M) END;
sPatLen := M; CalcDispVec(Oberon.Time()); (* calculate displacement vector *)
pos := 0;
IF ~ SPatFound(NIL, text, pos) THEN pos := 0 END;
V := OpenViewer(text, name, Max(0, pos-200), X, Y, 0);
IF pos > 0 THEN
SetFocus(V);
TextFrames.SetCaret(V.dsc.next(TextFrames.Frame), pos) (* passes the focus to this frame *)
END
END Show;
PROCEDURE WriteDate(VAR r: Files.Rider; t, d: LONGINT);
PROCEDURE WritePair(ch: CHAR; x: LONGINT);
BEGIN
Files.WriteChar(r, ch);
Files.Write(r, (x DIV 10 + 30H)); Files.Write(r, (x MOD 10 + 30H))
END WritePair;
BEGIN
WritePair(" ", d MOD 32); WritePair(".", d DIV 32 MOD 16); WritePair(".", d DIV 512 MOD 128);
WritePair(" ", t DIV 4096 MOD 32); WritePair(":", t DIV 64 MOD 64);
(* WritePair(":", t MOD 64) *)
END WriteDate;
PROCEDURE UpdateNameLog(IN name: ARRAY OF CHAR; typ: CHAR);
VAR t, d: LONGINT; i: INTEGER;
BEGIN
IF log.f # NIL THEN
Oberon.GetClock (t, d); WriteDate(log.r, t, d);
Files.WriteChar(log.r, " "); Files.WriteChar(log.r, " ");
i := 0; WHILE name[i] # 0X DO Files.WriteChar(log.r, name[i]); INC(i) END;
IF typ # "t" THEN Files.WriteChar(log.r, " "); Files.WriteChar(log.r, typ) END;
Files.WriteChar(log.r, CR);
Files.Close(log.f) (* to flush buffers *)
END
END UpdateNameLog;
PROCEDURE RenameOld(IN name: ARRAY OF CHAR);
VAR bck: ARRAY 32 OF CHAR; i, res: INTEGER;
BEGIN
i := 0; WHILE (i < 32-5) & (name[i]# 0X) DO bck[i] := name[i]; INC(i) END;
bck[i] := "."; INC(i); bck[i] := "B"; INC(i); bck[i] := "a"; INC(i); bck[i] := "k"; INC(i); bck[i] := 0X;
Files.Rename(name, bck, res)
END RenameOld;
PROCEDURE store(typ: CHAR);
(* typ specifies the type to store the text: "t": text / "a": ascii / "c": chars *)
VAR par : Oberon.ParList; V: Viewers.Viewer; tF: TextFrames.Frame;
f: Files.File; r: Files.Rider; S: Texts.Scanner; R: Texts.Reader; len: LONGINT; ch: CHAR;
BEGIN
par := Oberon.Par; tF := NIL; S.class := Texts.Inval;
IF par.frame = par.vwr.dsc THEN (* command in menu frame *)
IF par.vwr.dsc.next IS TextFrames.Frame THEN
tF := par.vwr.dsc.next(TextFrames.Frame); ViewerName(par.vwr, S)
END
ELSE
V := Oberon.MarkedViewer(); (* marked viewer *)
IF (V.dsc # NIL) & (V.dsc.next IS TextFrames.Frame) THEN (* test if text is in marked viewer *)
tF:= V.dsc.next(TextFrames.Frame);
OpenScanner(S, Oberon.Par.text, Oberon.Par.pos);
IF S.class = Err THEN S.class := Texts.Inval
ELSE Texts.Scan(S);
IF (S.class = Texts.Char) & (S.c = "*") THEN ViewerName(V, S) END (* get name of marked viewer *)
END
END
END;
Texts.WriteString(tW, "ET.Store");
IF typ = "a" THEN Texts.WriteString(tW, "Ascii") ELSIF typ = "c" THEN Texts.WriteString(tW, "Chars") ELSE typ := "t" END;
Texts.Write(tW, " "); Texts.Append(Oberon.Log, tW.buf);
IF tF = NIL THEN Texts.WriteString(tW, " not a text ")
ELSIF S.class = Texts.Name THEN
TextFrames.Mark(tF, -1); UnMarkMenu(tF);
RenameOld(S.s);
f := Files.New(S.s);
IF typ = "t" THEN Texts.Store(tF.text, f, 0, len)
ELSE Files.Set(r, f, 0);
Texts.OpenReader(R, tF.text, 0); Texts.Read(R, ch);
WHILE ~ R.eot DO
Files.WriteChar(r, ch); IF (ch = CR) & (typ = "a") THEN Files.WriteChar(r, LF) END;
Texts.Read(R, ch)
END
END;
Files.Register(f);
UpdateNameLog(S.s, typ); Texts.WriteString(tW, S.s);
TextFrames.Mark(tF, 1)
ELSE Texts.WriteString(tW, " illegal name ")
END;
Texts.WriteLn(tW); Texts.Append(Oberon.Log, tW.buf)
END store;
PROCEDURE Store*; BEGIN store("t") END Store;
PROCEDURE StoreChar*; BEGIN store("c") END StoreChar;
PROCEDURE StoreAscii*; BEGIN store("a") END StoreAscii;
PROCEDURE Cleartrack(X: INTEGER);
VAR Y : INTEGER; V, lV: Viewers.Viewer; M: Oberon.InputMsg;
BEGIN
Oberon.RemoveMarks(X, Display.Bottom, Display.Width, Display.Height);
Defocus(NIL);
REPEAT
V := Viewers.This(X, 0); lV := NIL; (* get bottom viewer *)
WHILE V.state > 1 DO (* if not filler *)
lV := V; V := Viewers.Next(V)
END;
IF lV # NIL THEN Viewers.Close(lV) END
UNTIL lV = NIL
END Cleartrack;
PROCEDURE ClearTrack*; BEGIN Cleartrack(Oberon.UserTrack(Oberon.Par.vwr.X)) END ClearTrack;
PROCEDURE ClearSysTrack*; BEGIN Cleartrack(Oberon.SystemTrack(Oberon.Par.vwr.X)) END ClearSysTrack;
PROCEDURE ValidX(X: INTEGER): BOOLEAN;
BEGIN
RETURN (Display.Left <= X) & (X < Display.Left + Display.Width)
OR (Display.ColLeft <= X) & (X < Display.ColLeft + Display.Width)
END ValidX;
PROCEDURE ValidY(Y: INTEGER): BOOLEAN;
BEGIN
RETURN (Display.Bottom <= Y) & (Y < Display.Bottom + Display.Height)
END ValidY;
PROCEDURE Marker*;
VAR S: Texts.Scanner; V : Viewers.Viewer; cM: Oberon.ControlMsg;
BEGIN
ScanPara(S); IF S.class # Texts.Name THEN RETURN END; (* ### *)
IF S.s = "set" THEN
Texts.Scan(S); cM.id := Oberon.mark + 999;
IF (S.class = Texts.Name) & (S.s = "saved") THEN
V := Viewers.This(sX + 1, sY - 1);
IF (V # NIL) & (V.X <= sX) & (sX < V.X + V.W) & (V.Y + V.H = sY) THEN
cM.id := Oberon.mark; cM.X := V.X + V.W DIV 2; cM.Y := V.Y + V.H DIV 2
END
ELSIF (S.class = Texts.Name) & (S.s = "this") THEN
IF Oberon.Par.vwr # NIL THEN
cM.id := Oberon.mark; cM.X := Oberon.Par.vwr.X + Oberon.Par.vwr.W DIV 2;
cM.Y := Oberon.Par.vwr.Y + Oberon.Par.vwr.H DIV 2
END
ELSIF (S.class = Texts.Int) & (S.i >= 0) THEN
cM.X := SHORT(S.i); Texts.Scan(S);
IF (S.class = Texts.Int) & (S.i >= 0) THEN
cM.Y := SHORT(S.i);
IF ValidX(cM.X) & ValidY(cM.Y) THEN cM.id := Oberon.mark END
END
END;
IF cM.id = Oberon.mark THEN
V := Viewers.This(cM.X, cM.Y); IF V # NIL THEN V.handle(V, cM) END (* set marker *)
END
ELSIF S.s = "save" THEN
Texts.Scan(S);
IF S.class = Texts.Name THEN
IF S.s = "system" THEN
Oberon.AllocateSystemViewer(Oberon.SystemTrack(Oberon.Par.vwr.X), sX, sY)
ELSIF S.s = "user" THEN
Oberon.AllocateUserViewer(Oberon.UserTrack(Oberon.Par.vwr.X), sX, sY)
ELSE sX := -1; sY := -1
END
END
END
END Marker;
PROCEDURE MarkPatPos(tF: TextFrames.Frame; pos: LONGINT);
VAR l: LONGINT;
BEGIN
RemoveMarks(tF);
IF (pos < TextFrames.Pos(tF, tF.X, tF.Y + tF.H)) OR (TextFrames.Pos(tF, tF.X + tF.W, tF.Y) < pos) THEN
l := LinesOf(tF);
IF l > 4 THEN l := LinesUp(tF.text, pos, 4) ELSE l := LinesUp(tF.text, pos, 1) END;
TextFrames.Show(tF, l)
END;
Defocus(tF);
TextFrames.SetCaret(tF, pos);
TextFrames.SetSelection(tF, pos - sPatLen, pos); lTime := tF.time
END MarkPatPos;
PROCEDURE Search*;
VAR tF: TextFrames.Frame; V: Viewers.Viewer;
R: Texts.Reader; text: Texts.Text;
pos, beg, end, time: LONGINT; i, j, d: INTEGER;
BEGIN
IF (Oberon.Par.vwr # NIL) & (Oberon.Par.frame = Oberon.Par.vwr.dsc) THEN V := Oberon.Par.vwr
ELSE V := FocusViewer()
END;
IF (V.dsc = NIL) OR ~ (V.dsc.next IS TextFrames.Frame) THEN RETURN END; (* ### *)
tF := V.dsc.next(TextFrames.Frame);
text := NIL; Oberon.GetSelection(text, beg, end, time);
IF (text # NIL) & (time > lTime) THEN (* set search pattern *)
Texts.OpenReader(R, text, beg);
i := 0; pos := beg;
REPEAT Texts.Read(R, sPat[i]); INC(i); INC(pos) UNTIL (i = MaxPatLen) OR (pos = end);
sPatLen := i; CalcDispVec(time) (* calculate displacement vector *)
END;
IF tF.car > 0 THEN pos := tF.carloc.pos ELSE pos := 0 END;
IF SPatFound(tF, tF.text, pos) THEN MarkPatPos(tF, pos)
ELSE TextFrames.RemoveSelection(tF); TextFrames.RemoveCaret(tF)
END
END Search;
PROCEDURE SearchDiff*;
VAR F1, F2: TextFrames.Frame; pos1, pos2: LONGINT; R1, R2: Texts.Reader; ch1, ch2: CHAR;
BEGIN
GetSelFrame(F1);
IF F1 # NIL THEN pos1 := F1.selbeg.pos; RemoveMarks(F1) END;
GetSelFrame(F2);
IF F2 # NIL THEN pos2 := F2.selbeg.pos; RemoveMarks(F2) END;
IF (F1 # NIL) & (F2 # NIL) THEN
TextFrames.Mark(F1, -1); TextFrames.Mark(F2, -1);