cmd: Simplify/cleanup WCMD_HandleTildaModifiers a bit

Frédéric Delanoy frederic.delanoy at gmail.com
Mon Nov 7 03:52:23 CST 2011


Got rid of hardcoded array length; simplified loop
---
 programs/cmd/batch.c |   18 +++++++-----------
 1 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index 7edb8df..c822581 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -313,10 +313,10 @@ void WCMD_splitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHA
 void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable,
                                const WCHAR *forValue, BOOL justFors) {
 
-#define NUMMODIFIERS 11
-  static const WCHAR validmodifiers[NUMMODIFIERS] = {
+  static const WCHAR validmodifiers[] = {
         '~', 'f', 'd', 'p', 'n', 'x', 's', 'a', 't', 'z', '$'
   };
+  static const int NUMMODIFIERS = sizeof(validmodifiers)/sizeof(validmodifiers[0]);
   static const WCHAR space[] = {' ', '\0'};
 
   WIN32_FILE_ATTRIBUTE_DATA fileInfo;
@@ -328,14 +328,13 @@ void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable,
   WCHAR  *firstModifier  = pos;
   WCHAR  *lastModifier   = NULL;
   int   modifierLen     = 0;
-  BOOL  finished        = FALSE;
   int   i               = 0;
   BOOL  exists          = TRUE;
   BOOL  skipFileParsing = FALSE;
   BOOL  doneModifier    = FALSE;
 
   /* Search forwards until find invalid character modifier */
-  while (!finished) {
+  while (TRUE) {
 
     /* Work on the previous character */
     if (lastModifier != NULL) {
@@ -353,16 +352,13 @@ void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable,
         }
       }
 
-      if (i==NUMMODIFIERS) {
-        finished = TRUE;
-      }
+      if (i==NUMMODIFIERS)
+        break;
     }
 
     /* Save this one away */
-    if (!finished) {
-      lastModifier = pos;
-      pos++;
-    }
+    lastModifier = pos;
+    pos++;
   }
 
   while (lastModifier > firstModifier) {
-- 
1.7.7.1




More information about the wine-patches mailing list