-- Grapevine: server support: internal DEFS for display

-- [Juniper]<Grapevine>MS>LogPrivateDefs.mesa

-- Roy Levin  February 18, 1980  3:45 PM
-- Andrew Birrell   2-Jun-81 11:58:29

DIRECTORY
  AltoDisplay: FROM "AltoDisplay" USING [
    DCBchainHead, DCBnil, LongDCBSeal, MaxBitsPerLine, MaxScanLines, MaxWordsPerLine],
  FontDefs: FROM "FontDefs" USING [FontHandle],
  LogDefs: FROM "LogDefs" USING [Format, Percentage],
  ProcessDefs: FROM "ProcessDefs" USING [Seconds],
  TimeDefs: FROM "TimeDefs" USING [PackedTime];

LogPrivateDefs: DEFINITIONS =

  BEGIN


  -- Types and Related Constants --

  DCB:          TYPE = RECORD[
			next: DCBHandle,
			resolution: {high, low} ← high,
			background: {white, black} ← white,
			indenting: [0..77B], -- in units of 16 bits --
			width: [0..377B], -- likewise; even --
			shortBitmap: POINTER ← NIL,
			tag: {short, long} ← short,
			height: [0..77777B],
			longBitmap: LONG POINTER ← NIL ];

  dcbSeal: POINTER = AltoDisplay.LongDCBSeal;

  DCBHandle:    TYPE = POINTER TO DCB;

  DCBnil:       DCBHandle = LOOPHOLE[AltoDisplay.DCBnil];
  DCBchainHead: POINTER TO DCBHandle = LOOPHOLE[AltoDisplay.DCBchainHead];

  NumberHouseObject: TYPE = RECORD [
    leftX, width: ScreenPoints,
    dcb: DCBHandle,
    caption: STRING,
    item: SELECT format: LogDefs.Format FROM
      short => [max, min: CARDINAL, p: POINTER TO UNSPECIFIED],
      long => [max, min: LONG CARDINAL, p: POINTER TO LONG CARDINAL],
      percent => [max, min: LogDefs.Percentage,
                  p: POINTER TO LogDefs.Percentage],
      ENDCASE];

  NumberHouse: TYPE = POINTER TO NumberHouseObject;

  ScreenPoints: TYPE = [0..MAX[AltoDisplay.MaxBitsPerLine,
			       AltoDisplay.MaxScanLines]);

  BitmapState: TYPE = RECORD[ -- similar to FontDefs, but LONG origin --
			origin: LONG POINTER,
			wordsPerLine, x, y: [0..77777B] ];

  BMStatePtr: TYPE = POINTER TO BitmapState;

  Face: TYPE = {plain, bold, italic};

  Cursor: TYPE = ARRAY [0..16) OF UNSPECIFIED;

  Machine: TYPE = { altoI, xmesa39, altoMesa, dMachine };


  -- Screen Parameters --

  maxBMWordsPerLine:	CARDINAL = AltoDisplay.MaxWordsPerLine;
  screenPointsPerWord:	ScreenPoints = 16;
  marginWords:		CARDINAL = 2;  -- equal words on each side
  bmWordsPerLine:	CARDINAL = maxBMWordsPerLine - 2*marginWords;
  bmPointsPerLine:	ScreenPoints = screenPointsPerWord*bmWordsPerLine;
  leftMargin:		ScreenPoints = screenPointsPerWord*marginWords;
  rightMargin:		ScreenPoints = leftMargin + bmPointsPerLine;
  italicSlant:		CARDINAL = 3;  -- (approximate) slope of italics
  topMargin:		ScreenPoints = 60;  -- should be even
  spaceAfterHeading:	ScreenPoints = 20;  -- should be even
  spaceAfterStatus:	ScreenPoints = 14;  -- should be even
  interValueSeparatorWidth: ScreenPoints = 15;
  intraValueSeparatorWidth: ScreenPoints = 4;


  -- Global Variables --

  houses:	DESCRIPTOR FOR ARRAY OF NumberHouseObject;
  statsFont:	FontDefs.FontHandle;
  scriptFont:	FontDefs.FontHandle;
  startUpTime:	TimeDefs.PackedTime;
  uptimeHouse:	NumberHouseObject;
  typescriptOn:	BOOLEAN;
  headingDCB, firstScriptDCB, lastScriptDCB, firstScriptLineDCB: DCBHandle;
  scriptCurrentDCB: DCBHandle;
  scriptBMStatePtr: BMStatePtr;
  machineFlavor: Machine;


  -- Miscellaneous Declarations --

  IllegalUseOfLog: ERROR;

  cursorBM: POINTER TO Cursor = LOOPHOLE[431B];


  -- Procedures --

  LogDisplayHot: PROGRAM;

  Displayer: PROCEDURE [waitInterval: ProcessDefs.Seconds];
  -- expects to be FORKed.  Loops until aborted, waiting for the argument
  -- interval, then updates the statistics display.

  PutStringInBitmap: PROCEDURE [
    s: STRING, font: FontDefs.FontHandle, face: Face, bmState: BMStatePtr];
  -- computes the width in ScreenPoints of the string 's' presented in
  -- 'font' and 'face'.

  AppendElapsedTime: PROCEDURE [s: STRING, pt: TimeDefs.PackedTime];
  -- appends to 's' a time derived from 'pt' of the form:  1314:35:28.

  Even: PROCEDURE [v: UNSPECIFIED] RETURNS [UNSPECIFIED];
  -- rounds 'v' up to an even number.

  Zero: PROC[p: LONG POINTER, count: CARDINAL];
  -- zeros "count" words starting at "p".

  END.