(*
    Title: 	UnixRun - Definitions
    LastEdit:	"Tue May  1 11:19:22 1984"
    Author: 	Mick Jordan
		Cambridge University Computer Laboratory

    A package to aid in executing Unix sub-processes
*)

DEFINITION MODULE UnixRun;

EXPORT QUALIFIED 
    RUNErrorCode, RUNERROR, RUNMESSAGE, 
    RunMessage, Run, PIPEMODE, PipeOpen, PipeClose;

TYPE RUNErrorCode = 
    (ok,                        (* everything went ok *)
     fork, exec, wait, pipe,    (* resepective call failed (catastrophic) *)
     exit,                      (* exited with status non-zero *)
     termination                (* abnormal termination *)
    );

     RUNERROR = 
        RECORD
            code: RUNErrorCode; (* one of the above *)
	    errno: INTEGER;     (* associated error code *)
        END;

     RUNMESSAGE = ARRAY [0 ..  39]  OF CHAR;

PROCEDURE Run(program: ARRAY OF CHAR; argv: ARRAY OF CARDINAL;
              VAR runError: RUNERROR);
(* run 'program' with arguments in 'argv'.
*)
PROCEDURE RunMessage(runError: RUNERROR; VAR m: RUNMESSAGE);
(* translate 'runError.code' into an appropriate string
*)

TYPE PIPEMODE = (READ, WRITE);

PROCEDURE PipeOpen(program: ARRAY OF CHAR; pipemode: PIPEMODE;
                   argv: ARRAY OF CARDINAL; VAR runError: RUNERROR): CARDINAL;
(* open a pipe between calling process and executed 'program',
   The result is the file descriptor for reading or writing
   (according to 'pipemode') to be used by the caller.
   Only 'fork', 'exec' and 'pipe' errors can be returned.
*)
PROCEDURE PipeClose(fd: CARDINAL; VAR runError: RUNERROR);
(* close pipe 'fd', and wait for child spawned by 'PipeOpen'
   to complete.  Status is returned in 'runError'.
*)

END UnixRun .
