-- Copyright (C) 1981, 1982  by Xerox Corporation. All rights reserved. 
-- PupDebugOut.mesa, HGM,  2-Dec-81 18:50:40

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

DIRECTORY
  Mopcodes USING [zEXCH],
  DebugUsefulDefs USING [AddPrinter, GetAddress, Handle, ReadValue, Text],
  String USING [AppendChar, AppendLongNumber],
  PupTypes USING [PupAddress, PupSocketID];

PupDebugOut: PROGRAM IMPORTS DebugUsefulDefs, String =
  BEGIN


  PrintPupAddress: PROCEDURE [f: DebugUsefulDefs.Handle] RETURNS [BOOLEAN] =
    BEGIN
    who: PupTypes.PupAddress;
    where: LONG POINTER TO PupTypes.PupAddress;
    temp: STRING = [20];
    DebugUsefulDefs.ReadValue[f];
    where ← DebugUsefulDefs.GetAddress[f].base;
    who ← where↑;
    AppendPupAddress[temp, who];
    DebugUsefulDefs.Text[temp];
    RETURN[TRUE];
    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

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