M2makeOS.def 2.0 KB

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