implement errorlevel in some cmd command and bug fix some errorlevel
command. Hopply it is last commit about errorlevel. Please can some test
see if all cmd command have right errorlevel set or not set. I have not
test every command if they got right errorlevel setting. But They should
have it now.
Modified: trunk/reactos/subsys/system/cmd/alias.c
Modified: trunk/reactos/subsys/system/cmd/call.c
Modified: trunk/reactos/subsys/system/cmd/chcp.c
Modified: trunk/reactos/subsys/system/cmd/color.c
Modified: trunk/reactos/subsys/system/cmd/copy.c
Modified: trunk/reactos/subsys/system/cmd/del.c
Modified: trunk/reactos/subsys/system/cmd/delay.c
Modified: trunk/reactos/subsys/system/cmd/dir.c
Modified: trunk/reactos/subsys/system/cmd/dirstack.c
Modified: trunk/reactos/subsys/system/cmd/move.c
Modified: trunk/reactos/subsys/system/cmd/path.c
Modified: trunk/reactos/subsys/system/cmd/ren.c
Modified: trunk/reactos/subsys/system/cmd/screen.c
Modified: trunk/reactos/subsys/system/cmd/set.c
Modified: trunk/reactos/subsys/system/cmd/shift.c
Modified: trunk/reactos/subsys/system/cmd/start.c
Modified: trunk/reactos/subsys/system/cmd/timer.c
Modified: trunk/reactos/subsys/system/cmd/type.c
Modified: trunk/reactos/subsys/system/cmd/vol.c
_____
Modified: trunk/reactos/subsys/system/cmd/alias.c
--- trunk/reactos/subsys/system/cmd/alias.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/alias.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -320,9 +320,14 @@
return 0;
}
+ nErrorLevel = 0;
+
/* error if no '=' found */
if ((ptr = _tcschr (param, _T('='))) == 0)
+ {
+ nErrorLevel = 1;
return 1;
+ }
/* Split rest into name and substitute */
*ptr++ = _T('\0');
_____
Modified: trunk/reactos/subsys/system/cmd/call.c
--- trunk/reactos/subsys/system/cmd/call.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/call.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -54,7 +54,7 @@
return 0;
}
- nErrorLevel = 1;
+ nErrorLevel = 0;
n = (LPBATCH_CONTEXT)malloc (sizeof (BATCH_CONTEXT));
_____
Modified: trunk/reactos/subsys/system/cmd/chcp.c
--- trunk/reactos/subsys/system/cmd/chcp.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/chcp.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -31,6 +31,8 @@
ConOutResPaging(TRUE,STRING_CHCP_HELP);
return 0;
}
+
+ nErrorLevel = 0;
/* get parameters */
arg = split (param, &args, FALSE);
@@ -48,6 +50,7 @@
/* too many parameters */
LoadString(CMD_ModuleHandle,
STRING_ERROR_INVALID_PARAM_FORMAT, szMsg, RC_STRING_MAX_SIZE);
ConErrPrintf(szMsg, param);
+ nErrorLevel = 1;
return 1;
}
@@ -58,6 +61,7 @@
LoadString(CMD_ModuleHandle,
STRING_ERROR_INVALID_PARAM_FORMAT, szMsg, RC_STRING_MAX_SIZE);
ConErrPrintf(szMsg, arg[0]);
freep (arg);
+ nErrorLevel = 1;
return 1;
}
_____
Modified: trunk/reactos/subsys/system/cmd/color.c
--- trunk/reactos/subsys/system/cmd/color.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/color.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -74,6 +74,8 @@
return 0;
}
+ nErrorLevel = 0;
+
if (rest[0] == _T('\0'))
{
/* set default color */
@@ -101,12 +103,14 @@
return 0;
}
ConErrResPuts(STRING_COLOR_ERROR2);
+ nErrorLevel = 1;
return 1;
}
if (StringToColor(&wColor, &rest) == FALSE)
{
ConErrResPuts(STRING_COLOR_ERROR2);
+ nErrorLevel = 1;
return 1;
}
@@ -117,6 +121,7 @@
{
LoadString(CMD_ModuleHandle, STRING_COLOR_ERROR4, szMsg,
RC_STRING_MAX_SIZE);
ConErrPrintf(szMsg, wColor);
+ nErrorLevel = 1;
return 1;
}
_____
Modified: trunk/reactos/subsys/system/cmd/copy.c
--- trunk/reactos/subsys/system/cmd/copy.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/copy.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -80,7 +80,7 @@
{
LoadString(CMD_ModuleHandle, STRING_COPY_ERROR1, szMsg,
RC_STRING_MAX_SIZE);
ConOutPrintf(szMsg, source);
- nErrorLevel = 1;
+ nErrorLevel = 1;
return 0;
}
@@ -92,6 +92,7 @@
if(SetFileTime(hFileSrc,(LPFILETIME) NULL, (LPFILETIME)
NULL, &NewFileTime))
{
CloseHandle(hFileSrc);
+ nErrorLevel = 1;
return 1;
}
@@ -110,7 +111,7 @@
{
LoadString(CMD_ModuleHandle, STRING_COPY_ERROR1, szMsg,
RC_STRING_MAX_SIZE);
ConOutPrintf(szMsg, source);
- nErrorLevel = 1;
+ nErrorLevel = 1;
return 0;
}
@@ -178,7 +179,7 @@
ConOutPrintf(szMsg, source);
CloseHandle (hFileSrc);
- nErrorLevel = 1;
+ nErrorLevel = 1;
return 0;
}
@@ -221,7 +222,7 @@
{
CloseHandle (hFileSrc);
ConOutResPuts(STRING_ERROR_PATH_NOT_FOUND);
- nErrorLevel = 1;
+ nErrorLevel = 1;
return 0;
}
buffer = (LPBYTE)malloc (BUFF_SIZE);
@@ -230,7 +231,7 @@
CloseHandle (hFileDest);
CloseHandle (hFileSrc);
ConOutResPuts(STRING_ERROR_OUT_OF_MEMORY);
- nErrorLevel = 1;
+ nErrorLevel = 1;
return 0;
}
@@ -504,9 +505,9 @@
default:
/* invaild switch */
- LoadString(CMD_ModuleHandle, STRING_ERROR_INVALID_SWITCH,
szMsg, RC_STRING_MAX_SIZE);
- ConOutPrintf(szMsg, _totupper(arg[i][1]));
-
+ LoadString(CMD_ModuleHandle,
STRING_ERROR_INVALID_SWITCH, szMsg, RC_STRING_MAX_SIZE);
+ ConOutPrintf(szMsg, _totupper(arg[i][1]));
+ nErrorLevel = 1;
return 1;
break;
}
@@ -555,9 +556,9 @@
if(nFiles > 2)
{
/* there is too many file names in command */
- LoadString(CMD_ModuleHandle, STRING_ERROR_TOO_MANY_PARAMETERS,
szMsg, RC_STRING_MAX_SIZE);
- ConErrPrintf(szMsg,_T(""));
- nErrorLevel = 1;
+ LoadString(CMD_ModuleHandle, STRING_ERROR_TOO_MANY_PARAMETERS,
szMsg, RC_STRING_MAX_SIZE);
+ ConErrPrintf(szMsg,_T(""));
+ nErrorLevel = 1;
freep (arg);
return 1;
}
_____
Modified: trunk/reactos/subsys/system/cmd/del.c
--- trunk/reactos/subsys/system/cmd/del.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/del.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -397,6 +397,8 @@
return 0;
}
+ nErrorLevel = 0;
+
arg = split (param, &args, FALSE);
if (args == 0)
_____
Modified: trunk/reactos/subsys/system/cmd/delay.c
--- trunk/reactos/subsys/system/cmd/delay.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/delay.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -26,6 +26,8 @@
return 0;
}
+ nErrorLevel = 0;
+
if (*param==0)
{
error_req_param_missing ();
_____
Modified: trunk/reactos/subsys/system/cmd/dir.c
--- trunk/reactos/subsys/system/cmd/dir.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/dir.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -1823,7 +1823,7 @@
free(ptrStartNode);
ptrStartNode = ptrNextNode;
dwCount --;
- }
+ }
return 1;
}
@@ -1951,14 +1951,22 @@
stFlags.stOrderBy.sCriteriaCount = 0;
stFlags.stOrderBy.bUnSet = FALSE;
+ nErrorLevel = 0;
+
/* read the parameters from the DIRCMD environment variable */
if (GetEnvironmentVariable (_T("DIRCMD"), dircmd, 256))
if (!DirReadParam(dircmd, ¶m, &stFlags))
+ {
+ nErrorLevel = 1;
return 1;
+ }
/* read the parameters */
if (!DirReadParam(rest, ¶m, &stFlags))
+ {
+ nErrorLevel = 1;
return 1;
+ }
/* default to current directory */
if (!param)
@@ -1966,7 +1974,10 @@
/* parse the directory info */
if (DirParsePathspec (param, szPath, szFilespec))
+ {
+ nErrorLevel = 1;
return 1;
+ }
/* <Debug :>
Uncomment this to show the final state of switch flags*/
@@ -1993,11 +2004,17 @@
/* print the header */
if (!stFlags.bBareFormat)
if (!PrintDirectoryHeader (szPath, &nLine, &stFlags))
+ {
+ nErrorLevel = 1;
return 1;
+ }
/* do the actual dir */
if (DirList (szPath, szFilespec, &nLine, &stFlags))
+ {
+ nErrorLevel = 1;
return 1;
+ }
/* print the footer */
PrintSummary(szPath,
@@ -2006,8 +2023,7 @@
recurse_bytes,
&nLine,
&stFlags);
-
- nErrorLevel = 0;
+
return 0;
}
_____
Modified: trunk/reactos/subsys/system/cmd/dirstack.c
--- trunk/reactos/subsys/system/cmd/dirstack.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/dirstack.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -37,6 +37,8 @@
{
LPDIRENTRY lpDir;
+ nErrorLevel = 0;
+
lpDir = (LPDIRENTRY)malloc (sizeof (DIRENTRY));
if (!lpDir)
{
@@ -78,6 +80,8 @@
{
LPDIRENTRY lpDir;
+ nErrorLevel = 0;
+
if (nStackDepth == 0)
return;
@@ -98,6 +102,8 @@
static VOID
GetDirectoryStackTop (LPTSTR pszPath)
{
+ nErrorLevel = 0;
+
if (lpStackTop)
_tcsncpy (pszPath, lpStackTop->pszPath, MAX_PATH);
else
@@ -147,6 +153,8 @@
return 0;
}
+ nErrorLevel = 0;
+
if (rest[0] != _T('\0'))
{
GetFullPathName (rest, MAX_PATH, newPath, NULL);
@@ -177,6 +185,8 @@
return 0;
}
+ nErrorLevel = 0;
+
if (GetDirectoryStackDepth () == 0)
return 0;
@@ -202,6 +212,7 @@
return 0;
}
+ nErrorLevel = 0;
lpDir = lpStackBottom;
_____
Modified: trunk/reactos/subsys/system/cmd/move.c
--- trunk/reactos/subsys/system/cmd/move.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/move.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -140,6 +140,7 @@
return 0;
}
+ nErrorLevel = 0;
arg = split (param, &argc, FALSE);
nFiles = argc;
_____
Modified: trunk/reactos/subsys/system/cmd/path.c
--- trunk/reactos/subsys/system/cmd/path.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/path.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -43,6 +43,8 @@
return 0;
}
+ nErrorLevel = 0;
+
/* if param is empty, display the PATH environment variable */
if (!param || !*param)
{
@@ -76,7 +78,10 @@
/* set PATH environment variable */
if (!SetEnvironmentVariable (_T("PATH"), param))
+ {
+ nErrorLevel = 1;
return 1;
+ }
return 0;
}
_____
Modified: trunk/reactos/subsys/system/cmd/ren.c
--- trunk/reactos/subsys/system/cmd/ren.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/ren.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -66,6 +66,8 @@
return 0;
}
+ nErrorLevel = 0;
+
/* split the argument list */
arg = split(param, &args, FALSE);
_____
Modified: trunk/reactos/subsys/system/cmd/screen.c
--- trunk/reactos/subsys/system/cmd/screen.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/screen.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -28,6 +28,8 @@
return 0;
}
+ nErrorLevel = 0;
+
//get row
while(_istspace(*param))
param++;
@@ -42,6 +44,7 @@
if (y<0 || y>(maxy-1))
{
ConOutResPuts(STRING_SCREEN_ROW);
+
return 1;
}
_____
Modified: trunk/reactos/subsys/system/cmd/set.c
--- trunk/reactos/subsys/system/cmd/set.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/set.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -55,6 +55,7 @@
return 0;
}
+
/* if no parameters, show the environment */
if (param[0] == _T('\0'))
{
_____
Modified: trunk/reactos/subsys/system/cmd/shift.c
--- trunk/reactos/subsys/system/cmd/shift.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/shift.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -50,9 +50,12 @@
return 0;
}
+ nErrorLevel = 0;
+
if (bc == NULL)
{
/* not in batch - error!! */
+ nErrorLevel = 1;
return 1;
}
_____
Modified: trunk/reactos/subsys/system/cmd/start.c
--- trunk/reactos/subsys/system/cmd/start.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/start.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -29,6 +29,8 @@
return 0;
}
+ nErrorLevel = 0;
+
/* check for a drive change */
if (!_tcscmp (first + 1, _T(":")) && _istalpha (*first))
{
_____
Modified: trunk/reactos/subsys/system/cmd/timer.c
--- trunk/reactos/subsys/system/cmd/timer.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/timer.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -107,6 +107,8 @@
return 0;
}
+ nErrorLevel = 0;
+
LoadString( CMD_ModuleHandle, STRING_TIMER_TIME, szMsg,
RC_STRING_MAX_SIZE);
p = split (param, &argc, FALSE);
_____
Modified: trunk/reactos/subsys/system/cmd/type.c
--- trunk/reactos/subsys/system/cmd/type.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/type.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -50,7 +50,7 @@
{
ConOutResPaging(TRUE,STRING_TYPE_HELP1);
return 0;
- }
+ }
if (!*param)
{
_____
Modified: trunk/reactos/subsys/system/cmd/vol.c
--- trunk/reactos/subsys/system/cmd/vol.c 2005-08-18 19:26:37 UTC
(rev 17429)
+++ trunk/reactos/subsys/system/cmd/vol.c 2005-08-18 20:52:52 UTC
(rev 17430)
@@ -107,6 +107,7 @@
/* print the header */
if (!PrintVolumeHeader (szRootPath))
{
+ nErrorLevel = 1;
return 1;
}