-- wwTIPTableTest.mesa; 
-- Written by Winiger, 20-Sep-81 21:06:43

DIRECTORY
  wwTIPUser USING [InstantiateNewTIPTable],
  wwTIPTables,
  TTY USING [Handle, Create, PutChar, PutCR, PutBlanks,
    PutString, PutLongString, PutLongDecimal],
  CedarAtoms USING [GetPName];

wwTIPTableTest: PROGRAM

IMPORTS wwTIPUser, TTY, CedarAtoms = 

BEGIN
  OPEN wwTIPUser, wwTIPTables, TTY, CedarAtoms;

  tty: TTY.Handle;
  table: TIPChoiceSeries;
  ind: CARDINAL ← 0;
  
  DebugChoiceSeries: PROC[tcs: TIPChoiceSeries] = BEGIN
    FOR t: TIPChoiceSeries ← tcs, t.rest UNTIL t=NIL DO
      DebugChoice[t.first];
--      PutCR[tty]; PutBlanks[tty, ind];
      ENDLOOP;
    END;
  
  DebugChoice: PROC[tc: TIPChoice] = BEGIN
    PutString[tty,"CHOICE"];
    PutCR[tty]; PutBlanks[tty, ind];
    FOR t: TIPChoice ← tc, t.rest UNTIL t=NIL DO
      DebugTerm[t.first];
      PutCR[tty]; PutBlanks[tty, ind];
      ENDLOOP;
    PutString[tty,"END CHOICE"];
    PutCR[tty]; PutBlanks[tty, ind];
    END;
  
  DebugTerm: PROC[t: TIPTerm] = BEGIN
    WITH t SELECT FROM
      trigger => BEGIN
        PutString[tty,"trigger"];
        END;
      enable => BEGIN
        PutString[tty,"enable"];
        END;
      char => BEGIN
        PutString[tty,"char"];
        END;
      coords => BEGIN
        PutString[tty,"coords"];
        END;
      nested => BEGIN
        PutString[tty,"nested: "];
	ind ← ind + 4;
        DebugChoiceSeries[statement];
	ind ← ind - 4;
        END;
      result => BEGIN
        PutString[tty,"result: "];
        DebugRes[list];
        END;
      ENDCASE;
    END;
  
  DebugRes: PROC[l: LIST OF REF ANY] = BEGIN
    FOR a: LIST OF REF ANY ← l, a.rest UNTIL a=NIL DO
      WITH a.first SELECT FROM
        x: ATOM => PutLongString[tty, LOOPHOLE[GetPName[x]]];
	x: REF CHARACTER => PutString[tty, "Char"];
	x: REF LONG INTEGER => PutLongDecimal[tty, x↑];
	x: REF TEXT => PutLongString[tty, LOOPHOLE[x]];
	x: TIPScreenCoords => PutString[tty, "Coords"];
	ENDCASE;
      PutBlanks[tty, 1];
      ENDLOOP;
    END;

  table ← InstantiateNewTIPTable["ww.tip",NIL] ;
  tty ← TTY.Create["wwTIPTableTest.log"];
  DebugChoiceSeries[table];
END.