Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site voder.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!whuxl!whuxlm!akgua!mcnc!philabs!cmcl2!seismo!hao!hplabs!nsc!voder!gbs From: gbs@voder.UUCP (George Smith) Newsgroups: net.micro.pc Subject: Re: set environment Message-ID: <718@voder.UUCP> Date: Fri, 15-Mar-85 13:13:12 EST Article-I.D.: voder.718 Posted: Fri Mar 15 13:13:12 1985 Date-Received: Fri, 22-Mar-85 03:00:55 EST References: <1200005@ur-univax.UUCP> Organization: National Semiconductor, Santa Clara Lines: 73 > The DOS manual talks about adding things to the environment with the SET > ENVIRONMENT command and goes on to say that things in the environment can be > accessed from within an application. Can anyone tell me how to do this or > where it is documented ? > > Mark J. Dumic > ...!{allegra|decvax|seismo}rochester!ur-univax!marc The following procedure for Turbo Pascal illustrates how to use this very powerful feature in MS-DOS. Look at the description of the exec function and the description of the PSP (Program Segment Prefix) in the DOS Technical Ref manual and the SET command description in the DOS manual for more info. Hope this helps. (* ** The following function will look for an environment variable ** and return it's definition if found. If the variable is not ** found, then the returned definition variable will be empty. ** Compiled and run with Turbo Pascal v2.0 on an IBM PC/XT running ** PC-DOS v2.1. ** ** This code is entered into the Public Domain for free use by all. ** George B. Smith, March 15, 1985. *) { type mstring = string[255]; } procedure GetEnvParam(name: mstring; { environment variable to search for } var param: mstring { returned definition } ); var envseg: integer; { segment address of environment from PSP } ei: integer; { index into environment } envname: mstring; { current environment string name } ch: char; { current character from environment } found: boolean; { if true then environment name was found } begin envseg := MemW[CSeg:$2C]; { get address of environment from PSP } found := FALSE; ei := 0; ch := chr(Mem[envseg:ei]); { get first char from environment } while (ch <> chr(0) and (not found) do begin envname := ''; while ch <> '=' do begin { get environment string name } envname := envname + ch; ei := ei + 1; ch := chr(Mem[envseg:ei]) end; ei := ei + 1; { skip over the EQUALS } param := ''; ch := chr(Mem[envseg:ei]); while ch <> chr(0) do begin { get environment string parameter } param := param + ch; ei := ei + 1; ch := chr(Mem[envseg:ei]) end; if name = envname then { check for a match } found := TRUE; ei := ei + 1; ch := chr(Mem[envseg:ei]) end; if not found then param := '' end; -- George B. Smith National Semiconductor ...!{ihnp4!nsc | decvax!decwrl!nsc | ucbvax}!voder!gbs