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.

svn path=/trunk/; revision=17430
This commit is contained in:
Magnus Olsen 2005-08-18 20:52:52 +00:00
parent a6b62e7c0d
commit 9eeadb66ec
19 changed files with 82 additions and 16 deletions

View file

@ -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');

View file

@ -54,7 +54,7 @@ INT cmd_call (LPTSTR cmd, LPTSTR param)
return 0;
}
nErrorLevel = 1;
nErrorLevel = 0;
n = (LPBATCH_CONTEXT)malloc (sizeof (BATCH_CONTEXT));

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -397,6 +397,8 @@ INT CommandDelete (LPTSTR cmd, LPTSTR param)
return 0;
}
nErrorLevel = 0;
arg = split (param, &args, FALSE);
if (args == 0)

View file

@ -26,6 +26,8 @@ INT CommandDelay (LPTSTR cmd, LPTSTR param)
return 0;
}
nErrorLevel = 0;
if (*param==0)
{
error_req_param_missing ();

View file

@ -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, &param, &stFlags))
{
nErrorLevel = 1;
return 1;
}
/* read the parameters */
if (!DirReadParam(rest, &param, &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;
}
/* <Debug :>
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;
}

View file

@ -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;

View file

@ -140,6 +140,7 @@ INT cmd_move (LPTSTR cmd, LPTSTR param)
return 0;
}
nErrorLevel = 0;
arg = split (param, &argc, FALSE);
nFiles = argc;

View file

@ -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;
}

View file

@ -66,6 +66,8 @@ INT cmd_rename (LPTSTR cmd, LPTSTR param)
return 0;
}
nErrorLevel = 0;
/* split the argument list */
arg = split(param, &args, FALSE);

View file

@ -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;
}

View file

@ -55,6 +55,7 @@ INT cmd_set (LPTSTR cmd, LPTSTR param)
return 0;
}
/* if no parameters, show the environment */
if (param[0] == _T('\0'))
{

View file

@ -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;
}

View file

@ -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))
{

View file

@ -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);

View file

@ -50,7 +50,7 @@ INT cmd_type (LPTSTR cmd, LPTSTR param)
{
ConOutResPaging(TRUE,STRING_TYPE_HELP1);
return 0;
}
}
if (!*param)
{

View file

@ -107,6 +107,7 @@ INT cmd_vol (LPTSTR cmd, LPTSTR param)
/* print the header */
if (!PrintVolumeHeader (szRootPath))
{
nErrorLevel = 1;
return 1;
}