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!
31 #define WIN32_LEAN_AND_MEAN
35 #ifdef INCLUDE_CMD_SET
45 /* size of environment variable buffer */
46 #define ENV_BUFFER_SIZE 1024
49 INT
cmd_set (LPTSTR cmd
, LPTSTR param
)
53 if (!_tcsncmp (param
, _T("/?"), 2))
55 ConOutPuts (_T("Displays, sets, or removes environment variables.\n\n"
56 "SET [variable[=][string]]\n\n"
57 " variable Specifies the environment-variable name.\n"
58 " string Specifies a series of characters to assign to the variable.\n\n"
59 "Type SET without parameters to display the current environment variables.\n"));
63 /* if no parameters, show the environment */
64 if (param
[0] == _T('\0'))
70 lpEnv
= (LPTSTR
)GetEnvironmentStrings ();
76 len
= _tcslen(lpOutput
);
79 if (*lpOutput
!= _T('='))
80 ConOutPuts (lpOutput
);
81 lpOutput
+= (len
+ 1);
84 FreeEnvironmentStrings (lpEnv
);
90 p
= _tcschr (param
, _T('='));
93 /* set or remove environment variable */
97 SetEnvironmentVariable (param
, p
);
101 /* display environment variable */
105 pszBuffer
= (LPTSTR
)malloc (ENV_BUFFER_SIZE
* sizeof(TCHAR
));
106 dwBuffer
= GetEnvironmentVariable (param
, pszBuffer
, ENV_BUFFER_SIZE
);
109 ConErrPrintf ("CMD: Not in environment \"%s\"\n", param
);
112 else if (dwBuffer
> ENV_BUFFER_SIZE
)
114 pszBuffer
= (LPTSTR
)realloc (pszBuffer
, dwBuffer
* sizeof (TCHAR
));
115 GetEnvironmentVariable (param
, pszBuffer
, ENV_BUFFER_SIZE
);
118 ConOutPrintf ("%s\n", pszBuffer
);