home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / TURBOPAS / TP-UTIL.ARK / SRCHENV.SRC < prev    next >
Text File  |  1986-01-06  |  3KB  |  60 lines

  1. {->>>>SearchEnvironment<<<<------------------------------------}
  2. {                                                              }
  3. { Filename: SRCHENV.SRC -- Last modified 10/20/85              }
  4. {                                                              }
  5. { This routine searches the DOS environment for a parameter,   }
  6. { and if it finds the parameter, returns the value of that     }
  7. { parameter as read from the environment.  The function return }
  8. { value is set to True if the parameter is found.  The value   }
  9. { of the found parameter is placed in Value.  If the parameter }
  10. { is not found, Value will be set to the null string. ('')     }
  11. { The requested parameter is forced to upper-case before the   }
  12. { search is begun, since COMMAND.COM capslocks the parameter   }
  13. { when it is entered via the SET DOS command.                  }
  14. {--------------------------------------------------------------}
  15.  
  16. FUNCTION SearchEnvironment(Parm : String80;
  17.                            VAR Value : String80) : Boolean;
  18.  
  19. TYPE
  20.   String255 = String[255];
  21.  
  22. VAR
  23.   I,J,K      : Integer;
  24.   EnvSegment : Integer;
  25.   EnvOffset  : Integer;
  26.   TempString : String255;
  27.  
  28. BEGIN
  29.   SearchEnvironment := False;     { Defaults to "not found" }
  30.   Value := '';                    { Set Value to null string }
  31.   FOR I := 1 TO Length(Parm) DO   { Caps lock the parm }
  32.     Parm[I] := UpCase(Parm[I]);
  33.   EnvSegment := MEMW[CSEG:$2C];   { Locate the DOS environment }
  34.   EnvOffset  := 0;  J := 0;
  35.   { Until we run out of environment, search: }
  36.   WHILE MEM[EnvSegment : EnvOffset] <> 0 DO
  37.     BEGIN
  38.       TempString := '';
  39.       I := 1;
  40.       { Here we copy an environment string into TempString: }
  41.       REPEAT
  42.         TempString[I] := CHR(MEM[EnvSegment : EnvOffset]);
  43.         I := SUCC(I);
  44.         EnvOffset := SUCC(EnvOffset)
  45.       UNTIL MEM[EnvSegment : EnvOffset]=0;
  46.       TempString[0] := CHR(EnvOffset-J); { Set length of TempString }
  47.       K := Pos('=',TempString);          { Locate "=" in TempString }
  48.       IF K > 0 THEN          { If there is an "=" in this string... }
  49.         IF Copy(TempString,1,K-1) = Parm THEN    { If Parm is found }
  50.           BEGIN
  51.             SearchEnvironment := True;  { We found it! }
  52.             { Copy procedure's value into Value... }
  53.             Value := Copy(TempString,K+1,Length(TempString)-K);
  54.             Exit                        { ...and duck out of proc   }
  55.           END;
  56.       J := EnvOffset+1;
  57.       EnvOffset := SUCC(EnvOffset)
  58.     END
  59. END;
  60. ßJi£æcE5╤    ∙╪z╪Ç┌çôÖZºµO≤├ö¿Éj▌