-- File: PupDebugOut.mesa, Last Edit: HGM  July 16, 1980  6:52 PM

-- This module lives and runs in the debugger.   It prints things out in the "right" format.

DIRECTORY
  Mopcodes USING [zEXCH],
  DebugFormat USING [Foo],
  DI USING [GetValue],
  DOutput USING [Text],
  Dump USING [AddPrinter],
  String USING [AppendChar, AppendLongNumber],
  PupTypes USING [PupAddress, PupSocketID];

PupDebugOut: PROGRAM IMPORTS DI, DOutput, Dump, String =
  BEGIN


  PrintPupAddress: PROCEDURE [f: DebugFormat.Foo] =
    BEGIN
    temp: STRING = [20];
    who: PupTypes.PupAddress;
    DI.GetValue[f];
    who ← LOOPHOLE[f.addr.base, LONG POINTER TO PupTypes.PupAddress]↑;
    AppendPupAddress[temp, who];
    DOutput.Text[temp];
    END;

  AppendPupAddress: PUBLIC PROCEDURE [s: STRING, a: PupTypes.PupAddress] =
    BEGIN
    Flip: PROCEDURE [PupTypes.PupSocketID] RETURNS [LONG INTEGER] = MACHINE CODE
      BEGIN Mopcodes.zEXCH END;
    AppendOctal[s, a.net];
    String.AppendChar[s, '#];
    AppendOctal[s, a.host];
    String.AppendChar[s, '#];
    String.AppendLongNumber[s, Flip[a.socket], 8];
    END;

  AppendOctal: PROCEDURE [s: STRING, n: CARDINAL] =
    BEGIN
    IF n > 7 THEN AppendOctal[s, n/8];
    String.AppendChar[s, '0 + (n MOD 8)];
    END;


  -- initialization

  Dump.AddPrinter[
    "LOOPHOLE[13,POINTER TO PupTypes$PupAddress]↑", PrintPupAddress];
  END.