#endif
/*
- * is character a delimeter when used on first word?
+ * convert
*
+ * insert commas into a number
*/
+INT
+ConvertULargeInteger (ULARGE_INTEGER num, LPTSTR des, INT len, BOOL bPutSeperator)
+{
+ TCHAR temp[32];
+ INT c = 0;
+ INT n = 0;
+
+ if (num.QuadPart == 0)
+ {
+ des[0] = _T('0');
+ des[1] = _T('\0');
+ n = 1;
+ }
+ else
+ {
+ temp[31] = 0;
+ while (num.QuadPart > 0)
+ {
+ if ((((c + 1) % (nNumberGroups + 1)) == 0) && (bPutSeperator))
+ temp[30 - c++] = cThousandSeparator;
+ temp[30 - c++] = (TCHAR)(num.QuadPart % 10) + _T('0');
+ num.QuadPart /= 10;
+ }
+
+ for (n = 0; n <= c; n++)
+ des[n] = temp[31 - c + n];
+ }
+
+ return n;
+}
+/*
+ * is character a delimeter when used on first word?
+ *
+ */
static BOOL IsDelimiter (TCHAR c)
{
return (c == _T('/') || c == _T('=') || c == _T('\0') || _istspace (c));
if (first == NULL)
{
error_out_of_memory();
+ nErrorLevel = 1;
return ;
}
{
free (first);
error_out_of_memory();
+ nErrorLevel = 1;
return ;
}
free (first);
free (rest);
error_out_of_memory();
+ nErrorLevel = 1;
return ;
}
free (rest);
free (full);
error_out_of_memory();
+ nErrorLevel = 1;
return ;
}
free (rest);
free (full);
free (szFullName);
-
+ nErrorLevel = 1;
return;
}
free (rest);
free (full);
free (szFullName);
+ nErrorLevel = 1;
return;
}
GetExitCodeProcess (prci.hProcess, &dwExitCode);
nErrorLevel = (INT)dwExitCode;
}
+ else
+ {
+ nErrorLevel = 0;
+ }
CloseHandle (prci.hThread);
CloseHandle (prci.hProcess);
}
DebugPrintf (_T("[ShellExecute failed!: %s]\n"), full);
#endif
error_bad_command ();
+ nErrorLevel = 1;
}
+ else
+ {
+ nErrorLevel = 0;
+ }
}
// restore console mode
SetConsoleMode (
}
*/
- /* Skip over whitespace to rest of line */
- while (_istspace (*rest))
+ /* Skip over whitespace to rest of line, exclude 'echo' command */
+ if (_tcsicmp (com, _T("echo")))
+ {
+ while (_istspace (*rest))
rest++;
+ }
/* Scan internal command table */
for (cmdptr = cmds;; cmdptr++)
}
}
}
- /* Just in case a CTRL+C slipped through a command */
- bCtrlBreak = FALSE;
free(com);
}
return ret;
}
- return _T(""); /* not found - return empty string */
+ GrowIfNecessary(_tcslen(varName) + 2, &ret, &retlen);
+ _stprintf(ret,_T("%%%s%%"),varName);
+ return ret; /* not found - return orginal string */
}
LPCTSTR
if (!(ip = ReadBatchLine (&bEchoThisLine)))
{
if (bFlag)
- return 0;
+ return nErrorLevel;
ReadCommand (readline, CMDLINE_LENGTH);
ip = readline;
{
UINT envNameLen;
LPCTSTR envVal = GetParsedEnvVar ( ip, &envNameLen, bModeSetA );
- if ( !envVal )
- return 1;
- ip += envNameLen;
- cp = _stpcpy ( cp, envVal );
- continue;
+ if ( envVal )
+ {
+ ip += envNameLen;
+ cp = _stpcpy ( cp, envVal );
+ }
}
if (_istcntrl (*ip))
tmp = commandline;
tmp += _tcsspn(tmp,_T(" \t"));
/* first we find and skip and pre-redirections... */
- while ( _tcschr(_T("<>"),*tmp)
+ while (( tmp ) &&
+ ( _tcschr(_T("<>"),*tmp)
|| !_tcsncmp(tmp,_T("1>"),2)
- || !_tcsncmp(tmp,_T("2>"),2) )
+ || !_tcsncmp(tmp,_T("2>"),2) ))
{
if ( _istdigit(*tmp) )
tmp += 2;
}
else
tmp = _tcspbrk(tmp,_T(" \t"));
- tmp += _tcsspn(tmp,_T(" \t"));
+ if ( tmp )
+ tmp += _tcsspn(tmp,_T(" \t"));
}
/* we should now be pointing to the actual command
* (if there is one yet)*/
ConOutPuts (commandline);
}
- if (*commandline)
+ if (!CheckCtrlBreak(BREAK_INPUT) && *commandline)
{
ParseCommandLine (commandline);
if (bEcho && !bIgnoreEcho && (!bIsBatch || bEchoThisLine))
}
while (!bCanExit || !bExit);
- return 0;
+ return nErrorLevel;
}
BOOL WINAPI BreakHandler (DWORD dwCtrlType)
{
+ DWORD dwWritten;
+ INPUT_RECORD rec;
static BOOL SelfGenerated = FALSE;
-
- if ((dwCtrlType != CTRL_C_EVENT) &&
+
+ if ((dwCtrlType != CTRL_C_EVENT) &&
(dwCtrlType != CTRL_BREAK_EVENT))
{
return FALSE;
return TRUE;
}
+
+ rec.EventType = KEY_EVENT;
+ rec.Event.KeyEvent.bKeyDown = TRUE;
+ rec.Event.KeyEvent.wRepeatCount = 1;
+ rec.Event.KeyEvent.wVirtualKeyCode = _T('C');
+ rec.Event.KeyEvent.wVirtualScanCode = _T('C') - 35;
+ rec.Event.KeyEvent.uChar.AsciiChar = _T('C');
+ rec.Event.KeyEvent.uChar.UnicodeChar = _T('C');
+ rec.Event.KeyEvent.dwControlKeyState = RIGHT_CTRL_PRESSED;
+
+ WriteConsoleInput(
+ hIn,
+ &rec,
+ 1,
+ &dwWritten);
+
bCtrlBreak = TRUE;
/* FIXME: Handle batch files */