diff --git a/reactos/subsys/system/cmd/alias.c b/reactos/subsys/system/cmd/alias.c index 2479083d982..a3aebd2cd68 100644 --- a/reactos/subsys/system/cmd/alias.c +++ b/reactos/subsys/system/cmd/alias.c @@ -320,9 +320,14 @@ INT CommandAlias (LPTSTR cmd, LPTSTR param) 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'); diff --git a/reactos/subsys/system/cmd/call.c b/reactos/subsys/system/cmd/call.c index 337ac803896..08c10d129d0 100644 --- a/reactos/subsys/system/cmd/call.c +++ b/reactos/subsys/system/cmd/call.c @@ -54,7 +54,7 @@ INT cmd_call (LPTSTR cmd, LPTSTR param) return 0; } - nErrorLevel = 1; + nErrorLevel = 0; n = (LPBATCH_CONTEXT)malloc (sizeof (BATCH_CONTEXT)); diff --git a/reactos/subsys/system/cmd/chcp.c b/reactos/subsys/system/cmd/chcp.c index dfe793cc45f..bf34ded3533 100644 --- a/reactos/subsys/system/cmd/chcp.c +++ b/reactos/subsys/system/cmd/chcp.c @@ -31,6 +31,8 @@ INT CommandChcp (LPTSTR cmd, LPTSTR param) ConOutResPaging(TRUE,STRING_CHCP_HELP); return 0; } + + nErrorLevel = 0; /* get parameters */ arg = split (param, &args, FALSE); @@ -48,6 +50,7 @@ INT CommandChcp (LPTSTR cmd, LPTSTR param) /* 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 @@ INT CommandChcp (LPTSTR cmd, LPTSTR param) LoadString(CMD_ModuleHandle, STRING_ERROR_INVALID_PARAM_FORMAT, szMsg, RC_STRING_MAX_SIZE); ConErrPrintf(szMsg, arg[0]); freep (arg); + nErrorLevel = 1; return 1; } diff --git a/reactos/subsys/system/cmd/color.c b/reactos/subsys/system/cmd/color.c index bdf103506c4..c2861932e2b 100644 --- a/reactos/subsys/system/cmd/color.c +++ b/reactos/subsys/system/cmd/color.c @@ -74,6 +74,8 @@ INT CommandColor (LPTSTR first, LPTSTR rest) return 0; } + nErrorLevel = 0; + if (rest[0] == _T('\0')) { /* set default color */ @@ -101,12 +103,14 @@ INT CommandColor (LPTSTR first, LPTSTR rest) 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 @@ INT CommandColor (LPTSTR first, LPTSTR rest) { LoadString(CMD_ModuleHandle, STRING_COLOR_ERROR4, szMsg, RC_STRING_MAX_SIZE); ConErrPrintf(szMsg, wColor); + nErrorLevel = 1; return 1; } diff --git a/reactos/subsys/system/cmd/copy.c b/reactos/subsys/system/cmd/copy.c index 099f4712444..fbae8f812c0 100644 --- a/reactos/subsys/system/cmd/copy.c +++ b/reactos/subsys/system/cmd/copy.c @@ -80,7 +80,7 @@ int copy (TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFl { LoadString(CMD_ModuleHandle, STRING_COPY_ERROR1, szMsg, RC_STRING_MAX_SIZE); ConOutPrintf(szMsg, source); - nErrorLevel = 1; + nErrorLevel = 1; return 0; } @@ -92,6 +92,7 @@ int copy (TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFl if(SetFileTime(hFileSrc,(LPFILETIME) NULL, (LPFILETIME) NULL, &NewFileTime)) { CloseHandle(hFileSrc); + nErrorLevel = 1; return 1; } @@ -110,7 +111,7 @@ int copy (TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFl { LoadString(CMD_ModuleHandle, STRING_COPY_ERROR1, szMsg, RC_STRING_MAX_SIZE); ConOutPrintf(szMsg, source); - nErrorLevel = 1; + nErrorLevel = 1; return 0; } @@ -178,7 +179,7 @@ int copy (TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFl ConOutPrintf(szMsg, source); CloseHandle (hFileSrc); - nErrorLevel = 1; + nErrorLevel = 1; return 0; } @@ -221,7 +222,7 @@ int copy (TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFl { CloseHandle (hFileSrc); ConOutResPuts(STRING_ERROR_PATH_NOT_FOUND); - nErrorLevel = 1; + nErrorLevel = 1; return 0; } buffer = (LPBYTE)malloc (BUFF_SIZE); @@ -230,7 +231,7 @@ int copy (TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFl CloseHandle (hFileDest); CloseHandle (hFileSrc); ConOutResPuts(STRING_ERROR_OUT_OF_MEMORY); - nErrorLevel = 1; + nErrorLevel = 1; return 0; } @@ -504,9 +505,9 @@ INT cmd_copy (LPTSTR cmd, LPTSTR param) 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 @@ INT cmd_copy (LPTSTR cmd, LPTSTR param) 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; } diff --git a/reactos/subsys/system/cmd/del.c b/reactos/subsys/system/cmd/del.c index 21fb9215ad4..35a240d7f1f 100644 --- a/reactos/subsys/system/cmd/del.c +++ b/reactos/subsys/system/cmd/del.c @@ -397,6 +397,8 @@ INT CommandDelete (LPTSTR cmd, LPTSTR param) return 0; } + nErrorLevel = 0; + arg = split (param, &args, FALSE); if (args == 0) diff --git a/reactos/subsys/system/cmd/delay.c b/reactos/subsys/system/cmd/delay.c index 0e99c9f9df0..4b383102e33 100644 --- a/reactos/subsys/system/cmd/delay.c +++ b/reactos/subsys/system/cmd/delay.c @@ -26,6 +26,8 @@ INT CommandDelay (LPTSTR cmd, LPTSTR param) return 0; } + nErrorLevel = 0; + if (*param==0) { error_req_param_missing (); diff --git a/reactos/subsys/system/cmd/dir.c b/reactos/subsys/system/cmd/dir.c index 01636f4cb49..983163da6fb 100644 --- a/reactos/subsys/system/cmd/dir.c +++ b/reactos/subsys/system/cmd/dir.c @@ -1823,7 +1823,7 @@ TCHAR szMsg[RC_STRING_MAX_SIZE]; free(ptrStartNode); ptrStartNode = ptrNextNode; dwCount --; - } + } return 1; } @@ -1951,14 +1951,22 @@ INT CommandDir(LPTSTR first, LPTSTR rest) 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 @@ INT CommandDir(LPTSTR first, LPTSTR rest) /* parse the directory info */ if (DirParsePathspec (param, szPath, szFilespec)) + { + nErrorLevel = 1; return 1; + } /* Uncomment this to show the final state of switch flags*/ @@ -1993,11 +2004,17 @@ INT CommandDir(LPTSTR first, LPTSTR rest) /* 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 @@ INT CommandDir(LPTSTR first, LPTSTR rest) recurse_bytes, &nLine, &stFlags); - - nErrorLevel = 0; + return 0; } diff --git a/reactos/subsys/system/cmd/dirstack.c b/reactos/subsys/system/cmd/dirstack.c index 3cc83a15e21..8d6ad17ab41 100644 --- a/reactos/subsys/system/cmd/dirstack.c +++ b/reactos/subsys/system/cmd/dirstack.c @@ -37,6 +37,8 @@ PushDirectory (LPTSTR pszPath) { LPDIRENTRY lpDir; + nErrorLevel = 0; + lpDir = (LPDIRENTRY)malloc (sizeof (DIRENTRY)); if (!lpDir) { @@ -78,6 +80,8 @@ PopDirectory (VOID) { LPDIRENTRY lpDir; + nErrorLevel = 0; + if (nStackDepth == 0) return; @@ -98,6 +102,8 @@ PopDirectory (VOID) static VOID GetDirectoryStackTop (LPTSTR pszPath) { + nErrorLevel = 0; + if (lpStackTop) _tcsncpy (pszPath, lpStackTop->pszPath, MAX_PATH); else @@ -147,6 +153,8 @@ INT CommandPushd (LPTSTR first, LPTSTR rest) return 0; } + nErrorLevel = 0; + if (rest[0] != _T('\0')) { GetFullPathName (rest, MAX_PATH, newPath, NULL); @@ -177,6 +185,8 @@ INT CommandPopd (LPTSTR first, LPTSTR rest) return 0; } + nErrorLevel = 0; + if (GetDirectoryStackDepth () == 0) return 0; @@ -202,6 +212,7 @@ INT CommandDirs (LPTSTR first, LPTSTR rest) return 0; } + nErrorLevel = 0; lpDir = lpStackBottom; diff --git a/reactos/subsys/system/cmd/move.c b/reactos/subsys/system/cmd/move.c index 00f6dafb201..9d6916d327c 100644 --- a/reactos/subsys/system/cmd/move.c +++ b/reactos/subsys/system/cmd/move.c @@ -140,6 +140,7 @@ INT cmd_move (LPTSTR cmd, LPTSTR param) return 0; } + nErrorLevel = 0; arg = split (param, &argc, FALSE); nFiles = argc; diff --git a/reactos/subsys/system/cmd/path.c b/reactos/subsys/system/cmd/path.c index 4984b76fb27..601863a1dfa 100644 --- a/reactos/subsys/system/cmd/path.c +++ b/reactos/subsys/system/cmd/path.c @@ -43,6 +43,8 @@ INT cmd_path (LPTSTR cmd, LPTSTR param) return 0; } + nErrorLevel = 0; + /* if param is empty, display the PATH environment variable */ if (!param || !*param) { @@ -76,7 +78,10 @@ INT cmd_path (LPTSTR cmd, LPTSTR param) /* set PATH environment variable */ if (!SetEnvironmentVariable (_T("PATH"), param)) + { + nErrorLevel = 1; return 1; + } return 0; } diff --git a/reactos/subsys/system/cmd/ren.c b/reactos/subsys/system/cmd/ren.c index 925c633b157..b096fc8f876 100644 --- a/reactos/subsys/system/cmd/ren.c +++ b/reactos/subsys/system/cmd/ren.c @@ -66,6 +66,8 @@ INT cmd_rename (LPTSTR cmd, LPTSTR param) return 0; } + nErrorLevel = 0; + /* split the argument list */ arg = split(param, &args, FALSE); diff --git a/reactos/subsys/system/cmd/screen.c b/reactos/subsys/system/cmd/screen.c index 1cfcdff44bd..315e7c83c0f 100644 --- a/reactos/subsys/system/cmd/screen.c +++ b/reactos/subsys/system/cmd/screen.c @@ -28,6 +28,8 @@ INT CommandScreen (LPTSTR cmd, LPTSTR param) return 0; } + nErrorLevel = 0; + //get row while(_istspace(*param)) param++; @@ -42,6 +44,7 @@ INT CommandScreen (LPTSTR cmd, LPTSTR param) if (y<0 || y>(maxy-1)) { ConOutResPuts(STRING_SCREEN_ROW); + return 1; } diff --git a/reactos/subsys/system/cmd/set.c b/reactos/subsys/system/cmd/set.c index 57b6070f074..544e8ba8253 100644 --- a/reactos/subsys/system/cmd/set.c +++ b/reactos/subsys/system/cmd/set.c @@ -55,6 +55,7 @@ INT cmd_set (LPTSTR cmd, LPTSTR param) return 0; } + /* if no parameters, show the environment */ if (param[0] == _T('\0')) { diff --git a/reactos/subsys/system/cmd/shift.c b/reactos/subsys/system/cmd/shift.c index 2300faf28c0..82c1f39d51b 100644 --- a/reactos/subsys/system/cmd/shift.c +++ b/reactos/subsys/system/cmd/shift.c @@ -50,9 +50,12 @@ INT cmd_shift (LPTSTR cmd, LPTSTR param) return 0; } + nErrorLevel = 0; + if (bc == NULL) { /* not in batch - error!! */ + nErrorLevel = 1; return 1; } diff --git a/reactos/subsys/system/cmd/start.c b/reactos/subsys/system/cmd/start.c index a1c692eb81a..31839a19a4d 100644 --- a/reactos/subsys/system/cmd/start.c +++ b/reactos/subsys/system/cmd/start.c @@ -29,6 +29,8 @@ INT cmd_start (LPTSTR first, LPTSTR rest) return 0; } + nErrorLevel = 0; + /* check for a drive change */ if (!_tcscmp (first + 1, _T(":")) && _istalpha (*first)) { diff --git a/reactos/subsys/system/cmd/timer.c b/reactos/subsys/system/cmd/timer.c index a1ae700fd78..34567dafa40 100644 --- a/reactos/subsys/system/cmd/timer.c +++ b/reactos/subsys/system/cmd/timer.c @@ -107,6 +107,8 @@ INT CommandTimer (LPTSTR cmd, LPTSTR param) return 0; } + nErrorLevel = 0; + LoadString( CMD_ModuleHandle, STRING_TIMER_TIME, szMsg, RC_STRING_MAX_SIZE); p = split (param, &argc, FALSE); diff --git a/reactos/subsys/system/cmd/type.c b/reactos/subsys/system/cmd/type.c index 877bf4478ae..100ef034318 100644 --- a/reactos/subsys/system/cmd/type.c +++ b/reactos/subsys/system/cmd/type.c @@ -50,7 +50,7 @@ INT cmd_type (LPTSTR cmd, LPTSTR param) { ConOutResPaging(TRUE,STRING_TYPE_HELP1); return 0; - } + } if (!*param) { diff --git a/reactos/subsys/system/cmd/vol.c b/reactos/subsys/system/cmd/vol.c index e9dc767a778..ac8a11af466 100644 --- a/reactos/subsys/system/cmd/vol.c +++ b/reactos/subsys/system/cmd/vol.c @@ -107,6 +107,7 @@ INT cmd_vol (LPTSTR cmd, LPTSTR param) /* print the header */ if (!PrintVolumeHeader (szRootPath)) { + nErrorLevel = 1; return 1; }