| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- MODULE editor;
- (* based on the kilo editor building course*)
- (* Step 13 *)
- (* identical to step 6 : it was set with BufferMode *)
- IMPORT IO, termios, FIO, libc, CharClass, NumberIO, ASCII ;
- IMPORT STextIO;
- VAR
- c : CHAR;
- theTermios : termios.TERMIOS;
- TCSAFLUSH : INTEGER;
- PROCEDURE disablerawMode() : INTEGER;
- VAR
- result : INTEGER;
- BEGIN
- IO.BufferedMode(0,TRUE);
- IO.BufferedMode(1,TRUE);
- result := termios.tcsetattr(FIO.StdIn, TCSAFLUSH, theTermios);
- IF result = -1 THEN
- theTermios := termios.KillTermios(theTermios);
- HALT
- ELSE
- RETURN result
- END;
- END disablerawMode;
- PROCEDURE enablerawMode;
- BEGIN
- libc.atexit(disablerawMode);
- theTermios := termios.InitTermios();
- IF termios.tcgetattr(FIO.StdIn, theTermios) = -1 THEN
- HALT
- END;
- IO.UnBufferedMode(0,TRUE);
- IO.UnBufferedMode(1,TRUE);
- END enablerawMode;
- BEGIN
- TCSAFLUSH := termios.tcsflush ();
- enablerawMode;
- LOOP
- IO.Read(c);
- IF c = "q" THEN
- EXIT
- ELSIF CharClass.IsControl(c) THEN
- NumberIO.WriteCard(ORD(c),5);
- IO.Write(ASCII.EOL);
- IO.Write(ASCII.lf);
- ELSE
- NumberIO.WriteCard(ORD(c),5);
- IO.Write(" ");
- IO.Write("(");
- IO.Write("'");
- IO.Write(c);
- IO.Write(" ");
- IO.Write("'");
- IO.Write(")");
- IO.Write(ASCII.EOL);
- IO.Write(ASCII.lf);
-
- END;
- END;
- END editor.
|