-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathConfiguration.Mod
212 lines (192 loc) · 6.79 KB
/
Configuration.Mod
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
(* OBERON System 3, Release 2.3.
Copyright 1999 ETH Zürich Institute for Computer Systems,
ETH Center, CH-8092 Zürich. e-mail: [email protected].
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 Configuration; (** portable *) (* jm, Configuration module/code borrowed from ET by uh **)
(*
contains a lot of code borrowed from ET
*)
IMPORT Modules, Display, Viewers, Texts, Oberon;
CONST
CR = 0DX;
Default = "Configuration.Text";
VAR
W: Texts.Writer;
sX, sY: INTEGER; (* saved coordinates for newm viewer [used in Marker ] *)
PROCEDURE OpenScanner(VAR S: Texts.Scanner);
VAR
text: Texts.Text;
beg, end, time: LONGINT;
BEGIN
Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos);
Texts.Scan(S);
IF (S.class = Texts.Char) & (S.c = "^") THEN
text := NIL; time := 0; Oberon.GetSelection(text, beg, end, time);
IF (text = NIL) OR (time <= 0) THEN S.class := Texts.Inval; RETURN END;
Texts.OpenScanner(S, text, beg); Texts.Scan(S)
END
END OpenScanner;
(** Execute commands contained in the text. Each command must be on a separate line. *)
PROCEDURE do*(T: Texts.Text; beg, end: LONGINT);
VAR S: Texts.Scanner; pos: LONGINT; res: INTEGER;
PROCEDURE NextLine(text: Texts.Text; pos: LONGINT): LONGINT;
VAR tR: Texts.Reader; ch: CHAR;
BEGIN
IF pos < text.len THEN
Texts.OpenReader(tR, text, pos); Texts.Read(tR, ch);
WHILE ~ tR.eot & (ch # CR) DO Texts.Read(tR, ch) END;
IF tR.eot THEN RETURN -1 ELSE RETURN Texts.Pos(tR) END
ELSE RETURN -1
END
END NextLine;
BEGIN
pos := beg;
Texts.OpenScanner(S, T, pos); Texts.Scan(S);
WHILE ((S.class = Texts.Name) OR ((S.class = Texts.Char) & (S.c = "!"))) & (pos < end) DO
pos := Texts.Pos(S) - 1;
IF S.class = Texts.Name THEN
Oberon.Par.text := T; Oberon.Par.pos := pos;
Oberon.Call(S.s, Oberon.Par, FALSE, res);
IF res # 0 THEN
Texts.WriteString(W, "Call error: "); Texts.WriteString(W, Modules.resMsg);
Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf)
END
END;
pos := NextLine(T, pos);
IF pos > 0 THEN Texts.OpenScanner(S, T, pos); Texts.Scan(S)
ELSE S.class := Texts.Inval
END
END
END do;
(** Configuration.DoText ( "*" | "^" | textfile { textfile } "~" )
Execute the commands in textfile . Each command must be written on a separate line. *)
PROCEDURE DoText*;
VAR S: Texts.Scanner; T: Texts.Text;
BEGIN
OpenScanner(S);
IF (S.class = Texts.Char) & (S.c = "*") THEN
T := Oberon.MarkedText()
ELSIF S.class IN {Texts.Name, Texts.String} THEN
NEW(T); Texts.Open(T, S.s)
ELSE
T := NIL
END;
IF T # NIL THEN
do(T, 0, T.len)
END
END DoText;
(** Configuration.DoCommands ( "^" | cmd { cmd } "~" )
Execute the commands. Each command must be written on a separate line. *)
PROCEDURE DoCommands*;
VAR
S: Texts.Scanner; T: Texts.Text;
beg, end, time: LONGINT;
BEGIN
Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos);
Texts.Scan(S);
IF (S.class = Texts.Char) & (S.c = "^") THEN
T := NIL; time := -1; Oberon.GetSelection(T, beg, end, time);
ELSE
T := Oberon.Par.text; beg := Oberon.Par.pos; end := T.len
END;
IF T # NIL THEN
do(T, beg, end)
END
END DoCommands;
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;
(** Set the star marker under program control:
Configuration.Marker set save (* set at saved position *)
Configuration.Marker set this (* set to current viewer *)
Configuration.Marker set system (* in system track *)
Configuration.Marker set user (* in user track *)
Configuration.Marker set X Y (* at absolute pixel position X, Y *)
Configuration.Marker set X% Y% (* at relative pixel position X, Y *)
Configuration.Marker save system (* save marker in system track *)
Configuration.Marker save user (* save marker in user track *)
*)
PROCEDURE Marker*;
VAR S: Texts.Scanner; V : Viewers.Viewer; cM: Oberon.ControlMsg;
BEGIN
Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(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) & (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.Name) & (S.s = "system") THEN
Oberon.AllocateSystemViewer(Oberon.SystemTrack(Oberon.Par.vwr.X), cM.X, cM.Y);
cM.id := Oberon.mark;
ELSIF (S.class = Texts.Name) & (S.s = "user") THEN
Oberon.AllocateUserViewer(Oberon.UserTrack(Oberon.Par.vwr.X), cM.X, cM.Y);
cM.id := Oberon.mark;
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
ELSIF (S.class = Texts.Char) & (S.c = "%") THEN
Texts.Scan(S);
IF (S.class = Texts.Int) & (S.i >= 0) THEN
cM.Y := SHORT(S.i*Display.Height DIV 100);
cM.X := SHORT(LONG(Display.Width)*cM.X DIV 100);
IF ValidX(cM.X) & ValidY(cM.Y) THEN cM.id := Oberon.mark END
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 Init();
VAR
s: Texts.Scanner;
T: Texts.Text;
x, y: INTEGER;
BEGIN
Oberon.OpenScanner(s, "System.Configuration");
IF ~(s.class IN {Texts.Name, Texts.String}) THEN
s.s := Default
END;
NEW(T); Texts.Open(T, s.s);
IF T.len > 0 THEN
Oberon.AllocateSystemViewer(Display.Left, x, y);
NEW(Oberon.Par);
Oberon.Par.vwr := Viewers.This(x+1, y-1); NEW(Oberon.Par.frame);
do(T, 0, T.len)
END
END Init;
BEGIN Texts.OpenWriter(W); Init()
END Configuration.