-- File: Indirection.mesa,  Last Edit: HGM  November 18, 1980  9:40 AM

DIRECTORY
  CmFile USING [OpenSection, NextItem, Close],
  Put USING [Line],
  Storage USING [FreeString],
  String USING [AppendChar, AppendString, EquivalentString],
  Time USING [AppendCurrent],
  Indirect USING [];

Indirection: PROGRAM IMPORTS CmFile, Put, Storage, String, Time EXPORTS Indirect =
  BEGIN

  parmFileName: STRING ← NIL;

  FindOurName: PROCEDURE =
    BEGIN
    token, arg: STRING;
    userDotCm: STRING = "User.cm"L;
    IF ~CmFile.OpenSection[userDotCm, "Indirect"L] THEN RETURN;
    DO
      [token, arg] ← CmFile.NextItem[];
      IF token = NIL THEN EXIT;
      SELECT TRUE FROM
	token = NIL => EXIT;
	String.EquivalentString[token, "ParameterFile"L] =>
	  BEGIN
	  Storage.FreeString[parmFileName];
	  parmFileName ← arg;
	  arg ← NIL;
	  END;
	ENDCASE => Warning["Unknown parameter: "L, token];
      Storage.FreeString[token];
      Storage.FreeString[arg];
      ENDLOOP;
    CmFile.Close[userDotCm];
    END;

  Warning: PROCEDURE [one, two, three: STRING ← NIL] =
    BEGIN
    text: STRING = [100];
    Time.AppendCurrent[text];
    String.AppendString[text, "  TimeServer: "L];
    String.AppendString[text, one];
    IF two # NIL THEN String.AppendString[text, two];
    IF three # NIL THEN String.AppendString[text, three];
    String.AppendChar[text, '.];
    Put.Line[NIL, text];
    END;


  GetParmFileName: PUBLIC PROCEDURE RETURNS [STRING] =
    BEGIN RETURN[parmFileName]; END;

  -- Initialization

  FindOurName[];
  END.