TIPTableWriter.mesa;
Last Edited by McGregor, September 10, 1982 10:16 am
Last Edited by: Maxwell, January 3, 1983 11:36 am
DIRECTORY
Atom USING [GetPName],
Interminal USING [KeyName],
IO USING [CreateViewerStreams, PutBlock, PutChar, Handle],
TIPPrivate,
TIPUser,
TIPTables;
TIPTableWriter: CEDAR PROGRAM
IMPORTS IO, Atom, TIPUser
EXPORTS TIPPrivate =
BEGIN
OPEN TIPPrivate, TIPTables, TIPUser;
debug: BOOLEANFALSE;
debugStream: IO.Handle;
WriteTIPTable: PUBLIC PROC [table: TIPTable, keyOption: KeyOption, s: IO.Handle] = {
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: BOOLEAN] = { Char[IF flag THEN 'T ELSE 'F] };
Key: PROC [k:Interminal.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:Interminal.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[table.ignore.up];
Flag[table.ignore.down];
Flag[table.ignore.move];
TRUSTED {
WITH x:table SELECT FROM
small => { Char['S]; ChoiceSeries[x.all] };
fast => {
Char['F];
Choice[x.mouse];
Char['U];
Char['(];
FOR k:Interminal.KeyName IN Interminal.KeyName DO
ChoiceItem[k,x.keyUp[k]]; ENDLOOP;
Char[')];
Char['D];
Char['(];
FOR k:Interminal.KeyName IN Interminal.KeyName DO
ChoiceItem[k,x.keyDown[k]]; ENDLOOP;
Char[')];
Choice[x.time] };
ENDCASE => ERROR};
};
END.