-- Copyright (C) 1986  by Xerox Corporation. All rights reserved. 
-- File: FBasicsImpl.mesa - created by JKF. Last edit:
-- JKF                 22-May-86 11:32:10



DIRECTORY
  FBasics USING [LibraryProblem],
  CRuntime USING [ConfigHandle, GetConfigHandle, ProcessNotRegistered,
    SetConfigHandle],
  Heap USING [systemZone],
  IsAround USING [FortranMathLibraryIsLoadedIfIsboundIsTrueForThisProc],
  MFile USING [Error, Handle, ReadOnly],
  Runtime USING [ControlLink, IsBound],
  StartState USING [normalOutcome, StartOrRestart];

FBasicsImpl: PROGRAM
  IMPORTS CRuntime, FBasics, Heap, IsAround, MFile, Runtime, StartState
  EXPORTS FBasics =
  BEGIN

  z: UNCOUNTED ZONE = Heap.systemZone;

  -- Raised if library can't be found or loaded:
  LibraryProblem: PUBLIC ERROR [s: LONG STRING] = CODE;


  FortranLoaded: PUBLIC PROC [] = {
    retval: BOOLEAN ← FALSE;

    -- check for FSupport loaded
    retval ← CheckLib[
      "FSupport.archivebcd"L,
      LOOPHOLE[IsAround.FortranMathLibraryIsLoadedIfIsboundIsTrueForThisProc]];
    IF retval = FALSE THEN {
      retval ← CheckLib[
        "FSupport.bcd"L,
        LOOPHOLE[IsAround.FortranMathLibraryIsLoadedIfIsboundIsTrueForThisProc]];
      IF retval = FALSE THEN FBasics.LibraryProblem["Could not load FSupport"L]};
    };


  CheckLib: PROC [s: LONG STRING, link: Runtime.ControlLink]
    RETURNS [retval: BOOLEAN ← TRUE] = {
    i: INTEGER ← 0;
    file: MFile.Handle ← NIL;
    cH:CRuntime.ConfigHandle ← NIL;

    IF Runtime.IsBound[link] THEN RETURN[TRUE];
    file ← MFile.ReadOnly[
      s, [NIL, NIL] ! MFile.Error => {retval ← FALSE; CONTINUE}];
    IF retval = FALSE THEN RETURN[FALSE];
    cH ← CRuntime.GetConfigHandle[!CRuntime.ProcessNotRegistered => CONTINUE];
    i ← StartState.StartOrRestart[
      file: file, argc: 0, argv: NIL, stdin: NIL, stdout: NIL, stderr: NIL];
    IF cH # NIL THEN CRuntime.SetConfigHandle[cH];
    IF i = StartState.normalOutcome THEN RETURN[TRUE] ELSE RETURN[FALSE]};


  END...