home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / oberon / system / terminal.mod (.txt) < prev    next >
Oberon Text  |  1977-12-31  |  6KB  |  135 lines

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 28 Feb 96
  6. Syntax10b.Scn.Fnt
  7. MODULE Terminal; (* ww 
  8.     IMPORT
  9.         TerminalFrames, Terminals, Sessions, Oberon, MenuViewers, Viewers, TextFrames, Texts, Fonts, Display, Files;
  10.     CONST
  11.         DefaultMenu = "System.Close  System.Copy  System.Grow  Terminal.Reset  Terminal.Stop ";
  12.     TYPE
  13.         Text = POINTER TO TextDesc;
  14.         Terminal* = POINTER TO TerminalDesc;
  15.         TerminalDesc = RECORD(Sessions.TerminalDesc)
  16.             text: Text;
  17.             state: INTEGER
  18.         END;
  19.         TextDesc = RECORD(Terminals.TerminalDesc)
  20.             term: Terminal
  21.         END;
  22.         w: Texts.Writer;
  23.     PROCEDURE Receive(t: Sessions.Terminal; ch: CHAR);
  24.     BEGIN Terminals.Receive(t(Terminal).text, ch)
  25.     END Receive;
  26.     PROCEDURE TelnetInitReceiver(t: Sessions.Terminal; ch: CHAR);
  27.         VAR s: Sessions.Session;
  28.     BEGIN
  29.         WITH t: Terminal DO
  30.             IF t.state = 1 THEN
  31.                 IF ch = 0FFX THEN t.state := 2 ELSE t.receive := Receive; Receive(t, ch) END
  32.             ELSIF t.state = 2 THEN
  33.                 IF ch = 0FDX THEN t.state := 4 ELSIF ch > 0FAX THEN t.state := 3 ELSE t.state := 1 END
  34.             ELSIF t.state = 3 THEN t.state := 1
  35.             ELSIF t.state = 4 THEN
  36.                 IF ch = 18X THEN s := Sessions.ThisSession(t);
  37.                     Sessions.SendChar(s, 0FFX); Sessions.SendChar(s, 0FCX); Sessions.SendChar(s, 18X)
  38.                 END;
  39.                 t.state := 1
  40.             ELSE t.state := 1
  41.             END
  42.         END
  43.     END TelnetInitReceiver;
  44.     PROCEDURE Flush(t: Sessions.Terminal; changed, terminated: BOOLEAN);
  45.     BEGIN Terminals.Flush(t(Terminal).text);
  46.         IF terminated THEN Sessions.Remove(t) END
  47.     END Flush;
  48.     PROCEDURE Send(t: Terminals.Terminal; ch: CHAR);
  49.         VAR s: Sessions.Session;
  50.     BEGIN s := Sessions.ThisSession(t(Text).term);
  51.         IF s # NIL THEN Sessions.SendChar(s, ch) END
  52.     END Send;
  53.     PROCEDURE Break(t: Terminals.Terminal);
  54.         VAR s: Sessions.Session;
  55.     BEGIN s := Sessions.ThisSession(t(Text).term);
  56.         IF s # NIL THEN Sessions.SendBreak(s) END
  57.     END Break;
  58.     PROCEDURE IsTerminal(t: Sessions.Terminal): BOOLEAN;
  59.     BEGIN RETURN t IS Terminal
  60.     END IsTerminal;
  61.     PROCEDURE New*(s: Sessions.Session): Terminal;
  62.         VAR t: Terminal; text: Text;
  63.     BEGIN NEW(t); NEW(text); t.text := text; text.term := t; t.state := 1;
  64.         Terminals.Open(text, NIL, Send, Break, TerminalFrames.NotifyDisplay);
  65.         Sessions.Install(t, s, TelnetInitReceiver, Flush, -1); RETURN t
  66.     END New;
  67.     PROCEDURE HandleFrame*(f: Display.Frame; VAR m: Display.FrameMsg);
  68.     BEGIN
  69.         IF m IS Sessions.IdentifyMsg THEN
  70.             m(Sessions.IdentifyMsg).session := Sessions.ThisSession(f(TerminalFrames.Frame).text(Text).term)
  71.         ELSE TerminalFrames.Handle(f, m)
  72.         END
  73.     END HandleFrame;
  74.     PROCEDURE OpenViewer*(t: Terminal; fnt: Fonts.Font);
  75.         VAR x, y: INTEGER; v: Viewers.Viewer; mf: TextFrames.Frame; cf: TerminalFrames.Frame; name: ARRAY 64 OF CHAR;
  76.     BEGIN Sessions.GetName(Sessions.ThisSession(t), name);
  77.         mf := TextFrames.NewMenu(name, DefaultMenu);
  78.         IF Files.Old("Terminal.Menu.Text") # NIL THEN Texts.Open(mf.text, "Terminal.Menu.Text");
  79.             Texts.WriteString(w, name); Texts.WriteString(w, " | "); Texts.Insert(mf.text, 0, w.buf)
  80.         END;
  81.         NEW(cf); TerminalFrames.Open(cf, HandleFrame, t.text, fnt);
  82.         Oberon.AllocateUserViewer(Oberon.Mouse.X, x, y);
  83.         v := MenuViewers.New(mf, cf, TextFrames.menuH, x, y)
  84.     END OpenViewer;
  85.     PROCEDURE Reset*;
  86.         VAR v: Viewers.Viewer; f: Display.Frame;
  87.     BEGIN f := NIL;
  88.         IF Oberon.Par.vwr.dsc = Oberon.Par.frame THEN f := Oberon.Par.frame.next
  89.         ELSE v := Oberon.MarkedViewer();
  90.             IF v.dsc # NIL THEN f := v.dsc.next END
  91.         END;
  92.         IF (f # NIL) & (f IS TerminalFrames.Frame) THEN Terminals.Reset(f(TerminalFrames.Frame).text) END
  93.     END Reset;
  94.     PROCEDURE Stop*;
  95.         VAR v: Viewers.Viewer; f: Display.Frame; term: Terminal; s: Sessions.Session;
  96.     BEGIN f := NIL;
  97.         IF Oberon.Par.vwr.dsc = Oberon.Par.frame THEN f := Oberon.Par.frame.next
  98.         ELSE v := Oberon.MarkedViewer();
  99.             IF v.dsc # NIL THEN f := v.dsc.next END
  100.         END;
  101.         IF (f # NIL) & (f IS TerminalFrames.Frame) THEN term := f(TerminalFrames.Frame).text(Text).term;
  102.             s := Sessions.ThisSession(term);
  103.             IF s # NIL THEN Sessions.Remove(term)
  104.             END
  105.         ELSE Texts.WriteString(w, "Terminal.Stop failed (bad receiver)"); Texts.WriteLn(w);Texts.Append(Oberon.Log, w.buf)
  106.         END
  107.     END Stop;
  108.     PROCEDURE Open*;
  109.         VAR beg, end, time: LONGINT; v: Viewers.Viewer; text: Texts.Text; t: Sessions.Terminal; term: Terminal;
  110.             fnt: Fonts.Font; s: Texts.Scanner; msg: Sessions.IdentifyMsg; host: ARRAY 32 OF CHAR;
  111.     BEGIN Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(s);
  112.         IF (s.class = Texts.Char) & (s.line = 0) & (s.c = "^") THEN Oberon.GetSelection(text, beg, end, time);
  113.             IF time > 0 THEN Texts.OpenScanner(s, text, beg); Texts.Scan(s) END
  114.         END;
  115.         msg.session := NIL;
  116.         IF (s.line = 0) & (s.class = Texts.Char) & (s.c = "*") THEN v := Oberon.MarkedViewer(); v.handle(v, msg); Texts.Scan(s)
  117.         ELSE
  118.             IF (s.line = 0) & ((s.class = Texts.Name) OR (s.class = Texts.String)) THEN COPY(s.s, host); Texts.Scan(s);
  119.                 IF (s.line = 0) & (s.class = Texts.Int) THEN msg.session := Sessions.New(host, s.i); Texts.Scan(s)
  120.                 ELSE msg.session := Sessions.New(host, 23)
  121.                 END
  122.             END
  123.         END;
  124.         IF msg.session # NIL THEN t := Sessions.ThisTerminal(msg.session, IsTerminal);
  125.             IF t # NIL THEN term := t(Terminal) ELSE term := New(msg.session) END;
  126.             IF (s.line = 0) & (s.class = Texts.Name) THEN fnt := Fonts.This(s.s);
  127.                 IF fnt.name # s.s THEN fnt := Fonts.This("Courier10.Scn.Fnt") END
  128.             ELSE fnt := Fonts.This("Courier10.Scn.Fnt")
  129.             END;
  130.             OpenViewer(term, fnt)
  131.         END
  132.     END Open;
  133. BEGIN Texts.OpenWriter(w)
  134. END Terminal.
  135.