-- wwTIPTest.mesa
-- Last Edited by Winiger, 28-Sep-81 17:07:44

DIRECTORY
  CedarLists USING [ListOfRefAny],
  CedarAtoms USING [GetPName],
  Real USING [FixI],
  TTY USING [Handle, Create, PutChar, PutCR, PutBlanks,
    PutString, PutLongString, PutLongDecimal, PutDecimal, GetString],
  TIPUser USING [CreateClient, InstantiateNewTIPTable, TIPButtonProc, TIPClient,
	TIPScreenCoords, TIPNotifyProc, TIPTable, PushTIPTable];

wwTIPTest: PROGRAM

IMPORTS CedarAtoms, Real, TTY, TIPUser =

BEGIN OPEN TTY;

client: TIPUser.TIPClient;

tty: Handle ← Create["wwTIPTest.log"];

tioga: BOOLEAN ← TRUE;
tiogaTable: TIPUser.TIPTable;
name: STRING ← [32];

-- the string terminating procedure for GetString:
  EndString: PROC [ch: CHARACTER] RETURNS [BOOLEAN] = {
    RETURN[ch = 15C];
    };

GoForIt: PROCEDURE = BEGIN
    DO
        PutCR[tty];
	PutString[tty, "enter new tip table name: "];
        GetString[tty, name, EndString];
	PutCR[tty];
	tiogaTable ← TIPUser.InstantiateNewTIPTable[LOOPHOLE[LONG[name]]];
	IF tiogaTable = NIL THEN BEGIN
	    PutString[tty, "you better check your tiptable"];
	    PutCR[tty];
	    END
	ELSE BEGIN
	    client ← TIPUser.CreateClient[notify: NotifyTestProc];
	    TIPUser.PushTIPTable[client, tiogaTable, FALSE];
	    END;
	ENDLOOP;
    END;

NotifyTestProc: TIPUser.TIPNotifyProc = BEGIN

	WriteCoords: PROCEDURE [coords: TIPUser.TIPScreenCoords] = INLINE BEGIN
		PutChar[tty, '(]; PutDecimal[tty, Real.FixI[coords.x]]; PutString[tty, ", "];
		PutDecimal[tty, Real.FixI[coords.y]]; PutChar[tty, ')];
		END;

	params: CedarLists.ListOfRefAny;
	first: BOOLEAN ← TRUE;

	PutString[tty, " ["];

	FOR params ← results, params.rest UNTIL params=NIL DO
		IF first THEN first ← FALSE ELSE PutString[tty, "; "];
		WITH params.first SELECT FROM
        		x: ATOM => PutLongString[tty, LOOPHOLE[CedarAtoms.GetPName[x]]];
			x: REF CHARACTER => PutChar[tty, x↑];
			x: REF LONG INTEGER => PutLongDecimal[tty, x↑];
			x: REF TEXT => PutLongString[tty, LOOPHOLE[x]];
			x: TIPUser.TIPScreenCoords => WriteCoords[x];
			ENDCASE	=> PutString[tty, "(unknown parameter flavor)"];
		ENDLOOP;

	PutString[tty, "]"];
	PutCR[tty];

	END;

-- here do something to get the ball rolling

GoForIt;

END.