[CMD] setlocal.c : Code style and formatting fixes

This commit is contained in:
Hermès Bélusca-Maïto 2020-07-26 20:32:39 +02:00
parent 90159e1e51
commit e8e31267c5
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -12,10 +12,10 @@
typedef struct _SETLOCAL typedef struct _SETLOCAL
{ {
struct _SETLOCAL *Prev; struct _SETLOCAL *Prev;
LPTSTR Environment;
BOOL EnableExtensions; BOOL EnableExtensions;
BOOL DelayedExpansion; BOOL DelayedExpansion;
LPTSTR Environment; } SETLOCAL, *PSETLOCAL;
} SETLOCAL;
/* Create a copy of the current environment */ /* Create a copy of the current environment */
LPTSTR LPTSTR
@ -38,11 +38,11 @@ DuplicateEnvironment(VOID)
INT cmd_setlocal(LPTSTR param) INT cmd_setlocal(LPTSTR param)
{ {
SETLOCAL *Saved; PSETLOCAL Saved;
LPTSTR *arg; LPTSTR* arg;
INT argc, i; INT argc, i;
/* SETLOCAL only works inside a batch file */ /* SETLOCAL only works inside a batch context */
if (!bc) if (!bc)
return 0; return 0;
@ -53,9 +53,6 @@ INT cmd_setlocal(LPTSTR param)
error_out_of_memory(); error_out_of_memory();
return 1; return 1;
} }
Saved->Prev = bc->setlocal;
Saved->EnableExtensions = bEnableExtensions;
Saved->DelayedExpansion = bDelayedExpansion;
Saved->Environment = DuplicateEnvironment(); Saved->Environment = DuplicateEnvironment();
if (!Saved->Environment) if (!Saved->Environment)
{ {
@ -63,6 +60,10 @@ INT cmd_setlocal(LPTSTR param)
cmd_free(Saved); cmd_free(Saved);
return 1; return 1;
} }
Saved->EnableExtensions = bEnableExtensions;
Saved->DelayedExpansion = bDelayedExpansion;
Saved->Prev = bc->setlocal;
bc->setlocal = Saved; bc->setlocal = Saved;
nErrorLevel = 0; nErrorLevel = 0;
@ -70,15 +71,13 @@ INT cmd_setlocal(LPTSTR param)
arg = splitspace(param, &argc); arg = splitspace(param, &argc);
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
if (!_tcsicmp(arg[i], _T("enableextensions"))) if (!_tcsicmp(arg[i], _T("ENABLEEXTENSIONS")))
/* FIXME: not implemented! */
bEnableExtensions = TRUE; bEnableExtensions = TRUE;
else if (!_tcsicmp(arg[i], _T("disableextensions"))) else if (!_tcsicmp(arg[i], _T("DISABLEEXTENSIONS")))
/* FIXME: not implemented! */
bEnableExtensions = FALSE; bEnableExtensions = FALSE;
else if (!_tcsicmp(arg[i], _T("enabledelayedexpansion"))) else if (!_tcsicmp(arg[i], _T("ENABLEDELAYEDEXPANSION")))
bDelayedExpansion = TRUE; bDelayedExpansion = TRUE;
else if (!_tcsicmp(arg[i], _T("disabledelayedexpansion"))) else if (!_tcsicmp(arg[i], _T("DISABLEDELAYEDEXPANSION")))
bDelayedExpansion = FALSE; bDelayedExpansion = FALSE;
else else
{ {
@ -91,13 +90,15 @@ INT cmd_setlocal(LPTSTR param)
return nErrorLevel; return nErrorLevel;
} }
/* endlocal doesn't take any params */
INT cmd_endlocal(LPTSTR param) INT cmd_endlocal(LPTSTR param)
{ {
LPTSTR Environ, Name, Value; LPTSTR Environ, Name, Value;
SETLOCAL *Saved; PSETLOCAL Saved;
/* Pop a SETLOCAL struct off of this batch file's stack */ /* ENDLOCAL doesn't take any params */
UNREFERENCED_PARAMETER(param);
/* Pop a SETLOCAL struct off of this batch context's stack */
if (!bc || !(Saved = bc->setlocal)) if (!bc || !(Saved = bc->setlocal))
return 0; return 0;
bc->setlocal = Saved->Prev; bc->setlocal = Saved->Prev;
@ -107,7 +108,7 @@ INT cmd_endlocal(LPTSTR param)
/* First, clear out the environment. Since making any changes to the /* First, clear out the environment. Since making any changes to the
* environment invalidates pointers obtained from GetEnvironmentStrings(), * environment invalidates pointers obtained from GetEnvironmentStrings(),
* we must make a copy of it and get the variable names from that */ * we must make a copy of it and get the variable names from that. */
Environ = DuplicateEnvironment(); Environ = DuplicateEnvironment();
if (Environ) if (Environ)
{ {
@ -122,7 +123,7 @@ INT cmd_endlocal(LPTSTR param)
cmd_free(Environ); cmd_free(Environ);
} }
/* Now, restore variables from the copy saved by cmd_setlocal */ /* Now, restore variables from the copy saved by cmd_setlocal() */
for (Name = Saved->Environment; *Name; Name += _tcslen(Name) + 1) for (Name = Saved->Environment; *Name; Name += _tcslen(Name) + 1)
{ {
if (!(Value = _tcschr(Name + 1, _T('=')))) if (!(Value = _tcschr(Name + 1, _T('='))))