TIPTableWriter.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited by McGregor, September 10, 1982 10:16 am
Last Edited by: Maxwell, January 3, 1983 11:36 am
Last Edited by: Paul Rovner, June 15, 1983 4:36 pm
Doug Wyatt, April 14, 1985 10:39:49 pm PST
DIRECTORY
Atom USING [GetPName],
TerminalDefs USING [KeyName],
IO USING [--CreateViewerStreams,-- PutBlock, PutChar, STREAM],
TIPPrivate USING [KeyOption, stdChar, stdCoords, stdTime, version],
TIPTables USING [TIPChoice, TIPChoiceSeries, TIPKeyState, TIPResults, TIPTableImplRep, TIPTerm],
TIPUser USING [TIPTable];
TIPTableWriter: CEDAR PROGRAM
IMPORTS IO, Atom, TIPPrivate
EXPORTS TIPPrivate, TIPUser
=
BEGIN
OPEN TIPPrivate, TIPTables, TIPUser;
TIPTableImpl: TYPE ~ REF TIPTableImplRep;
TIPTableImplRep: PUBLIC TYPE ~ TIPTables.TIPTableImplRep;
KeyName: TYPE ~ TerminalDefs.KeyName;
debug: BOOL = FALSE;
debugStream: IO.STREAM;
WriteTIPTable:
PUBLIC
PROC [table: TIPTable, keyOption: KeyOption, s:
IO.
STREAM] = {
impl: TIPTableImpl ~ table.impl;
Char:
PROC [c:
CHAR] = {
IO.PutChar[s,c];
IF debug THEN IO.PutChar[debugStream,c];
};
String:
PROC [str:
REF
READONLY
TEXT] = {
IO.PutBlock[s,str];
IF debug THEN IO.PutBlock[debugStream,str];
};
Text:
PROC [txt:
REF
READONLY
TEXT] = {
IF txt.length > 255 THEN ERROR;
Char[LOOPHOLE[txt.length]];
String[txt];
};
Flag: PROC [flag: BOOL] = { Char[IF flag THEN 'T ELSE 'F] };
Key: PROC [k: KeyName] = { Char[LOOPHOLE[k]] };
Int:
PROC [x:
INT] = {
Bytes:
TYPE =
MACHINE
DEPENDENT
RECORD [
byte0(0:0..7), byte1(0:8..15),
byte2(1:0..7), byte3(1:8..15): [0..255] ← 0];
b: Bytes ← LOOPHOLE[x];
Char[LOOPHOLE[b.byte0]];
Char[LOOPHOLE[b.byte1]];
Char[LOOPHOLE[b.byte2]];
Char[LOOPHOLE[b.byte3]];
};
ChoiceItem:
PROC [k: KeyName, c: TIPChoice] = {
IF c=NIL THEN RETURN;
Char['(]; Key[k]; Choice[c]; Char[')]
};
ChoiceSeries:
PROC [cs: TIPChoiceSeries] = {
Char['(];
FOR x: TIPChoiceSeries ← cs, x.rest
UNTIL x=
NIL
DO
Choice[x.first]; ENDLOOP;
Char[')];
};
Choice:
PROC [c: TIPChoice] = {
Char['(];
FOR x: TIPChoice ← c, x.rest
UNTIL x=
NIL
DO
Term[x.first]; ENDLOOP;
Char[')];
};
KeyState:
PROC [keyState: TIPKeyState] = {
Key[keyState.key];
Char[
SELECT keyState.state
FROM
up => 'U, down => 'D, ENDCASE => ERROR] };
Term:
PROC [t: TIPTerm] =
TRUSTED {
WITH x:t SELECT FROM
keyTrigger => {
Char['1];
Key[x.keyState.key];
Char[
SELECT x.keyState.state
FROM
up => 'U, down => 'D, ENDCASE => ERROR] };
mouseTrigger => Char['2];
timeTrigger => {
Char['3];
Char[SELECT x.flavor FROM gt => 'G, lt => 'L, ENDCASE => ERROR];
Char[LOOPHOLE[x.mSecs / 256]];
Char[LOOPHOLE[x.mSecs MOD 256]] };
keyEnable => { Char['4]; KeyState[x.keyState] };
predEnable => { Char['5]; Text[LOOPHOLE[Atom.GetPName[x.predicate]]] };
char => Char['6];
coords => Char['7];
nested => { Char['8]; ChoiceSeries[x.statement] };
result => { Char['9]; Results[x.list] };
key2Enable => { Char['A]; KeyState[x.keyState1]; KeyState[x.keyState2] };
keyEnableList => {
Char['B]; Char['(];
FOR lst:
LIST
OF TIPKeyState ← x.lst, lst.rest
UNTIL lst=
NIL
DO
KeyState[lst.first]; ENDLOOP;
Char[')] };
time => Char['C];
ENDCASE => ERROR;
};
Results:
PROC [c: TIPResults] = {
Char['(];
FOR x: TIPResults ← c, x.rest
UNTIL x=
NIL
DO
Result[x.first]; ENDLOOP;
Char[')] };
Result:
PROC [r:
REF
ANY] =
TRUSTED {
IF r=stdCoords THEN Char['5]
ELSE IF r=stdChar THEN Char['2]
ELSE IF r=stdTime THEN Char['6]
ELSE WITH r SELECT FROM
x: ATOM => { Char['1]; Text[LOOPHOLE[Atom.GetPName[x]]] };
x: REF INT => { Char['3]; Int[x^] };
x: REF TEXT => { Char['4]; Text[x] };
ENDCASE => ERROR };
IF debug THEN debugStream ← IO.CreateViewerStreams["TIPTableWriterDebugLog"].out;
String["TIPTABLE"];
Char[version];
Flag[table.opaque];
Char[
SELECT keyOption
FROM
none => 'N, printKeys => 'P, defaultKeys => 'D, ENDCASE => ERROR];
Flag[impl.ignore.up];
Flag[impl.ignore.down];
Flag[impl.ignore.move];
WITH impl
SELECT
FROM
x: REF small TIPTableImplRep => { Char['S]; ChoiceSeries[x.all] };
x:
REF fast TIPTableImplRep => {
Char['F];
Choice[x.mouse];
Char['U];
Char['(];
FOR k: KeyName IN KeyName DO ChoiceItem[k, x.keyUp[k]] ENDLOOP;
Char[')];
Char['D];
Char['(];
FOR k: KeyName IN KeyName DO ChoiceItem[k, x.keyDown[k]] ENDLOOP;
Char[')];
Choice[x.time];
};
ENDCASE => ERROR;
};
END.