home *** CD-ROM | disk | FTP | other *** search
- /*Program 5_10a - Display the Environment
- by Stephen R. Davis, 1987
-
- Display the entire current environment. This program
- gets the environment address directly from offset 0x2C in
- the Program Segment Prefix. The environment consists of a
- series of ASCII strings, each terminated with a 0, with the
- entire thing terminated by a 0.
- */
-
- #include <stdio.h>
- #include <dos.h>
-
- /*prototyping definitions*/
- char far *getenv (void);
- void main (void);
-
- /*Main - dump the environment on the screen*/
- void main (void)
- {
- char far *envptr;
- char localbuf [128];
- char *localptr;
- unsigned count;
-
- count = 0;
- envptr = getenv ();
- while (*envptr) {
-
- localptr = localbuf; /*xfer this to a local buffer*/
- while (*envptr)
- *localptr++ = *envptr++;
- *localptr = '\0';
-
- printf ("entry %d: %s\n", count++, localbuf);
- envptr++;
- }
- }
-
- /*Getenv - return a pointer to the environment strings*/
- char far *getenv (void)
- {
- unsigned far *envseg;
- unsigned pspseg;
-
- pspseg = getpsp (); /*get the psp segment*/
-
- /*at offset 2C in the PSP is the segment address of
- the environment*/
- envseg = (unsigned far *)MK_FP ( pspseg, 0x2C);
- return (char far *) MK_FP (*envseg, 0x00);
- }