[13/16] CMD.exe: Add support for env var RANDOM

Ann & Jason Edmeades us at edmeades.me.uk
Mon Feb 19 18:44:24 CST 2007


Spotted when reading the cmd.exe help!
-------------- next part --------------
>From nobody Mon Sep 17 00:00:00 2001
From: Jason Edmeades <us at edmeades.me.uk>
Date: Mon Feb 19 18:20:19 2007 +0000
Subject: [PATCH] Add support for %RANDOM%

---

 programs/cmd/wcmdmain.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

32ab32a85d6bae25590d4cd5e89c41d738a2451d
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 9ffc65d..13ceb73 100755
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -318,8 +318,8 @@ void WCMD_process_command (char *command
     /*   Expand environment variables in a batch file %{0-9} first */
     /*     including support for any ~ modifiers                   */
     /* Additionally:                                               */
-    /*   Expand the DATE, TIME, CD and ERRORLEVEL special names    */
-    /*     allowing environment variable overrides                 */
+    /*   Expand the DATE, TIME, CD, RANDOM and ERRORLEVEL special  */
+    /*     names allowing environment variable overrides           */
 
     /* FIXME: Winnt would replace %1%fred%1 with first parm, then */
     /*   contents of fred, then the digit 1. Would need to remove */
@@ -399,6 +399,16 @@ void WCMD_process_command (char *command
         strcpy (p, temp);
         strcat (p, s);
 
+      } else if ((CompareString (LOCALE_USER_DEFAULT, 
+                                NORM_IGNORECASE | SORT_STRINGSORT,
+                                (p+1), 7, "RANDOM%", -1) == 2) &&
+                (GetEnvironmentVariable("RANDOM", temp, 1) == 0) &&
+                (GetLastError() == ERROR_ENVVAR_NOT_FOUND)) {
+        sprintf(temp, "%d", rand() % 32768);
+        s = strdup (p+8);
+        strcpy (p, temp);
+        strcat (p, s);
+
       } else {
         p++;
       }
-- 
1.3.0



More information about the wine-patches mailing list