Happy computing!
Manfred
> MODULE TextMath;
>
> IMPORT TextModels, TextControllers, TextMappers;
>
> CONST line = 0DX;
>
> PROCEDURE ProcessLine*;
> (*
> PRE: The caret is located at the end of a line
> POST: The text on the line is read, processed and written on the next line
> preceded by "<< "
> *)
> VAR
> i, j, n: INTEGER;
> ch: CHAR;
> oldPos: INTEGER;
> buf, str: ARRAY 128 OF CHAR;
> text: TextModels.Model;
> c: TextControllers.Controller;
> r: TextModels.Reader;
> f: TextMappers.Formatter;
> BEGIN
> c := TextControllers.Focus(); (* get the controler of the focus text *)
> IF c.HasSelection() THEN RETURN END; (* otherwise Trap when setting the
reader *)
> text := c.text; (* get the text of the focus window *)
> r := text.NewReader(NIL); (* connect a reader to the text *)
> oldPos := c.CaretPos(); (* remember position of the caret *)
> IF oldPos = 0 THEN RETURN END; (* caret is at beginning of text *)
> r.SetPos(oldPos); (* set the reader on the caret position in the text *)
> (* Now read backward a stretch of text into a buffer, e.g. until the start
of the line *)
> n := 0; r.ReadPrevChar(ch);
> WHILE ch # line DO
> buf[n] := ch;
> INC(n); r.ReadPrevChar(ch)
> END;
> (* Do something with the characters in the (inverse!) buffer *)
> j := 0;
> FOR i := n - 1 TO 0 BY -1 DO str[j] := buf[i]; INC(j) END; str[j] := 0X;
> (* Write the string to the text at the proper position *)
> f.ConnectTo(text); (* open formatter on text *)
> f.SetPos(oldPos); (* set caret to old position *)
> f.WriteLn;
> f.WriteString("<< " + str);
> END ProcessLine;
>
> END TextMath.
------------------------------------------------------
Dr. Manfred Wuttke phone: +49 (0) 5204 2944
Hilterweg 14
D-33803 Steinhagen e-mail: wuttke@stein.teuto.de
Germany