home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / misc2 / dialv23.lzh / FINDENV.INC < prev    next >
Text File  |  1985-08-03  |  2KB  |  63 lines

  1.  
  2. {********* This file is an "include" file to be used with DIAL.PAS. *********}
  3.  
  4.  
  5. Function Find_Env ( ev : str255 ) : str255;
  6. {
  7. This procedure finds the variable the user wanted and returns as its result the
  8. corresponding string.  If it cannot be found, the null string is returned.
  9. }
  10. Const
  11.   env_size      = 256;
  12. Var
  13.   env_seg       : Integer Absolute CSeg:$2C;
  14.   seg           : Integer;
  15.   ofs           : Integer;
  16.   ch            : Byte;
  17.   no_more_env   : Boolean;
  18.   one_null_seen : Boolean;
  19.   equals_seen   : Boolean;
  20.   name          : String[255];
  21.   value         : String[255];
  22.   ii            : Integer;
  23. Begin
  24.   seg := env_seg;                     { Init segment address }
  25.   ofs := 0;                           { Offset 0 into that segment }
  26.   name := '';                         { Variable name is initially null }
  27.   value := '';                        { And its value also }
  28.   no_more_env := false;               { Set true when we're done }
  29.   one_null_seen := false;             { Set true when we see a null character }
  30.   equals_seen := false;               { Set true when we see an "=" character }
  31.   find_env := '';                     { Return at least this }
  32.   For ii := 1 to Length(ev) Do ev[ii] := UpCase(ev[ii]);
  33.   Repeat
  34.     Begin
  35.       ch := Mem[seg:ofs];             { Get the character }
  36.       no_more_env := one_null_seen and (ch = 0);    { Set appropriate flags }
  37.       equals_seen := equals_seen or (ch = ord('='));
  38.       one_null_seen := (ch = 0);
  39.       If not no_more_env Then         { If not done, check character }
  40.         If one_null_seen Then         { End of a string, check results }
  41.           If name = ev Then
  42.             Begin
  43.               find_env := value;      { Found it, return now }
  44.               no_more_env := true
  45.             End
  46.           Else
  47.             Begin
  48.               equals_seen := false;   { Didn't find it.  Re-init }
  49.               name := '';
  50.               value := ''
  51.             End
  52.         Else
  53.           If equals_seen Then        { Store character in proper string }
  54.             Begin
  55.               If chr(ch) <> '=' Then value := value + UpCase(chr(ch))
  56.             End
  57.           Else
  58.             name := name + UpCase(chr(ch));
  59.       ofs := ofs + 1;                { Increment offset pointer }
  60.     End;
  61.   Until no_more_env or (ofs > env_size);
  62. End;
  63.