1999-06-06 17:24:04 +02:00
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* WCMD - Wine-compatible command line interface.
|
1999-06-06 17:24:04 +02:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* Copyright (C) 1999 - 2001 D A Pickles
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1999-06-06 17:24:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME:
|
|
|
|
* - Cannot handle parameters in quotes
|
|
|
|
* - Lots of functionality missing from builtins
|
|
|
|
*/
|
|
|
|
|
2006-03-18 17:10:36 +01:00
|
|
|
#include "config.h"
|
1999-06-06 17:24:04 +02:00
|
|
|
#include "wcmd.h"
|
|
|
|
|
2005-06-27 11:48:57 +02:00
|
|
|
const char * const inbuilt[] = {"ATTRIB", "CALL", "CD", "CHDIR", "CLS", "COPY", "CTTY",
|
1999-06-06 17:24:04 +02:00
|
|
|
"DATE", "DEL", "DIR", "ECHO", "ERASE", "FOR", "GOTO",
|
|
|
|
"HELP", "IF", "LABEL", "MD", "MKDIR", "MOVE", "PATH", "PAUSE",
|
|
|
|
"PROMPT", "REM", "REN", "RENAME", "RD", "RMDIR", "SET", "SHIFT",
|
2004-03-22 23:56:58 +01:00
|
|
|
"TIME", "TITLE", "TYPE", "VERIFY", "VER", "VOL",
|
|
|
|
"ENDLOCAL", "SETLOCAL", "EXIT" };
|
1999-06-06 17:24:04 +02:00
|
|
|
|
2000-08-02 00:02:18 +02:00
|
|
|
HINSTANCE hinst;
|
|
|
|
DWORD errorlevel;
|
1999-06-26 12:24:08 +02:00
|
|
|
int echo_mode = 1, verify_mode = 0;
|
2004-05-04 06:13:05 +02:00
|
|
|
const char nyi[] = "Not Yet Implemented\n\n";
|
|
|
|
const char newline[] = "\n";
|
2006-03-18 17:10:36 +01:00
|
|
|
const char version_string[] = "WCMD Version " PACKAGE_VERSION "\n\n";
|
2004-05-04 06:13:05 +02:00
|
|
|
const char anykey[] = "Press Return key to continue: ";
|
1999-06-06 17:24:04 +02:00
|
|
|
char quals[MAX_PATH], param1[MAX_PATH], param2[MAX_PATH];
|
1999-06-26 12:24:08 +02:00
|
|
|
BATCH_CONTEXT *context = NULL;
|
2005-07-15 11:55:52 +02:00
|
|
|
static HANDLE old_stdin = INVALID_HANDLE_VALUE, old_stdout = INVALID_HANDLE_VALUE;
|
1999-06-06 17:24:04 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Main entry point. This is a console application so we have a main() not a
|
|
|
|
* winmain().
|
|
|
|
*/
|
|
|
|
|
2003-05-11 04:48:17 +02:00
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char string[1024];
|
|
|
|
char* cmd=NULL;
|
|
|
|
DWORD count;
|
|
|
|
HANDLE h;
|
|
|
|
int opt_c, opt_k, opt_q;
|
|
|
|
|
|
|
|
opt_c=opt_k=opt_q=0;
|
|
|
|
while (*argv!=NULL)
|
|
|
|
{
|
|
|
|
if (lstrcmpi(*argv,"/c")==0) {
|
|
|
|
opt_c=1;
|
|
|
|
argv++;
|
|
|
|
break;
|
|
|
|
} else if (lstrcmpi(*argv,"/q")==0) {
|
|
|
|
opt_q=1;
|
|
|
|
} else if (lstrcmpi(*argv,"/k")==0) {
|
|
|
|
opt_k=1;
|
|
|
|
argv++;
|
|
|
|
break;
|
|
|
|
} else if (lstrcmpi(*argv,"/t")==0 || lstrcmpi(*argv,"/x")==0 ||
|
|
|
|
lstrcmpi(*argv,"/y")==0) {
|
|
|
|
/* Ignored for compatibility with Windows */
|
|
|
|
}
|
|
|
|
argv++;
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
|
|
|
|
2003-05-11 04:48:17 +02:00
|
|
|
if (opt_q) {
|
|
|
|
WCMD_echo("OFF");
|
2002-11-04 23:36:07 +01:00
|
|
|
}
|
|
|
|
|
2003-05-11 04:48:17 +02:00
|
|
|
if (opt_c || opt_k) {
|
|
|
|
int len;
|
|
|
|
char** arg;
|
|
|
|
char* p;
|
|
|
|
|
|
|
|
/* Build the command to execute */
|
|
|
|
len = 0;
|
|
|
|
for (arg = argv; *arg; arg++)
|
|
|
|
{
|
|
|
|
int has_space,bcount;
|
|
|
|
char* a;
|
|
|
|
|
|
|
|
has_space=0;
|
|
|
|
bcount=0;
|
|
|
|
a=*arg;
|
2003-07-09 04:50:15 +02:00
|
|
|
if( !*a ) has_space=1;
|
2003-05-11 04:48:17 +02:00
|
|
|
while (*a!='\0') {
|
|
|
|
if (*a=='\\') {
|
|
|
|
bcount++;
|
|
|
|
} else {
|
|
|
|
if (*a==' ' || *a=='\t') {
|
|
|
|
has_space=1;
|
|
|
|
} else if (*a=='"') {
|
2005-03-02 14:53:50 +01:00
|
|
|
/* doubling of '\' preceding a '"',
|
2003-05-11 04:48:17 +02:00
|
|
|
* plus escaping of said '"'
|
|
|
|
*/
|
|
|
|
len+=2*bcount+1;
|
|
|
|
}
|
|
|
|
bcount=0;
|
|
|
|
}
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
len+=(a-*arg)+1 /* for the separating space */;
|
|
|
|
if (has_space)
|
|
|
|
len+=2; /* for the quotes */
|
|
|
|
}
|
1999-06-06 17:24:04 +02:00
|
|
|
|
2003-05-11 04:48:17 +02:00
|
|
|
cmd = HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
if (!cmd)
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
p = cmd;
|
|
|
|
for (arg = argv; *arg; arg++)
|
|
|
|
{
|
|
|
|
int has_space,has_quote;
|
|
|
|
char* a;
|
|
|
|
|
|
|
|
/* Check for quotes and spaces in this argument */
|
|
|
|
has_space=has_quote=0;
|
|
|
|
a=*arg;
|
2003-07-09 04:50:15 +02:00
|
|
|
if( !*a ) has_space=1;
|
2003-05-11 04:48:17 +02:00
|
|
|
while (*a!='\0') {
|
|
|
|
if (*a==' ' || *a=='\t') {
|
|
|
|
has_space=1;
|
|
|
|
if (has_quote)
|
|
|
|
break;
|
|
|
|
} else if (*a=='"') {
|
|
|
|
has_quote=1;
|
|
|
|
if (has_space)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now transfer it to the command line */
|
|
|
|
if (has_space)
|
|
|
|
*p++='"';
|
|
|
|
if (has_quote) {
|
|
|
|
int bcount;
|
|
|
|
char* a;
|
|
|
|
|
|
|
|
bcount=0;
|
|
|
|
a=*arg;
|
|
|
|
while (*a!='\0') {
|
|
|
|
if (*a=='\\') {
|
|
|
|
*p++=*a;
|
|
|
|
bcount++;
|
|
|
|
} else {
|
|
|
|
if (*a=='"') {
|
|
|
|
int i;
|
|
|
|
|
2005-03-02 14:53:50 +01:00
|
|
|
/* Double all the '\\' preceding this '"', plus one */
|
2003-05-11 04:48:17 +02:00
|
|
|
for (i=0;i<=bcount;i++)
|
|
|
|
*p++='\\';
|
|
|
|
*p++='"';
|
|
|
|
} else {
|
|
|
|
*p++=*a;
|
|
|
|
}
|
|
|
|
bcount=0;
|
|
|
|
}
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
strcpy(p,*arg);
|
|
|
|
p+=strlen(*arg);
|
|
|
|
}
|
|
|
|
if (has_space)
|
|
|
|
*p++='"';
|
|
|
|
*p++=' ';
|
|
|
|
}
|
|
|
|
if (p > cmd)
|
|
|
|
p--; /* remove last space */
|
|
|
|
*p = '\0';
|
|
|
|
}
|
1999-06-06 17:24:04 +02:00
|
|
|
|
2003-05-11 04:48:17 +02:00
|
|
|
if (opt_c) {
|
|
|
|
/* If we do a "wcmd /c command", we don't want to allocate a new
|
|
|
|
* console since the command returns immediately. Rather, we use
|
|
|
|
* the currently allocated input and output handles. This allows
|
|
|
|
* us to pipe to and read from the command interpreter.
|
|
|
|
*/
|
2003-07-09 23:58:26 +02:00
|
|
|
if (strchr(cmd,'|') != NULL)
|
|
|
|
WCMD_pipe(cmd);
|
|
|
|
else
|
|
|
|
WCMD_process_command(cmd);
|
2003-05-11 04:48:17 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, cmd);
|
|
|
|
return 0;
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
|
|
|
|
2003-05-11 04:48:17 +02:00
|
|
|
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_LINE_INPUT |
|
|
|
|
ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT);
|
|
|
|
SetConsoleTitle("Wine Command Prompt");
|
|
|
|
|
|
|
|
if (opt_k) {
|
|
|
|
WCMD_process_command(cmd);
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmd);
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is an AUTOEXEC.BAT file, try to execute it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
GetFullPathName ("\\autoexec.bat", sizeof(string), string, NULL);
|
2003-01-15 04:35:32 +01:00
|
|
|
h = CreateFile (string, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
1999-06-06 17:24:04 +02:00
|
|
|
if (h != INVALID_HANDLE_VALUE) {
|
|
|
|
CloseHandle (h);
|
2000-03-24 21:40:41 +01:00
|
|
|
#if 0
|
2003-03-05 03:49:04 +01:00
|
|
|
WCMD_batch_command (string);
|
2000-03-24 21:40:41 +01:00
|
|
|
#endif
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop forever getting commands and executing them.
|
|
|
|
*/
|
|
|
|
|
|
|
|
WCMD_version ();
|
|
|
|
while (TRUE) {
|
|
|
|
WCMD_show_prompt ();
|
1999-07-10 13:36:45 +02:00
|
|
|
ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
|
1999-06-06 17:24:04 +02:00
|
|
|
if (count > 1) {
|
2003-05-11 04:48:17 +02:00
|
|
|
string[count-1] = '\0'; /* ReadFile output is not null-terminated! */
|
1999-06-06 17:24:04 +02:00
|
|
|
if (string[count-2] == '\r') string[count-2] = '\0'; /* Under Windoze we get CRLF! */
|
|
|
|
if (lstrlen (string) != 0) {
|
2001-06-04 04:55:38 +02:00
|
|
|
if (strchr(string,'|') != NULL) {
|
|
|
|
WCMD_pipe (string);
|
|
|
|
}
|
2003-05-11 04:48:17 +02:00
|
|
|
else {
|
2001-06-04 04:55:38 +02:00
|
|
|
WCMD_process_command (string);
|
2003-05-11 04:48:17 +02:00
|
|
|
}
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Process one command. If the command is EXIT this routine does not return.
|
|
|
|
* We will recurse through here executing batch files.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-07-10 00:21:04 +02:00
|
|
|
void WCMD_process_command (char *command)
|
|
|
|
{
|
|
|
|
char *cmd, *p;
|
|
|
|
int status, i, len;
|
2003-09-11 22:41:26 +02:00
|
|
|
DWORD count, creationDisposition;
|
2005-07-15 11:55:52 +02:00
|
|
|
HANDLE h;
|
2003-07-10 00:21:04 +02:00
|
|
|
char *whichcmd;
|
2003-08-28 01:12:06 +02:00
|
|
|
SECURITY_ATTRIBUTES sa;
|
1999-06-06 17:24:04 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Expand up environment variables.
|
|
|
|
*/
|
2003-07-10 00:21:04 +02:00
|
|
|
len = ExpandEnvironmentStrings (command, NULL, 0);
|
|
|
|
cmd = HeapAlloc( GetProcessHeap(), 0, len );
|
|
|
|
status = ExpandEnvironmentStrings (command, cmd, len);
|
1999-06-06 17:24:04 +02:00
|
|
|
if (!status) {
|
|
|
|
WCMD_print_error ();
|
2003-07-10 00:21:04 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, cmd );
|
1999-06-06 17:24:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Changing default drive has to be handled as a special case.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((cmd[1] == ':') && IsCharAlpha (cmd[0]) && (strlen(cmd) == 2)) {
|
|
|
|
status = SetCurrentDirectory (cmd);
|
|
|
|
if (!status) WCMD_print_error ();
|
2003-07-10 00:21:04 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, cmd );
|
1999-06-06 17:24:04 +02:00
|
|
|
return;
|
|
|
|
}
|
2000-08-01 04:14:33 +02:00
|
|
|
|
2004-01-06 23:08:33 +01:00
|
|
|
/* Don't issue newline WCMD_output (newline); @JED*/
|
1999-06-06 17:24:04 +02:00
|
|
|
|
2003-08-28 01:12:06 +02:00
|
|
|
sa.nLength = sizeof(sa);
|
|
|
|
sa.lpSecurityDescriptor = NULL;
|
|
|
|
sa.bInheritHandle = TRUE;
|
1999-07-10 13:36:45 +02:00
|
|
|
/*
|
|
|
|
* Redirect stdin and/or stdout if required.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((p = strchr(cmd,'<')) != NULL) {
|
2003-08-28 01:12:06 +02:00
|
|
|
h = CreateFile (WCMD_parameter (++p, 0, NULL), GENERIC_READ, FILE_SHARE_READ, &sa, OPEN_EXISTING,
|
2001-01-02 21:40:58 +01:00
|
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
1999-07-10 13:36:45 +02:00
|
|
|
if (h == INVALID_HANDLE_VALUE) {
|
|
|
|
WCMD_print_error ();
|
2003-07-10 00:21:04 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, cmd );
|
1999-07-10 13:36:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
old_stdin = GetStdHandle (STD_INPUT_HANDLE);
|
|
|
|
SetStdHandle (STD_INPUT_HANDLE, h);
|
|
|
|
}
|
|
|
|
if ((p = strchr(cmd,'>')) != NULL) {
|
2003-09-11 22:41:26 +02:00
|
|
|
*p++ = '\0';
|
|
|
|
if ('>' == *p) {
|
|
|
|
creationDisposition = OPEN_ALWAYS;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
creationDisposition = CREATE_ALWAYS;
|
|
|
|
}
|
|
|
|
h = CreateFile (WCMD_parameter (p, 0, NULL), GENERIC_WRITE, 0, &sa, creationDisposition,
|
2001-01-02 21:40:58 +01:00
|
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
1999-07-10 13:36:45 +02:00
|
|
|
if (h == INVALID_HANDLE_VALUE) {
|
|
|
|
WCMD_print_error ();
|
2003-07-10 00:21:04 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, cmd );
|
1999-07-10 13:36:45 +02:00
|
|
|
return;
|
|
|
|
}
|
2003-09-11 22:41:26 +02:00
|
|
|
if (SetFilePointer (h, 0, NULL, FILE_END) ==
|
|
|
|
INVALID_SET_FILE_POINTER) {
|
|
|
|
WCMD_print_error ();
|
|
|
|
}
|
1999-07-10 13:36:45 +02:00
|
|
|
old_stdout = GetStdHandle (STD_OUTPUT_HANDLE);
|
|
|
|
SetStdHandle (STD_OUTPUT_HANDLE, h);
|
|
|
|
}
|
|
|
|
if ((p = strchr(cmd,'<')) != NULL) *p = '\0';
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
|
|
|
* Strip leading whitespaces, and a '@' if supplied
|
|
|
|
*/
|
|
|
|
whichcmd = WCMD_strtrim_leading_spaces(cmd);
|
|
|
|
if (whichcmd[0] == '@') whichcmd++;
|
2000-08-01 04:14:33 +02:00
|
|
|
|
1999-06-06 17:24:04 +02:00
|
|
|
/*
|
|
|
|
* Check if the command entered is internal. If it is, pass the rest of the
|
|
|
|
* line down to the command. If not try to run a program.
|
|
|
|
*/
|
|
|
|
|
|
|
|
count = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
while (IsCharAlphaNumeric(whichcmd[count])) {
|
1999-06-06 17:24:04 +02:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
for (i=0; i<=WCMD_EXIT; i++) {
|
|
|
|
if (CompareString (LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
|
2002-06-01 01:06:46 +02:00
|
|
|
whichcmd, count, inbuilt[i], -1) == 2) break;
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
p = WCMD_strtrim_leading_spaces (&whichcmd[count]);
|
1999-06-06 17:24:04 +02:00
|
|
|
WCMD_parse (p, quals, param1, param2);
|
|
|
|
switch (i) {
|
|
|
|
|
|
|
|
case WCMD_ATTRIB:
|
|
|
|
WCMD_setshow_attrib ();
|
|
|
|
break;
|
|
|
|
case WCMD_CALL:
|
2006-02-06 14:11:40 +01:00
|
|
|
WCMD_run_program (p, 1);
|
1999-06-06 17:24:04 +02:00
|
|
|
break;
|
|
|
|
case WCMD_CD:
|
|
|
|
case WCMD_CHDIR:
|
|
|
|
WCMD_setshow_default ();
|
|
|
|
break;
|
|
|
|
case WCMD_CLS:
|
|
|
|
WCMD_clear_screen ();
|
|
|
|
break;
|
|
|
|
case WCMD_COPY:
|
|
|
|
WCMD_copy ();
|
|
|
|
break;
|
|
|
|
case WCMD_CTTY:
|
|
|
|
WCMD_change_tty ();
|
|
|
|
break;
|
|
|
|
case WCMD_DATE:
|
|
|
|
WCMD_setshow_date ();
|
|
|
|
break;
|
|
|
|
case WCMD_DEL:
|
|
|
|
case WCMD_ERASE:
|
|
|
|
WCMD_delete (0);
|
|
|
|
break;
|
|
|
|
case WCMD_DIR:
|
|
|
|
WCMD_directory ();
|
|
|
|
break;
|
|
|
|
case WCMD_ECHO:
|
2004-03-18 05:01:32 +01:00
|
|
|
WCMD_echo(&whichcmd[count]);
|
2002-06-01 01:06:46 +02:00
|
|
|
break;
|
1999-06-06 17:24:04 +02:00
|
|
|
case WCMD_FOR:
|
1999-06-26 12:24:08 +02:00
|
|
|
WCMD_for (p);
|
1999-06-06 17:24:04 +02:00
|
|
|
break;
|
|
|
|
case WCMD_GOTO:
|
1999-06-26 12:24:08 +02:00
|
|
|
WCMD_goto ();
|
1999-06-06 17:24:04 +02:00
|
|
|
break;
|
|
|
|
case WCMD_HELP:
|
|
|
|
WCMD_give_help (p);
|
|
|
|
break;
|
|
|
|
case WCMD_IF:
|
1999-07-10 13:36:45 +02:00
|
|
|
WCMD_if (p);
|
1999-06-06 17:24:04 +02:00
|
|
|
break;
|
|
|
|
case WCMD_LABEL:
|
|
|
|
WCMD_volume (1, p);
|
|
|
|
break;
|
|
|
|
case WCMD_MD:
|
|
|
|
case WCMD_MKDIR:
|
|
|
|
WCMD_create_dir ();
|
|
|
|
break;
|
|
|
|
case WCMD_MOVE:
|
|
|
|
WCMD_move ();
|
|
|
|
break;
|
|
|
|
case WCMD_PATH:
|
2003-02-11 23:01:11 +01:00
|
|
|
WCMD_setshow_path (p);
|
1999-06-06 17:24:04 +02:00
|
|
|
break;
|
|
|
|
case WCMD_PAUSE:
|
|
|
|
WCMD_pause ();
|
|
|
|
break;
|
|
|
|
case WCMD_PROMPT:
|
|
|
|
WCMD_setshow_prompt ();
|
|
|
|
break;
|
|
|
|
case WCMD_REM:
|
|
|
|
break;
|
|
|
|
case WCMD_REN:
|
|
|
|
case WCMD_RENAME:
|
|
|
|
WCMD_rename ();
|
|
|
|
break;
|
|
|
|
case WCMD_RD:
|
|
|
|
case WCMD_RMDIR:
|
|
|
|
WCMD_remove_dir ();
|
|
|
|
break;
|
2004-03-22 23:56:58 +01:00
|
|
|
case WCMD_SETLOCAL:
|
|
|
|
WCMD_setlocal(p);
|
|
|
|
break;
|
|
|
|
case WCMD_ENDLOCAL:
|
|
|
|
WCMD_endlocal();
|
|
|
|
break;
|
1999-06-06 17:24:04 +02:00
|
|
|
case WCMD_SET:
|
|
|
|
WCMD_setshow_env (p);
|
|
|
|
break;
|
|
|
|
case WCMD_SHIFT:
|
|
|
|
WCMD_shift ();
|
|
|
|
break;
|
|
|
|
case WCMD_TIME:
|
|
|
|
WCMD_setshow_time ();
|
2002-05-04 20:29:31 +02:00
|
|
|
break;
|
|
|
|
case WCMD_TITLE:
|
2002-06-01 01:06:46 +02:00
|
|
|
if (strlen(&whichcmd[count]) > 0)
|
|
|
|
WCMD_title(&whichcmd[count+1]);
|
2002-05-04 20:29:31 +02:00
|
|
|
break;
|
1999-06-06 17:24:04 +02:00
|
|
|
case WCMD_TYPE:
|
|
|
|
WCMD_type ();
|
|
|
|
break;
|
|
|
|
case WCMD_VER:
|
|
|
|
WCMD_version ();
|
|
|
|
break;
|
|
|
|
case WCMD_VERIFY:
|
1999-06-26 12:24:08 +02:00
|
|
|
WCMD_verify (p);
|
1999-06-06 17:24:04 +02:00
|
|
|
break;
|
|
|
|
case WCMD_VOL:
|
|
|
|
WCMD_volume (0, p);
|
|
|
|
break;
|
|
|
|
case WCMD_EXIT:
|
|
|
|
ExitProcess (0);
|
|
|
|
default:
|
2006-02-06 14:11:40 +01:00
|
|
|
WCMD_run_program (whichcmd, 0);
|
2003-07-10 00:21:04 +02:00
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, cmd );
|
2005-07-15 11:55:52 +02:00
|
|
|
if (old_stdin != INVALID_HANDLE_VALUE) {
|
1999-07-10 13:36:45 +02:00
|
|
|
CloseHandle (GetStdHandle (STD_INPUT_HANDLE));
|
|
|
|
SetStdHandle (STD_INPUT_HANDLE, old_stdin);
|
2005-07-15 11:55:52 +02:00
|
|
|
old_stdin = INVALID_HANDLE_VALUE;
|
1999-07-10 13:36:45 +02:00
|
|
|
}
|
2005-07-15 11:55:52 +02:00
|
|
|
if (old_stdout != INVALID_HANDLE_VALUE) {
|
1999-07-10 13:36:45 +02:00
|
|
|
CloseHandle (GetStdHandle (STD_OUTPUT_HANDLE));
|
|
|
|
SetStdHandle (STD_OUTPUT_HANDLE, old_stdout);
|
2005-07-15 11:55:52 +02:00
|
|
|
old_stdout = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_msvcrt_io_block(STARTUPINFO* st)
|
|
|
|
{
|
|
|
|
STARTUPINFO st_p;
|
|
|
|
/* fetch the parent MSVCRT info block if any, so that the child can use the
|
|
|
|
* same handles as its grand-father
|
|
|
|
*/
|
|
|
|
st_p.cb = sizeof(STARTUPINFO);
|
|
|
|
GetStartupInfo(&st_p);
|
|
|
|
st->cbReserved2 = st_p.cbReserved2;
|
|
|
|
st->lpReserved2 = st_p.lpReserved2;
|
|
|
|
if (st_p.cbReserved2 && st_p.lpReserved2 &&
|
|
|
|
(old_stdin != INVALID_HANDLE_VALUE || old_stdout != INVALID_HANDLE_VALUE))
|
|
|
|
{
|
|
|
|
/* Override the entries for fd 0,1,2 if we happened
|
|
|
|
* to change those std handles (this depends on the way wcmd sets
|
|
|
|
* it's new input & output handles)
|
|
|
|
*/
|
|
|
|
size_t sz = max(sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE)) * 3, st_p.cbReserved2);
|
2005-08-19 12:04:03 +02:00
|
|
|
BYTE* ptr = HeapAlloc(GetProcessHeap(), 0, sz);
|
2005-07-15 11:55:52 +02:00
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
unsigned num = *(unsigned*)st_p.lpReserved2;
|
|
|
|
char* flags = (char*)(ptr + sizeof(unsigned));
|
|
|
|
HANDLE* handles = (HANDLE*)(flags + num * sizeof(char));
|
|
|
|
|
|
|
|
memcpy(ptr, st_p.lpReserved2, st_p.cbReserved2);
|
|
|
|
st->cbReserved2 = sz;
|
|
|
|
st->lpReserved2 = ptr;
|
2005-08-19 12:04:03 +02:00
|
|
|
|
2005-07-15 11:55:52 +02:00
|
|
|
#define WX_OPEN 0x01 /* see dlls/msvcrt/file.c */
|
|
|
|
if (num <= 0 || (flags[0] & WX_OPEN))
|
|
|
|
{
|
|
|
|
handles[0] = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
flags[0] |= WX_OPEN;
|
|
|
|
}
|
|
|
|
if (num <= 1 || (flags[1] & WX_OPEN))
|
|
|
|
{
|
|
|
|
handles[1] = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
flags[1] |= WX_OPEN;
|
|
|
|
}
|
|
|
|
if (num <= 2 || (flags[2] & WX_OPEN))
|
|
|
|
{
|
|
|
|
handles[2] = GetStdHandle(STD_ERROR_HANDLE);
|
|
|
|
flags[2] |= WX_OPEN;
|
|
|
|
}
|
|
|
|
#undef WX_OPEN
|
|
|
|
}
|
1999-07-10 13:36:45 +02:00
|
|
|
}
|
2003-07-10 00:21:04 +02:00
|
|
|
}
|
1999-06-06 17:24:04 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* WCMD_run_program
|
|
|
|
*
|
|
|
|
* Execute a command line as an external program. If no extension given then
|
|
|
|
* precedence is given to .BAT files. Must allow recursion.
|
2006-02-06 14:11:40 +01:00
|
|
|
*
|
|
|
|
* called is 1 if the program was invoked with a CALL command - removed
|
|
|
|
* from command -. It is only used for batch programs.
|
1999-06-06 17:24:04 +02:00
|
|
|
*
|
|
|
|
* FIXME: Case sensitivity in suffixes!
|
|
|
|
*/
|
|
|
|
|
2006-02-06 14:11:40 +01:00
|
|
|
void WCMD_run_program (char *command, int called) {
|
1999-06-06 17:24:04 +02:00
|
|
|
|
|
|
|
STARTUPINFO st;
|
|
|
|
PROCESS_INFORMATION pe;
|
2000-11-02 21:07:07 +01:00
|
|
|
SHFILEINFO psfi;
|
|
|
|
DWORD console;
|
1999-06-06 17:24:04 +02:00
|
|
|
BOOL status;
|
|
|
|
HANDLE h;
|
2000-11-02 21:07:07 +01:00
|
|
|
HINSTANCE hinst;
|
1999-06-06 17:24:04 +02:00
|
|
|
char filetorun[MAX_PATH];
|
|
|
|
|
|
|
|
WCMD_parse (command, quals, param1, param2); /* Quick way to get the filename */
|
2002-07-24 21:00:48 +02:00
|
|
|
if (!(*param1) && !(*param2))
|
|
|
|
return;
|
2003-07-22 03:03:53 +02:00
|
|
|
if (strpbrk (param1, "/\\:") == NULL) { /* No explicit path given */
|
|
|
|
char *ext = strrchr( param1, '.' );
|
|
|
|
if (!ext || !strcasecmp( ext, ".bat"))
|
|
|
|
{
|
1999-06-06 17:24:04 +02:00
|
|
|
if (SearchPath (NULL, param1, ".bat", sizeof(filetorun), filetorun, NULL)) {
|
2006-02-06 14:11:40 +01:00
|
|
|
WCMD_batch (filetorun, command, called);
|
1999-06-06 17:24:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2003-07-22 03:03:53 +02:00
|
|
|
if (!ext || !strcasecmp( ext, ".cmd"))
|
|
|
|
{
|
2003-03-25 01:33:56 +01:00
|
|
|
if (SearchPath (NULL, param1, ".cmd", sizeof(filetorun), filetorun, NULL)) {
|
2006-02-06 14:11:40 +01:00
|
|
|
WCMD_batch (filetorun, command, called);
|
2003-03-25 01:33:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
|
|
|
else { /* Explicit path given */
|
2003-07-22 03:03:53 +02:00
|
|
|
char *ext = strrchr( param1, '.' );
|
|
|
|
if (ext && (!strcasecmp( ext, ".bat" ) || !strcasecmp( ext, ".cmd" )))
|
|
|
|
{
|
2006-02-06 14:11:40 +01:00
|
|
|
WCMD_batch (param1, command, called);
|
1999-06-06 17:24:04 +02:00
|
|
|
return;
|
|
|
|
}
|
2003-08-22 07:01:59 +02:00
|
|
|
|
|
|
|
if (ext && strpbrk( ext, "/\\:" )) ext = NULL;
|
2003-07-22 03:03:53 +02:00
|
|
|
if (!ext)
|
|
|
|
{
|
1999-06-06 17:24:04 +02:00
|
|
|
strcpy (filetorun, param1);
|
|
|
|
strcat (filetorun, ".bat");
|
2003-01-15 04:35:32 +01:00
|
|
|
h = CreateFile (filetorun, GENERIC_READ, FILE_SHARE_READ,
|
|
|
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
1999-06-06 17:24:04 +02:00
|
|
|
if (h != INVALID_HANDLE_VALUE) {
|
|
|
|
CloseHandle (h);
|
2006-02-06 14:11:40 +01:00
|
|
|
WCMD_batch (param1, command, called);
|
1999-06-06 17:24:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No batch file found, assume executable */
|
|
|
|
|
2000-11-02 21:07:07 +01:00
|
|
|
hinst = FindExecutable (param1, NULL, filetorun);
|
2006-03-21 12:00:17 +01:00
|
|
|
if ((int)hinst < 32)
|
|
|
|
console = 0;
|
|
|
|
else
|
|
|
|
console = SHGetFileInfo (filetorun, 0, &psfi, sizeof(psfi), SHGFI_EXETYPE);
|
|
|
|
|
1999-06-06 17:24:04 +02:00
|
|
|
ZeroMemory (&st, sizeof(STARTUPINFO));
|
|
|
|
st.cb = sizeof(STARTUPINFO);
|
2005-07-15 11:55:52 +02:00
|
|
|
init_msvcrt_io_block(&st);
|
|
|
|
|
2003-08-28 01:12:06 +02:00
|
|
|
status = CreateProcess (NULL, command, NULL, NULL, TRUE,
|
|
|
|
0, NULL, NULL, &st, &pe);
|
1999-06-06 17:24:04 +02:00
|
|
|
if (!status) {
|
|
|
|
WCMD_print_error ();
|
2002-10-09 22:38:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!console) errorlevel = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!HIWORD(console)) WaitForSingleObject (pe.hProcess, INFINITE);
|
|
|
|
GetExitCodeProcess (pe.hProcess, &errorlevel);
|
|
|
|
if (errorlevel == STILL_ACTIVE) errorlevel = 0;
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
2003-08-28 01:12:06 +02:00
|
|
|
CloseHandle(pe.hProcess);
|
|
|
|
CloseHandle(pe.hThread);
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* WCMD_show_prompt
|
|
|
|
*
|
|
|
|
* Display the prompt on STDout
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-02-27 02:41:21 +01:00
|
|
|
void WCMD_show_prompt (void) {
|
1999-06-06 17:24:04 +02:00
|
|
|
|
|
|
|
int status;
|
|
|
|
char out_string[MAX_PATH], curdir[MAX_PATH], prompt_string[MAX_PATH];
|
|
|
|
char *p, *q;
|
|
|
|
|
|
|
|
status = GetEnvironmentVariable ("PROMPT", prompt_string, sizeof(prompt_string));
|
|
|
|
if ((status == 0) || (status > sizeof(prompt_string))) {
|
2003-01-02 18:47:40 +01:00
|
|
|
lstrcpy (prompt_string, "$P$G");
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
|
|
|
p = prompt_string;
|
|
|
|
q = out_string;
|
|
|
|
*q = '\0';
|
|
|
|
while (*p != '\0') {
|
|
|
|
if (*p != '$') {
|
|
|
|
*q++ = *p++;
|
|
|
|
*q = '\0';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p++;
|
|
|
|
switch (toupper(*p)) {
|
|
|
|
case '$':
|
|
|
|
*q++ = '$';
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
*q++ = '|';
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
GetDateFormat (LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, q, MAX_PATH);
|
|
|
|
while (*q) q++;
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
*q++ = '\E';
|
|
|
|
break;
|
|
|
|
case 'G':
|
|
|
|
*q++ = '>';
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
*q++ = '<';
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
status = GetCurrentDirectory (sizeof(curdir), curdir);
|
|
|
|
if (status) {
|
|
|
|
*q++ = curdir[0];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
status = GetCurrentDirectory (sizeof(curdir), curdir);
|
|
|
|
if (status) {
|
|
|
|
lstrcat (q, curdir);
|
|
|
|
while (*q) q++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'Q':
|
|
|
|
*q++ = '=';
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
GetTimeFormat (LOCALE_USER_DEFAULT, 0, NULL, NULL, q, MAX_PATH);
|
|
|
|
while (*q) q++;
|
|
|
|
break;
|
2002-12-11 01:15:20 +01:00
|
|
|
case 'V':
|
|
|
|
lstrcat (q, version_string);
|
|
|
|
while (*q) q++;
|
|
|
|
break;
|
1999-06-06 17:24:04 +02:00
|
|
|
case '_':
|
|
|
|
*q++ = '\n';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
*q = '\0';
|
|
|
|
}
|
|
|
|
}
|
2005-12-02 11:25:51 +01:00
|
|
|
WCMD_output_asis (out_string);
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* WCMD_print_error
|
|
|
|
*
|
2000-08-02 00:02:18 +02:00
|
|
|
* Print the message for GetLastError
|
1999-06-06 17:24:04 +02:00
|
|
|
*/
|
|
|
|
|
2003-02-27 02:41:21 +01:00
|
|
|
void WCMD_print_error (void) {
|
1999-06-06 17:24:04 +02:00
|
|
|
LPVOID lpMsgBuf;
|
|
|
|
DWORD error_code;
|
2000-08-02 00:02:18 +02:00
|
|
|
int status;
|
1999-06-06 17:24:04 +02:00
|
|
|
|
|
|
|
error_code = GetLastError ();
|
2000-08-02 00:02:18 +02:00
|
|
|
status = FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL, error_code, 0, (LPTSTR) &lpMsgBuf, 0, NULL);
|
|
|
|
if (!status) {
|
|
|
|
WCMD_output ("FIXME: Cannot display message for error %d, status %d\n",
|
|
|
|
error_code, GetLastError());
|
|
|
|
return;
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
2005-12-02 11:25:51 +01:00
|
|
|
WCMD_output_asis (lpMsgBuf);
|
2000-08-02 00:02:18 +02:00
|
|
|
LocalFree ((HLOCAL)lpMsgBuf);
|
2005-12-02 11:25:51 +01:00
|
|
|
WCMD_output_asis (newline);
|
1999-06-06 17:24:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* WCMD_parse - parse a command into parameters and qualifiers.
|
|
|
|
*
|
|
|
|
* On exit, all qualifiers are concatenated into q, the first string
|
|
|
|
* not beginning with "/" is in p1 and the
|
|
|
|
* second in p2. Any subsequent non-qualifier strings are lost.
|
|
|
|
* Parameters in quotes are handled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void WCMD_parse (char *s, char *q, char *p1, char *p2) {
|
|
|
|
|
|
|
|
int p = 0;
|
|
|
|
|
|
|
|
*q = *p1 = *p2 = '\0';
|
|
|
|
while (TRUE) {
|
|
|
|
switch (*s) {
|
|
|
|
case '/':
|
|
|
|
*q++ = *s++;
|
|
|
|
while ((*s != '\0') && (*s != ' ') && *s != '/') {
|
|
|
|
*q++ = toupper (*s++);
|
|
|
|
}
|
|
|
|
*q = '\0';
|
|
|
|
break;
|
|
|
|
case ' ':
|
2005-10-03 12:16:48 +02:00
|
|
|
case '\t':
|
1999-06-06 17:24:04 +02:00
|
|
|
s++;
|
|
|
|
break;
|
|
|
|
case '"':
|
|
|
|
s++;
|
|
|
|
while ((*s != '\0') && (*s != '"')) {
|
|
|
|
if (p == 0) *p1++ = *s++;
|
|
|
|
else if (p == 1) *p2++ = *s++;
|
|
|
|
else s++;
|
|
|
|
}
|
|
|
|
if (p == 0) *p1 = '\0';
|
|
|
|
if (p == 1) *p2 = '\0';
|
|
|
|
p++;
|
|
|
|
if (*s == '"') s++;
|
|
|
|
break;
|
|
|
|
case '\0':
|
|
|
|
return;
|
|
|
|
default:
|
2005-10-03 12:16:48 +02:00
|
|
|
while ((*s != '\0') && (*s != ' ') && (*s != '\t')) {
|
1999-06-06 17:24:04 +02:00
|
|
|
if (p == 0) *p1++ = *s++;
|
|
|
|
else if (p == 1) *p2++ = *s++;
|
|
|
|
else s++;
|
|
|
|
}
|
|
|
|
if (p == 0) *p1 = '\0';
|
|
|
|
if (p == 1) *p2 = '\0';
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* WCMD_output - send output to current standard output device.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-10-09 06:39:01 +02:00
|
|
|
void WCMD_output (const char *format, ...) {
|
1999-06-06 17:24:04 +02:00
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
char string[1024];
|
2005-12-01 15:58:16 +01:00
|
|
|
int ret;
|
1999-06-06 17:24:04 +02:00
|
|
|
|
|
|
|
va_start(ap,format);
|
2005-12-01 15:58:16 +01:00
|
|
|
ret = vsnprintf (string, sizeof( string), format, ap);
|
1999-06-06 17:24:04 +02:00
|
|
|
va_end(ap);
|
2005-12-01 15:58:16 +01:00
|
|
|
if( ret >= sizeof( string)) {
|
|
|
|
WCMD_output_asis("ERR: output truncated in WCMD_output\n" );
|
|
|
|
string[sizeof( string) -1] = '\0';
|
|
|
|
}
|
2003-02-25 04:58:42 +01:00
|
|
|
WCMD_output_asis(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int line_count;
|
|
|
|
static int max_height;
|
|
|
|
static BOOL paged_mode;
|
|
|
|
|
|
|
|
void WCMD_enter_paged_mode(void)
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
|
|
|
|
|
2003-02-27 02:41:21 +01:00
|
|
|
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleInfo))
|
|
|
|
max_height = consoleInfo.dwSize.Y;
|
|
|
|
else
|
|
|
|
max_height = 25;
|
2003-02-25 04:58:42 +01:00
|
|
|
paged_mode = TRUE;
|
|
|
|
line_count = 5; /* keep 5 lines from previous output */
|
|
|
|
}
|
|
|
|
|
|
|
|
void WCMD_leave_paged_mode(void)
|
|
|
|
{
|
|
|
|
paged_mode = FALSE;
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*******************************************************************
|
2000-08-01 04:14:33 +02:00
|
|
|
* WCMD_output_asis - send output to current standard output device.
|
|
|
|
* without formatting eg. when message contains '%'
|
|
|
|
*/
|
|
|
|
|
2003-10-09 06:39:01 +02:00
|
|
|
void WCMD_output_asis (const char *message) {
|
2000-08-01 04:14:33 +02:00
|
|
|
DWORD count;
|
2003-02-25 04:58:42 +01:00
|
|
|
char* ptr;
|
|
|
|
char string[1024];
|
|
|
|
|
|
|
|
if (paged_mode) {
|
|
|
|
do {
|
|
|
|
if ((ptr = strchr(message, '\n')) != NULL) ptr++;
|
|
|
|
WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), message,
|
|
|
|
(ptr) ? ptr - message : lstrlen(message), &count, NULL);
|
|
|
|
if (ptr) {
|
|
|
|
if (++line_count >= max_height - 1) {
|
|
|
|
line_count = 0;
|
|
|
|
WCMD_output_asis (anykey);
|
|
|
|
ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while ((message = ptr) != NULL);
|
|
|
|
} else {
|
|
|
|
WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), message, lstrlen(message), &count, NULL);
|
|
|
|
}
|
2000-08-01 04:14:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-02 00:02:18 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* WCMD_strtrim_leading_spaces
|
|
|
|
*
|
|
|
|
* Remove leading spaces from a string. Return a pointer to the first
|
1999-06-06 17:24:04 +02:00
|
|
|
* non-space character. Does not modify the input string
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *WCMD_strtrim_leading_spaces (char *string) {
|
|
|
|
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
ptr = string;
|
|
|
|
while (*ptr == ' ') ptr++;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2000-08-02 00:02:18 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* WCMD_strtrim_trailing_spaces
|
|
|
|
*
|
|
|
|
* Remove trailing spaces from a string. This routine modifies the input
|
1999-06-06 17:24:04 +02:00
|
|
|
* string by placing a null after the last non-space character
|
|
|
|
*/
|
|
|
|
|
|
|
|
void WCMD_strtrim_trailing_spaces (char *string) {
|
|
|
|
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
ptr = string + lstrlen (string) - 1;
|
|
|
|
while ((*ptr == ' ') && (ptr >= string)) {
|
|
|
|
*ptr = '\0';
|
|
|
|
ptr--;
|
|
|
|
}
|
|
|
|
}
|
2001-06-04 04:55:38 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* WCMD_pipe
|
|
|
|
*
|
|
|
|
* Handle pipes within a command - the DOS way using temporary files.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void WCMD_pipe (char *command) {
|
|
|
|
|
|
|
|
char *p;
|
|
|
|
char temp_path[MAX_PATH], temp_file[MAX_PATH], temp_file2[MAX_PATH], temp_cmd[1024];
|
|
|
|
|
|
|
|
GetTempPath (sizeof(temp_path), temp_path);
|
|
|
|
GetTempFileName (temp_path, "WCMD", 0, temp_file);
|
|
|
|
p = strchr(command, '|');
|
|
|
|
*p++ = '\0';
|
|
|
|
wsprintf (temp_cmd, "%s > %s", command, temp_file);
|
|
|
|
WCMD_process_command (temp_cmd);
|
|
|
|
command = p;
|
|
|
|
while ((p = strchr(command, '|'))) {
|
|
|
|
*p++ = '\0';
|
|
|
|
GetTempFileName (temp_path, "WCMD", 0, temp_file2);
|
|
|
|
wsprintf (temp_cmd, "%s < %s > %s", command, temp_file, temp_file2);
|
|
|
|
WCMD_process_command (temp_cmd);
|
|
|
|
DeleteFile (temp_file);
|
|
|
|
lstrcpy (temp_file, temp_file2);
|
|
|
|
command = p;
|
|
|
|
}
|
|
|
|
wsprintf (temp_cmd, "%s < %s", command, temp_file);
|
|
|
|
WCMD_process_command (temp_cmd);
|
|
|
|
DeleteFile (temp_file);
|
|
|
|
}
|