TermEmCmds.Mesa
Last Edited by: Spreitzer, November 8, 1985 2:37:57 pm PST
DIRECTORY Ascii, Atom, Basics, BasicTime, CharDisplays, Commander, CommandTool, Convert, DisplayControllers, IO, Menus, MessageWindow, Protocols, Rope, TermProgs, ViewerOps, ViewerTools;
TermEmCmds: CEDAR PROGRAM
IMPORTS CharDisplays, Commander, CommandTool, DisplayControllers, IO, Menus, MessageWindow, Protocols, Rope, TermProgs, ViewerOps, ViewerTools
= {OPEN CharDisplays, DisplayControllers, TermProgs;
Protocol: TYPE = Protocols.Protocol;
Conversation: TYPE = Protocols.Conversation;
Em: TYPE = REF EmRep;
EmRep: TYPE = RECORD [
termName: ROPE,
term: Term,
dc: DisplayController,
p: Protocol,
c: Conversation];
installationDirectory: ROPE ← CommandTool.CurrentWorkingDirectory[];
lastEm: Em ← NIL;
MakeEm: PROC [cmd: Commander.Handle] RETURNS [result: REFNIL, msg: ROPENIL] = {
termName: ROPE ← "dm2500w";
displayClass: ROPE ← "BufferedTioga";
protocolName: ROPE ← "PupTelnet";
serverName: ROPENIL;
login: BOOLTRUE;
em: Em;
term: Term;
cdc: CharDisplayClass;
cd: CharDisplay ← NIL;
dc: DisplayController ← NIL;
p: Protocol;
i: INT ← 1;
argv: CommandTool.ArgumentVector ← CommandTool.Parse[cmd];
WHILE i < argv.argc DO
SELECT TRUE FROM
argv[i].Equal["-term"] => {termName ← argv[i+1]; i ← i+2};
argv[i].Equal["-display"] => {displayClass ← argv[i+1]; i ← i+2};
argv[i].Equal["-protocol"] => {protocolName ← argv[i+1]; i ← i+2};
argv[i].Equal["-host"] => {serverName ← argv[i+1]; i ← i+2};
argv[i].Equal["-login"] => {login ← TRUE; i ← i + 1};
argv[i].Equal["-connect"] => {login ← FALSE; i ← i + 1};
argv[i].Length[]=0 => RETURN [$Failure, IO.PutFR["Arg %g empty", IO.int[i]]];
argv[i].Fetch[0]='- => RETURN [$Failure, IO.PutFR["Unrecognized switch: %g", IO.refAny[argv[i]]]];
ENDCASE => {serverName ← argv[i]; i ← i+1};
ENDLOOP;
IF termName.Equal["?"] THEN {
first: BOOLTRUE;
NoteTerm: PROC [name: ROPE, term: Term] = {
IF first THEN first ← FALSE ELSE cmd.out.PutRope[", "];
cmd.out.PutRope[name];
};
cmd.out.PutRope["Available Terminal Types: "];
TermProgs.EnumerateTerms[NoteTerm];
cmd.out.PutRope[".\n"];
RETURN;
};
term ← TermProgs.GetTerm[termName, cmd];
IF term = NIL THEN RETURN [$Failed, IO.PutFR["Couldn't find terminal %g", IO.rope[termName]]];
cdc ← CharDisplays.GetClass[displayClass];
IF cdc = NIL THEN RETURN [$Failed, IO.PutFR["Couldn't find display class %g", IO.rope[displayClass]]];
p ← Protocols.GetProtocol[protocolName];
IF p = NIL THEN RETURN [$Failed, IO.PutFR["Couldn't find protocol %g", IO.rope[protocolName]]];
cd ← CharDisplays.Create[class: cdc, det: term.det];
dc ← DisplayControllers.Create[cd, term.cp];
em ← NEW [EmRep ← [termName, term, dc, p]];
IF dc.cd.viewer # NIL THEN {
m: Menus.Menu ← em.dc.cd.viewer.menu;
oldLines: Menus.MenuLine ← m.GetNumberOfLines[];
m.ChangeNumberOfLines[oldLines+1];
m.AppendMenuEntry[Menus.CreateEntry["Login", Login, em], oldLines];
m.AppendMenuEntry[Menus.CreateEntry["Connect", Connect, em], oldLines];
m.AppendMenuEntry[Menus.CreateEntry["Disconnect", Disconnect, em], oldLines];
SetName[em, NIL];
};
lastEm ← em;
IF serverName.Length[] > 0 THEN ConnectWork[em, serverName, login];
};
SetName: PROC [em: Em, serverName: ROPE] = {
em.dc.cd.viewer.name ← IO.PutFR["%g; %g; %g", IO.rope[em.termName], IO.rope[em.dc.cd.class.name], IO.rope[em.p.name]];
IF serverName # NIL THEN em.dc.cd.viewer.name ← serverName.Cat["; ", em.dc.cd.viewer.name];
ViewerOps.PaintViewer[em.dc.cd.viewer, all];
};
Login: PROC [parent: REF ANY, clientData: REF ANYNIL, mouseButton: Menus.MouseButton ← red, shift, control: BOOLFALSE] --Menus.MenusProc-- = {
em: Em ← NARROW[clientData];
serverName: ROPE ← ViewerTools.GetSelectionContents[];
ConnectWork[em, serverName, TRUE];
};
Connect: PROC [parent: REF ANY, clientData: REF ANYNIL, mouseButton: Menus.MouseButton ← red, shift, control: BOOLFALSE] --Menus.MenusProc-- = {
em: Em ← NARROW[clientData];
serverName: ROPE ← ViewerTools.GetSelectionContents[];
ConnectWork[em, serverName, FALSE];
};
ConnectWork: PROC [em: Em, serverName: ROPE, login: BOOL] = {
IF em.c # NIL THEN {
MessageWindow.Append["Already connected!", TRUE];
}
ELSE {
em.c ← em.p.Connect[serverName: serverName, fromClient: em.dc.fromDisplay, toClient: em.dc.toDisplay, noteDisconnect: NoteDisconnect, clientData: em, login: login];
SetName[em, IF em.c # NIL THEN serverName ELSE NIL];
};
};
Disconnect: PROC [parent: REF ANY, clientData: REF ANYNIL, mouseButton: Menus.MouseButton ← red, shift, control: BOOLFALSE] --Menus.MenusProc-- = {
em: Em ← NARROW[clientData];
IF em.c # NIL THEN {
em.p.Disconnect[em.c];
}
ELSE {
MessageWindow.Append["Already disconnected!", TRUE];
};
};
NoteDisconnect: PROC [clientData: REF ANY] = {
em: Em ← NARROW[clientData];
SetName[em, NIL];
em.c ← NIL;
};
Commander.Register[key: "TerminalEmulator", proc: MakeEm, doc: "Make a terminal emulator"];
}.