Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!husc6!bu-cs!bucsb.bu.edu!madd From: madd@bucsb.bu.edu.UUCP (Jim "Jack" Frost) Newsgroups: comp.lang.pascal,comp.sys.ibm.pc Subject: Re: Environment variables in Turbo Pascal Message-ID: <1078@bucsb.bu.edu.UUCP> Date: Sat, 1-Aug-87 20:54:14 EDT Article-I.D.: bucsb.1078 Posted: Sat Aug 1 20:54:14 1987 Date-Received: Sun, 2-Aug-87 10:47:06 EDT References: <151@ivory.SanDiego.NCR.COM> Reply-To: madd@bucsb.bu.edu.UUCP (Jim "Jack" Frost) Distribution: world Organization: ODO (Organization for the Disorganization of Organization) Lines: 42 Xref: mnetor comp.lang.pascal:228 comp.sys.ibm.pc:6255 In article <151@ivory.SanDiego.NCR.COM> mike@ivory.UUCP (Michael Lodman) writes: >Could someone please email and tell me how to read the DOS environment >variables with Turbo Pascal? > >Thanks. This is easy. Note that MS-DOS gives you a pointer to the environment variable list at memw[cseg:$2C]. This simple program will print out the environment; I suspect that anyone with a little knowledge can expand it to a complete getenv() style function in just a few minutes. [note -- I am just making this up now. no flames if I screw it up a little] program printenv; var eseg, { segment of environment } p : integer; { pointer within segment } begin eseg:= memw[cseg:$2C]; { get pointer to env segment } p:= 0; { initialize pointer within segment } repeat { loop for all environment entries } while mem[eseg:p]<>0 do begin { loop for chars in each entry } write(chr(mem[eseg:p])); { display character in entry } p:= p+1 { go to next character in entry } end; { end environment enty loop } writeln; { next line for next entry } p:= p+1 { go to next environment entry } until mem[eseg:p]=0 { environment ends in a null byte } end. For those of you who don't know, MS-DOS defines the environment as a series of null-terminated strings that ends in a null. This means that each entry in the environment ends in a null (chr(0), #0, whatever), and the last entry has another null following the null of the last string. Pretty easy to program with that info and the address of the segment! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Jim Frost * The Madd Hacker | UUCP: ..!harvard!bu-cs!bucsb!madd H H | ARPA: madd@bucsb.bu.edu H-C-C-OH <- heehee +---------+---------------------------------- H H | "We are strangers in a world we never made"