OS
Module for basic OS functionality
Const
Unknown* = 0;
Position* = 1;
Flag* = 2;
Parameter* = 3;
Types
Argument* =
RECORD
name* : String.STRING;
value* : String.STRING;
index* : LENGTH;
type* : LENGTH
END;
Procedures
ProgramName
Get program name
PROCEDURE ProgramName*(VAR name : String.STRING);
Args
Get number of program arguments
PROCEDURE Args*(): LENGTH;
Arg
Get n-th argument
PROCEDURE Arg*(VAR str : String.STRING; n : LENGTH);
InitArgument
Initialize argument parser.
The parser support a on purpose limited for unambigious parsing. The POSIX type of arguments with space between flag and value is ambigious and therfore not supported.
-f, sets type to Flag and name to f. value is empty.
-fval1, sets type to Parameter, name to f and value to val1
Only alpha numeric characters are supported for short arguments.
–flag, sets type to Flag and name to flag. value is empty.
-flag=val1, sets type to Parameter, name to flag and value to val1
Any character is valid after =. Whitespace is supported by enclosing the value in quotes.
An invalid argument is marked with type set to Unknown and with value set the argument.
Other arguments are returned as type Position and with value set to the argument.
PROCEDURE InitArgument*(VAR arg : Argument);
NextArgument
Fetch next argument or return FALSE if finished
PROCEDURE NextArgument*(VAR arg : Argument): BOOLEAN;
HasEnv
Check if environment variable exists
PROCEDURE HasEnv*(name- : ARRAY OF CHAR): BOOLEAN;
Env
Get environment variable
PROCEDURE Env*(VAR value : String.STRING; name- : ARRAY OF CHAR);
ConsoleReadKey
Read single key from console without echo.
PROCEDURE ConsoleReadKey*(): CHAR;
Execute
Execute cmd without arguments. STDIN, STDOUT & STDERR is redirected to /dev/null. Returns 0 on success.
PROCEDURE Execute*(cmd- : ARRAY OF CHAR): INTEGER;
ExecuteArgs
Execute cmd with arguments. STDIN, STDOUT & STDERR is redirected to /dev/null. Returns 0 on success.
PROCEDURE ExecuteArgs*(cmd- : ARRAY OF CHAR; args- : ARRAY OF Type.STRING): INTEGER;
ExecuteWithCapture
Execute cmd with arguments and capture STDOUT & STDERR. STDIN is redirected to /dev/null. Returns 0 on success.
PROCEDURE ExecuteWithCapture*(cmd- : ARRAY OF CHAR; args- : ARRAY OF Type.STRING; VAR fh : Type.Stream): INTEGER;
GetLastError
Get last error code or OK on no error.
PROCEDURE GetLastError*(VAR error: INTEGER);
Exit
Exit with return code
PROCEDURE Exit*(code : INTEGER);