home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c072 / 1.ddi / PRG5_10A.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-19  |  1.3 KB  |  53 lines

  1. /*Program 5_10a - Display the Environment
  2.    by Stephen R. Davis, 1987
  3.  
  4.   Display the entire current environment.  This program
  5.   gets the environment address directly from offset 0x2C in
  6.   the Program Segment Prefix.  The environment consists of a
  7.   series of ASCII strings, each terminated with a 0, with the
  8.   entire thing terminated by a 0.
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <dos.h>
  13.  
  14. /*prototyping definitions*/
  15. char far *getenv (void);
  16. void main (void);
  17.  
  18. /*Main - dump the environment on the screen*/
  19. void main (void)
  20. {
  21.      char far *envptr;
  22.      char localbuf [128];
  23.      char *localptr;
  24.      unsigned count;
  25.  
  26.      count = 0;
  27.      envptr = getenv ();
  28.      while (*envptr) {
  29.  
  30.           localptr = localbuf;         /*xfer this to a local buffer*/
  31.           while (*envptr)
  32.                *localptr++ = *envptr++;
  33.           *localptr = '\0';
  34.  
  35.           printf ("entry %d: %s\n", count++, localbuf);
  36.           envptr++;
  37.      }
  38. }
  39.  
  40. /*Getenv - return a pointer to the environment strings*/
  41. char far *getenv (void)
  42. {
  43.      unsigned far *envseg;
  44.      unsigned pspseg;
  45.  
  46.      pspseg = getpsp ();               /*get the psp segment*/
  47.  
  48.      /*at offset 2C in the PSP is the segment address of
  49.        the environment*/
  50.      envseg = (unsigned far *)MK_FP ( pspseg, 0x2C);
  51.      return   (char far *)    MK_FP (*envseg, 0x00);
  52. }
  53.