forked from rochus-keller/OberonSystem3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiskSpace.Mod
174 lines (154 loc) · 4.52 KB
/
DiskSpace.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
(* 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 DiskSpace; (** non-portable *) (* pmuller 22.06.95 *)
IMPORT Kernel, Texts, Oberon, Disk, In, Modules, Files;
CONST
LogName = "DiskSpace.Log";
VAR
W: Texts.Writer;
task: Oberon.Task;
prev, threshold: LONGINT;
fprev, fthreshold, lprev, lthreshold: LONGINT;
mem: BOOLEAN;
text: Texts.Text;
PROCEDURE WriteInt(VAR r: Files.Rider; x, n: LONGINT);
VAR i: INTEGER; x0: LONGINT;
a: ARRAY 14 OF CHAR;
BEGIN i := 0;
IF x < 0 THEN
IF x = MIN(LONGINT) THEN
a := " -2147483648"; i := 0;
WHILE a[i] # 0X DO Files.Write(r, a[i]); INC(i) END;
RETURN
ELSE DEC(n); x0 := -x
END
ELSE x0 := x
END;
REPEAT
a[i] := CHR(x0 MOD 10 + 30H); x0 := x0 DIV 10; INC(i)
UNTIL x0 = 0;
WHILE n > i DO Files.Write(r, " "); DEC(n) END;
IF x < 0 THEN Files.Write(r, "-") END;
REPEAT DEC(i); Files.Write(r, a[i]) UNTIL i = 0
END WriteInt;
PROCEDURE WriteDate(VAR r: Files.Rider; t, d: LONGINT);
PROCEDURE WritePair(ch: CHAR; x: LONGINT);
BEGIN
Files.Write(r, ch);
Files.Write(r, CHR(x DIV 10 + 30H)); Files.Write(r, CHR(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 UpdateLog(on: BOOLEAN);
VAR t, d: LONGINT; f: Files.File; log: Files.Rider;
BEGIN
f := Files.Old(LogName);
IF f = NIL THEN f := Files.New(LogName); Files.Register(f) END;
Files.Set(log, f, Files.Length(f));
Oberon.GetClock(t, d); WriteDate(log, t, d);
Files.Write(log, " "); Files.Write(log, "o");
IF on THEN Files.Write(log, "n")
ELSE Files.Write(log, "f"); Files.Write(log, "f")
END;
Files.Write(log, " ");
WriteInt(log, Disk.Available()*Disk.SectorSize DIV 1024, 1);
Files.Write(log, 0DX);
Files.Close(f)
END UpdateLog;
PROCEDURE Stop*;
BEGIN
IF task # NIL THEN
UpdateLog(FALSE);
Oberon.Remove(task); task := NIL
END
END Stop;
PROCEDURE Handler(t: Oberon.Task);
VAR s: LONGINT; u: BOOLEAN;
BEGIN
s := Disk.Available(); u := FALSE;
IF ABS(s - prev) > threshold THEN
IF s < 2*threshold THEN threshold := 1 END; (* so little space, warn often! *)
prev := s;
Texts.WriteInt(W, s*Disk.SectorSize DIV 1024, 1);
Texts.WriteString(W, "k disk space free");
u := TRUE
END;
IF mem THEN
s := Kernel.Available();
IF ABS(s - fprev) > fthreshold THEN
fprev := s;
IF u THEN Texts.WriteString(W, ", ") END;
Texts.WriteInt(W, s DIV 1024, 1);
Texts.WriteString(W, "k bytes available");
u := TRUE
END;
s := Kernel.LargestAvailable();
IF ABS(s - lprev) > lthreshold THEN
lprev := s;
IF u THEN Texts.WriteString(W, ", ") END;
Texts.WriteInt(W, s DIV 1024, 1);
Texts.WriteString(W, "k byte block available");
u := TRUE
END
END;
IF u THEN Texts.WriteLn(W); Texts.Append(text, W.buf) END
END Handler;
PROCEDURE Start*;
BEGIN
IF task = NIL THEN
UpdateLog(TRUE);
NEW(task); task.time := -1; task.safe := FALSE; task.handle := Handler;
Oberon.Install(task)
END
END Start;
PROCEDURE ShowMem*;
VAR s: ARRAY 32 OF CHAR;
BEGIN
In.Open; In.Name(s);
IF In.Done & (s = "on") THEN
mem := TRUE; fprev := -fthreshold; lprev := -lthreshold;
ELSIF In.Done & (s = "off") THEN
mem := FALSE
END
END ShowMem;
PROCEDURE SetColor*;
VAR i: INTEGER;
BEGIN
In.Open; In.Int(i);
IF In.Done THEN Texts.SetColor(W, SHORT(i)) END
END SetColor;
PROCEDURE StartViewer*;
BEGIN
NEW(text); Texts.Open(text, "");
Oberon.OpenText("DiskSpace.Out", text, 200, 200)
END StartViewer;
PROCEDURE StopViewer*;
BEGIN
text := Oberon.Log
END StopViewer;
BEGIN
text := Oberon.Log;
task := NIL; threshold := 100; prev := -threshold;
fthreshold := 128*1024; fprev := -fthreshold;
lthreshold := 128*1024; lprev := -lthreshold;
mem := FALSE;
Texts.OpenWriter(W);
Modules.InstallTermHandler(Stop)
END DiskSpace.
DiskSpace.Start
DiskSpace.Stop
DiskSpace.SetColor ^
DiskSpace.ShowMem ^ on off
DiskSpace.StartViewer
DiskSpace.StopViewer