Commit d98f4a5e authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

Fix handling of wcmd /c "c:\Program Files\hello.bat".

Make /c and /k effectively exclusive, like the real cmd does. Fix handling of /q: it's compatible with /c and /k. Added compatibility with /t /x and /y, just ignore them.
parent bf022eec
...@@ -47,50 +47,162 @@ BATCH_CONTEXT *context = NULL; ...@@ -47,50 +47,162 @@ BATCH_CONTEXT *context = NULL;
* winmain(). * winmain().
*/ */
int main (int argc, char *argv[]) { int main (int argc, char *argv[])
{
char string[1024];
char* cmd=NULL;
DWORD count;
HANDLE h;
int opt_c, opt_k, opt_q;
char string[1024], args[MAX_PATH], param[MAX_PATH]; argv++;
int i; opt_c=opt_k=opt_q=0;
DWORD count; while (*argv!=NULL)
HANDLE h; {
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 */
} else {
break;
}
argv++;
}
if (opt_q) {
WCMD_echo("OFF");
}
args[0] = param[0] = '\0'; if (opt_c || opt_k) {
if (argc > 1) { int len;
/* interpreter options must come before the command to execute. char** arg;
* Any options after the command are command options, not interpreter options. 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;
while (*a!='\0') {
if (*a=='\\') {
bcount++;
} else {
if (*a==' ' || *a=='\t') {
has_space=1;
} else if (*a=='"') {
/* doubling of '\' preceeding a '"',
* plus escaping of said '"'
*/ */
for (i=1; i<argc && argv[i][0] == '/'; i++) len+=2*bcount+1;
strcat (args, argv[i]); }
for (; i<argc; i++) { bcount=0;
strcat (param, argv[i]);
strcat (param, " ");
} }
a++;
} }
len+=(a-*arg)+1 /* for the separating space */;
if (has_space)
len+=2; /* for the quotes */
}
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;
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;
/* Double all the '\\' preceeding this '"', plus one */
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';
}
if (opt_c) {
/* If we do a "wcmd /c command", we don't want to allocate a new /* If we do a "wcmd /c command", we don't want to allocate a new
* console since the command returns immediately. Rather, we use * console since the command returns immediately. Rather, we use
* the surrently allocated input and output handles. This allows * the currently allocated input and output handles. This allows
* us to pipe to and read from the command interpreter. * us to pipe to and read from the command interpreter.
*/ */
if (strstr(args, "/c") != NULL) { WCMD_process_command(cmd);
WCMD_process_command (param); HeapFree(GetProcessHeap(), 0, cmd);
return 0; return 0;
} }
SetConsoleMode (GetStdHandle(STD_INPUT_HANDLE), ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_LINE_INPUT |
ENABLE_PROCESSED_INPUT); ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT);
SetConsoleTitle("Wine Command Prompt"); SetConsoleTitle("Wine Command Prompt");
/* if (opt_k) {
* Execute any command-line options. WCMD_process_command(cmd);
*/ HeapFree(GetProcessHeap(), 0, cmd);
if (strstr(args, "/q") != NULL) {
WCMD_echo ("OFF");
}
if (strstr(args, "/k") != NULL) {
WCMD_process_command (param);
} }
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment