home *** CD-ROM | disk | FTP | other *** search
/ Programming Win32 Under the API / ProgrammingWin32UnderTheApiPatVillani.iso / Chapter9 / cmd32 / Set.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-15  |  2.5 KB  |  110 lines

  1. /****************************************************************/
  2. /*                                */
  3. /*                 set.c                */
  4. /*                                */
  5. /*            Copyright (c) 2000            */
  6. /*            Pasquale J. Villani            */
  7. /*            All Rights Reserved            */
  8. /*                                */
  9. /* This file is part of CMD32.                    */
  10. /*                                */
  11. /* CMD32 is free software; you can redistribute it and/or    */
  12. /* modify it under the terms of the GNU General Public License    */
  13. /* as published by the Free Software Foundation; either version    */
  14. /* 2, or (at your option) any later version.            */
  15. /*                                */
  16. /* CMD32 is distributed in the hope that it will be useful, but    */
  17. /* WITHOUT ANY WARRANTY; without even the implied warranty of    */
  18. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See    */
  19. /* the GNU General Public License for more details.        */
  20. /*                                */
  21. /* You should have received a copy of the GNU General Public    */
  22. /* License along with CMD32; see the file COPYING.  If not,    */
  23. /* write to the Free Software Foundation, 675 Mass Ave,        */
  24. /* Cambridge, MA 02139, USA.                    */
  25. /****************************************************************/
  26.  
  27. /* $Logfile$ */
  28.  
  29. /* $Log$ 
  30.  * $EndLog$ */
  31.  
  32. #ifdef VERSION_STRINGS
  33. static char *RcsId = "$Header$";
  34. #endif
  35.  
  36. #include <windows.h>
  37. #include "globals.h"
  38. #include "proto.h"
  39.  
  40. extern BYTE *dflt_pr_string;
  41.  
  42. void EnvDump(void);
  43.  
  44. BOOL set_bat(INT argc, BYTE *argv[])
  45. {
  46.     BYTE env_var[MAX_CMDLINE];
  47.     BYTE *lp, *p;
  48.  
  49.     lp = skipwh(tail);
  50.     if(*lp == '\0')
  51.     {
  52.         EnvDump();
  53.         printf("\n");
  54.         return TRUE;
  55.     }
  56.  
  57.     lp = scanspl(tail, env_var, '=');
  58.     if(!lp && *lp != '=')
  59.     {
  60.         error_message(INV_SYNTAX);
  61.         return FALSE;
  62.     }
  63.     else
  64.         ++lp;
  65.  
  66.     if(*lp == '\r' || *lp == '\n')
  67.     {
  68.         /* set env_var in environment to empty            */
  69.         SetEnvironmentVariable(env_var, NULL);
  70.  
  71.         /* Update system PROMPT immediately            */
  72.         if(strcmp(env_var,"PROMPT") == 0)
  73.             strcpy(szPrompt, dflt_pr_string);
  74.  
  75.     }
  76.     else
  77.     {
  78.         /* Trim trailing newline                */
  79.  
  80.         for(p = lp; (*p != '\r') && (*p != '\n'); p++)
  81.             ;
  82.         *p = '\0';
  83.  
  84.         SetEnvironmentVariable(env_var, lp);
  85.  
  86.         /* Update system PROMPT immediately            */
  87.         if(strcmp(env_var,"PROMPT") == 0)
  88.             strcpy(szPrompt, lp);
  89.  
  90.         /* Update system PATH immediately            */
  91.         if(strcmp(env_var,"PATH") == 0)
  92.             strcpy(pszPath, lp);
  93.     }
  94.     return TRUE;
  95. }
  96.  
  97.  
  98. void EnvDump(void)
  99. {
  100.     BYTE *pszEnvStrings;
  101.  
  102.     pszEnvStrings = GetEnvironmentStrings();
  103.     while(*pszEnvStrings)
  104.     {
  105.         printf("%s\n", pszEnvStrings);
  106.         pszEnvStrings += (strlen(pszEnvStrings) + 1);
  107.     }
  108. }
  109.  
  110.