summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 738684e)
raw | patch | inline | side by side (parent: 738684e)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Thu, 13 Feb 2020 21:33:17 +0000 (00:33 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Thu, 13 Feb 2020 21:33:17 +0000 (00:33 +0300) |
24 files changed:
index f704a52662d522706d6fa009cdfd7d1392463828..f7dab7da7822f842c5088647d1f7a00c78d487f9 100755 (executable)
--- a/make.sh
+++ b/make.sh
Posix/Mod/Csys_stat.cp Posix/Mod/Cfcntl.cp Posix/Mod/Cerrno.cp \
Posix/Mod/Ciconv.cp Posix/Mod/Cwctype.cp Posix/Mod/Csys_mman.cp \
Posix/Mod/Cdlfcn.cp Posix/Mod/Csignal.cp Posix/Mod/Csetjmp.cp \
- Posix/Mod/Clibgen.cp \
+ Posix/Mod/Clibgen.cp Posix/Mod/Csys_wait.cp \
Posix/Mod/Cmacro.cp
if [ "$_target" = "cpfront" ]; then
compile Lib/Mod/FFI.cp
if [ "$_target" = "native" ]; then
compile Dsw/Mod/Debug.odc
fi
- compile Dsw/Mod/Documents.cp Dsw/Mod/Log.odc Dsw/Mod/Compiler486Main.cp \
- Dsw/Mod/CompilerCPfrontMain.cp Dsw/Mod/Linker486Main.cp
+
+ compile Dsw/Mod/Documents.cp Dsw/Mod/Log.odc Dsw/Mod/Opts.cp Dsw/Mod/Procs.cp
+ compile Dsw/Mod/HostProcs.cp
+
+ ###^^^^^^^^^^^^^^^^^^^^^^^^^^^###
+ ### Compile bbdsw executables ###
+ ###___________________________###
+
+ compile \
+ Dsw/Mod/Compiler486Main.cp \
+ Dsw/Mod/CompilerCPfrontMain.cp \
+ Dsw/Mod/Linker486Main.cp \
+ Dsw/Mod/MakeMain.cp
}
link_all() {
CPfrontCPG CPfrontCPC CPfrontCPV\
DswDocuments DswCompilerCPfrontMain
+ link cpmake \
+ PosixCtypes PosixCmacro \
+ Kernel Console Files Dates Math Strings Services Log \
+ HostLang HostConsole HostFiles HostDates DswLog $_debug_module \
+ DevCPM DevCPT DevCPR DevCPS \
+ DswDocuments DswOpts DswProcs DswHostProcs DswMakeMain
+
if $_dolink; then
chmod a+x cpc486 cpl486 cpfront
fi
index 4391cfbd41c4325332913f5b46302f049c66fe46..ada0d29b517c49623415760b5b9c75771b00386d 100644 (file)
ENOTCONN* = 107;
ENOTDIR* = 20;
ENOTEMPTY* = 39;
- ENOTRECOVERABLE* = 131;
ENOTSOCK* = 88;
ENOTSUP* = 95;
ENOTTY* = 25;
ENXIO* = 6;
EOPNOTSUPP* = 95;
EOVERFLOW* = 75;
- EOWNERDEAD* = 130;
EPERM* = 1;
EPIPE* = 32;
EPROTO* = 71;
EWOULDBLOCK* = 11;
EXDEV* = 18;
+ CONST
+ ENOTRECOVERABLE* = 131;
+ EOWNERDEAD* = 130;
+
PROCEDURE [ccall] __errno_location* (): POINTER TO ARRAY [untagged] 1 OF int;
END PosixCerrno.
index 25c73a5623fc8db65a20e7a87fe84ae9fce9ae68..157ea20840465c5138ef2fcf8d1a2de381d7c88f 100644 (file)
CONST
F_DUPFD* = 0;
- F_DUPFD_CLOEXEC* = 1030;
F_GETFD* = 1;
F_SETFD* = 2;
F_GETFL* = 3;
F_GETOWN* = 9;
F_SETOWN* = 8;
+ CONST
+ F_DUPFD_CLOEXEC* = 1030;
+
CONST
FD_CLOEXEC* = 1;
SEEK_END* = 2;
CONST
- O_CLOEXEC* = 524288;
O_CREAT* = 64;
O_DIRECTORY* = 65536;
O_EXCL* = 128;
O_NOFOLLOW* = 131072;
O_TRUNC* = 512;
O_APPEND* = 1024;
- O_DSYNC* = 4096;
O_NONBLOCK* = 2048;
- O_RSYNC* = 1052672;
O_SYNC* = 1052672;
O_ACCMODE* = 3;
O_RDONLY* = 0;
O_RDWR* = 2;
O_WRONLY* = 1;
+ CONST
+ O_CLOEXEC* = 524288;
+ O_DSYNC* = 4096;
+ O_RSYNC* = 1052672;
+
CONST
AT_FDCWD* = -100;
AT_EACCESS* = 512;
diff --git a/src/cpfront/linux/486/Posix/Mod/Csys_types.cp b/src/cpfront/linux/486/Posix/Mod/Csys_types.cp
index 25f6e93a570e860da43a790e14017b62f74bf153..48fe5003dd978d6b5e436e1dc51fe0e6b6a8cff6 100644 (file)
blkcnt_t* = INTEGER;
blksize_t* = INTEGER;
clock_t* = INTEGER;
- clockid_t* = INTEGER;
- dev_t* = LONGINT;
+ dev_t* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END;
fsblkcnt_t* = INTEGER;
fsfilcnt_t* = INTEGER;
gid_t* = INTEGER;
off_t* = INTEGER;
pid_t* = INTEGER;
pthread_attr_t* = RECORD [noalign] _: ARRAY [untagged] 36 OF BYTE END;
- pthread_barrier_t* = RECORD [noalign] _: ARRAY [untagged] 20 OF BYTE END;
- pthread_barrierattr_t* = INTEGER;
pthread_cond_t* = RECORD [noalign] _: ARRAY [untagged] 48 OF BYTE END;
pthread_condattr_t* = INTEGER;
pthread_key_t* = INTEGER;
pthread_once_t* = INTEGER;
pthread_rwlock_t* = RECORD [noalign] _: ARRAY [untagged] 32 OF BYTE END;
pthread_rwlockattr_t* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END;
- pthread_spinlock_t* = INTEGER;
pthread_t* = INTEGER;
size_t* = INTEGER;
ssize_t* = INTEGER;
suseconds_t* = INTEGER;
time_t* = INTEGER;
- timer_t* = INTEGER;
uid_t* = INTEGER;
+ TYPE
+ pthread_barrier_t* = RECORD [noalign] _: ARRAY [untagged] 20 OF BYTE END;
+ pthread_barrierattr_t* = INTEGER;
+ pthread_spinlock_t* = INTEGER;
+ timer_t* = INTEGER;
+ clockid_t* = INTEGER;
+
END PosixCsys_types.
diff --git a/src/cpfront/linux/486/Posix/Mod/Csys_wait.cp b/src/cpfront/linux/486/Posix/Mod/Csys_wait.cp
--- /dev/null
@@ -0,0 +1,67 @@
+MODULE PosixCsys_wait ['sys/wait.h'];
+
+ (* generated by genposix.sh, do not modify *)
+
+ IMPORT SYSTEM, PosixCtypes, PosixCsys_types, PosixCsignal;
+
+ TYPE
+ char* = PosixCtypes.char;
+ signed_char* = PosixCtypes.signed_char;
+ unsigned_char* = PosixCtypes.unsigned_char;
+ short* = PosixCtypes.short;
+ short_int* = PosixCtypes.short_int;
+ signed_short* = PosixCtypes.signed_short;
+ signed_short_int* = PosixCtypes.signed_short_int;
+ unsigned_short* = PosixCtypes.unsigned_short;
+ unsigned_short_int* = PosixCtypes.unsigned_short_int;
+ int* = PosixCtypes.int;
+ signed* = PosixCtypes.signed;
+ signed_int* = PosixCtypes.signed_int;
+ unsigned* = PosixCtypes.unsigned;
+ unsigned_int* = PosixCtypes.unsigned_int;
+ long* = PosixCtypes.long;
+ long_int* = PosixCtypes.long_int;
+ signed_long* = PosixCtypes.signed_long;
+ signed_long_int* = PosixCtypes.signed_long_int;
+ unsigned_long* = PosixCtypes.unsigned_long;
+ unsigned_long_int* = PosixCtypes.unsigned_long_int;
+ long_long* = PosixCtypes.long_long;
+ long_long_int* = PosixCtypes.long_long_int;
+ signed_long_long* = PosixCtypes.signed_long_long;
+ signed_long_long_int* = PosixCtypes.signed_long_long_int;
+ unsigned_long_long* = PosixCtypes.unsigned_long_long;
+ unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int;
+ float* = PosixCtypes.float;
+ double* = PosixCtypes.double;
+ long_double* = PosixCtypes.long_double;
+
+ CONST
+ WCONTINUED* = 8;
+ WNOHANG* = 1;
+ WUNTRACED* = 2;
+
+ CONST
+ WEXITED* = 4;
+ WNOWAIT* = 16777216;
+ WSTOPPED* = 2;
+
+ TYPE
+ idtype_t* = INTEGER;
+
+ CONST
+ P_ALL* = 0;
+ P_PGID* = 2;
+ P_PID* = 1;
+
+ TYPE
+ id_t* = PosixCsys_types.id_t;
+ pid_t* = PosixCsys_types.pid_t;
+
+ TYPE
+ siginfo_t* = PosixCsignal.siginfo_t;
+
+ PROCEDURE [ccall] wait* (VAR [nil] wstatus: int): pid_t;
+ PROCEDURE [ccall] waitid* (idtype: idtype_t; id: id_t; VAR [nil] infop: siginfo_t; options: int): int;
+ PROCEDURE [ccall] waitpid* (pid: pid_t; VAR [nil] wstatus: int; options: int): pid_t;
+
+END PosixCsys_wait.
index e9ece924f2de5b57b2500c4fc8fd03fac663a2fd..9f2033bb18e7de473dcf3b3823ffb422e4454b87 100644 (file)
clock_t* = PosixCsys_types.clock_t;
size_t* = PosixCsys_types.size_t;
time_t* = PosixCsys_types.time_t;
- clockid_t* = PosixCsys_types.clockid_t;
- timer_t* = PosixCsys_types.timer_t;
pid_t* = PosixCsys_types.pid_t;
+ TYPE
+ timer_t* = PosixCsys_types.timer_t;
+ clockid_t* = PosixCsys_types.clockid_t;
+
TYPE
locale_t* = PosixClocale.locale_t;
index 6cdc535f8569becd6b1f4b73e7ad8b90bca5fa1f..46c2a3bf09fdf5353cc4627b5ae2209714691c16 100644 (file)
long_long_int* = LONGINT;
signed_long_long* = LONGINT;
signed_long_long_int* = LONGINT;
- unsigned_long_long* = LONGINT;
- unsigned_long_long_int* = LONGINT;
+ unsigned_long_long* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END;
+ unsigned_long_long_int* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END;
float* = SHORTREAL;
double* = REAL;
long_double* = RECORD [noalign] _: ARRAY [untagged] 12 OF BYTE END;
index 2bc66082f6eeca4beca840e6020fbdc28da29727..25c73a5623fc8db65a20e7a87fe84ae9fce9ae68 100644 (file)
CONST
O_CLOEXEC* = 524288;
O_CREAT* = 64;
- O_DIRECTORY* = 16384;
+ O_DIRECTORY* = 65536;
O_EXCL* = 128;
O_NOCTTY* = 256;
- O_NOFOLLOW* = 32768;
+ O_NOFOLLOW* = 131072;
O_TRUNC* = 512;
O_APPEND* = 1024;
O_DSYNC* = 4096;
diff --git a/src/cpfront/linux/arm/Posix/Mod/Csetjmp.cp b/src/cpfront/linux/arm/Posix/Mod/Csetjmp.cp
index 269c6f2825a734f704eb6a89da397fab0ad56ac7..2a44eadfba37ce9e555c0bec3ddba8373814aa59 100644 (file)
long_double* = PosixCtypes.long_double;
TYPE
- jmp_buf* = ARRAY [untagged] 392 OF BYTE;
- sigjmp_buf* = ARRAY [untagged] 392 OF BYTE;
+ jmp_buf* = ARRAY [untagged] 156 OF BYTE;
+ sigjmp_buf* = ARRAY [untagged] 156 OF BYTE;
PROCEDURE [ccall] _longjmp* (IN env: jmp_buf; val: int);
PROCEDURE [ccall] longjmp* (IN env: jmp_buf; val: int);
diff --git a/src/cpfront/linux/arm/Posix/Mod/Csignal.cp b/src/cpfront/linux/arm/Posix/Mod/Csignal.cp
index df1f93489e1faf221d5ae8b00549cbfb38873a72..1e2c77df9f1676389a6a96c9d83af39d875597bc 100644 (file)
SIGTTOU* = 22;
SIGUSR1* = 10;
SIGUSR2* = 12;
- SIGPOLL* = 29;
- SIGPROF* = 27;
SIGSYS* = 31;
SIGTRAP* = 5;
SIGURG* = 23;
TYPE
Pstruct_sigaction* = POINTER TO struct_sigaction;
struct_sigaction* ['struct sigaction'] = RECORD [noalign] (* 140 *)
- handler*: RECORD [union] (* 4 *)
- sa_handler*: PROCEDURE [ccall] (sig: int); (* 0+4 *)
- sa_sigaction*: PROCEDURE [ccall] (sig: int; IN siginfo: siginfo_t; context: PosixCtypes.Pvoid); (* 0+4 *)
+ handler* ["/*handler"]: RECORD [union] (* 4 *)
+ sa_handler* ["*/sa_handler"]: PROCEDURE [ccall] (sig: int); (* 0+4 *)
+ sa_sigaction* ["*/sa_sigaction"]: PROCEDURE [ccall] (sig: int; IN siginfo: siginfo_t; context: PosixCtypes.Pvoid); (* 0+4 *)
END; (* 0+4 *)
sa_mask*: sigset_t; (* 4+128 *)
sa_flags*: int; (* 132+4 *)
SA_RESETHAND* = -2147483648;
SA_RESTART* = 268435456;
SA_SIGINFO* = 4;
- SA_NOCLDWAIT* = 2;
SA_NODEFER* = 1073741824;
SS_ONSTACK* = 1;
SS_DISABLE* = 2;
MINSIGSTKSZ* = 2048;
SIGSTKSZ* = 8192;
+ CONST
+ __NGREG* = 19;
+
+ TYPE
+ greg_t* = INTEGER;
+
+ TYPE gregset_t* = ARRAY [untagged] __NGREG OF greg_t;
+
+ TYPE
+ Pstruct__libc_fpreg* = POINTER TO struct__libc_fpreg;
+ struct__libc_fpreg* ['struct _libc_fpreg'] = RECORD [noalign] (* 10 *)
+ significand*: INTEGER; (* 0+8 *)
+ exponent*: unsigned_short_int; (* 8+2 *)
+ END;
+
+ TYPE
+ Pstruct__libc_fpstate* = POINTER TO struct__libc_fpstate;
+ struct__libc_fpstate* ['struct _libc_fpstate'] = RECORD [noalign] (* 112 *)
+ cw*: unsigned_long_int; (* 0+4 *)
+ sw*: unsigned_long_int; (* 4+4 *)
+ tag*: unsigned_long_int; (* 8+4 *)
+ ipoff*: unsigned_long_int; (* 12+4 *)
+ cssel*: unsigned_long_int; (* 16+4 *)
+ dataoff*: unsigned_long_int; (* 20+4 *)
+ datasel*: unsigned_long_int; (* 24+4 *)
+ _st*: ARRAY [untagged] 8 OF struct__libc_fpreg; (* 28+80 *)
+ status*: unsigned_long_int; (* 108+4 *)
+ END;
+
+ TYPE fpregset_t* = Pstruct__libc_fpstate;
+
TYPE
- mcontext_t* = RECORD [noalign] _: ARRAY [untagged] 84 OF BYTE END;
+ Pmcontext_t* = POINTER TO mcontext_t;
+ mcontext_t* ['mcontext_t'] = RECORD [noalign] (* 88 *)
+ gregs*: gregset_t; (* 0+76 *)
+ fpregs*: fpregset_t; (* 76+4 *)
+ oldmask*: unsigned_long_int; (* 80+4 *)
+ cr2*: unsigned_long_int; (* 84+4 *)
+ END;
TYPE
Pucontext_t* = POINTER TO ucontext_t;
- ucontext_t* ['ucontext_t'] = RECORD [noalign] (* 744 *)
+ ucontext_t* ['ucontext_t'] = RECORD [noalign] (* 348 *)
+ uc_flags*: unsigned_long_int; (* 0+4 *)
uc_link*: Pucontext_t; (* 4+4 *)
uc_stack*: stack_t; (* 8+12 *)
- uc_mcontext*: mcontext_t; (* 20+84 *)
- uc_sigmask*: sigset_t; (* 104+128 *)
+ uc_mcontext*: mcontext_t; (* 20+88 *)
+ uc_sigmask*: sigset_t; (* 108+128 *)
+ __fpregs_mem*: struct__libc_fpstate; (* 236+112 *)
END;
TYPE
ss_size*: size_t; (* 8+4 *)
END;
- TYPE
- P_siginfo_t* = POINTER TO _siginfo_t;
- _siginfo_t* ['siginfo_t'] = RECORD [noalign] (* 128 *)
- si_signo*: int; (* 0+4 *)
- si_errno*: int; (* 4+4 *)
- si_code*: int; (* 8+4 *)
- si_pid*: pid_t; (* 12+4 *)
- si_addr*: PosixCtypes.Pvoid; (* 12+4 *)
- si_band*: long; (* 12+4 *)
- si_uid*: uid_t; (* 16+4 *)
- si_status*: int; (* 20+4 *)
- si_value*: union_sigval; (* 20+4 *)
- END;
-
TYPE
Psiginfo_t* = POINTER TO siginfo_t;
siginfo_t* ['siginfo_t'] = RECORD [noalign] (* 128 *)
si_signo*: int; (* 0+4 *)
si_errno*: int; (* 4+4 *)
si_code*: int; (* 8+4 *)
- info*: RECORD [union] (* 12 *)
+ info* ["/*info"]: RECORD [union] (* 12 *)
sigill*: RECORD [noalign] (* 4 *)
- si_addr*: PosixCtypes.Pvoid; (* 0+4 *)
+ si_addr* ["*/si_addr"]: PosixCtypes.Pvoid; (* 0+4 *)
END; (* 0+4 *)
sigfpe*: RECORD [noalign] (* 4 *)
- si_addr*: PosixCtypes.Pvoid; (* 0+4 *)
+ si_addr* ["*/si_addr"]: PosixCtypes.Pvoid; (* 0+4 *)
END; (* 0+4 *)
sigsegv*: RECORD [noalign] (* 4 *)
- si_addr*: PosixCtypes.Pvoid; (* 0+4 *)
+ si_addr* ["*/si_addr"]: PosixCtypes.Pvoid; (* 0+4 *)
END; (* 0+4 *)
sigbus*: RECORD [noalign] (* 4 *)
- si_addr*: PosixCtypes.Pvoid; (* 0+4 *)
+ si_addr* ["*/si_addr"]: PosixCtypes.Pvoid; (* 0+4 *)
END; (* 0+4 *)
sigchld*: RECORD [noalign] (* 12 *)
- si_pid*: pid_t; (* 0+4 *)
- si_uid*: uid_t; (* 4+4 *)
- si_status*: int; (* 8+4 *)
+ si_pid* ["*/si_pid"]: pid_t; (* 0+4 *)
+ si_uid* ["*/si_uid"]: uid_t; (* 4+4 *)
+ si_status* ["*/si_status"]: int; (* 8+4 *)
END; (* 0+12 *)
- sigpoll*: RECORD [noalign] (* 4 *)
- si_band*: long; (* 0+4 *)
- END; (* 0+4 *)
other*: RECORD [noalign] (* 4 *)
- si_value*: union_sigval; (* 0+4 *)
+ si_value* ["*/si_value"]: union_sigval; (* 0+4 *)
END; (* 8+4 *)
END; (* 12+12 *)
END;
CLD_STOPPED* = 5;
CLD_CONTINUED* = 6;
- CONST
- POLL_IN* = 1;
- POLL_OUT* = 2;
- POLL_MSG* = 3;
- POLL_ERR* = 4;
- POLL_PRI* = 5;
- POLL_HUP* = 6;
-
CONST
SI_USER* = 0;
SI_QUEUE* = -1;
PROCEDURE [ccall] psiginfo* (IN pinfo: siginfo_t; IN [nil] s: ARRAY [untagged] OF SHORTCHAR);
PROCEDURE [ccall] psignal* (sig: int; IN [nil] s: ARRAY [untagged] OF SHORTCHAR);
PROCEDURE [ccall] pthread_kill* (thread: pthread_t; sig: int): int;
- PROCEDURE [ccall] pthread_sigmask* (how: int; IN [nil] set: sigset_t; VAR [nil] oldset: sigset_t): int;
+ PROCEDURE [ccall] pthread_sigmask* (how: int; VAR [nil] set: sigset_t; VAR [nil] oldset: sigset_t): int;
PROCEDURE [ccall] raise* (sig: int): int;
PROCEDURE [ccall] sigaction* (sig: int; IN [nil] act: struct_sigaction; VAR [nil] oact: struct_sigaction): int;
PROCEDURE [ccall] sigaddset* (VAR set: sigset_t; signum: int): int;
PROCEDURE [ccall] sigdelset* (VAR set: sigset_t; signum: int): int;
PROCEDURE [ccall] sigemptyset* (VAR set: sigset_t): int;
PROCEDURE [ccall] sigfillset* (VAR set: sigset_t): int;
- PROCEDURE [ccall] sighold* (sig: int): int;
- PROCEDURE [ccall] sigignore* (sig: int): int;
- PROCEDURE [ccall] siginterrupt* (sig, flag: int): int;
- PROCEDURE [ccall] sigismember* (IN set: sigset_t; signum: int): int;
- PROCEDURE [ccall] sigpause* (sig: int): int;
+ PROCEDURE [ccall] sigismember* (VAR set: sigset_t; signum: int): int;
PROCEDURE [ccall] sigpending* (VAR set: sigset_t): int;
- PROCEDURE [ccall] sigprocmask* (how: int; IN [nil] set: sigset_t; VAR [nil] oset: sigset_t): int;
+ PROCEDURE [ccall] sigprocmask* (how: int; VAR [nil] set: sigset_t; VAR [nil] oset: sigset_t): int;
PROCEDURE [ccall] sigqueue* (pid: pid_t; sig: int; IN value: union_sigval): int;
- PROCEDURE [ccall] sigrelse* (sig: int): int;
- PROCEDURE [ccall] sigsuspend* (IN sigmask: sigset_t): int;
- PROCEDURE [ccall] sigtimedwait* (IN set: sigset_t; VAR [nil] info: siginfo_t; IN timeout: struct_timespec): int;
- PROCEDURE [ccall] sigwait* (IN set: sigset_t; VAR sig: int): int;
- PROCEDURE [ccall] sigwaitinfo* (IN set: sigset_t; VAR [nil] info: siginfo_t): int;
+ PROCEDURE [ccall] sigsuspend* (VAR sigmask: sigset_t): int;
+ PROCEDURE [ccall] sigtimedwait* (VAR set: sigset_t; VAR [nil] info: siginfo_t; IN timeout: struct_timespec): int;
+ PROCEDURE [ccall] sigwait* (VAR set: sigset_t; VAR sig: int): int;
+ PROCEDURE [ccall] sigwaitinfo* (VAR set: sigset_t; VAR [nil] info: siginfo_t): int;
END PosixCsignal.
diff --git a/src/cpfront/linux/arm/Posix/Mod/Csys_mman.cp b/src/cpfront/linux/arm/Posix/Mod/Csys_mman.cp
index 6ff9357cb52c7eba00e59bde7e7b4d4b50edc4f3..d27cecd5a8f00a9dfccfd4ac8b4e866cc2f8ba69 100644 (file)
MS_INVALIDATE* = 2;
MS_SYNC* = 4;
- CONST
- MCL_CURRENT* = 1;
- MCL_FUTURE* = 2;
-
CONST
MAP_FAILED* = -1;
size_t* = PosixCsys_types.size_t;
PROCEDURE [ccall] mlock* (addr: PosixCtypes.Pvoid; len: size_t): int;
- PROCEDURE [ccall] mlockall* (flags: int): int;
PROCEDURE [ccall] mmap* (addr: PosixCtypes.Pvoid; len: size_t; prot, flags, fildes: int; off: off_t): PosixCtypes.Pvoid;
PROCEDURE [ccall] mprotect* (addr: PosixCtypes.Pvoid; len: size_t; prot: int): int;
PROCEDURE [ccall] msync* (addr: PosixCtypes.Pvoid; len: size_t; flags: int): int;
PROCEDURE [ccall] munlock* (addr: PosixCtypes.Pvoid; len: size_t): int;
- PROCEDURE [ccall] munlockall* (): int;
PROCEDURE [ccall] munmap* (addr: PosixCtypes.Pvoid; len: size_t): int;
PROCEDURE [ccall] posix_madvise* (addr: PosixCtypes.Pvoid; len: size_t; advice: int): int;
PROCEDURE [ccall] posix_mem_offset* (addr: PosixCtypes.Pvoid; len: size_t; VAR off: off_t; VAR contng_len: size_t; VAR fildes: int): int;
index fab32f1f5735ff586fdc0e0565654164c76b89d8..6cdc535f8569becd6b1f4b73e7ad8b90bca5fa1f 100644 (file)
unsigned_long_long_int* = LONGINT;
float* = SHORTREAL;
double* = REAL;
- long_double* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END;
+ long_double* = RECORD [noalign] _: ARRAY [untagged] 12 OF BYTE END;
Pvoid* = INTEGER;
diff --git a/src/generic/Dsw/Mod/MakeMain.cp b/src/generic/Dsw/Mod/MakeMain.cp
--- /dev/null
@@ -0,0 +1,563 @@
+MODULE DswMakeMain;
+
+ IMPORT Kernel, Files, Log, Strings, DswOpts, DswProcs, DswDocuments, DevCPM, DevCPT, DevCPR, DevCPS;
+
+ CONST
+ maxImps = 127;
+ maxJobs = maxImps;
+
+ (* symbol values *)
+ null = 0; times = 1; slash = 2; div = 3; mod = 4;
+ and = 5; plus = 6; minus = 7; or = 8; eql = 9;
+ neq = 10; lss = 11; leq = 12; gtr = 13; geq = 14;
+ in = 15; is = 16; arrow = 17; dollar = 18; period = 19;
+ comma = 20; colon = 21; upto = 22; rparen = 23; rbrak = 24;
+ rbrace = 25; of = 26; then = 27; do = 28; to = 29;
+ by = 30; not = 33;
+ lparen = 40; lbrak = 41; lbrace = 42; becomes = 44;
+ number = 45; nil = 46; string = 47; ident = 48; semicolon = 49;
+ bar = 50; end = 51; else = 52; elsif = 53; until = 54;
+ if = 55; case = 56; while = 57; repeat = 58; for = 59;
+ loop = 60; with = 61; exit = 62; return = 63; array = 64;
+ record = 65; pointer = 66; begin = 67; const = 68; type = 69;
+ var = 70; out = 71; procedure = 72; close = 73; import = 74;
+ module = 75; eof = 76;
+
+ (* module state flags *)
+ imported = 0; trace = 1; hasObj = 2; hasSym = 3; hasErrors = 4; library = 5;
+
+ debugImport = FALSE;
+ debugJobs = FALSE;
+
+ TYPE
+ String = POINTER TO ARRAY OF CHAR;
+
+ Selector = POINTER TO RECORD
+ name: DevCPT.Name;
+ value: BOOLEAN;
+ next: Selector
+ END;
+
+ Module = POINTER TO RECORD
+ name: DevCPT.Name;
+ path: Files.Name;
+ selectors: Selector; (* with head, list of selectors for this module *)
+ mno, depth: INTEGER;
+ imp: ARRAY maxImps OF Module;
+ flags: SET;
+ worker: DswProcs.Process;
+ END;
+
+ VAR
+ err: INTEGER;
+ mno, rno: INTEGER; (* num modules *)
+ modList, lnkList, cmpList: ARRAY maxImps OF Module;
+ def: Selector; (* with head, global list of selectors *)
+ auto: INTEGER;
+ jobs: INTEGER;
+ exe: String;
+
+ PROCEDURE IdentLen (IN s: ARRAY OF CHAR): INTEGER;
+ VAR i: INTEGER;
+ BEGIN
+ i := 0;
+ IF Strings.IsIdentStart(s[0]) THEN
+ REPEAT INC(i) UNTIL ~Strings.IsIdent(s[i])
+ END;
+ RETURN i
+ END IdentLen;
+
+ PROCEDURE Define (n: ARRAY OF CHAR);
+ VAR i: INTEGER; v: BOOLEAN; s: Selector;
+ BEGIN
+ i := IdentLen(n);
+ IF i # 0 THEN
+ IF ~((n[i] = 0X) OR (((n[i] = "+") OR (n[i] = "-")) & (n[i + 1] = 0X))) THEN
+ Log.String("option -D expect + or - after identifier"); Log.Ln; INC(err)
+ END;
+ v := n[i] # "-"; n[i] := 0X; s := def;
+ WHILE (s.next # NIL) & (s.next.name$ # n$) DO s := s.next END;
+ IF s.next = NIL THEN
+ NEW(s.next);
+ Strings.StringToUtf8(n, s.next.name, i);
+ ASSERT(i = 0)
+ END;
+ s.next.value := v
+ ELSE
+ Log.String("option -D expect identifier"); Log.Ln; INC(err)
+ END
+ END Define;
+
+ PROCEDURE Undefine (IN n: ARRAY OF CHAR);
+ VAR i: INTEGER; s: Selector;
+ BEGIN
+ i := IdentLen(n);
+ IF (i # 0) & (n[i] = 0X) THEN
+ s := def;
+ WHILE (s.next # NIL) & (s.next.name$ # n$) DO s := s.next END;
+ IF s.next # NIL THEN s.next := s.next.next END
+ ELSE
+ Log.String("option -U expect identifier"); Log.Ln; INC(err)
+ END
+ END Undefine;
+
+ PROCEDURE CopySelectorList (base: Selector): Selector;
+ VAR s, t, x: Selector;
+ BEGIN
+ ASSERT(base # NIL, 20);
+ s := base; NEW(t); x := t;
+ WHILE s # NIL DO
+ x^ := s^;
+ IF s.next # NIL THEN NEW(x.next); x := x.next END;
+ s := s.next
+ END;
+ RETURN t
+ END CopySelectorList;
+
+ PROCEDURE AddModule (IN n: ARRAY OF CHAR; selectors: Selector);
+ VAR i, res: INTEGER; m: Module;
+ BEGIN
+ i := IdentLen(n);
+ IF (i # 0) & (n[i] = 0X) THEN
+ i := 0;
+ WHILE (i < mno) & (modList[i].name$ # n$) DO INC(i) END;
+ IF i >= mno THEN
+ NEW(m);
+ Strings.StringToUtf8(n, m.name, res);
+ ASSERT(res = 0);
+ m.selectors := CopySelectorList(selectors);
+ modList[i] := m;
+ INC(mno)
+ END
+ ELSE
+ Log.String("module name must be identifier"); Log.Ln; INC(err)
+ END
+ END AddModule;
+
+ PROCEDURE StrToInt (IN s: ARRAY OF CHAR; def: INTEGER): INTEGER;
+ VAR x, res: INTEGER;
+ BEGIN
+ Strings.StringToInt(s, x, res);
+ IF res # 0 THEN
+ Log.String("expected integer"); Log.Ln; INC(err);
+ x := def
+ END;
+ RETURN x
+ END StrToInt;
+
+ PROCEDURE ParseArgs;
+ VAR res: INTEGER;
+ BEGIN
+ jobs := 1;
+ LOOP
+ CASE DswOpts.GetOpt("ao:j:D:U:") OF
+ | "a": INC(auto)
+ | "o": exe := DswOpts.str
+ | "j": IF DswOpts.str = NIL THEN jobs := maxJobs ELSE jobs := MIN(MAX(StrToInt(DswOpts.str, 0), 1), maxJobs) END
+ | "D": Define(DswOpts.str)
+ | "U": Undefine(DswOpts.str)
+ | ":": Log.String("missing argument for option -"); Log.String(DswOpts.str); Log.Ln; INC(err)
+ | "?": Log.String("unknown option -"); Log.String(DswOpts.str); Log.Ln; INC(err)
+ | "$": AddModule(DswOpts.str, def)
+ | 0X: EXIT
+ END
+ END
+ END ParseArgs;
+
+ PROCEDURE Import (m: Module; IN name: DevCPT.Name);
+ VAR i, j: INTEGER; imp: Module;
+ BEGIN
+ ASSERT(m # NIL, 20);
+ ASSERT(name # "", 21);
+ IF debugImport THEN Log.String(" import "); Log.String(name$) END;
+ IF name = "SYSTEM" THEN INCL(DevCPM.options, DevCPM.sysImp)
+ ELSIF name = "COM" THEN INCL(DevCPM.options, DevCPM.com)
+ ELSIF name = "JAVA" THEN INCL(DevCPM.options, DevCPM.java)
+ ELSE
+ IF debugImport THEN Log.Char(" ") END;
+ i := 0; (* find module in local list *)
+ WHILE (i < m.mno) & (m.imp[i].name$ # name$) DO INC(i) END;
+ IF i >= m.mno THEN
+ j := 0; (* find module in global list *)
+ WHILE (j < mno) & (modList[j].name$ # name$) DO INC(j) END;
+ IF j >= mno THEN
+ NEW(imp); imp.name := name$; imp.selectors := CopySelectorList(m.selectors);
+ modList[mno] := imp; INC(mno)
+ ELSE
+ imp := modList[j]
+ END;
+ m.imp[m.mno] := imp; INC(m.mno)
+ ELSE DevCPM.err(1)
+ END
+ END;
+ IF debugImport THEN Log.Ln END;
+ END Import;
+
+ PROCEDURE ParseModule (m: Module);
+ VAR sym: BYTE; SelfName, impName, aliasName: DevCPT.Name;
+
+ PROCEDURE err (n: SHORTINT);
+ BEGIN DevCPM.err(n)
+ END err;
+
+ PROCEDURE CheckSym(s: SHORTINT);
+ BEGIN
+ IF sym = s THEN DevCPS.Get(sym) ELSE DevCPM.err(s) END
+ END CheckSym;
+
+ BEGIN
+ IF debugImport THEN Log.String("module " + m.name); Log.Ln END;
+ DevCPS.Init; DevCPS.Get(sym);
+ IF sym = module THEN DevCPS.Get(sym) ELSE err(16) END;
+ IF sym = ident THEN
+ SelfName := DevCPS.name$; DevCPS.Get(sym);
+ IF sym = lbrak THEN
+ INCL(DevCPM.options, DevCPM.interface); DevCPS.Get(sym);
+ IF sym = eql THEN DevCPS.Get(sym)
+ ELSE INCL(DevCPM.options, DevCPM.noCode)
+ END;
+ IF sym = string THEN INCL(m.flags, library); DevCPS.Get(sym)
+ ELSE err(string)
+ END;
+ CheckSym(rbrak)
+ END;
+ CheckSym(semicolon);
+ IF sym = import THEN DevCPS.Get(sym);
+ LOOP
+ IF sym = ident THEN
+ aliasName := DevCPS.name$; impName := aliasName$; DevCPS.Get(sym);
+ IF sym = becomes THEN DevCPS.Get(sym);
+ IF sym = ident THEN impName := DevCPS.name$; DevCPS.Get(sym) ELSE err(ident) END
+ END;
+ Import(m, impName)
+ ELSE err(ident)
+ END;
+ IF sym = comma THEN DevCPS.Get(sym)
+ ELSIF sym = ident THEN err(comma)
+ ELSE EXIT
+ END
+ END;
+ CheckSym(semicolon)
+ END
+ ELSE err(ident)
+ END;
+ DevCPS.str := NIL
+ END ParseModule;
+
+ PROCEDURE CheckModule (m: Module; source: String; OUT ok: BOOLEAN);
+ VAR s: Selector;
+ BEGIN
+ DevCPM.Init(source);
+(*
+ DevCPM.symList := m.insym;
+ DevCPM.codePath := m.outcode;
+ DevCPM.symPath := m.outsym;
+*)
+ DevCPM.name := m.name$;
+(*
+ IF m.found THEN INCL(DevCPM.options, DevCPM.comAware) END;
+ IF errorTrap IN m.opts THEN INCL(DevCPM.options, DevCPM.trap) END;
+ IF oberon IN m.opts THEN INCL(DevCPM.options, DevCPM.oberon) END;
+*)
+ DevCPR.Init;
+ s := m.selectors.next;
+ WHILE s # NIL DO
+ DevCPR.Set(s.name, s.value);
+ s := s.next
+ END;
+ ParseModule(m);
+ DevCPR.Check;
+ ok := DevCPM.noerr;
+ DevCPR.Close;
+ DevCPM.InsertMarks;
+ DevCPM.Close;
+ Kernel.FastCollect
+ END CheckModule;
+
+ PROCEDURE GetSource (IN modName: ARRAY OF CHAR; OUT path: Files.Name; OUT s: String);
+ CONST modDir = "Mod"; sysDir = "System";
+ VAR dir, name: Files.Name; loc: Files.Locator;
+ text: DswDocuments.Model; r: DswDocuments.Reader; i, res: INTEGER;
+
+ PROCEDURE MakePath (dir, name: Files.Name; type: Files.Type; OUT path: Files.Name);
+ BEGIN
+ ASSERT(name # "", 21);
+ IF dir = "" THEN path := modDir + "/" + name
+ ELSE path := dir + "/" + modDir + "/" + name
+ END;
+ Kernel.MakeFileName(path, type)
+ END MakePath;
+
+ BEGIN
+ s := NIL; path := "";
+ Kernel.SplitName(modName, dir, name);
+ loc := Files.dir.This(dir).This(modDir);
+ (* --> Kernel.MakeFileName(name, Kernel.docType); <-- *)
+ MakePath(dir, name, "cp", path);
+ DswDocuments.Open(loc, name + ".cp", text, res);
+ IF text = NIL THEN
+ MakePath(dir, name, "odc", path);
+ DswDocuments.Open(loc, name + ".odc", text, res);
+ IF (text = NIL) & (dir = "") THEN
+ MakePath(sysDir, name, "cp", path);
+ loc := Files.dir.This(sysDir).This(modDir);
+ DswDocuments.Open(loc, name + ".cp", text, res);
+ IF text = NIL THEN
+ MakePath(sysDir, name, "odc", path);
+ DswDocuments.Open(loc, name + ".odc", text, res);
+ IF text = NIL THEN
+ path := ""
+ END
+ END
+ END
+ END;
+ IF text # NIL THEN
+ NEW(s, text.Length() + 1);
+ IF s # NIL THEN
+ r := text.NewReader(NIL);
+ FOR i := 0 TO text.Length() - 1 DO
+ r.Read; s[i] := r.char
+ END
+ END
+ END
+ END GetSource;
+
+ PROCEDURE Trace (m, parent: Module; depth: INTEGER; VAR lno: INTEGER);
+ VAR i: INTEGER;
+ BEGIN
+ m.depth := MAX(m.depth, depth);
+ IF ~(trace IN m.flags) THEN
+ INCL(m.flags, trace);
+ IF m.mno > 0 THEN
+ FOR i := 0 TO m.mno - 1 DO
+ Trace(m.imp[i], m, depth + 1, lno)
+ END
+ END;
+ IF ~(imported IN m.flags) THEN
+ INCL(m.flags, imported);
+ lnkList[lno] := m;
+ INC(lno)
+ END;
+ EXCL(m.flags, trace)
+ ELSE
+ Log.String("recursive import of " + m.name + " in " + parent.name); Log.Ln; INC(err)
+ END
+ END Trace;
+
+ PROCEDURE Sort;
+ VAR i, j: INTEGER; m: Module;
+ BEGIN
+ ASSERT((mno = 0) OR (lnkList[0] # NIL), 20);
+ cmpList := lnkList;
+ i := 1;
+ WHILE i < mno DO
+ m := cmpList[i];
+ j := i - 1;
+ WHILE (j >= 0) & (cmpList[j].depth < m.depth) DO
+ cmpList[j + 1] := cmpList[j];
+ DEC(j)
+ END;
+ cmpList[j + 1] := m;
+ INC(i)
+ END
+ END Sort;
+
+ PROCEDURE MakeTree;
+ VAR i, j, num: INTEGER; m: Module; s: String; ok: BOOLEAN;
+ BEGIN
+ i := 0; rno := mno;
+ WHILE (err = 0) & (i < mno) DO
+ m := modList[i];
+ GetSource(m.name$, m.path, s);
+ IF s # NIL THEN
+ CheckModule(m, s, ok);
+ IF ~ok THEN INC(err) END
+ ELSE
+ Log.String("unable to open module " + m.name); Log.Ln; INC(err)
+ END;
+ INC(i)
+ END;
+ num := 0;
+ FOR i := 0 TO rno - 1 DO
+ Trace(modList[i], modList[i], 0, num);
+ END;
+ ASSERT((err # 0) OR (num = mno), 100);
+ Sort;
+ END MakeTree;
+
+ PROCEDURE IsCompiled (m: Module): BOOLEAN;
+ CONST target = {hasSym, hasObj};
+ VAR i: INTEGER; ready: BOOLEAN;
+ BEGIN
+ ASSERT(m # NIL, 20);
+ i := 0;
+ ready := ~(hasErrors IN m.flags) & (m.flags * target = target);
+ WHILE ready & (i < m.mno) DO
+ ready := IsCompiled(m.imp[i]);
+ INC(i)
+ END;
+ RETURN ready
+ END IsCompiled;
+
+ PROCEDURE Ready (m: Module): BOOLEAN;
+ CONST target = {hasSym, hasObj};
+ VAR i: INTEGER; ready: BOOLEAN;
+ BEGIN
+ i := 0;
+ ready := ~(hasErrors IN m.flags) & (m.flags * target # target) & (m.worker = NIL);
+ WHILE ready & (i < m.mno) DO
+ ready := IsCompiled(m.imp[i]);
+ INC(i)
+ END;
+ RETURN ready
+ END Ready;
+
+ PROCEDURE ExecuteCompiler (m: Module): DswProcs.Process;
+ VAR w: DswProcs.Process; ok: BOOLEAN;
+ BEGIN
+ ASSERT(m # NIL, 20);
+ ASSERT(m.path # "", 21);
+ ASSERT(m.worker = NIL, 22);
+ w := DswProcs.dir.New();
+ w.Program("cpc486");
+ w.PutParam("-legacy");
+ w.PutParam(m.path);
+ w.Execute(ok);
+ IF ok THEN
+ Log.String("Compile " + m.name + " (" + m.path + ")"); Log.Ln;
+ ELSE
+ w := NIL
+ END;
+ RETURN w
+ END ExecuteCompiler;
+
+ PROCEDURE Compile;
+ VAR i, j, num: INTEGER; ok: BOOLEAN; m: Module; w: DswProcs.Process;
+ BEGIN
+ IF mno = 0 THEN RETURN END;
+ num := 0; j := 0;
+ WHILE (err = 0) & (num < mno) OR (j > 0) DO
+ i := 0;
+ WHILE (err = 0) & (i < mno) & (j < jobs) DO
+ m := cmpList[i];
+ IF Ready(m) THEN
+ w := ExecuteCompiler(m);
+ IF debugJobs THEN Log.String("Start job " + m.name) END;
+ IF w # NIL THEN
+ IF debugJobs THEN Log.String(" ok") END;
+ m.worker := w;
+ INC(j)
+ ELSE
+ IF debugJobs THEN Log.String(" fail") END;
+ INCL(m.flags, hasErrors);
+ INC(err)
+ END;
+ IF debugJobs THEN Log.Ln END
+ END;
+ INC(i)
+ END;
+ WHILE (err = 0) & (j >= jobs) OR (j > 0) DO
+ i := 0;
+ WHILE (j > 0) & (i < mno) DO
+ m := cmpList[i];
+ w := m.worker;
+ IF (w # NIL) & w.IsTerminated() THEN
+ IF debugJobs THEN Log.String("Stop job " + m.name); Log.Int(w.Result()); Log.Ln END;
+ IF w.Result() = 0 THEN
+ INCL(m.flags, hasObj);
+ INCL(m.flags, hasSym);
+ INC(num)
+ ELSE
+ INCL(m.flags, hasErrors);
+ INC(err)
+ END;
+ m.worker := NIL;
+ DEC(j)
+ END;
+ INC(i)
+ END
+ END
+ END
+ END Compile;
+
+ PROCEDURE Link;
+ VAR p: DswProcs.Process; i: INTEGER; ok: BOOLEAN;
+ BEGIN
+ ASSERT(exe # NIL, 20);
+ ASSERT(exe^ # "", 21);
+ p := DswProcs.dir.New();
+ p.Program("cpl486");
+ p.PutParam("-os");
+ p.PutParam("linux");
+ p.PutParam("-kernel");
+ p.PutParam("Kernel");
+ p.PutParam("-main");
+ p.PutParam("Kernel");
+ p.PutParam("-legacycodedir");
+ p.PutParam(".");
+ p.PutParam("-o");
+ p.PutParam(exe);
+ i := 0;
+ WHILE i < mno DO
+ IF ~(library IN lnkList[i].flags) THEN
+ p.PutParam(lnkList[i].name$)
+ END;
+ INC(i)
+ END;
+ p.Execute(ok);
+ IF ok THEN
+ i := p.Result();
+ IF i # 0 THEN
+ Log.String("linker terminated with error"); Log.Int(i); Log.Ln;
+ INC(err)
+ END
+ ELSE
+ Log.String("unable to execute linker"); Log.Int(i); Log.Ln;
+ INC(err)
+ END
+ END Link;
+
+ PROCEDURE WriteSelector (s: Selector);
+ BEGIN
+ Log.String(s.name$);
+ IF s.value THEN Log.Char("+") ELSE Log.Char("-") END
+ END WriteSelector;
+
+ PROCEDURE Main;
+ VAR m: Module; s: Selector; p: DswProcs.Process; ok: BOOLEAN; i, res: INTEGER;
+ BEGIN
+ IF Kernel.trapCount # 0 THEN Kernel.Quit(1) END;
+ ParseArgs;
+ IF err = 0 THEN
+ MakeTree;
+ IF err = 0 THEN
+ Compile;
+ IF err = 0 THEN
+ IF exe # NIL THEN Link END;
+ END
+ END
+ END;
+ IF err = 0 THEN
+ Log.String("no errors"); Log.Ln;
+ Kernel.Quit(0)
+ ELSE
+ Kernel.Quit(1)
+ END;
+ END Main;
+
+BEGIN
+ NEW(def);
+ Kernel.Start(Main)
+END DswMakeMain.
+
+==============================
+
+SYNTAX
+ cpmake {options module}
+
+OPTIONS
+ -a Enable automatic dependency resolution
+ -o name Generate executable file
+ -j num Specifies the number of jobs to run simultaneously
+ -D ident["+"|"-"] Add preprocessor selector
+ -U ident Remove proprocessor selector
diff --git a/src/generic/Dsw/Mod/Opts.cp b/src/generic/Dsw/Mod/Opts.cp
--- /dev/null
@@ -0,0 +1,167 @@
+MODULE DswOpts;
+
+ IMPORT Kernel, Log;
+
+ CONST
+ (* symbol *)
+ null* = 0; opt* = 1; char* = 2; string* = 3; ident* = 4; eos* = 5; eof* = 6;
+
+ (* scanner options *)
+ options* = 0; strings* = 1; identifiers* = 2; chars* = 3; terminators* = 4;
+ emptystr* = 5; emptyident* = 6; invalid* = 7;
+
+ (* errors *)
+ ok* = 0; unkopt* = 1; missarg* = 2;
+
+ TYPE
+ String* = POINTER TO ARRAY OF CHAR;
+
+ VAR
+ optMode: BOOLEAN;
+ args: POINTER TO ARRAY OF String;
+ argn-, argi-: INTEGER;
+ str-: String;
+ ch-: CHAR;
+ opts*: SET;
+
+ PROCEDURE Skip (n: INTEGER);
+ BEGIN
+ ASSERT(n >= 0, 20);
+ ASSERT(argn < LEN(args), 21);
+ ASSERT(argi + n <= LEN(args[argn]$), 22);
+ INC(argi, n)
+ END Skip;
+
+ PROCEDURE IsOpt (ch: CHAR): BOOLEAN;
+ BEGIN
+ RETURN (CAP(ch) >= "A") & (CAP(ch) <= "Z") OR (ch >= "0") & (ch <= "9") OR (ch = "-")
+ END IsOpt;
+
+ PROCEDURE IsIdentStart (ch: CHAR): BOOLEAN;
+ BEGIN
+ RETURN (CAP(ch) >= "A") & (CAP(ch) <= "Z") OR (ch = "_")
+ END IsIdentStart;
+
+ PROCEDURE IsIdent (ch: CHAR): BOOLEAN;
+ BEGIN
+ RETURN (CAP(ch) >= "A") & (CAP(ch) <= "Z") OR (ch = "_") OR (ch >= "0") & (ch <= "9")
+ END IsIdent;
+
+ PROCEDURE Get* (VAR x: BYTE);
+ VAR i, j, len: INTEGER; sym: BYTE; c: CHAR;
+ BEGIN
+ ch := 0X; str := NIL;
+ IF argn >= LEN(args) THEN
+ optMode := FALSE; sym := eof
+ ELSE
+ sym := null;
+ c := args[argn, argi];
+ IF c = 0X THEN
+ optMode := FALSE; INC(argn); argi := 0;
+ IF terminators IN opts THEN sym := eos; (* !!! *)
+ ELSIF argn >= LEN(args) THEN sym := eof (* !!! *)
+ ELSE c := args[argn, argi] (* continue parsing *)
+ END
+ END;
+ IF sym = null THEN
+ IF (options IN opts) & (optMode & IsOpt(c) OR (c = "-") & IsOpt(args[argn, argi + 1])) THEN
+ sym := opt;
+ IF optMode THEN
+ ch := c; optMode := TRUE; Skip(1)
+ ELSE
+ ch := args[argn, argi + 1]; optMode := TRUE; Skip(2)
+ END
+ ELSIF (identifiers IN opts) OR (strings IN opts) THEN
+ len := 0; i := argi; sym := null;
+ (* --- get length of identifier --- *)
+ IF (identifiers IN opts) & (IsIdentStart(args[argn, i]) OR (emptyident IN opts)) THEN
+ WHILE IsIdent(args[argn, i]) DO
+ INC(len);
+ INC(i)
+ END;
+ sym := ident
+ END;
+ (* --- get length of string --- *)
+ IF strings IN opts THEN
+ WHILE args[argn, i] # 0X DO
+ INC(len);
+ INC(i)
+ END;
+ sym := string
+ ELSIF (identifiers IN opts) & (args[argn, i] # 0X) & ~(invalid IN opts) THEN
+ WHILE args[argn, i] # 0X DO INC(i) END;
+ sym := null
+ END;
+ (* --- copy string --- *)
+ IF (sym # null) & ((len > 0) OR (sym = string) & (emptystr IN opts) OR (sym = ident) & (emptyident IN opts)) THEN
+ NEW(str, len + 1);
+ FOR j := 0 TO len - 1 DO
+ str[j] := args[argn, argi + j]
+ END;
+ str[len] := 0X
+ END;
+ optMode := FALSE;
+ Skip(i - argi)
+ ELSIF chars IN opts THEN
+ ch := c; optMode := FALSE; Skip(1)
+ ELSE
+ optMode := FALSE; sym := null; Skip(1)
+ END
+ END
+ END;
+ x := sym
+ END Get;
+
+ PROCEDURE Reset*;
+ BEGIN
+ argn := 1; argi := 0; ch := 0X; str := NIL; optMode := FALSE;
+ opts := {options, strings, emptystr}
+ END Reset;
+
+ PROCEDURE GetOpt* (IN optstring: ARRAY OF CHAR): CHAR;
+ VAR save: SET; sym: BYTE; c: CHAR; i, mode: INTEGER;
+ BEGIN
+ save := opts; opts := {options, strings, emptystr}; c := 0X;
+ Get(sym);
+ IF sym = opt THEN
+ c := ch; i := 0;
+ WHILE (optstring[i] # 0X) & (optstring[i] # c) DO
+ INC(i);
+ WHILE optstring[i] = ":" DO
+ INC(i)
+ END
+ END;
+ IF optstring[i] = c THEN
+ opts := {strings, emptystr}; mode := 0; INC(i);
+ WHILE optstring[i] = ":" DO
+ INC(mode);
+ INC(i)
+ END;
+ IF mode # 0 THEN Get(sym);
+ IF (sym # string) & (mode = 1) THEN
+ NEW(str, 2); str[0] := c; c := ":"
+ END
+ END
+ ELSE NEW(str, 2); str[0] := c; c := "?"
+ END
+ ELSIF sym = eof THEN c := 0X (* eof *)
+ ELSE c := "$" (* string *)
+ END;
+ opts := save;
+ RETURN c
+ END GetOpt;
+
+ PROCEDURE Init;
+ VAR i: INTEGER;
+ BEGIN
+ NEW(args, Kernel.argc);
+ FOR i := 0 TO Kernel.argc - 1 DO
+ NEW(args[i], LEN(Kernel.argv[i]$) + 1);
+ args[i]^ := Kernel.argv[i]$
+ END;
+ Reset
+ END Init;
+
+BEGIN
+ Init
+END DswOpts.
diff --git a/src/generic/Dsw/Mod/Procs.cp b/src/generic/Dsw/Mod/Procs.cp
--- /dev/null
@@ -0,0 +1,33 @@
+MODULE DswProcs;
+
+ (* todo: pipe control, set cwd, set env vars, get program path from name *)
+
+ IMPORT Kernel;
+
+ TYPE
+ Directory* = POINTER TO ABSTRACT RECORD END;
+
+ Process* = POINTER TO ABSTRACT RECORD END;
+
+ VAR
+ dir-, stdDir-: Directory;
+
+ PROCEDURE (d: Directory) New* (): Process, NEW, ABSTRACT;
+
+ PROCEDURE (p: Process) Program* (IN exe: ARRAY OF CHAR), NEW, ABSTRACT;
+ PROCEDURE (p: Process) PutParam* (IN par: ARRAY OF CHAR), NEW, ABSTRACT;
+ PROCEDURE (p: Process) Execute* (OUT ok: BOOLEAN), NEW, ABSTRACT;
+
+ PROCEDURE (p: Process) Terminate* (OUT ok: BOOLEAN), NEW, ABSTRACT;
+ PROCEDURE (p: Process) IsTerminated* (): BOOLEAN, NEW, ABSTRACT;
+ PROCEDURE (p: Process) Wait*, NEW, ABSTRACT;
+ PROCEDURE (p: Process) Result* (): INTEGER, NEW, ABSTRACT;
+
+ PROCEDURE SetDir* (d: Directory);
+ BEGIN
+ ASSERT(d # NIL, 20);
+ dir := d;
+ IF stdDir = NIL THEN stdDir := d END
+ END SetDir;
+
+END DswProcs.
index 7127eaf3413b1a3ae12a397d497039f4827c0cd0..5a3a0b627e20f21359034f05559a10fb5fadebc0 100644 (file)
ENOTCONN* = 107;
ENOTDIR* = 20;
ENOTEMPTY* = 39;
- ENOTRECOVERABLE* = 131;
ENOTSOCK* = 88;
ENOTSUP* = 95;
ENOTTY* = 25;
ENXIO* = 6;
EOPNOTSUPP* = 95;
EOVERFLOW* = 75;
- EOWNERDEAD* = 130;
EPERM* = 1;
EPIPE* = 32;
EPROTO* = 71;
EWOULDBLOCK* = 11;
EXDEV* = 18;
+ CONST
+ ENOTRECOVERABLE* = 131;
+ EOWNERDEAD* = 130;
+
PROCEDURE [ccall] __errno_location* (): POINTER TO ARRAY [untagged] 1 OF int;
END PosixCerrno.
index cbea74d7c9ecd7607496b11b9bad93a3b62cf57c..637a42a450b2d36f24913209253a61c867b1d8dc 100644 (file)
CONST
F_DUPFD* = 0;
- F_DUPFD_CLOEXEC* = 1030;
F_GETFD* = 1;
F_SETFD* = 2;
F_GETFL* = 3;
F_GETOWN* = 9;
F_SETOWN* = 8;
+ CONST
+ F_DUPFD_CLOEXEC* = 1030;
+
CONST
FD_CLOEXEC* = 1;
SEEK_END* = 2;
CONST
- O_CLOEXEC* = 524288;
O_CREAT* = 64;
O_DIRECTORY* = 65536;
O_EXCL* = 128;
O_NOFOLLOW* = 131072;
O_TRUNC* = 512;
O_APPEND* = 1024;
- O_DSYNC* = 4096;
O_NONBLOCK* = 2048;
- O_RSYNC* = 1052672;
O_SYNC* = 1052672;
O_ACCMODE* = 3;
O_RDONLY* = 0;
O_RDWR* = 2;
O_WRONLY* = 1;
+ CONST
+ O_CLOEXEC* = 524288;
+ O_DSYNC* = 4096;
+ O_RSYNC* = 1052672;
+
CONST
AT_FDCWD* = -100;
AT_EACCESS* = 512;
index b063d925dcb86033d663fa333d8b4894b080c723..9df1b97c06fae166b693e83f6a79afc3955b61f9 100644 (file)
SIGTTOU* = 22;
SIGUSR1* = 10;
SIGUSR2* = 12;
- SIGPOLL* = 29;
- SIGPROF* = 27;
SIGSYS* = 31;
SIGTRAP* = 5;
SIGURG* = 23;
SA_RESETHAND* = -2147483648;
SA_RESTART* = 268435456;
SA_SIGINFO* = 4;
- SA_NOCLDWAIT* = 2;
SA_NODEFER* = 1073741824;
SS_ONSTACK* = 1;
SS_DISABLE* = 2;
si_uid*: uid_t; (* 4+4 *)
si_status*: int; (* 8+4 *)
END; (* 0+12 *)
- sigpoll*: RECORD [noalign] (* 4 *)
- si_band*: long; (* 0+4 *)
- END; (* 0+4 *)
other*: RECORD [noalign] (* 4 *)
si_value*: union_sigval; (* 0+4 *)
END; (* 8+4 *)
CLD_STOPPED* = 5;
CLD_CONTINUED* = 6;
- CONST
- POLL_IN* = 1;
- POLL_OUT* = 2;
- POLL_MSG* = 3;
- POLL_ERR* = 4;
- POLL_PRI* = 5;
- POLL_HUP* = 6;
-
CONST
SI_USER* = 0;
SI_QUEUE* = -1;
PROCEDURE [ccall] psiginfo* (IN pinfo: siginfo_t; IN [nil] s: ARRAY [untagged] OF SHORTCHAR);
PROCEDURE [ccall] psignal* (sig: int; IN [nil] s: ARRAY [untagged] OF SHORTCHAR);
PROCEDURE [ccall] pthread_kill* (thread: pthread_t; sig: int): int;
- PROCEDURE [ccall] pthread_sigmask* (how: int; IN [nil] set: sigset_t; VAR [nil] oldset: sigset_t): int;
+ PROCEDURE [ccall] pthread_sigmask* (how: int; VAR [nil] set: sigset_t; VAR [nil] oldset: sigset_t): int;
PROCEDURE [ccall] raise* (sig: int): int;
PROCEDURE [ccall] sigaction* (sig: int; IN [nil] act: struct_sigaction; VAR [nil] oact: struct_sigaction): int;
PROCEDURE [ccall] sigaddset* (VAR set: sigset_t; signum: int): int;
PROCEDURE [ccall] sigdelset* (VAR set: sigset_t; signum: int): int;
PROCEDURE [ccall] sigemptyset* (VAR set: sigset_t): int;
PROCEDURE [ccall] sigfillset* (VAR set: sigset_t): int;
- PROCEDURE [ccall] sighold* (sig: int): int;
- PROCEDURE [ccall] sigignore* (sig: int): int;
- PROCEDURE [ccall] siginterrupt* (sig, flag: int): int;
- PROCEDURE [ccall] sigismember* (IN set: sigset_t; signum: int): int;
- PROCEDURE [ccall] sigpause* (sig: int): int;
+ PROCEDURE [ccall] sigismember* (VAR set: sigset_t; signum: int): int;
PROCEDURE [ccall] sigpending* (VAR set: sigset_t): int;
- PROCEDURE [ccall] sigprocmask* (how: int; IN [nil] set: sigset_t; VAR [nil] oset: sigset_t): int;
+ PROCEDURE [ccall] sigprocmask* (how: int; VAR [nil] set: sigset_t; VAR [nil] oset: sigset_t): int;
PROCEDURE [ccall] sigqueue* (pid: pid_t; sig: int; IN value: union_sigval): int;
- PROCEDURE [ccall] sigrelse* (sig: int): int;
- PROCEDURE [ccall] sigsuspend* (IN sigmask: sigset_t): int;
- PROCEDURE [ccall] sigtimedwait* (IN set: sigset_t; VAR [nil] info: siginfo_t; IN timeout: struct_timespec): int;
- PROCEDURE [ccall] sigwait* (IN set: sigset_t; VAR sig: int): int;
- PROCEDURE [ccall] sigwaitinfo* (IN set: sigset_t; VAR [nil] info: siginfo_t): int;
+ PROCEDURE [ccall] sigsuspend* (VAR sigmask: sigset_t): int;
+ PROCEDURE [ccall] sigtimedwait* (VAR set: sigset_t; VAR [nil] info: siginfo_t; IN timeout: struct_timespec): int;
+ PROCEDURE [ccall] sigwait* (VAR set: sigset_t; VAR sig: int): int;
+ PROCEDURE [ccall] sigwaitinfo* (VAR set: sigset_t; VAR [nil] info: siginfo_t): int;
END PosixCsignal.
diff --git a/src/native/linux/486/Posix/Mod/Csys_mman.cp b/src/native/linux/486/Posix/Mod/Csys_mman.cp
index 98ed68fdcbd176b3407504a58ad0ee8e9006d1cb..f7fa5bc92e46d230a16b00f3adcf88e7e105ddff 100644 (file)
MS_INVALIDATE* = 2;
MS_SYNC* = 4;
- CONST
- MCL_CURRENT* = 1;
- MCL_FUTURE* = 2;
-
CONST
MAP_FAILED* = -1;
size_t* = PosixCsys_types.size_t;
PROCEDURE [ccall] mlock* (addr: PosixCtypes.Pvoid; len: size_t): int;
- PROCEDURE [ccall] mlockall* (flags: int): int;
PROCEDURE [ccall] mmap* (addr: PosixCtypes.Pvoid; len: size_t; prot, flags, fildes: int; off: off_t): PosixCtypes.Pvoid;
PROCEDURE [ccall] mprotect* (addr: PosixCtypes.Pvoid; len: size_t; prot: int): int;
PROCEDURE [ccall] msync* (addr: PosixCtypes.Pvoid; len: size_t; flags: int): int;
PROCEDURE [ccall] munlock* (addr: PosixCtypes.Pvoid; len: size_t): int;
- PROCEDURE [ccall] munlockall* (): int;
PROCEDURE [ccall] munmap* (addr: PosixCtypes.Pvoid; len: size_t): int;
PROCEDURE [ccall] posix_madvise* (addr: PosixCtypes.Pvoid; len: size_t; advice: int): int;
PROCEDURE [ccall] posix_mem_offset* (addr: PosixCtypes.Pvoid; len: size_t; VAR off: off_t; VAR contng_len: size_t; VAR fildes: int): int;
diff --git a/src/native/linux/486/Posix/Mod/Csys_types.cp b/src/native/linux/486/Posix/Mod/Csys_types.cp
index 919de7f5804f4eb06fc62bb2378f023f8cdb56ee..1848077b62c8102702a071f0770a4c969e87a159 100644 (file)
blkcnt_t* = INTEGER;
blksize_t* = INTEGER;
clock_t* = INTEGER;
- clockid_t* = INTEGER;
- dev_t* = LONGINT;
+ dev_t* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END;
fsblkcnt_t* = INTEGER;
fsfilcnt_t* = INTEGER;
gid_t* = INTEGER;
off_t* = INTEGER;
pid_t* = INTEGER;
pthread_attr_t* = RECORD [noalign] _: ARRAY [untagged] 36 OF BYTE END;
- pthread_barrier_t* = RECORD [noalign] _: ARRAY [untagged] 20 OF BYTE END;
- pthread_barrierattr_t* = INTEGER;
pthread_cond_t* = RECORD [noalign] _: ARRAY [untagged] 48 OF BYTE END;
pthread_condattr_t* = INTEGER;
pthread_key_t* = INTEGER;
pthread_once_t* = INTEGER;
pthread_rwlock_t* = RECORD [noalign] _: ARRAY [untagged] 32 OF BYTE END;
pthread_rwlockattr_t* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END;
- pthread_spinlock_t* = INTEGER;
pthread_t* = INTEGER;
size_t* = INTEGER;
ssize_t* = INTEGER;
suseconds_t* = INTEGER;
time_t* = INTEGER;
- timer_t* = INTEGER;
uid_t* = INTEGER;
+ TYPE
+ pthread_barrier_t* = RECORD [noalign] _: ARRAY [untagged] 20 OF BYTE END;
+ pthread_barrierattr_t* = INTEGER;
+ pthread_spinlock_t* = INTEGER;
+ timer_t* = INTEGER;
+ clockid_t* = INTEGER;
+
END PosixCsys_types.
diff --git a/src/native/linux/486/Posix/Mod/Csys_wait.cp b/src/native/linux/486/Posix/Mod/Csys_wait.cp
--- /dev/null
@@ -0,0 +1,67 @@
+MODULE PosixCsys_wait ['libc.so.6'];
+
+ (* generated by genposix.sh, do not modify *)
+
+ IMPORT SYSTEM, PosixCtypes, PosixCsys_types, PosixCsignal;
+
+ TYPE
+ char* = PosixCtypes.char;
+ signed_char* = PosixCtypes.signed_char;
+ unsigned_char* = PosixCtypes.unsigned_char;
+ short* = PosixCtypes.short;
+ short_int* = PosixCtypes.short_int;
+ signed_short* = PosixCtypes.signed_short;
+ signed_short_int* = PosixCtypes.signed_short_int;
+ unsigned_short* = PosixCtypes.unsigned_short;
+ unsigned_short_int* = PosixCtypes.unsigned_short_int;
+ int* = PosixCtypes.int;
+ signed* = PosixCtypes.signed;
+ signed_int* = PosixCtypes.signed_int;
+ unsigned* = PosixCtypes.unsigned;
+ unsigned_int* = PosixCtypes.unsigned_int;
+ long* = PosixCtypes.long;
+ long_int* = PosixCtypes.long_int;
+ signed_long* = PosixCtypes.signed_long;
+ signed_long_int* = PosixCtypes.signed_long_int;
+ unsigned_long* = PosixCtypes.unsigned_long;
+ unsigned_long_int* = PosixCtypes.unsigned_long_int;
+ long_long* = PosixCtypes.long_long;
+ long_long_int* = PosixCtypes.long_long_int;
+ signed_long_long* = PosixCtypes.signed_long_long;
+ signed_long_long_int* = PosixCtypes.signed_long_long_int;
+ unsigned_long_long* = PosixCtypes.unsigned_long_long;
+ unsigned_long_long_int* = PosixCtypes.unsigned_long_long_int;
+ float* = PosixCtypes.float;
+ double* = PosixCtypes.double;
+ long_double* = PosixCtypes.long_double;
+
+ CONST
+ WCONTINUED* = 8;
+ WNOHANG* = 1;
+ WUNTRACED* = 2;
+
+ CONST
+ WEXITED* = 4;
+ WNOWAIT* = 16777216;
+ WSTOPPED* = 2;
+
+ TYPE
+ idtype_t* = INTEGER;
+
+ CONST
+ P_ALL* = 0;
+ P_PGID* = 2;
+ P_PID* = 1;
+
+ TYPE
+ id_t* = PosixCsys_types.id_t;
+ pid_t* = PosixCsys_types.pid_t;
+
+ TYPE
+ siginfo_t* = PosixCsignal.siginfo_t;
+
+ PROCEDURE [ccall] wait* (VAR [nil] wstatus: int): pid_t;
+ PROCEDURE [ccall] waitid* (idtype: idtype_t; id: id_t; VAR [nil] infop: siginfo_t; options: int): int;
+ PROCEDURE [ccall] waitpid* (pid: pid_t; VAR [nil] wstatus: int; options: int): pid_t;
+
+END PosixCsys_wait.
index 3f3d5ec08f2b3da3e0c51b55f9b80916c638795d..1a8a2e661d8dc0943406c545b3413899d9fdfd50 100644 (file)
clock_t* = PosixCsys_types.clock_t;
size_t* = PosixCsys_types.size_t;
time_t* = PosixCsys_types.time_t;
- clockid_t* = PosixCsys_types.clockid_t;
- timer_t* = PosixCsys_types.timer_t;
pid_t* = PosixCsys_types.pid_t;
+ TYPE
+ timer_t* = PosixCsys_types.timer_t;
+ clockid_t* = PosixCsys_types.clockid_t;
+
TYPE
locale_t* = PosixClocale.locale_t;
index 6cdc535f8569becd6b1f4b73e7ad8b90bca5fa1f..46c2a3bf09fdf5353cc4627b5ae2209714691c16 100644 (file)
long_long_int* = LONGINT;
signed_long_long* = LONGINT;
signed_long_long_int* = LONGINT;
- unsigned_long_long* = LONGINT;
- unsigned_long_long_int* = LONGINT;
+ unsigned_long_long* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END;
+ unsigned_long_long_int* = RECORD [noalign] _: ARRAY [untagged] 8 OF BYTE END;
float* = SHORTREAL;
double* = REAL;
long_double* = RECORD [noalign] _: ARRAY [untagged] 12 OF BYTE END;
diff --git a/src/posix/generic/Dsw/Mod/HostProcs.cp b/src/posix/generic/Dsw/Mod/HostProcs.cp
--- /dev/null
@@ -0,0 +1,156 @@
+MODULE DswHostProcs;
+
+ IMPORT SYSTEM, Log, DswProcs, HostLang, unistd := PosixCunistd, stdlib := PosixCstdlib,
+ signal := PosixCsignal, sys_wait := PosixCsys_wait, macro := PosixCmacro,
+ errno := PosixCerrno;
+
+ TYPE
+ Directory = POINTER TO RECORD (DswProcs.Directory) END;
+
+ String = POINTER TO ARRAY OF SHORTCHAR;
+ SString = POINTER TO ARRAY OF String;
+
+ Process = POINTER TO RECORD (DswProcs.Process)
+ argv: SString;
+ pid: unistd.pid_t;
+ 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
+ NEW(ss, LEN(s$) * 3 + 1);
+ ASSERT(ss # NIL, 100);
+ HostLang.StringToHost(s, ss, HostLang.pep383x, res);
+ ASSERT(res = 0, 101);
+ RETURN ss
+ END ToHost;
+
+ PROCEDURE (p: Process) Program* (IN exe: ARRAY OF CHAR);
+ VAR argv: SString;
+ BEGIN
+ ASSERT(p.pid = -1, 20);
+ NEW(argv, 1); argv[0] := ToHost(exe);
+ p.argv := argv
+ END Program;
+
+ PROCEDURE (p: Process) PutParam* (IN par: ARRAY OF CHAR);
+ VAR i: INTEGER; argv: SString;
+ BEGIN
+ ASSERT(p.pid = -1, 20);
+ ASSERT(p.argv # NIL, 21);
+ NEW(argv, LEN(p.argv) + 1);
+ FOR i := 0 TO LEN(p.argv) - 1 DO
+ argv[i] := p.argv[i]
+ END;
+ argv[i] := ToHost(par);
+ p.argv := argv
+ END PutParam;
+
+ PROCEDURE (p: Process) Execute* (OUT ok: BOOLEAN);
+ TYPE
+ UString = POINTER [untagged] TO ARRAY [untagged] OF SHORTCHAR;
+ SUString = POINTER TO ARRAY OF UString;
+ VAR
+ i, j: INTEGER; pid: unistd.pid_t; res: unistd.int; argv: SUString;
+ BEGIN
+ ASSERT(p.pid = -1, 20);
+ ASSERT(p.argv # NIL, 21);
+ NEW(argv, LEN(p.argv) + 1);
+ FOR i := 0 TO LEN(p.argv) - 1 DO
+ argv[i] := SYSTEM.VAL(UString, SYSTEM.ADR(p.argv[i, 0]))
+ END;
+ pid := unistd.fork();
+ IF pid = 0 THEN
+ res := unistd.execv(argv[0], argv);
+ unistd._exit(127); (* system() and most utils exit with 126/127 *)
+ ok := FALSE
+ ELSIF pid = -1 THEN
+ ok := FALSE
+ ELSE
+ p.argv := NIL; (* or save it for debugging and reuse? *)
+ p.pid := pid;
+ ok := TRUE
+ END
+ END Execute;
+
+ PROCEDURE (p: Process) Terminate* (OUT ok: BOOLEAN);
+ VAR res, e: signal.int;
+ BEGIN
+ ASSERT(p.pid > 0, 20);
+ res := signal.kill(p.pid, signal.SIGTERM);
+ IF res = 0 THEN p.Wait; ok := TRUE
+ ELSIF res = -1 THEN
+ e := macro.errno();
+ CASE e OF
+ | errno.EINVAL: HALT(100) (* wat *)
+ | errno.EPERM: ok := FALSE (* process can not be killed *)
+ | errno.ESRCH: p.code := 0; p.pid := -1; ok := TRUE (* process already killed *)
+ END
+ ELSE HALT(101) (* wat *)
+ END
+ END Terminate;
+
+ PROCEDURE (p: Process) IsTerminated* (): BOOLEAN;
+ VAR pid: unistd.pid_t; e: unistd.int;
+ BEGIN
+ IF p.pid # -1 THEN
+ ASSERT(p.pid > 0, 100); (* wat *)
+ pid := sys_wait.waitpid(p.pid, p.code, sys_wait.WNOHANG);
+ IF pid = 0 THEN (* process still executes *)
+ ELSIF pid = p.pid THEN p.pid := -1 (* process returns code *)
+ ELSIF pid = -1 THEN
+ e := macro.errno();
+ CASE e OF
+ | errno.ECHILD: p.code := 0; p.pid := -1 (* process was killed externally *)
+ | errno.EINVAL: HALT(101) (* wat *)
+ | errno.EINTR: (* assume that process still executes *)
+ END
+ ELSE HALT(102) (* wat *)
+ END
+ END;
+ RETURN p.pid = -1
+ END IsTerminated;
+
+ PROCEDURE (p: Process) Wait*;
+ VAR pid: unistd.pid_t; e: unistd.int;
+ BEGIN
+ ASSERT(p.pid > 0, 20);
+ REPEAT
+ pid := sys_wait.waitpid(p.pid, p.code, 0);
+ IF pid = p.pid THEN p.pid := -1 (* was terminated *)
+ ELSIF pid = -1 THEN
+ e := macro.errno();
+ CASE e OF
+ | errno.ECHILD: p.code := 0; p.pid := -1 (* process was killed externally *)
+ | errno.EINVAL: HALT(100) (* wat *)
+ | errno.EINTR: (* continue wait for process termination *)
+ END
+ ELSE HALT(101) (* wat *)
+ END
+ UNTIL p.pid = -1
+ END Wait;
+
+ PROCEDURE (p: Process) Result (): INTEGER;
+ BEGIN
+ IF p.pid # -1 THEN p.Wait END;
+ (* RETURN SYSTEM.CONV(INTEGER, sys_wait.WEXITSTATUS(p.code)) *) (* !!! *)
+ RETURN SYSTEM.VAL(INTEGER, p.code) DIV 256 MOD 128
+ END Result;
+
+ PROCEDURE Init;
+ VAR d: Directory;
+ BEGIN
+ NEW(d); DswProcs.SetDir(d)
+ END Init;
+
+BEGIN
+ Init
+END DswHostProcs.