| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- DEFINITION MODULE M2makeOS;
- (* OS bridge for M2make: file existence/timestamps, command execution,
- process exit, and sequential text input.
- This definition module is compiler-neutral (plain ISO Modula-2 plus
- SYSTEM.ADDRESS, available in both GNU Modula-2 and the V3 M2
- compiler). The two implementations share no source:
- M2makeOS_gm2.mod binds m2make_os.c via M2makeC (FOR "C"),
- M2makeOS_v3.mod binds m2make_os.c via EXTERNAL.
- Strings are NUL-terminated buffers on both sides (V3 fixed buffers
- are NUL-padded with count == capacity), so no length bookkeeping
- crosses this boundary. *)
- FROM SYSTEM IMPORT ADDRESS;
- TYPE
- RdFile = ADDRESS; (* opaque read handle; NIL when OpenRead fails *)
- PROCEDURE FileExists(VAR name: ARRAY OF CHAR): BOOLEAN;
- (* TRUE when name can be statted. *)
- PROCEDURE FileMTime(VAR name: ARRAY OF CHAR; VAR t: LONGINT): BOOLEAN;
- (* t := modification time (seconds since the epoch) of name.
- FALSE when the file cannot be statted. *)
- PROCEDURE ExecCmd(VAR cmd: ARRAY OF CHAR): INTEGER;
- (* Runs cmd via /bin/sh; returns the system() status (0 = success). *)
- PROCEDURE ExitNow(code: INTEGER);
- (* Terminates the process with the given exit code. Does not return. *)
- PROCEDURE OpenRead(VAR name: ARRAY OF CHAR): RdFile;
- (* Opens name for sequential text input; NIL on failure. *)
- PROCEDURE ArgCount(): CARDINAL;
- (* Number of command-line arguments, not counting the program name. *)
- PROCEDURE GetArg(i: CARDINAL; VAR s: ARRAY OF CHAR;
- cap: CARDINAL): BOOLEAN;
- (* Copies argument i (0-based, program name excluded) into s, truncated
- to cap-1 characters plus NUL. FALSE when there is no such
- argument or cap is 0. *)
- PROCEDURE ReadLine(h: RdFile; VAR buf: ARRAY OF CHAR;
- cap: CARDINAL): BOOLEAN;
- (* Reads the next physical line (newline stripped) into buf, truncated
- to cap-1 characters plus NUL. FALSE at end of file (a final line
- without a newline still returns TRUE once). *)
- PROCEDURE CloseRead(h: RdFile);
- (* Closes a handle from OpenRead (NIL is ignored). *)
- END M2makeOS.
|