// IfsTelnetLeafStat.bcpl -- IFS system statistics for Leaf
// Copyright Xerox Corporation 1979, 1980

// Last modified November 6, 1980  1:00 PM by Wobber

get "IfsLeaf.decl"; get "IfsSequin.decl";

external
[
// outgoing procedures
LeafSystat; LeafServStat;

// incoming procedures
MoveBlock; NextLockedSequin; Plural; PrintPort; Puts;
PutTemplate; StringCompare; Ws;

// incoming statics
dsp; scb;
]

//---------------------------------------------------------------------------
let LeafSystat() be
//---------------------------------------------------------------------------
[
if scb eq 0 return;
let sequin = 0; let firstTime = true;
   [ // Loop through all sequins.
   sequin = NextLockedSequin(sequin); if sequin eq 0 break;
   if firstTime then [ Ws("*n*nLeaf connections:"); firstTime = false; ]
   let name = sequin>>Sequin.unam;
   if name eq 0 then name = "Not logged in";
   Puts(dsp, $*n); Ws(name)
   for j = name>>String.length to 15 do Puts(dsp, $*s)
   let port = vec lenPort; MoveBlock(port, lv sequin>>Sequin.port, lenPort)
   port>>Port.socket↑1 = 0; port>>Port.socket↑2 = 0
   Ws(" ["); PrintPort(dsp, port); Ws("]")

   let lvmds = 0;
   let fh = sequin>>Sequin.fhQ.head;
   while fh ne 0 do
      [
      if fh>>FH.lvmd ne 0 then lvmds = lvmds + 1;
      fh = fh>>FH.link;
      ]
   if lvmds ne 0 then
      PutTemplate(dsp, "  --  $2D file$S", lvmds, Plural(lvmds));

   let state = selecton sequin>>Sequin.state into
      [
      case timedOutState: "  (timed out)"
      case brokenState: "  (broken)"
      case dallyingState: "  (dallying)"
      default: 0
      ]
   if state ne 0 then Ws(state);
   if sequin>>Sequin.brokenLeaf then Ws(" **");
   ] repeat
]

//---------------------------------------------------------------------------
and LeafServStat() be
//---------------------------------------------------------------------------
[
PutTemplate(dsp, "*n$S$10ED$10ED", "Leaf  ",
 lv scb>>SCB.acceptedRFCs, lv scb>>SCB.refusedRFCs);
]