-- ReadLog.mesa
-- Copyright (C) 1981, 1984, 1985  by Xerox Corporation. All rights reserved. 
-- Transport mechanism: TelNet interface to Log facilities

-- HGM, 17-May-85 11:59:36
-- Randy Gobbel		19-May-81 18:46:13
-- Andrew Birrell	 2-Jun-81 15:45:36

DIRECTORY
  Ascii USING [CR, SP],
  EnquiryDefs USING [Handle],
  LogPrivateDefs USING [
    AppendElapsedTime, houses, NumberHouse, startUpTime, uptimeHouse],
  String USING [AppendLongDecimal],
  Time USING [Current];

ReadLog: PROGRAM IMPORTS LogPrivateDefs, String, Time EXPORTS EnquiryDefs =
  BEGIN

  DisplayStats: PUBLIC PROC [str: EnquiryDefs.Handle] =
    BEGIN
    Number: PROCEDURE [n: LONG CARDINAL] = {
      s: STRING = [20];
      String.AppendLongDecimal[s, n];
      THROUGH [s.length..10) DO str.WriteChar[Ascii.SP]; ENDLOOP;
      str.WriteString[s]; };
    str.WriteChar[Ascii.CR];
    str.WriteString[LogPrivateDefs.uptimeHouse.caption];
    BEGIN
    s: STRING = [20];
    LogPrivateDefs.AppendElapsedTime[
      s, Time.Current[] - LogPrivateDefs.startUpTime];
    str.WriteString[s];
    END;
    str.WriteChar[Ascii.CR];
    str.WriteChar[Ascii.CR];
    FOR houseIndex: CARDINAL IN [0..LENGTH[LogPrivateDefs.houses]) DO
      house: LogPrivateDefs.NumberHouse = @(LogPrivateDefs.houses[houseIndex]);
      WITH h: house SELECT FROM
        short => IF h.min = 0 AND h.max = 0 THEN LOOP;
        long => IF h.min = 0 AND h.max = 0 THEN LOOP;
        percent => IF h.min = 0 AND h.max = 0 THEN LOOP;
        ENDCASE => ERROR;
      str.WriteString[house.caption];
      THROUGH [house.caption.length..25) DO str.WriteChar[Ascii.SP]; ENDLOOP;
      WITH h: house SELECT FROM
        short =>
          BEGIN
          Number[h.min];
          Number[LONG[h.p↑]];
          Number[h.max];
          END;
        long =>
          BEGIN
          Number[h.min];
          Number[h.p↑];
          Number[h.max];
          END;
        percent =>
          BEGIN
          Number[h.min];
          Number[h.p↑];
          Number[h.max];
          str.WriteChar['%];
          END;
        ENDCASE => ERROR;
      str.WriteChar[Ascii.CR];
      ENDLOOP;
    END;


  END.