editor3.mod 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. MODULE editor2;
  2. (* based on the kilo editor building course*)
  3. (* Step 3 *)
  4. (* using different libreries for the same purpose, some lowlevel, some higher level *)
  5. (* using ISO libs *)
  6. IMPORT RawIO, TermFile, IOChan, ChanConsts, SYSTEM, STextIO;
  7. (* CONST
  8. flags = ChanConsts.FlagSet{read,write,raw}; *)
  9. VAR
  10. c : CHAR;
  11. chan : IOChan.ChanId;
  12. result : ChanConsts.OpenResults;
  13. flags : ChanConsts.FlagSet;
  14. BEGIN
  15. (* PROCEDURE Read (cid: IOChan.ChanId; VAR to: ARRAY OF SYSTEM.LOC); *)
  16. (* Reads storage units from cid, and assigns them to
  17. successive components of to. The read result is set
  18. to the value allRight, wrongFormat, or endOfInput.
  19. *)
  20. (* CONST *)
  21. (* read = FlagSet{ChanConsts.readFlag}; *)
  22. (* input operations are requested/available *)
  23. (* write = FlagSet{ChanConsts.writeFlag}; *)
  24. (* output operations are requested/available *)
  25. (* text = FlagSet{ChanConsts.textFlag}; *)
  26. (* text operations are requested/available *)
  27. (* raw = FlagSet{ChanConsts.rawFlag}; *)
  28. (* raw operations are requested/available *)
  29. (* echo = FlagSet{ChanConsts.echoFlag}; *)
  30. (* echoing by interactive device on reading of characters from input stream requested/applies
  31. *)
  32. (* PROCEDURE Open (VAR cid: ChanId; flagset: FlagSet; VAR res: OpenResults); *)
  33. (* Attempts to obtain and open a channel connected to
  34. the terminal. Without the raw flag, text is implied.
  35. Without the echo flag, line mode is requested,
  36. otherwise single character mode is requested.
  37. If successful, assigns to cid the identity of
  38. the opened channel, and assigns the value opened to res.
  39. If a channel cannot be opened as required, the value of
  40. res indicates the reason, and cid identifies the
  41. invalid channel.
  42. *)
  43. (* doesn't work .......; dunno why ! *)
  44. flags := ChanConsts.read + ChanConsts.write + ChanConsts.raw;
  45. TermFile.Open(chan, flags,result);
  46. IF result = ChanConsts.opened THEN
  47. STextIO.WriteString(" file opened");
  48. STextIO.WriteLn;
  49. LOOP
  50. RawIO.Read(chan,SYSTEM.ADR(c));
  51. IF c = "q" THEN
  52. EXIT
  53. END;
  54. END;
  55. END;
  56. END editor2.