summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7f1b7f0)
raw | patch | inline | side by side (parent: 7f1b7f0)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 24 Feb 2020 19:44:45 +0000 (22:44 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 24 Feb 2020 19:44:45 +0000 (22:44 +0300) |
src/generic/Dsw/Mod/Procs.cp | patch | blob | history | |
src/posix/generic/Dsw/Mod/HostProcs.cp | patch | blob | history |
index 261415f6c0d86e6405cecf9c4dcd9dc535170e9e..e5a31b3c24a6a078d5942d6bd1812d5625e36b42 100644 (file)
IMPORT Kernel;
TYPE
+ String* = POINTER TO ARRAY OF CHAR;
+
Directory* = POINTER TO ABSTRACT RECORD END;
Process* = POINTER TO ABSTRACT RECORD END;
dir-, stdDir-: Directory;
PROCEDURE (d: Directory) New* (): Process, NEW, ABSTRACT;
+ PROCEDURE (d: Directory) GetPath* (IN name: ARRAY OF CHAR): String, NEW, ABSTRACT;
PROCEDURE (p: Process) Program* (IN exe: ARRAY OF CHAR), NEW, ABSTRACT;
PROCEDURE (p: Process) PutParam* (IN par: ARRAY OF CHAR), NEW, ABSTRACT;
index efe84737b230ce44a7bb1002943768e77c208231..2aa47588c7f01b23520cbb15b40d655d14a38486 100644 (file)
MODULE DswHostProcs;
- IMPORT SYSTEM, Log, DswProcs, HostLang, unistd := PosixCunistd, stdlib := PosixCstdlib,
+ IMPORT SYSTEM, DswProcs, HostLang, unistd := PosixCunistd, stdlib := PosixCstdlib,
signal := PosixCsignal, sys_wait := PosixCsys_wait, macro := PosixCmacro,
- errno := PosixCerrno;
+ errno := PosixCerrno, sys_stat := PosixCsys_stat;
TYPE
Directory = POINTER TO RECORD (DswProcs.Directory) END;
code: unistd.int;
END;
- PROCEDURE (d: Directory) New* (): Process;
- VAR p: Process;
- BEGIN
- NEW(p); p.argv := NIL; p.pid := -1; p.code := 0;
- RETURN p
- END New;
-
PROCEDURE ToHost (IN s: ARRAY OF CHAR): String;
VAR ss: String; res: INTEGER;
BEGIN
RETURN ss
END ToHost;
+ PROCEDURE IsRegular (mode: sys_stat.mode_t): BOOLEAN;
+ BEGIN
+ RETURN BITS(mode) * BITS(sys_stat.S_IFMT) = BITS(sys_stat.S_IFREG)
+ END IsRegular;
+
+ PROCEDURE (d: Directory) New* (): Process;
+ VAR p: Process;
+ BEGIN
+ NEW(p); p.argv := NIL; p.pid := -1; p.code := 0;
+ RETURN p
+ END New;
+
+ PROCEDURE (d: Directory) GetPath (IN name: ARRAY OF CHAR): DswProcs.String;
+ VAR
+ ch: CHAR;
+ v: POINTER [untagged] TO ARRAY [untagged] OF SHORTCHAR;
+ s, e, ret: POINTER TO ARRAY OF CHAR;
+ w: String;
+ cres: sys_stat.int;
+ i, j, k, len, res: INTEGER;
+ buf: sys_stat.struct_stat;
+ found: BOOLEAN;
+ BEGIN
+ v := stdlib.getenv("PATH");
+ IF v # NIL THEN
+ NEW(s, LEN(v$) * 3 + 1);
+ HostLang.HostToString(v$, s, HostLang.pep383x, res);
+ ASSERT(res = 0, 100);
+ len := LEN(name$);
+ NEW(e, LEN(s$) + len + 2);
+ i := 0;
+ REPEAT
+ j := -1; found := FALSE;
+ REPEAT ch := s[i]; INC(i); INC(j); e[j] := ch UNTIL (ch = ":") OR (ch = 0X);
+ IF e[0] = "/" THEN
+ e[j] := "/"; INC(j);
+ FOR k := 0 TO len DO
+ e[j + k] := name[k]
+ END;
+ e[j + k] := 0X;
+ w := ToHost(e);
+ cres := macro.stat(w, buf);
+ found := (cres = 0) & IsRegular(buf.st_mode) & (unistd.access(w, unistd.X_OK) = 0)
+ END
+ UNTIL found OR (ch = 0X);
+ IF ~found THEN e := NIL END
+ END;
+ RETURN e
+ END GetPath;
+
PROCEDURE (p: Process) Program* (IN exe: ARRAY OF CHAR);
VAR argv: SString;
BEGIN