fix if command to work more like expected. seta_test.cmd gets much further now.

fixed some msvc6 warnings while I was in here

svn path=/trunk/; revision=17927
This commit is contained in:
Royce Mitchell III 2005-09-19 05:42:01 +00:00
parent 636cb4e66c
commit 07070d0d52

View file

@ -52,8 +52,15 @@ INT cmd_if (LPTSTR cmd, LPTSTR param)
return 0; return 0;
} }
/* First check if param string begins with word 'not' */ /* First check if param string begins with '!' or 'not' */
if (!_tcsnicmp (param, _T("not"), 3) && _istspace (*(param + 3))) if ( param[0] == _T('!') )
{
x_flag = X_EXEC; /* Remember '!' */
++param; /* Step over '!' */
while (_istspace (*param)) /* And subsequent spaces */
param++;
}
else if (!_tcsnicmp (param, _T("not"), 3) && _istspace (*(param + 3)))
{ {
x_flag = X_EXEC; /* Remember 'NOT' */ x_flag = X_EXEC; /* Remember 'NOT' */
param += 3; /* Step over 'NOT' */ param += 3; /* Step over 'NOT' */
@ -64,14 +71,15 @@ INT cmd_if (LPTSTR cmd, LPTSTR param)
/* Check for 'exist' form */ /* Check for 'exist' form */
if (!_tcsnicmp (param, _T("exist"), 5) && _istspace (*(param + 5))) if (!_tcsnicmp (param, _T("exist"), 5) && _istspace (*(param + 5)))
{ {
UINT i;
BOOL bInside = FALSE;
param += 5; param += 5;
while (_istspace (*param)) while (_istspace (*param))
param++; param++;
pp = param; pp = param;
INT i;
BOOL bInside = FALSE;
/* find the whole path to the file */ /* find the whole path to the file */
for(i = 0; i < _tcslen(param); i++) for(i = 0; i < _tcslen(param); i++)
{ {
@ -155,38 +163,34 @@ INT cmd_if (LPTSTR cmd, LPTSTR param)
x_flag |= X_EMPTY; /* Syntax error if comd empty */ x_flag |= X_EMPTY; /* Syntax error if comd empty */
} }
else if (NULL == (pp = _tcsstr (param, _T("=="))))
{
/* Check that '==' is present, syntax error if not */
error_syntax (NULL);
return 1;
}
else else
{ {
/* Change first '='to space to terminate comparison loop */ BOOL bInQuote = FALSE;
INT p1len;
*pp = _T(' '); /* Need a space to terminate comparison loop */ pp = param;
pp += 2; /* over '==' */ while ( *pp && ( bInQuote || *pp != _T('=') ) )
{
if ( *pp == _T('\"') )
bInQuote = !bInQuote;
++pp;
}
p1len = pp-param;
/* check for "==" */
if ( *pp++ != _T('=') || *pp++ != _T('=') )
{
error_syntax ( NULL );
return 1;
}
while (_istspace (*pp)) /* Skip subsequent spaces */ while (_istspace (*pp)) /* Skip subsequent spaces */
pp++; pp++;
_tcscat (pp, _T(" ")); /* Add one space to ensure comparison ends */ /* are the two sides equal, and does the second end in the same place? */
if ( !_tcsncmp(param,pp,p1len) && _tcschr(_T(" ("),pp[p1len]) )
while (*param == *pp) /* Comparison loop */ x_flag ^= X_EXEC;
{ pp += p1len;
if (_istspace (*param)) /* Terminates on space */
break;
param++, pp++;
}
if (x_flag ^= (*param != *pp) ? 0 : X_EXEC)
{
while (*pp && !_istspace (*pp)) /* Find first space, */
pp++;
if ( x_flag )
x_flag |= X_EMPTY; x_flag |= X_EMPTY;
}
} }
if (x_flag & X_EMPTY) if (x_flag & X_EMPTY)