{***********************************************************************}
{									}
{ __GetEnUtl  Return an environment parameter				}
{									}
{ function  __GetEnUtl(EnvName : string) : string			}
{									}
{	      EnvName	The environment variable to be searched for	}
{			in the environment space.			}
{									}
{ Description The __GetEnUtl function searches the list of environment	}
{	      variables for an entry corresponding to EnvName.	The	}
{	      value of the function is the string value of the environ- }
{	      ment variable if it is found.  If the variable is not	}
{	      found, the returned function value is the NULL string.	}
{									}
{	      __GetEnUtl calls the function __RetEnUtl to return the	}
{	      entries in the environment.  The string EnvName is	}
{	      regarded as uppercase, and any trailing equals signs (=)	}
{	      are ignored.  The string returned by __RetEnUtl is	}
{	      checked for a match.  If there is, the parameter string	}
{	      is returned.						}
{									}
{	      Notice that the maximum size of the environment variable	}
{	      and parameter is 255, the maximum length of the Turbo	}
{	      Pascal string type.					}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc. 1987		}
{_______________________________________________________________________}

function __GetEnUtl(EnvName : string) : string;

  const
    EQUAL = '=';
    BLANK = ' ';
    TAB   = #9;

  var
    EnvPos     : word;
    EnvStr     : string;
    I,J        : integer;
    LenEnvName : integer;
    EqualPos   : integer;
    Found      : boolean;

  begin {__GetEnUtl}

    { First reformat EnvName so it is all upper case, has no leading	}
    { blanks or tabs, and no trailing equal sign.			}

    I	       := 1;
    Found      := TRUE;
    LenEnvName := Length(EnvName);

    while ((I <= LenEnvName) and Found) do
      if ((EnvName[I] = BLANK) or (EnvName[I] = TAB)) then
	 Inc(I)
      else
	 Found := FALSE;
    J	       := I - 1;	       { Number of blanks removed	}
    LenEnvName := Length(EnvName) - J; { This is the new length 	}

    Found := FALSE;
    I	  := 1;
    while ((I <= LenEnvName) and (not Found)) do
      if (EnvName[I + J] = EQUAL) then { Stop when an equals sign is	}
	 begin			       { found in the string.		}
	   LenEnvName := I - 1;
	   Found := TRUE
	 end
      else
	 begin			       { Shift to upper case and go on. }
	   EnvName[I] := UpCase(EnvName[I + J]);
	   Inc(I)
	 end;
    EnvName[0] := Chr(LenEnvName);

    { Now search the environment, returning each string in turn.	}

    Found  := FALSE;
    EnvPos := 1;
    EnvStr := __RetEnUtl(EnvPos);

    while ((not Found) and (Length(EnvStr) <> 0)) do
      begin
	EqualPos  := Pos(EQUAL,EnvStr);
	if (EnvName = Copy(EnvStr,1,EqualPos - 1)) then
	   Found  := TRUE
	else
	   EnvStr := __RetEnUtl(EnvPos)
      end;

    if (Found) then
       __GetEnUtl := Copy(EnvStr,EqualPos + 1,255)
    else
       __GetEnUtl := ''

  end;	{GetEnUtl}
