mirror of
https://github.com/reactos/reactos.git
synced 2025-04-27 00:50:23 +00:00
[CMD] SET: Fix displaying the environment variables with a given prefix.
- Restore any truncated space in the name prefix, before displaying any error message. - When trimming the name prefix from "special" characters (spaces, comma and semicolon), so that e.g. "set ,; ,;FOO" displays all the variables starting by "FOO", save also a pointer to the original name prefix, that we will use for variables lookup as well. This is done, because the SET command allows setting an environment variable whose name actually contains these characters (e.g. "set ,; ,;FOO=42"), however, by trimming the characters, doing "set ,; ,;FOO" would not allow seeing such variables. With the fix, it is now possible to show them.
This commit is contained in:
parent
8cea82b14c
commit
fe9aa42d5f
1 changed files with 25 additions and 3 deletions
|
@ -168,12 +168,27 @@ INT cmd_set(LPTSTR param)
|
|||
else
|
||||
{
|
||||
/* Display all the environment variables with the given prefix */
|
||||
BOOL bFound = FALSE;
|
||||
LPTSTR pOrgParam = param;
|
||||
BOOLEAN bFound = FALSE;
|
||||
BOOLEAN bRestoreSpace;
|
||||
|
||||
/*
|
||||
* Trim the prefix from "special" characters (only when displaying the
|
||||
* environment variables), so that e.g. "SET ,; ,;FOO" will display all
|
||||
* the variables starting by "FOO".
|
||||
* The SET command allows as well to set an environment variable whose name
|
||||
* actually contains these characters (e.g. "SET ,; ,;FOO=42"); however,
|
||||
* by trimming the characters, doing "SET ,; ,;FOO" would not allow seeing
|
||||
* such variables.
|
||||
* Thus, we also save a pointer to the original variable name prefix, that
|
||||
* we will look it up as well below.
|
||||
*/
|
||||
while (_istspace(*param) || *param == _T(',') || *param == _T(';'))
|
||||
param++;
|
||||
++param;
|
||||
|
||||
/* Just remove the very last space, if present */
|
||||
p = _tcsrchr(param, _T(' '));
|
||||
bRestoreSpace = (p != NULL);
|
||||
if (!p)
|
||||
p = param + _tcslen(param);
|
||||
*p = _T('\0');
|
||||
|
@ -184,7 +199,9 @@ INT cmd_set(LPTSTR param)
|
|||
lpOutput = lpEnv;
|
||||
while (*lpOutput)
|
||||
{
|
||||
if (!_tcsnicmp(lpOutput, param, p - param))
|
||||
/* Look up for both the original and truncated variable name prefix */
|
||||
if (!_tcsnicmp(lpOutput, pOrgParam, p - pOrgParam) ||
|
||||
!_tcsnicmp(lpOutput, param, p - param))
|
||||
{
|
||||
ConOutPuts(lpOutput);
|
||||
ConOutChar(_T('\n'));
|
||||
|
@ -195,6 +212,11 @@ INT cmd_set(LPTSTR param)
|
|||
FreeEnvironmentStrings(lpEnv);
|
||||
}
|
||||
|
||||
/* Restore the truncated space for correctly
|
||||
* displaying the error message, if any. */
|
||||
if (bRestoreSpace)
|
||||
*p = _T(' ');
|
||||
|
||||
if (!bFound)
|
||||
{
|
||||
ConErrResPrintf(STRING_SET_ENV_ERROR, param);
|
||||
|
|
Loading…
Reference in a new issue