2 * SET.C - set internal command.
7 * 06/14/97 (Tim Norman)
8 * changed static var in set() to a malloc'd space to pass to putenv.
9 * need to find a better way to do this, since it seems it is wasting
10 * memory when variables are redefined.
12 * 07/08/1998 (John P. Price)
13 * removed call to show_environment in set command.
14 * moved test for syntax before allocating memory in set command.
15 * misc clean up and optimization.
17 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
18 * added config.h include
20 * 28-Jul-1998 (John P Price <linux-guru@gcfl.net>)
21 * added set_env function to set env. variable without needing set command
23 * 09-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
24 * Added help text ("/?").
26 * 24-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
27 * Fixed Win32 environment handling.
28 * Unicode and redirection safe!
30 * 25-Feb-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
36 #ifdef INCLUDE_CMD_SET
46 /* initial size of environment variable buffer */
47 #define ENV_BUFFER_SIZE 1024
50 INT cmd_set (LPTSTR cmd, LPTSTR param)
54 if (!_tcsncmp (param, _T("/?"), 2))
56 ConOutPuts (_T("Displays, sets, or removes environment variables.\n\n"
57 "SET [variable[=][string]]\n\n"
58 " variable Specifies the environment-variable name.\n"
59 " string Specifies a series of characters to assign to the variable.\n\n"
60 "Type SET without parameters to display the current environment variables.\n"));
64 /* if no parameters, show the environment */
65 if (param[0] == _T('\0'))
71 lpEnv = (LPTSTR)GetEnvironmentStrings ();
77 len = _tcslen(lpOutput);
80 if (*lpOutput != _T('='))
81 ConOutPuts (lpOutput);
82 lpOutput += (len + 1);
85 FreeEnvironmentStrings (lpEnv);
91 p = _tcschr (param, _T('='));
94 /* set or remove environment variable */
98 SetEnvironmentVariable (param, p);
102 /* display environment variable */
106 pszBuffer = (LPTSTR)malloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
107 dwBuffer = GetEnvironmentVariable (param, pszBuffer, ENV_BUFFER_SIZE);
110 ConErrPrintf (_T("CMD: Not in environment \"%s\"\n"), param);
113 else if (dwBuffer > ENV_BUFFER_SIZE)
115 pszBuffer = (LPTSTR)realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
116 GetEnvironmentVariable (param, pszBuffer, dwBuffer);
118 ConOutPrintf (_T("%s\n"), pszBuffer);