-/* $Id: cmd.c,v 1.19 2000/02/18 00:53:11 ekohl Exp $
+/* $Id: cmd.c,v 1.24 2001/02/28 22:33:23 ekohl Exp $
*
* CMD.C - command-line interface.
*
*
* 28-Dec-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Restore window title after program/batch execution
+ *
+ * 03-Feb-2001 (Eric Kohl <ekohl@rz-online.de>)
+ * Workaround because argc[0] is NULL under ReactOS
+ *
+ * 23-Feb-2001 (Carl Nettelblad <cnettel@hem.passagen.se>)
+ * %envvar% replacement conflicted with for.
*/
#include "config.h"
#include "batch.h"
-#define CMDLINE_LENGTH 1024
-
-
BOOL bExit = FALSE; /* indicates EXIT was typed */
BOOL bCanExit = TRUE; /* indicates if this shell is exitable */
BOOL bCtrlBreak = FALSE; /* Ctrl-Break or Ctrl-C hit */
HANDLE hOut;
#ifdef INCLUDE_CMD_COLOR
-WORD wColor = FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN; /* current color */
-WORD wDefColor = FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN; /* default color */
+WORD wColor; /* current color */
+WORD wDefColor; /* default color */
#endif
{
/* exec the program */
#ifndef __REACTOS__
- TCHAR szFullCmdLine [1024];
+ TCHAR szFullCmdLine [CMDLINE_LENGTH];
#endif
PROCESS_INFORMATION prci;
STARTUPINFO stui;
break;
default:
- if ((tp = _tcschr (ip, _T('%'))))
+ if ((tp = _tcschr (ip, _T('%'))) && (tp<=(unsigned int)strchr(ip,_T(' '))-1))
{
char evar[512];
*tp = _T('\0');
ip = tp + 1;
}
+ else
+ {
+ *cp++ = _T('%');
+ }
break;
}
continue;
*cp = _T('\0');
/* strip trailing spaces */
- while ((--cp >= commandline) && _istspace (*cp))
- ;
+ while ((--cp >= commandline) && _istspace (*cp));
*(cp + 1) = _T('\0');
static VOID
ShowCommands (VOID)
{
- LPCOMMAND cmdptr;
- INT y;
-
+ /* print command list */
ConOutPrintf (_T("\nInternal commands available:\n"));
- y = 0;
- cmdptr = cmds;
- while (cmdptr->name)
- {
- if (++y == 8)
- {
- ConOutPuts (cmdptr->name);
- y = 0;
- }
- else
- ConOutPrintf (_T("%-10s"), cmdptr->name);
-
- cmdptr++;
- }
-
- if (y != 0)
- ConOutChar ('\n');
+ PrintCommandList ();
/* print feature list */
ConOutPuts ("\nFeatures available:");
{
/* This just runs a program and exits */
++i;
- _tcscpy (commandline, argv[i]);
- while (argv[++i])
+ if (argv[i])
{
- _tcscat (commandline, " ");
- _tcscat (commandline, argv[i]);
+ _tcscpy (commandline, argv[i]);
+ while (argv[++i])
+ {
+ _tcscat (commandline, " ");
+ _tcscat (commandline, argv[i]);
+ }
+
+ ParseCommandLine(commandline);
+ ExitProcess (ProcessInput (TRUE));
+ }
+ else
+ {
+ ExitProcess (0);
}
-
- ParseCommandLine(commandline);
- ExitProcess (ProcessInput (TRUE));
}
else if (!_tcsicmp (argv[i], _T("/k")))
{
/* This just runs a program and remains */
++i;
- _tcscpy (commandline, argv[i]);
- while (argv[++i])
+ if (argv[i])
{
- _tcscat (commandline, " ");
- _tcscat (commandline, argv[i]);
+ _tcscpy (commandline, argv[i]);
+ while (argv[++i])
+ {
+ _tcscat (commandline, " ");
+ _tcscat (commandline, argv[i]);
+ }
+
+ ParseCommandLine(commandline);
}
-
- ParseCommandLine(commandline);
}
#ifdef INCLUDE_CMD_COLOR
else if (!_tcsnicmp (argv[i], _T("/t:"), 3))
{
ParseCommandLine (_T("\\cmdstart.bat"));
}
+#ifndef __REACTOS__
else
{
/* try to run cmdstart.bat from install dir */
ParseCommandLine (commandline);
}
}
+#endif
#ifdef FEATURE_DIR_STACK
/* initialize directory stack */
ConErrPrintf ("Running \\cmdexit.bat...\n");
ParseCommandLine (_T("\\cmdexit.bat"));
}
+#ifndef __REACTOS__
else
{
/* try to run cmdexit.bat from install dir */
ParseCommandLine (commandline);
}
}
+#endif
#ifdef FEATURE_ALIASES
DestroyAlias ();
int main (int argc, char *argv[])
{
INT nExitCode;
+ CONSOLE_SCREEN_BUFFER_INFO Info;
AllocConsole ();
SetFileApisToOEM ();
+ if( GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &Info ) == FALSE )
+ printf( "GetConsoleScreenBufferInfo: Error: %ld\n", GetLastError() );
+ wColor = Info.wAttributes;
+ wDefColor = wColor;
/* check switches on command-line */
Initialize (argc, argv);