MODULE; IMPORT Rd, Wr, Thread, Stdio, FileRd, FileWr, Fmt, OSError, Lex, FloatMode; <* FATAL Rd.Failure, Wr.Failure, Thread.Alerted *> PROCEDURE IO Put (txt: TEXT; wr: Wr.T := NIL)= BEGIN IF wr = NIL THEN wr := Stdio.stdout END; Wr.PutText(wr, txt); Wr.Flush(wr); END Put; PROCEDUREPutChar (ch: CHAR; wr: Wr.T := NIL)= BEGIN IF wr = NIL THEN wr := Stdio.stdout END; Wr.PutChar(wr, ch); Wr.Flush(wr); END PutChar; PROCEDUREPutWideChar (ch: WIDECHAR; wr: Wr.T := NIL)= BEGIN IF wr = NIL THEN wr := Stdio.stdout END; Wr.PutWideChar(wr, ch); Wr.Flush(wr); END PutWideChar; PROCEDUREPutInt (n: INTEGER; wr: Wr.T := NIL)= BEGIN IF wr = NIL THEN wr := Stdio.stdout END; Wr.PutText(wr, Fmt.Int(n)); Wr.Flush(wr); END PutInt; PROCEDUREPutLongInt (n: LONGINT; wr: Wr.T := NIL)= BEGIN IF wr = NIL THEN wr := Stdio.stdout END; Wr.PutText(wr, Fmt.LongInt(n)); Wr.Flush(wr); END PutLongInt; PROCEDUREPutReal (r: REAL; wr: Wr.T := NIL)= BEGIN IF wr = NIL THEN wr := Stdio.stdout END; Wr.PutText(wr, Fmt.Real(r)); Wr.Flush(wr); END PutReal; PROCEDUREEOF (rd: Rd.T := NIL): BOOLEAN= BEGIN IF rd = NIL THEN rd := Stdio.stdin END; RETURN Rd.EOF(rd); END EOF; PROCEDUREGetLine (rd: Rd.T := NIL): TEXT RAISES {Error}= BEGIN IF rd = NIL THEN rd := Stdio.stdin END; TRY RETURN Rd.GetLine(rd); EXCEPT | Rd.EndOfFile => RAISE Error; END; END GetLine; PROCEDUREGetChar (rd: Rd.T := NIL): CHAR RAISES {Error}= BEGIN IF rd = NIL THEN rd := Stdio.stdin END; TRY RETURN Rd.GetChar(rd); EXCEPT | Rd.EndOfFile => RAISE Error; END; END GetChar; PROCEDUREGetWideChar (rd: Rd.T := NIL): WIDECHAR RAISES {Error}= BEGIN IF rd = NIL THEN rd := Stdio.stdin END; TRY RETURN Rd.GetWideChar(rd); EXCEPT | Rd.EndOfFile => RAISE Error; END; END GetWideChar; PROCEDUREGetInt (rd: Rd.T := NIL): INTEGER RAISES {Error}= BEGIN IF rd = NIL THEN rd := Stdio.stdin END; TRY RETURN Lex.Int(rd); EXCEPT | Lex.Error, FloatMode.Trap => RAISE Error; END; END GetInt; PROCEDUREGetLongInt (rd: Rd.T := NIL): LONGINT RAISES {Error}= BEGIN IF rd = NIL THEN rd := Stdio.stdin END; TRY RETURN Lex.LongInt(rd); EXCEPT | Lex.Error, FloatMode.Trap => RAISE Error; END; END GetLongInt; PROCEDUREGetReal (rd: Rd.T := NIL): REAL RAISES {Error}= BEGIN IF rd = NIL THEN rd := Stdio.stdin END; TRY RETURN Lex.Real(rd); EXCEPT | Lex.Error, FloatMode.Trap => RAISE Error; END; END GetReal; PROCEDUREOpenRead (f: TEXT): Rd.T= BEGIN TRY RETURN FileRd.Open(f); EXCEPT | OSError.E => RETURN NIL; END END OpenRead; PROCEDUREOpenWrite (f: TEXT): Wr.T= BEGIN TRY RETURN FileWr.Open(f); EXCEPT | OSError.E => RETURN NIL; END END OpenWrite; BEGIN END IO.