-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCommandLineSystem.Mod.txt
More file actions
86 lines (76 loc) · 2.48 KB
/
CommandLineSystem.Mod.txt
File metadata and controls
86 lines (76 loc) · 2.48 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
MODULE CommandLineSystem;
IMPORT SYSTEM, Files, Modules, Texts, TextFrames, Oberon;
CONST data = -56; stat = -52;
VAR T: Oberon.Task;
FR: TextFrames.Frame;
W: Texts.Writer;
Mod: Modules.Module;
LogPos: INTEGER;
PROCEDURE Rec(VAR x: BYTE);
BEGIN
REPEAT UNTIL SYSTEM.BIT(stat, 0);
SYSTEM.GET(data, x)
END Rec;
PROCEDURE RecLine(VAR s: ARRAY OF CHAR);
VAR i: INTEGER; x: BYTE;
BEGIN i := 0; Rec(x);
WHILE x > 0 DO s[i] := CHR(x); INC(i); Rec(x) END ;
s[i] := 0X
END RecLine;
PROCEDURE Send(x: BYTE);
BEGIN
REPEAT UNTIL SYSTEM.BIT(stat, 1);
SYSTEM.PUT(data, x)
END Send;
PROCEDURE FinishCommand*;
VAR ch: CHAR;
R: Texts.Reader;
BEGIN
Texts.OpenReader(R, Oberon.Log, LogPos); Texts.Read(R, ch);
WHILE ~R.eot DO Send(ORD(ch)); Texts.Read(R, ch) END;
LogPos := Texts.Pos(R) - 1;
IF Oberon.RetVal = 0 THEN Send(0) ELSE Send(1) END;
END FinishCommand;
PROCEDURE Task;
VAR i: INTEGER; x: BYTE;
line: ARRAY 1024 OF CHAR;
name: ARRAY 32 OF CHAR;
F: Files.File; R: Files.Rider;
BEGIN
IF SYSTEM.BIT(stat, 0) THEN (*byte available*)
RecLine(line);
IF line[0] = "+" THEN
i := 0; WHILE line[i+1] # 0X DO name[i] := line[i+1]; INC(i) END;
name[i] := 0X;
Rec(x); i := x; Rec(x); i:= i * 100H + x;
Rec(x); i := i * 100H + x; Rec(x); i := i * 100H + x;
F := Files.New(name);
Texts.WriteString(W, "receiving "); Texts.WriteString(W, name);
Texts.Append(Oberon.Log, W.buf);
Files.Set(R, F, 0);
WHILE i > 0 DO Rec(x); Files.WriteByte(R, x); DEC(i) END;
Rec(x); ASSERT(x = 0);
Files.Register(F); Texts.WriteString(W, " done"); Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf)
ELSE
Texts.WriteString(W, "> "); Texts.Append(Oberon.Log, W.buf);
i := Oberon.Log.len;
Texts.WriteString(W, line); Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf);
TextFrames.Call(FR, i, FALSE);
END;
FinishCommand
END
END Task;
PROCEDURE Run*;
BEGIN
Oberon.Install(T); Texts.WriteString(W, "CommandLineSystem started");
Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf)
END Run;
PROCEDURE Stop*;
BEGIN
Oberon.Install(T); Texts.WriteString(W, "CommandLineSystem stopped");
Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf)
END Stop;
BEGIN Texts.OpenWriter(W);
FR := TextFrames.NewText(Oberon.Log, 0);
T := Oberon.NewTask(Task, 0); LogPos := 0
END CommandLineSystem.