home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 03dos / showenv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  974 b   |  46 lines

  1. /*
  2.  *    showenv    -- display the values of any DOS variables
  3.  *    named on the invocation command line
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <local\std.h>
  10.  
  11. main(argc, argv, envp)
  12. int argc;
  13. char **argv;
  14. char **envp;
  15. {
  16.     register char *ep;
  17.     static char pgm[MAXNAME + 1] = { "showenv" };
  18.     extern void getpname(char *, char *);
  19.  
  20.     /* use an alias if one is given to this program */
  21.     if (_osmajor >= 3)
  22.         getpname(*argv, pgm);
  23.  
  24.     /* if no arguments, show full environment list */
  25.     if (argc == 1)
  26.         for (; *envp; ++envp)
  27.             printf("%s\n", *envp);
  28.     else {
  29.         /*
  30.          *  treat all args as DOS variable names and
  31.          *  display values of only specified variables
  32.          */
  33.         ++argv;    /* skip past command name */
  34.         --argc;
  35.         while (argc > 0) {
  36.             if ((ep = getenv(strupr(*argv))) == NULL)
  37.                 fprintf(stderr, "%s not defined\n", *argv);
  38.             else
  39.                 printf("%s=%s\n", *argv, ep);
  40.             ++argv;
  41.             --argc;
  42.         }
  43.     }
  44.     exit(0);
  45. }
  46.