Commit c3666489 authored by Jason Edmeades's avatar Jason Edmeades Committed by Alexandre Julliard

cmd.exe: Support exit [/b] returncode.

parent 758a3977
......@@ -87,13 +87,14 @@ BATCH_CONTEXT *prev_context;
context -> command = command;
context -> shift_count = 0;
context -> prev_context = prev_context;
context -> skip_rest = FALSE;
/*
* Work through the file line by line. Specific batch commands are processed here,
* the rest are handled by the main command processor.
*/
while (WCMD_fgets (string, sizeof(string), h)) {
while (context -> skip_rest == FALSE && WCMD_fgets (string, sizeof(string), h)) {
if (strlen(string) == MAXSTRING -1) {
WCMD_output_asis( "Line in Batch processing possibly truncated. Using:\n");
WCMD_output_asis( string);
......
......@@ -1159,3 +1159,22 @@ BOOL status;
}
return 1;
}
/**************************************************************************
* WCMD_exit
*
* Exit either the process, or just this batch program
*
*/
void WCMD_exit (void) {
int rc = atoi(param1); /* Note: atoi of empty parameter is 0 */
if (context && lstrcmpi(quals, "/B") == 0) {
errorlevel = rc;
context -> skip_rest = TRUE;
} else {
ExitProcess(rc);
}
}
......@@ -37,6 +37,7 @@ void WCMD_directory (void);
void WCMD_echo (const char *);
void WCMD_endlocal (void);
void WCMD_enter_paged_mode(void);
void WCMD_exit (void);
void WCMD_for (char *);
void WCMD_give_help (char *command);
void WCMD_goto (void);
......@@ -83,6 +84,7 @@ typedef struct {
HANDLE h; /* Handle to the open batch file */
int shift_count; /* Number of SHIFT commands executed */
void *prev_context; /* Pointer to the previous context block */
BOOL skip_rest; /* Skip the rest of the batch program and exit */
} BATCH_CONTEXT;
#endif /* !RC_INVOKED */
......
......@@ -244,7 +244,7 @@ int main (int argc, char *argv[])
else
WCMD_process_command(cmd);
HeapFree(GetProcessHeap(), 0, cmd);
return 0;
return errorlevel;
}
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_LINE_INPUT |
......@@ -504,7 +504,8 @@ void WCMD_process_command (char *command)
WCMD_volume (0, p);
break;
case WCMD_EXIT:
ExitProcess (0);
WCMD_exit ();
break;
default:
WCMD_run_program (whichcmd, 0);
}
......
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