-
Notifications
You must be signed in to change notification settings - Fork 3
/
artUnix.obn
83 lines (67 loc) · 1.88 KB
/
artUnix.obn
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
(** Unix provides asscess to some POSIX C based libraries and services.
Copyright (C) 2021 R. S. Doiel
Released under The 3-Clause BSD License.
See https://opensource.org/licenses/BSD-3-Clause
*)
MODULE artUnix;
VAR
kernel, architecture : ARRAY 24 OF CHAR;
(*
* C implemented procedures
* ------------------------
*)
(* uname does a popen call to `uname` *)
PROCEDURE uname(opt : CHAR; VAR dest : ARRAY OF CHAR);
BEGIN
END uname;
(** Exit performs a system exit with error number *)
PROCEDURE Exit*(exitCode : INTEGER);
BEGIN
END Exit;
(*
* Oberon-7 implemented procedures
* -------------------------------
*)
(* mininum returns the lesser of two integer *)
PROCEDURE minimum(a, b : INTEGER) : INTEGER;
VAR res : INTEGER;
BEGIN
IF a < b THEN res := a; ELSE res := b; END;
RETURN res
END minimum;
(* copy an array of chars, truncate dest if needed *)
PROCEDURE copyChars(source : ARRAY OF CHAR; VAR dest : ARRAY OF CHAR);
VAR i, l : INTEGER;
BEGIN
l := minimum(LEN(source), LEN(dest)) - 2; (* leave room of 0X *)
IF l < 1 THEN l := 0 END;
i := 0; dest[i] := 0X;
WHILE (i < l) & (source[i] # 0X) DO
dest[i] := source[i];
INC(i);
END;
dest[i] := 0X; DEC(i);
IF (dest[i] = 10X) OR (dest[i] = 13X) THEN
dest[i] := 0X;
END;
END copyChars;
(** KernelName attempts a system exec call to `uname -s` to determine the
Kernel name, e.g. Linux, Darwin, Windows *)
PROCEDURE KernelName*(VAR dest : ARRAY OF CHAR);
BEGIN
IF kernel[0] = 0X THEN
uname("s", kernel);
END;
copyChars(kernel, dest);
END KernelName;
(** Architecture attempts a system exec call to `uname -m` to determine
the machine archtecture, e.g. i386, x86_64 *)
PROCEDURE Architecture*(VAR dest : ARRAY OF CHAR);
BEGIN
IF architecture[0] = 0X THEN
uname("m", architecture);
END;
copyChars(architecture, dest);
END Architecture;
BEGIN kernel[0] := 0X; architecture[0] := 0X;
END artUnix.