[09/16] CMD.exe: Add support for %ERRORLEVEL% in both batch and cmd
line
Ann & Jason Edmeades
us at edmeades.me.uk
Mon Feb 19 18:40:28 CST 2007
Added in both places which parse command lines
-------------- next part --------------
>From nobody Mon Sep 17 00:00:00 2001
From: Jason Edmeades <us at edmeades.me.uk>
Date: Sat Feb 17 22:57:59 2007 +0000
Subject: [PATCH] Support %errorlevel% in both command and batch modes
---
programs/cmd/batch.c | 10 +++++++++-
programs/cmd/wcmdmain.c | 21 ++++++++++++++++++++-
2 files changed, 29 insertions(+), 2 deletions(-)
2e9cb17b249256933a2b371a9c5d05ff522376ce
diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index 324d8cf..47bb9db 100755
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -161,13 +161,21 @@ int i;
/* contents of fred, then the digit 1. Would need to remove */
/* ExpandEnvStrings to achieve this */
- /* Replace use of %0...%9 */
+ /* Replace use of %0...%9 and errorlevel*/
p = cmd1;
while ((p = strchr(p, '%'))) {
i = *(p+1) - '0';
if (*(p+1) == '~') {
WCMD_HandleTildaModifiers(&p, NULL);
p++;
+ } else if (CompareString (LOCALE_USER_DEFAULT,
+ NORM_IGNORECASE | SORT_STRINGSORT,
+ (p+1), 11, "ERRORLEVEL%", -1) == 2) {
+ char output[10];
+ sprintf(output, "%d", errorlevel);
+ s = strdup (p+12);
+ strcpy (p, output);
+ strcat (p, s);
} else if ((i >= 0) && (i <= 9)) {
s = strdup (p+2);
t = WCMD_parameter (context -> command, i + context -> shift_count, NULL);
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 0a06099..d5c6157 100755
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -301,13 +301,32 @@ #endif
void WCMD_process_command (char *command)
{
- char *cmd, *p;
+ char *cmd, *p, *s;
int status, i, len;
DWORD count, creationDisposition;
HANDLE h;
char *whichcmd;
SECURITY_ATTRIBUTES sa;
+/*
+ * Replace errorlevel with current value (This shrinks in
+ * place and hence no need to reallocate the memory yet)
+ */
+ p = command;
+ while ((p = strchr(p, '%'))) {
+ if (CompareString (LOCALE_USER_DEFAULT,
+ NORM_IGNORECASE | SORT_STRINGSORT,
+ (p+1), 11, "ERRORLEVEL%", -1) == 2) {
+ char output[10];
+ sprintf(output, "%d", errorlevel);
+ s = strdup (p+12);
+ strcpy (p, output);
+ strcat (p, s);
+ } else {
+ p++;
+ }
+ }
+
/*
* Expand up environment variables.
*/
--
1.3.0
More information about the wine-patches
mailing list