home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
vp21beta.zip
/
LRTLSRC.RAR
/
LINUX.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
2000-08-15
|
48KB
|
1,910 lines
{█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█}
{█ █}
{█ Virtual Pascal for Linux █}
{█ Linux Operating System Interface Unit █}
{█ ─────────────────────────────────────────────────█}
{█ Copyright (C) 1999 Joerg Pleumann █}
{█ █}
{▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀}
(**
* This unit provides an interface to the Linux kernel.
* All constant names are the same as under Linux. Function
* names (system calls, that is) have a 'Lnx' prefix to avoid
* confusion with stuff from 'System'. Primitive types have
* been converted to Pascal types. Compound types have been
* declared with a suitable Pascal name (with usual 'T'
* prefix).
*
* To get more info on a certain function, say 'LnxWrite', do
* the following:
*
* - Read the man page in section 2 for the lowercase function
* name without the 'Lnx' prefix. For our example, this is
* 'man 2 write'. The parameter names should be more or less
* the same.
*
* - Grep around in /usr/src/linux :-)
*
* In system calls, the registers are used the following way:
*
* - EAX ... system call number
* - EBX ... first parameter
* - ECX ... second parameter
* - EDX ... third parameter
* - ESI ... fourth parameter
* - EDI ... fifth parameter
*
* When more than five parameters are used, EBX holds the
* address of the structure or memory block where the
* parameters are stored instead.
*
*)
{&Speed+,AlignCode+,AlignRec-,CDecl+,Delphi+}
{$X+,W-,H-,R-,S-,Q-,B-,T-,Use32+}
unit Linux;
interface
var
TrmHandle: LongInt;
const
(* Error codes *)
EPERM = 1; (* Operation not permitted *)
ENOENT = 2; (* No such file or directory *)
ESRCH = 3; (* No such process *)
EINTR = 4; (* Interrupted system call *)
EIO = 5; (* I/O error *)
ENXIO = 6; (* No such device or address *)
E2BIG = 7; (* Arg list too long *)
ENOEXEC = 8; (* Exec format error *)
EBADF = 9; (* Bad file number *)
ECHILD = 10; (* No child processes *)
EAGAIN = 11; (* Try again *)
ENOMEM = 12; (* Out of memory *)
EACCES = 13; (* Permission denied *)
EFAULT = 14; (* Bad address *)
ENOTBLK = 15; (* Block device required *)
EBUSY = 16; (* Device or resource busy *)
EEXIST = 17; (* File exists *)
EXDEV = 18; (* Cross-device link *)
ENODEV = 19; (* No such device *)
ENOTDIR = 20; (* Not a directory *)
EISDIR = 21; (* Is a directory *)
EINVAL = 22; (* Invalid argument *)
ENFILE = 23; (* File table overflow *)
EMFILE = 24; (* Too many open files *)
ENOTTY = 25; (* Not a typewriter *)
ETXTBSY = 26; (* Text file busy *)
EFBIG = 27; (* File too large *)
ENOSPC = 28; (* No space left on device *)
ESPIPE = 29; (* Illegal seek *)
EROFS = 30; (* Read-only file system *)
EMLINK = 31; (* Too many links *)
EPIPE = 32; (* Broken pipe *)
EDOM = 33; (* Math argument out of domain of func *)
ERANGE = 34; (* Math result not representable *)
EDEADLK = 35; (* Resource deadlock would occur *)
ENAMETOOLONG = 36; (* File name too long *)
ENOLCK = 37; (* No record locks available *)
ENOSYS = 38; (* Function not implemented *)
ENOTEMPTY = 39; (* Directory not empty *)
ELOOP = 40; (* Too many symbolic links encountered *)
ENOMSG = 42; (* No message of desired type *)
EIDRM = 43; (* Identifier removed *)
ECHRNG = 44; (* Channel number out of range *)
EL2NSYNC = 45; (* Level 2 not synchronized *)
EL3HLT = 46; (* Level 3 halted *)
EL3RST = 47; (* Level 3 reset *)
ELNRNG = 48; (* Link number out of range *)
EUNATCH = 49; (* Protocol driver not attached *)
ENOCSI = 50; (* No CSI structure available *)
EL2HLT = 51; (* Level 2 halted *)
EBADE = 52; (* Invalid exchange *)
EBADR = 53; (* Invalid request descriptor *)
EXFULL = 54; (* Exchange full *)
ENOANO = 55; (* No anode *)
EBADRQC = 56; (* Invalid request code *)
EBADSLT = 57; (* Invalid slot *)
EBFONT = 59; (* Bad font file format *)
ENOSTR = 60; (* Device not a stream *)
ENODATA = 61; (* No data available *)
ETIME = 62; (* Timer expired *)
ENOSR = 63; (* Out of streams resources *)
ENONET = 64; (* Machine is not on the network *)
ENOPKG = 65; (* Package not installed *)
EREMOTE = 66; (* Object is remote *)
ENOLINK = 67; (* Link has been severed *)
EADV = 68; (* Advertise error *)
ESRMNT = 69; (* Srmount error *)
ECOMM = 70; (* Communication error on send *)
EPROTO = 71; (* Protocol error *)
EMULTIHOP = 72; (* Multihop attempted *)
EDOTDOT = 73; (* RFS specific error *)
EBADMSG = 74; (* Not a data message *)
EOVERFLOW = 75; (* Value too large for defined data type *)
ENOTUNIQ = 76; (* Name not unique on network *)
EBADFD = 77; (* File descriptor in bad state *)
EREMCHG = 78; (* Remote address changed *)
ELIBACC = 79; (* Can not access a needed shared library *)
ELIBBAD = 80; (* Accessing a corrupted shared library *)
ELIBSCN = 81; (* .lib section in a.out corrupted *)
ELIBMAX = 82; (* Attempting to link in too many shared libraries *)
ELIBEXEC = 83; (* Cannot exec a shared library directly *)
EILSEQ = 84; (* Illegal byte sequence *)
ERESTART = 85; (* Interrupted system call should be restarted *)
ESTRPIPE = 86; (* Streams pipe error *)
EUSERS = 87; (* Too many users *)
ENOTSOCK = 88; (* Socket operation on non-socket *)
EDESTADDRREQ = 89; (* Destination address required *)
EMSGSIZE = 90; (* Message too long *)
EPROTOTYPE = 91; (* Protocol wrong type for socket *)
ENOPROTOOPT = 92; (* Protocol not available *)
EPROTONOSUPPORT = 93; (* Protocol not supported *)
ESOCKTNOSUPPORT = 94; (* Socket type not supported *)
EOPNOTSUPP = 95; (* Operation not supported on transport endpoint *)
EPFNOSUPPORT = 96; (* Protocol family not supported *)
EAFNOSUPPORT = 97; (* Address family not supported by protocol *)
EADDRINUSE = 98; (* Address already in use *)
EADDRNOTAVAIL = 99; (* Cannot assign requested address *)
ENETDOWN = 100; (* Network is down *)
ENETUNREACH = 101; (* Network is unreachable *)
ENETRESET = 102; (* Network dropped connection because of reset *)
ECONNABORTED = 103; (* Software caused connection abort *)
ECONNRESET = 104; (* Connection reset by peer *)
ENOBUFS = 105; (* No buffer space available *)
EISCONN = 106; (* Transport endpoint is already connected *)
ENOTCONN = 107; (* Transport endpoint is not connected *)
ESHUTDOWN = 108; (* Cannot send after transport endpoint shutdown *)
ETOOMANYREFS = 109; (* Too many references: cannot splice *)
ETIMEDOUT = 110; (* Connection timed out *)
ECONNREFUSED = 111; (* Connection refused *)
EHOSTDOWN = 112; (* Host is down *)
EHOSTUNREACH = 113; (* No route to host *)
EALREADY = 114; (* Operation already in progress *)
EINPROGRESS = 115; (* Operation now in progress *)
ESTALE = 116; (* Stale NFS file handle *)
EUCLEAN = 117; (* Structure needs cleaning *)
ENOTNAM = 118; (* Not a XENIX named type file *)
ENAVAIL = 119; (* No XENIX semaphores available *)
EISNAM = 120; (* Is a named type file *)
EREMOTEIO = 121; (* Remote I/O error *)
EDQUOT = 122; (* Quota exceeded *)
ENOMEDIUM = 123; (* No medium found *)
EMEDIUMTYPE = 124; (* Wrong medium type *)
EWOULDBLOCK = EAGAIN; (* Operation would block *)
EDEADLOCK = EDEADLK; (* Resource deadlock would occur *)
(* Standard file descriptors. *)
STDIN_FILENO = 0; (* Standard input. *)
STDOUT_FILENO = 1; (* Standard output. *)
STDERR_FILENO = 2; (* Standard error output. *)
(* Values for the second argument to access.
These may be OR'd together. *)
R_OK = 4; (* Test for read permission. *)
W_OK = 2; (* Test for write permission. *)
X_OK = 1; (* Test for execute permission. *)
F_OK = 0; (* Test for existence. *)
(* Values for the WHENCE argument to lseek. *)
SEEK_SET = 0; (* Seek from beginning of file. *)
SEEK_CUR = 1; (* Seek from current position. *)
SEEK_END = 2; (* Seek from end of file. *)
F_ULOCK = 0; (* Unlock a previously locked region. *)
F_LOCK = 1; (* Lock a region for exclusive use. *)
F_TLOCK = 2; (* Test and lock a region for exclusive use. *)
F_TEST = 3; (* Test a region for other processes locks. *)
LOCK_SH = 1;
LOCK_EX = 2;
LOCK_UN = 4;
LOCK_NB = 8;
(* fcntl cmd options *)
F_GETFD = 1;
F_SETFD = 2;
F_GETFL = 3;
F_SETFL = 4;
F_GETLK = 5;
F_SETLK = 6;
F_SETLKW = 7;
F_GETOWN = 8;
F_SETOWN = 9;
(* fcntl flock.l_type options *)
F_RDLCK = 0;
F_WRLCK = 1;
F_UNLCK = 2;
(* File open modes *)
O_ACCMODE = $00000003;
O_RDONLY = $00000000;
O_WRONLY = $00000001;
O_RDWR = $00000002;
O_NDELAY = $00000004;
O_APPEND = $00000008;
O_TEXT = $00000010;
O_BINARY = $00000100;
O_CREAT = $00000200;
O_TRUNC = $00000400;
O_EXCL = $00000800;
O_NOINHERIT = $00001000;
O_SYNC = $00002000;
O_NOCTTY = $00004000;
O_SIZE = $00008000;
(* File modes *)
S_IFSOCK = $0000C000;
S_IFLNK = $0000A000;
S_IFREG = $00008000;
S_IFBLK = $00006000;
S_IFDIR = $00004000;
S_IFCHR = $00002000;
S_IFIFO = $00001000;
S_ISUID = $00000800;
S_ISGID = $00000400;
S_ISVTX = $00000200;
S_IRWXU = $000001C0;
S_IRUSR = $00000100;
S_IWUSR = $00000080;
S_IXUSR = $00000040;
S_IRWXG = $00000038;
S_IRGRP = $00000020;
S_IWGRP = $00000010;
S_IXGRP = $00000008;
S_IRWXO = $00000007;
S_IROTH = $00000004;
S_IWOTH = $00000002;
S_IXOTH = $00000001;
(* ? *)
F_EOF = $00000020;
F_TERMIO = $00000040;
F_DEV = $00000080;
F_SOCKET = $10000000;
F_PIPE = $20000000;
F_WRCRPEND = $40000000;
F_CRLF = $80000000;
(* mmap *)
PROT_NONE = $00; (* No access. *)
PROT_READ = $04; (* Pages can be read. *)
PROT_WRITE = $02; (* Pages can be written. *)
PROT_EXEC = $01; (* Pages can be executed. *)
(* Flags contain mapping type, sharing type and options. *)
(* Mapping type (must choose one and only one of these). *)
MAP_FILE = $0001; (* Mapped from a file or device. *)
MAP_ANON = $0002; (* Allocated from anonymous virtual memory. *)
MAP_TYPE = $000f; (* Mask for type field. *)
(* Sharing types (must choose one and only one of these). *)
MAP_COPY = $0020; (* Virtual copy of region at mapping time. *)
MAP_SHARED = $0010; (* Share changes. *)
MAP_PRIVATE = $0000; (* Changes private; copy pages on write. *)
(* Other flags. *)
MAP_FIXED = $0100; (* Map address must be exactly as requested. *)
MAP_NOEXTEND = $0200; (* For MAP_FILE, don't change file size. *)
MAP_HASSEMPHORE = $0400; (* Region may contain semaphores. *)
MAP_INHERIT = $0800; (* Region is retained after exec. *)
(* Cloning flags *)
CLONE_VM = $0100; // Set if VM shared between processes
CLONE_FS = $0200; // Set if FS info shared between processes
CLONE_FILES = $0400; // Set if open files shared between processes
CLONE_SIGHAND = $0800; // Set if signal handlers shared between processes
CLONE_PID = $1000; // Set if PID shared between processes
CLONE_PTRACE = $2000; // Set if tracing shall continue on the child process
CLONE_VFORK = $4000; // Set if if parent wants child to wake up on mm__release
(* Signals *)
SIGHUP = 1;
SIGINT = 2;
SIGQUIT = 3;
SIGILL = 4;
SIGTRAP = 5;
SIGABRT = 6;
SIGIOT = 6;
SIGBUS = 7;
SIGFPE = 8;
SIGKILL = 9;
SIGUSR1 = 10;
SIGSEGV = 11;
SIGUSR2 = 12;
SIGPIPE = 13;
SIGALRM = 14;
SIGTERM = 15;
SIGSTKFLT = 16;
SIGCHLD = 17;
SIGCONT = 18;
SIGSTOP = 19;
SIGTSTP = 20;
SIGTTIN = 21;
SIGTTOU = 22;
SIGURG = 23;
SIGXCPU = 24;
SIGXFSZ = 25;
SIGVTALRM = 26;
SIGPROF = 27;
SIGWINCH = 28;
SIGIO = 29;
SIGPOLL = 29;
SIGPWR = 30;
SIGUNUSED = 31;
(* Signal handler flags *)
SA_NOCLDSTOP = $00000001; // Turn off SIGCHLD when children stop
SA_NOCHLDWAIT = $00000002; // Not supported
SA_SIGINFO = $00000004; // Want TSigInfo structure in signal handler
SA_RESTORER = $04000000; // ?
SA_ONSTACK = $08000000; // Use registered stack for signals
SA_RESTART = $10000000; // Restarting signals
SA_INTERRUPT = $20000000; // Ignored
SA_NODEFER = $40000000; // Current signal is not masked in handler
SA_RESETHAND = $80000000; // Clear handler when signal is delivered
SA_NOMASK = SA_NODEFER;
SA_ONESHOT = SA_RESETHAND;
(* Control codes for IOCtl() *)
TCGETS = $00005401;
TCSETS = $00005402;
TIOCGWINSZ = $00005413;
TIOCSWINSZ = $00005414;
TIOCLINUX = $0000541C;
TIOCMGET = $00005415;
TIOCMSET = $00005418;
KDGKBMETA = $00004B62;
KDSKBMETA = $00004B63;
K_METABIT = $03;
K_ESCPREFIX = $04;
(* Terminal control bits for c_iflag field *)
IGNBRK = $00000001;
BRKINT = $00000002;
IGNPAR = $00000004;
PARMRK = $00000008;
INPCK = $00000010;
ISTRIP = $00000020;
INLCR = $00000040;
IGNCR = $00000080;
ICRNL = $00000100;
IUCLC = $00000200;
IXON = $00000400;
IXANY = $00000800;
IXOFF = $00001000;
IMAXBEL = $00002000;
(* Terminal control bits for c_oflag field *)
OPOST = $00000001;
OLCUC = $00000002;
ONLCR = $00000004;
OCRNL = $00000008;
ONOCR = $00000010;
ONLRET = $00000020;
OFILL = $00000040;
OFDEL = $00000080;
NLDLY = $00000100;
NL0 = $00000000;
NL1 = $00000100;
CRDLY = $00000600;
CR0 = $00000000;
CR1 = $00000200;
CR2 = $00000400;
CR3 = $00000600;
TABDLY = $00001800;
TAB0 = $00000000;
TAB1 = $00000800;
TAB2 = $00001000;
TAB3 = $00001800;
XTABS = $00001800;
BSDLY = $00002000;
BS0 = $00000000;
BS1 = $00002000;
VTDLY = $00004000;
VT0 = $00000000;
VT1 = $00004000;
FFDLY = $00008000;
FF0 = $00000000;
FF1 = $00008000;
(* Terminal control bits for c_c flag field *)
CBAUD = $0000100F;
B0 = $00000000;
B50 = $00000001;
B75 = $00000002;
B110 = $00000003;
B134 = $00000004;
B150 = $00000005;
B200 = $00000006;
B300 = $00000007;
B600 = $00000008;
B1200 = $00000009;
B1800 = $0000000A;
B2400 = $0000000B;
B4800 = $0000000C;
B9600 = $0000000D;
B19200 = $0000000E;
B38400 = $0000000F;
EXTA = B19200;
EXTB = B38400;
CSIZE = $00000030;
CS5 = $00000000;
CS6 = $00000010;
CS7 = $00000020;
CS8 = $00000030;
CSTOPB = $00000040;
CREAD = $00000080;
PARENB = $00000100;
CHUPCL = $00000200;
CLOCAL = $00000400;
CBAUDEX = $00000800;
B57600 = $00008001;
B115200 = $00008002;
B230400 = $00008003;
B460800 = $00008004;
B500000 = $00008005;
B576000 = $00008006;
B921600 = $00008007;
B1000000 = $00008008;
B1152000 = $00008009;
B1500000 = $0000800A;
B2000000 = $0000800B;
B2500000 = $0000800C;
B3000000 = $0000800D;
B3500000 = $0000800E;
B4000000 = $0000800F;
CIBAUD = $100F0000;
CMSPAR = $40000000;
CRTSCTS = $80000000;
(* Terminal control bits for c_lflag field *)
ISIG = $00000001;
ICANON = $00000002;
XCASE = $00000004;
ECHO = $00000008;
ECHOE = $00000010;
ECHOK = $00000020;
ECHONL = $00000040;
NOFLSH = $00000080;
TOSTOP = $00000100;
ECHOCTL = $00000200;
ECHOPRT = $00000400;
ECHOKE = $00000800;
FLUSHO = $00001000;
PENDIN = $00002000;
IEXTEN = $00004000;
(* Values for c_cc field *)
VINTR = 0;
VQUIT = 1;
VERASE = 2;
VKILL = 3;
VEOF = 4;
VTIME = 5;
VMIN = 6;
VSWTC = 7;
VSTART = 8;
VSTOP = 9;
VSUSP = 10;
VEOL = 11;
VREPRINT = 12;
VDISCARD = 13;
VWERASE = 14;
VLNEXT = 15;
VEOL2 = 16;
(* Flags for tcflow and TCXONC *)
TCOOFF = 0;
TCOON = 1;
TCIOFF = 2;
TCION = 3;
(* Flags for tcflush and TCFLSH *)
TCIFLUSH = 0;
TCOFLUSH = 1;
TCIOFLUSH = 2;
(* Flags for tcsetattr *)
TCSANOW = 0;
TCSADRAIN = 1;
TCSAFLUSH = 2;
(* IoCtl and Keyboard *)
KDGKBMODE = $00004B44;
KDSKBMODE = $00004B45;
K_RAW = 0;
K_XLATE = 1;
K_MEDIUMRAW = 2;
K_UNICODE = 3;
KDGETKEYCODE = $00004B4C;
KDSETKEYCODE = $00004B4D;
type
TKdKeyCode = record
ScanCode, KeyCode: LongInt;
end;
type
PDirEnt = ^TDirEnt;
TDirEnt = record
d_Ino: LongInt;
d_Off: LongInt;
d_RecLen: SmallInt;
d_Name: array[0..255] of Char;
end;
TStat = record
st_Dev: SmallInt;
__pad1: SmallInt;
st_Ino: LongInt;
st_Mode: SmallInt;
st_Nlink: SmallInt;
st_Uid: SmallInt;
st_Gid: SmallInt;
st_Rdev: SmallInt;
__pad2: SmallInt;
st_Size: LongInt;
st_BlkSize: LongInt;
st_Blocks: LongInt;
st_ATime: LongInt;
__unused1: LongInt;
st_MTime: LongInt;
__unused2: LongInt;
st_CTime: LongInt;
__unused3: LongInt;
__unused4: LongInt;
__unused5: LongInt;
end;
TTimeVal = record
tv_Sec: LongInt;
tv_USec: LongInt;
end;
TTimeZone = record
tz_MinutesWest: LongInt;
tz_DstTime: LongInt;
end;
TUTimBuf = record
actime: LongInt;
modtime: LongInt;
end;
TStatFS = record
f_Type: LongInt;
f_BSize: LongInt;
f_Blocks: LongInt;
f_BFree: LongInt;
f_BAvail: LongInt;
f_Files: LongInt;
f_FFree: LongInt;
f_FSid: array[0..1] of LongInt;
f_NameLen: LongInt;
f_Spare: array[0..5] of LongInt;
end;
TSigAction = record
sa_Handler: Pointer; (* procedure(Sig: LongInt); cdecl; *)
sa_Mask: LongInt;
sa_Flags: LongInt;
sa_Restorer: Pointer;
end;
TModifyLDT = record
Index: LongInt;
Base: Pointer;
Limit: LongInt;
Flags: LongInt;
end;
TFpReg = record
Significand: array[0..3] of Word;
Exponent: Word;
end;
TFpState = record
cw, sw, tag, ipoff, cssel, dataoff, datasel: LongInt;
_st: array[0..7] of TFpReg;
status: LongInt;
end;
TSigContext = record
gs, __gsh: Word;
fs, __fsh: Word;
es, __esh: Word;
ds, __dsh: Word;
edi: LongInt;
esi: LongInt;
ebp: LongInt;
esp: LongInt;
ebx: LongInt;
edx: LongInt;
ecx: LongInt;
eax: LongInt;
trapno: LongInt;
err: LongInt;
eip: LongInt;
cs, __csh: Word;
eflags: LongInt;
esp_at_signal: LongInt;
ss, __ssh: Word;
fpstate: ^TFpState;
oldmask: LongInt;
cr2: LongInt;
end;
TSysInfo = record
Uptime: LongInt;
Loads: array[0..2] of LongInt;
TotalRam: LongInt;
FreeRam: LongInt;
SharedRam: LongInt;
BufferRam: LongInt;
TotalSwap: LongInt;
FreeSwap: LongInt;
Procs: Word;
__Unused: array[0..21] of Char;
end;
TTimeSpec = record
tv_Sec: LongInt;
tv_NSec: LongInt;
end;
TTermios = record
c_iflag: LongInt;
c_oflag: LongInt;
c_cflag: LongInt;
c_lflag: LongInt;
c_line : Byte;
c_cc: array[0..18] of Byte;
end;
TWinSize = record
ws_row: SmallWord;
ws_col: SmallWord;
ws_xpixel: SmallWord;
ws_ypixel: SmallWord;
end;
TPipe = record
RdFile, WrFile: LongInt;
end;
PFLock = ^TFLock;
TFLock = record
l_Type: SmallInt;
l_Whence: SmallInt;
l_Start: LongInt;
l_Len: LongInt;
l_PID: LongInt;
end;
(* 1 *)
function LnxExit(Status: LongInt): LongInt;
(* 2 *)
function LnxFork: LongInt;
(* 3 *)
function LnxRead(Fd: LongInt; var Buf; Count: LongInt): LongInt;
(* 4 *)
function LnxWrite(Fd: LongInt; const Buf; Count: LongInt): LongInt;
(* 5 *)
function LnxOpen(PathName: PChar; Flags, Mode: LongInt): LongInt;
(* 6 *)
function LnxClose(Fd: LongInt): LongInt;
(* 7 *)
function LnxWaitPid(PID: LongInt; var Status: LongInt; Options: LongInt): LongInt;
(* 8 *)
function LnxCreat(PathName: PChar; Mode: LongInt): LongInt;
(* 10 *)
function LnxUnlink(PathName: PChar): LongInt;
(* 11 *)
function LnxExecve(FileName: PChar; Args: Pointer; Env: Pointer): LongInt;
(* 12 *)
function LnxChDir(Path: PChar): LongInt;
(* 13 *)
function LnxTime(var Time: LongInt): LongInt;
(* 15 *)
function LnxChMod(Path: PChar; Mode: LongInt): LongInt;
(* 17 *)
function LnxBrk(End_Data_Segment: Pointer): LongInt;
(* 19 *)
function LnxLSeek(Fd, _Offset, Whence: LongInt): LongInt;
(* 20 *)
function LnxGetPid: LongInt;
(* 25 *)
function LnxSTime(const Time: LongInt): LongInt;
(* 30 *)
function LnxUTime(FileName: PChar; const Buf: TUTimBuf): LongInt;
(* 33 *)
function LnxAccess(PathName: PChar; Mode: LongInt): LongInt;
(* 37 *)
function LnxKill(PID, Sig: LongInt): LongInt;
(* 38 *)
function LnxRename(const OldPath, NewPath: PChar): LongInt;
(* 39 *)
function LnxMkDir(Path: PChar; Mode: LongInt): LongInt;
(* 40 *)
function LnxRmDir(Path: PChar): LongInt;
(* 42 *)
function LnxPipe(var Pipe: TPipe): LongInt;
(* 54 *)
function LnxIOCtl(Fd, Request: LongInt; Arg: Pointer): LongInt;
(* 55 *)
function LnxFCntl_3(FD: LongInt; Cmd: LongInt; Lock: PFLock): LongInt;
(* 60 *)
function LnxUmask(Mask: LongInt): LongInt;
(* 67 *)
function LnxSigAction(SigNum: LongInt; const Act: TSigAction; var OldAct: TSigAction): LongInt;
(* 72 *)
function LnxSigSuspend(const Mask: LongInt): LongInt;
(* 73 *)
function LnxSigPending(var SigSet: LongInt): LongInt;
(* 78 *)
function LnxGetTimeOfDay(var TimeVal: TTimeVal; var TimeZone: TTimeZone): LongInt;
(* 79 *)
function LnxSetTimeOfDay(const TimeVal: TTimeVal; const TimeZone: TTimeZone): LongInt;
(* 85 *)
function LnxReadLink(Path, Buf: PChar; BufSize: LongInt): LongInt;
(* 89 *)
function LnxReadDir(FD: LongInt; var Dir: TDirEnt; Count: LongInt): LongInt;
(* 90 *)
function LnxMMap(Start: Pointer; Length, Prot, Flags, Fd, Offset: LongInt): Pointer;
(* 91 *)
function LnxMUnmap(Start: Pointer; Length: LongInt): LongInt;
(* 93 *)
function LnxFTruncate(FD, NewSize: LongInt): LongInt;
(* 99 *)
function LnxStatFS(Path: PChar; var StatFS: TStatFS): LongInt;
(* 106 *)
function LnxStat(FileName: PChar; var Buffer: TStat): LongInt;
(* 108 *)
function LnxFStat(FD: LongInt; var Buffer: TStat): LongInt;
(* 116 *)
function LnxSysInfo(var Info: TSysInfo): LongInt;
(* 118 *)
function LnxFSync(Fd: Longint): Longint;
(* 120 *)
function LnxClone(Child_Stack: Pointer; Flags: LongInt): LongInt;
(* 123 *)
function LnxModifyLDT(Func: LongInt; var _Ptr; ByteCount: LongInt): LongInt;
(* 125 *)
function LnxMProtect(Addr: Pointer; Len, Prot: LongInt): LongInt;
(* 126 *)
function LnxSigProcMask(How: LongInt; const NewSet: LongInt; var OldSet: LongInt): LongInt;
(* 143 *)
function LnxFlock(Fd, Operation: LongInt): LongInt;
(* 162 *)
function LnxNanoSleep(const Req: TTimeSpec; var Rem: TTimeSpec): LongInt;
{
(* Terminal stuff *)
(**
* Get Termical attributes
*)
function TrmGetAttr(var Termios: TTermios): LongInt;
(**
* Set terminal attributes. Option parameter
* is currently ignored - all changes are
* immediate.
*)
function TrmSetAttr(const Termios: TTermios): LongInt;
// TrmSetAttr
(*
* Initialize given terminal. Returns description of
* terminal or NIL if terminal capabilities couldn't
* be found.
*)
function TrmInit(TermName: PChar): PChar; // LnxGetTermInfo
// TrmInitCaps
(**
* End access to terminal.
*)
procedure TrmDone; // LnxFreeTermInfo
// TrmDoneCaps
(**
* Get a boolean terminal capability.
* See '/usr/include/term.h' for a list
* of terminal capabilities.
*)
function TrmGetBooleanCap(Index: LongInt): Boolean; // LnxGetBooleanTermCap
// TrmGetBooleanCap
(**
* Get an integer terminal capability.
* See '/usr/include/term.h' for a list
* of terminal capabilities.
*)
function TrmGetIntegerCap(Index: LongInt): SmallInt;
// TrmGetIntegerCap
(**
* Get a string terminal capability.
* See '/usr/include/term.h' for a list
* of terminal capabilities.
*)
function TrmGetStringCap(Index: LongInt): PChar;
// TrmGetStringCap
(**
* Output a terminal control string.
*)
procedure TrmControl(Format: PChar); // LnxSendTermControl
// TrmControl
(**
* Format and output a terminal control // LnxSendTermControlFmt
* string.
*)
procedure TrmControlFmt(Format: PChar; Args: array of LongInt);
// TrmControlFmt
// TrmWrite
function TrmWrite(Buffer: PChar; Count: LongInt): LongInt;
// TrmRead
function TrmRead(Buffer: PChar; Count: LongInt): LongInt;
}
(* others *)
procedure LnxDebug(S: ShortString);
implementation
uses
Strings, LnxRes;
{$r linux}
(* 1 *)
function LnxExit(Status: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 1;
mov ebx, Status;
int $80;
end;
(* 2 *)
function LnxFork: LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 2;
int $80;
end;
(* 3 *)
function LnxRead(Fd: LongInt; var Buf; Count: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 3;
mov ebx, Fd;
mov ecx, Buf;
mov edx, Count;
int $80;
end;
(* 4 *)
function LnxWrite(Fd: LongInt; const Buf; Count: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 4;
mov ebx, Fd;
mov ecx, Buf;
mov edx, Count;
int $80;
end;
(* 5 *)
function LnxOpen(PathName: PChar; Flags, Mode: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 5;
mov ebx, PathName;
mov ecx, Flags;
mov edx, Mode;
int $80;
end;
(* 6 *)
function LnxClose(Fd: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 6;
mov ebx, Fd;
int $80;
end;
(* 7 *)
function LnxWaitPid(PID: LongInt; var Status: LongInt; Options: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 7;
mov ebx, PID;
mov ecx, Status;
mov edx, Options;
int $80;
end;
(* 8 *)
function LnxCreat(PathName: PChar; Mode: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 8;
mov ebx, PathName;
mov ecx, Mode;
int $80;
end;
(* 10 *)
function LnxUnlink(PathName: PChar): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 10;
mov ebx, PathName;
int $80;
end;
(* 11 *)
function LnxExecve(FileName: PChar; Args: Pointer; Env: Pointer): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 11;
mov ebx, FileName;
mov ecx, Args;
mov edx, Env;
int $80;
end;
(* 12 *)
function LnxChDir(Path: PChar): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 12;
mov ebx, Path;
int $80;
end;
(* 13 *)
function LnxTime(var Time: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 13;
mov ebx, Time;
int $80;
end;
(* 15 *)
function LnxChMod(Path: PChar; Mode: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 15;
mov ebx, Path;
mov ecx, Mode;
int $80;
end;
(* 17 *)
function LnxBrk(End_Data_Segment: Pointer): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 17;
mov ebx, End_Data_Segment;
int $80;
end;
(* 19 *)
function LnxLSeek(Fd, _Offset, Whence: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 19;
mov ebx, Fd;
mov ecx, _Offset;
mov edx, Whence;
int $80;
end;
(* 20 *)
function LnxGetPid: LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 20;
int $80;
end;
(* 25 *)
function LnxSTime(const Time: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 25;
mov ebx, Time;
int $80;
end;
(* 30 *)
function LnxUTime(FileName: PChar; const Buf: TUTimBuf): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 30;
mov ebx, FileName;
mov ecx, Buf;
int $80;
end;
(* 33 *)
function LnxAccess(PathName: PChar; Mode: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 33;
mov ebx, PathName;
mov ecx, Mode;
int $80;
end;
(* 37 *)
function LnxKill(PID, Sig: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 37;
mov ebx, PID;
mov ecx, Sig;
int $80;
end;
(* 38 *)
// Achtung: Überschreibt!
function LnxRename(const OldPath, NewPath: PChar): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 38;
mov ebx, OldPath;
mov ecx, NewPath;
int $80;
end;
(* 39 *)
function LnxMkDir(Path: PChar; Mode: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 39;
mov ebx, Path;
mov ecx, Mode;
int $80;
end;
(* 40 *)
function LnxRmDir(Path: PChar): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 40;
mov ebx, Path;
int $80;
end;
(* 42 *)
function LnxPipe(var Pipe: TPipe): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 42;
mov ebx, Pipe;
int $80;
end;
(* 54 *)
function LnxIoCtl(Fd, Request: LongInt; Arg: Pointer): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 54;
mov ebx, Fd;
mov ecx, Request;
mov edx, Arg;
int $80;
end;
(* 55 *)
function LnxFCntl_3(FD: LongInt; Cmd: LongInt; Lock: PFLock): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 55
mov ebx, FD
mov ecx, Cmd
mov edx, Lock
int $80
end;
(* 60 *)
function LnxUmask(Mask: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 60;
mov ebx, Mask;
int $80;
end;
(* 67 *)
function LnxSigAction(SigNum: LongInt; const Act: TSigAction; var OldAct: TSigAction): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 67;
mov ebx, SigNum;
mov ecx, Act;
mov edx, OldAct;
int $80;
end;
(* 72 *)
function LnxSigSuspend(const Mask: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 72;
mov ebx, Mask;
int $80;
end;
(* 73 *)
function LnxSigPending(var SigSet: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 73;
mov ebx, SigSet;
int $80;
end;
(* 78 *)
function LnxGetTimeOfDay(var TimeVal: TTimeVal; var TimeZone: TTimeZone): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 78;
mov ebx, TimeVal;
mov ecx, TimeZone;
int $80;
end;
(* 79 *)
function LnxSetTimeOfDay(const TimeVal: TTimeVal; const TimeZone: TTimeZone): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 79;
mov ebx, TimeVal;
mov ecx, TimeZone;
int $80;
end;
(* 85 *)
function LnxReadLink(Path, Buf: PChar; BufSize: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 85;
mov ebx, Path;
mov ecx, Buf;
mov edx, BufSize;
int $80;
end;
(* 89 *)
function LnxReadDir(FD: LongInt; var Dir: TDirEnt; Count: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 89;
mov ebx, FD;
mov ecx, Dir;
mov edx, Count;
int $80;
end;
(* 90 *)
function LnxMMap(Start: Pointer; Length, Prot, Flags, Fd, Offset: LongInt): Pointer; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 90;
mov ebx, ebp;
add ebx, 8;
int $80;
end;
(* 91 *)
function LnxMUnmap(Start: Pointer; Length: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 91;
mov ebx, Start;
mov ecx, Length;
int $80;
end;
(* 93 *)
function LnxFTruncate(FD, NewSize: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 93;
mov ebx, FD;
mov ecx, NewSize;
int $80;
end;
(* 99 *)
function LnxStatFS(Path: PChar; var StatFS: TStatFS): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 99;
mov ebx, Path;
mov ecx, StatFS;
int $80;
end;
(* 106 *)
function LnxStat(FileName: PChar; var Buffer: TStat): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 106;
mov ebx, FileName;
mov ecx, Buffer;
int $80;
end;
(* 108 *)
function LnxFStat(FD: LongInt; var Buffer: TStat): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 108;
mov ebx, FD;
mov ecx, Buffer;
int $80;
end;
(* 116 *)
function LnxSysInfo(var Info: TSysInfo): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 116;
mov ebx, Info;
int $80;
end;
(* 118 *)
function LnxFSync(Fd: Longint): Longint; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 118;
mov ebx, Fd;
int $80;
end;
(* 120 *)
function LnxClone(Child_Stack: Pointer; Flags: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 120;
// mov ebx, Fn;
mov ebx, Flags;
mov ecx, Child_Stack;
// mov edi, Args;
int $80;
end;
(* 123 *)
function LnxModifyLDT(Func: LongInt; var _Ptr; ByteCount: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 123;
mov ebx, Func;
mov ecx, _Ptr;
mov edx, ByteCount;
int $80;
end;
(* 125 *)
function LnxMProtect(Addr: Pointer; Len, Prot: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 125;
mov ebx, Addr;
mov ecx, Len;
mov edx, Prot;
int $80;
end;
(* 126 *)
function LnxSigProcMask(How: LongInt; const NewSet: LongInt; var OldSet: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 126;
mov ebx, How;
mov ecx, NewSet;
mov edx, OldSet;
int $80;
end;
(* 143 *)
function LnxFlock(Fd, Operation: LongInt): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 143;
mov ebx, Fd;
mov ecx, Operation;
int $80;
end;
(* 162 *)
function LnxNanoSleep(const Req: TTimeSpec; var Rem: TTimeSpec): LongInt; {&uses ebx,ecx,edx,esi,edi}
asm
mov eax, 162;
mov ebx, Req;
mov ecx, Rem;
int $80;
end;
(* Terminal stuff *)
type
TTermInfo = record
Buffer: PChar; // Compiled terminal information read from file
OffNames: LongInt; // Offset of terminal names section
NumNames: LongInt; // Number of bytes in terminal names section
OffFlags: LongInt; // Offset of ordinal caps section
NumFlags: LongInt; // Number of ordinal caps available
OffNumbers: LongInt; // Offset of integer caps section
NumNumbers: LongInt; // Number of integer caps available
OffStrings: LongInt; // Offset of string caps section
NumStrings: LongInt; // Number of string caps available
OffValues: LongInt; // Offset of string values section
end;
var
TermInfo: TTermInfo;
function TrmGetAttr(var Termios: TTermios): LongInt;
begin
Result := LnxIOCtl(TrmHandle, TCGETS, @Termios);
end;
function TrmSetAttr(const Termios: TTermios): LongInt;
begin
Result := LnxIOCtl(TrmHandle, TCSETS, @Termios);
end;
function TrmInit(TermName: PChar): PChar;
var
FileName: array[0..1023] of Char;
P: PChar;
Handle, Actual: LongInt;
begin
Result := nil;
P := StrECopy(FileName, '/usr/lib/terminfo/');
P[0] := TermName[0];
P[1] := '/';
StrLCopy(P + 2, TermName, SizeOf(FileName) - LongInt(P - FileName) - 3);
Handle := LnxOpen(FileName, O_RDONLY, 0);
if Handle < 0 then Exit;
with TermInfo do
begin
GetMem(Buffer, 4096);
Actual := LnxRead(Handle, Buffer^, 4096);
LnxClose(Handle);
if Actual < 0 then Exit;
ReAllocMem(Buffer, Actual);
NumNames := Ord(Buffer[2]) + Ord(Buffer[3]) shl 8;
NumFlags := Ord(Buffer[4]) + Ord(Buffer[5]) shl 8;
NumNumbers := Ord(Buffer[6]) + Ord(Buffer[7]) shl 8;
NumStrings := Ord(Buffer[8]) + Ord(Buffer[9]) shl 8;
OffNames := 12;
OffFlags := OffNames + NumNames;
OffNumbers := OffFlags + NumFlags;
if Odd(OffNumbers) then Inc(OffNumbers);
OffStrings := OffNumbers + NumNumbers * 2;
OffValues := OffStrings + NumStrings * 2;
Result := StrScan(Buffer + OffNames, ' ');
if Result = nil then
Result := ''
else
Inc(Result);
end;
TrmHandle := LnxOpen('/dev/tty', O_RDWR, 0);
end;
procedure TrmDone;
begin
if TrmHandle > 0 then LnxClose(TrmHandle);
FreeMem(TermInfo.Buffer);
end;
function TrmGetBooleanCap(Index: LongInt): Boolean;
begin
with TermInfo do
begin
if Index >= NumFlags then
Result := False
else
Result := Buffer[OffFlags + Index] <> #0;
end;
end;
function TrmGetIntegerCap(Index: LongInt): SmallInt;
type
PSmallInt = ^SmallInt;
begin
with TermInfo do
begin
if Index >= NumNumbers then
Result := -1
else
Result := PSmallInt(@Buffer[OffNumbers + Index * 2])^;
end;
end;
function TrmGetStringCap(Index: LongInt): PChar;
type
PSmallInt = ^SmallInt;
var
Offset: SmallInt;
begin
with TermInfo do
begin
if Index >= NumStrings then
Result := ''
else
begin
Offset := PSmallInt(@Buffer[OffStrings + Index * 2])^;
if Offset = -1 then
Result := ''
else
Result := @Buffer[OffValues + Offset];
end;
end;
end;
procedure TrmControl(Format: PChar);
begin
LnxWrite(STDOUT_FILENO, Format^, StrLen(Format));
end;
procedure TrmControlFmt(Format: PChar; Args: array of LongInt);
var
BufferPtr, FormatPtr: PChar;
Stack: array[0..15] of LongInt;
StackPtr: LongInt;
Digits, Value: LongInt;
Condition: Boolean;
Buffer: array[0..1023] of Char;
procedure Push(I: LongInt);
begin
Inc(StackPtr);
Stack[StackPtr] := I;
end;
function Pop: LongInt;
begin
Result := Stack[StackPtr];
Dec(StackPtr);
end;
function GetInt: LongInt;
begin
Result := 0;
while FormatPtr^ in ['0'..'9'] do
begin
Result := Result * 10 + Ord(FormatPtr^) - Ord('0');
Inc(FormatPtr);
end;
end;
procedure PutChar(C: Char);
begin
if C > ' ' then Write(C) else Write('#', Ord(C));
BufferPtr^ := C;
Inc(BufferPtr);
end;
procedure PutHex(I, Digits: LongInt);
const
Hex: PChar = '0123456789abcdef';
begin
if (I > $FFF) or (Digits > 3) then
begin
PutChar(Hex[I shr 12]);
I := I and $FFF;
end;
if (I > $FF) or (Digits > 2) then
begin
PutChar(Hex[I shr 8]);
I := I and $FF;
end;
if (I > $F) or (Digits > 1) then
begin
PutChar(Hex[I shr 4]);
I := I and $F;
end;
PutChar(Hex[I]);
end;
procedure PutInt(I, Digits: LongInt);
begin
if I < 0 then
begin
PutChar('-');
I := -I;
end;
if (I > 999) or (Digits > 3) then
begin
PutChar(Char(48 + I div 1000));
I := I mod 1000;
end;
if (I > 99) or (Digits > 2) then
begin
PutChar(Char(48 + I div 100));
I := I mod 100;
end;
if (I > 9) or (Digits > 1) then
begin
PutChar(Char(48 + I div 10));
I := I mod 10;
end;
PutChar(Char(48 + I));
end;
procedure PutStr(P: PChar);
begin
BufferPtr := StrECopy(BufferPtr, P);
end;
begin
StackPtr := -1;
Condition := True;
FormatPtr := Format;
BufferPtr := Buffer;
while FormatPtr^ <> #0 do
begin
if FormatPtr^ = '%' then
begin
Inc(FormatPtr);
Digits := GetInt;
case FormatPtr^ of
'?':
begin
end;
't':
begin
Condition := (Pop <> 0);
// if condition not true, then ignore this part
if not Condition then
begin
Inc(FormatPtr);
while not ((FormatPtr[0] = '%') and (FormatPtr[1] in ['e', ';'])) do
Inc(FormatPtr);
Inc(FormatPtr);
end;
end;
'e':
begin
// if condition already true, then ignore this part
if Condition then
begin
Inc(FormatPtr);
while not ((FormatPtr[0] = '%') and (FormatPtr[1] = ';')) do
Inc(FormatPtr);
Inc(FormatPtr);
end;
end;
';':
begin
end;
'%':
begin
PutChar('%');
end;
'''':
begin
Inc(FormatPtr);
Push(Ord(FormatPtr^));
Inc(FormatPtr);
end;
'{':
begin
Inc(FormatPtr);
Push(GetInt);
end;
'+': Push(Pop + Pop);
'-': begin Value := Pop; Push(Pop - Value); end;
'*': Push(Pop * Pop);
'/': begin Value := Pop; Push(Pop div Value); end;
'm': begin Value := Pop; Push(Pop mod Value); end;
'&': Push(Pop and Pop);
'|': Push(Pop or Pop);
'^': Push(Pop xor Pop);
'=': Push(Ord(Pop = Pop));
'<': Push(Ord(Pop >= Pop));
'>': Push(Ord(Pop <= Pop));
'A': Push(Ord((Pop <> 0) and (Pop <> 0)));
'O': Push(Ord((Pop <> 0) or (Pop <> 0)));
'!': Push(Ord(Pop = 0));
'~': Push(not Pop);
'd':
begin
PutInt(Pop, Digits);
end;
'i':
begin
Inc(Args[0]);
Inc(Args[1]);
end;
'p':
begin
Inc(FormatPtr);
case FormatPtr^ of
'1'..'9':
begin
Push(Args[Ord(FormatPtr^) - Ord('1')]);
end;
else
WriteLn('Terminal error: Illegal parameter "', FormatPtr, '"');
Halt(255);
end;
end;
's':
begin
PutStr(PChar(Pop));
end;
'x':
begin
PutHex(Pop, Digits);
end;
else
WriteLn('Terminal error: Unknown terminal control sequence "%', FormatPtr^, '"');
Halt(255);
end;
end
else PutChar(FormatPtr^);
Inc(FormatPtr);
end;
BufferPtr^ := #0;
TrmControl(Buffer);
end;
function TrmRead(Buffer: PChar; Count: LongInt): LongInt;
begin
Result := LnxRead(TrmHandle, Buffer^, Count);
end;
function TrmWrite(Buffer: PChar; Count: LongInt): LongInt;
begin
Result := LnxWrite(TrmHandle, Buffer^, Count);
end;
(* others *)
(* Output a string - not really a system call *)
procedure LnxDebug(S: ShortString);
begin
S := S + #10;
LnxWrite(1, S[1], Length(S));
end;
end.
{
Currently unimplemeted system calls:
__NR_setup 0 (* used only by init, to get system going *)
__NR_link 9
__NR_mknod 14
__NR_chown 16
__NR_oldstat 18
__NR_mount 21
__NR_umount 22
__NR_setuid 23
__NR_getuid 24
__NR_ptrace 26
__NR_alarm 27
__NR_oldfstat 28
__NR_pause 29
__NR_stty 31
__NR_gtty 32
__NR_nice 34
__NR_ftime 35
__NR_sync 36
__NR_dup 41
__NR_times 43
__NR_prof 44
__NR_setgid 46
__NR_getgid 47
__NR_signal 48
__NR_geteuid 49
__NR_getegid 50
__NR_acct 51
__NR_phys 52
__NR_lock 53
__NR_fcntl 55
__NR_mpx 56
__NR_setpgid 57
__NR_ulimit 58
__NR_oldolduname 59
__NR_umask 60
__NR_chroot 61
__NR_ustat 62
__NR_dup2 63
__NR_getppid 64
__NR_getpgrp 65
__NR_setsid 66
__NR_sigaction 67
__NR_sgetmask 68
__NR_ssetmask 69
__NR_setreuid 70
__NR_setregid 71
__NR_sethostname 74
__NR_setrlimit 75
__NR_getrlimit 76
__NR_getrusage 77
__NR_getgroups 80
__NR_setgroups 81
__NR_select 82
__NR_symlink 83
__NR_oldlstat 84
__NR_uselib 86
__NR_swapon 87
__NR_reboot 88
__NR_truncate 92
__NR_fchmod 94
__NR_fchown 95
__NR_getpriority 96
__NR_setpriority 97
__NR_profil 98
__NR_fstatfs 100
__NR_ioperm 101
__NR_socketcall 102
__NR_syslog 103
__NR_setitimer 104
__NR_getitimer 105
__NR_lstat 107
__NR_olduname 109
__NR_iopl 110
__NR_vhangup 111
__NR_idle 112
__NR_vm86 113
__NR_wait4 114
__NR_swapoff 115
__NR_ipc 117
__NR_sigreturn 119
__NR_setdomainname 121
__NR_uname 122
__NR_adjtimex 124
__NR_create_module 127
__NR_init_module 128
__NR_delete_module 129
__NR_get_kernel_syms 130
__NR_quotactl 131
__NR_getpgid 132
__NR_fchdir 133
__NR_bdflush 134
__NR_sysfs 135
__NR_personality 136
__NR_afs_syscall 137 (* Syscall for Andrew File System *)
__NR_setfsuid 138
__NR_setfsgid 139
__NR__llseek 140
__NR_getdents 141
__NR__newselect 142
__NR_msync 144
__NR_readv 145
__NR_writev 146
__NR_getsid 147
__NR_fdatasync 148
__NR__sysctl 149
__NR_mlock 150
__NR_munlock 151
__NR_mlockall 152
__NR_munlockall 153
__NR_sched_setparam 154
__NR_sched_getparam 155
__NR_sched_setscheduler 156
__NR_sched_getscheduler 157
__NR_sched_yield 158
__NR_sched_get_priority_max 159
__NR_sched_get_priority_min 160
__NR_sched_rr_get_interval 161
__NR_mremap 163
__NR_poll 168
__NR_getpmsg 188
__NR_putpmsg 189
}