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
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);
GetLastError
Get last error code or OK on no error.
PROCEDURE GetLastError*(VAR error: INTEGER);
Exit
Exit with return code
PROCEDURE Exit*(code : INTEGER);