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>)
33 * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
34 * Remove all hardcode string to En.rc
40 #ifdef INCLUDE_CMD_SET
43 /* initial size of environment variable buffer */
44 #define ENV_BUFFER_SIZE 1024
47 INT
cmd_set (LPTSTR cmd
, LPTSTR param
)
49 TCHAR szMsg
[RC_STRING_MAX_SIZE
];
52 if (!_tcsncmp (param
, _T("/?"), 2))
54 LoadString(GetModuleHandle(NULL
), STRING_SET_HELP
, szMsg
, RC_STRING_MAX_SIZE
);
59 /* if no parameters, show the environment */
60 if (param
[0] == _T('\0'))
66 lpEnv
= (LPTSTR
)GetEnvironmentStrings ();
72 len
= _tcslen(lpOutput
);
75 if (*lpOutput
!= _T('='))
76 ConOutPuts (lpOutput
);
77 lpOutput
+= (len
+ 1);
80 FreeEnvironmentStrings (lpEnv
);
86 p
= _tcschr (param
, _T('='));
89 /* set or remove environment variable */
96 SetEnvironmentVariable (param
, p
);
100 /* display environment variable */
104 pszBuffer
= (LPTSTR
)malloc (ENV_BUFFER_SIZE
* sizeof(TCHAR
));
105 dwBuffer
= GetEnvironmentVariable (param
, pszBuffer
, ENV_BUFFER_SIZE
);
108 ConErrPrintf (_T("CMD: Not in environment \"%s\"\n"), param
);
111 else if (dwBuffer
> ENV_BUFFER_SIZE
)
113 pszBuffer
= (LPTSTR
)realloc (pszBuffer
, dwBuffer
* sizeof (TCHAR
));
114 GetEnvironmentVariable (param
, pszBuffer
, dwBuffer
);
116 ConOutPrintf (_T("%s\n"), pszBuffer
);