MODULE editor2; (* based on the kilo editor building course*) (* Step 3 *) (* using different libreries for the same purpose, some lowlevel, some higher level *) (* using ISO libs *) IMPORT RawIO, TermFile, IOChan, ChanConsts, SYSTEM, STextIO; (* CONST flags = ChanConsts.FlagSet{read,write,raw}; *) VAR c : CHAR; chan : IOChan.ChanId; result : ChanConsts.OpenResults; flags : ChanConsts.FlagSet; BEGIN (* PROCEDURE Read (cid: IOChan.ChanId; VAR to: ARRAY OF SYSTEM.LOC); *) (* Reads storage units from cid, and assigns them to successive components of to. The read result is set to the value allRight, wrongFormat, or endOfInput. *) (* CONST *) (* read = FlagSet{ChanConsts.readFlag}; *) (* input operations are requested/available *) (* write = FlagSet{ChanConsts.writeFlag}; *) (* output operations are requested/available *) (* text = FlagSet{ChanConsts.textFlag}; *) (* text operations are requested/available *) (* raw = FlagSet{ChanConsts.rawFlag}; *) (* raw operations are requested/available *) (* echo = FlagSet{ChanConsts.echoFlag}; *) (* echoing by interactive device on reading of characters from input stream requested/applies *) (* PROCEDURE Open (VAR cid: ChanId; flagset: FlagSet; VAR res: OpenResults); *) (* Attempts to obtain and open a channel connected to the terminal. Without the raw flag, text is implied. Without the echo flag, line mode is requested, otherwise single character mode is requested. If successful, assigns to cid the identity of the opened channel, and assigns the value opened to res. If a channel cannot be opened as required, the value of res indicates the reason, and cid identifies the invalid channel. *) (* doesn't work .......; dunno why ! *) flags := ChanConsts.read + ChanConsts.write + ChanConsts.raw; TermFile.Open(chan, flags,result); IF result = ChanConsts.opened THEN STextIO.WriteString(" file opened"); STextIO.WriteLn; LOOP RawIO.Read(chan,SYSTEM.ADR(c)); IF c = "q" THEN EXIT END; END; END; END editor2.