cmd: Avoid duplication of commonly used strings

Frédéric Delanoy frederic.delanoy at gmail.com
Sat Nov 12 06:58:01 CST 2011


---
 programs/cmd/batch.c     |    1 -
 programs/cmd/builtins.c  |   12 ++++++------
 programs/cmd/directory.c |   17 +++++------------
 programs/cmd/wcmd.h      |    7 +++++++
 programs/cmd/wcmdmain.c  |   10 ++++------
 5 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index 7edb8df..10af36b 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -317,7 +317,6 @@ void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable,
   static const WCHAR validmodifiers[NUMMODIFIERS] = {
         '~', 'f', 'd', 'p', 'n', 'x', 's', 'a', 't', 'z', '$'
   };
-  static const WCHAR space[] = {' ', '\0'};
 
   WIN32_FILE_ATTRIBUTE_DATA fileInfo;
   WCHAR  outputparam[MAX_PATH];
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 5272bfc..d304fdb 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -58,17 +58,17 @@ extern DWORD errorlevel;
 
 static BOOL verify_mode = FALSE;
 
-static const WCHAR dotW[]    = {'.','\0'};
-static const WCHAR dotdotW[] = {'.','.','\0'};
-static const WCHAR slashW[]  = {'\\','\0'};
-static const WCHAR starW[]   = {'*','\0'};
-static const WCHAR equalW[]  = {'=','\0'};
+const WCHAR dotW[]    = {'.','\0'};
+const WCHAR dotdotW[] = {'.','.','\0'};
+const WCHAR nullW[]   = {'\0'};
+const WCHAR starW[]   = {'*','\0'};
+const WCHAR slashW[]  = {'\\','\0'};
+const WCHAR equalW[]  = {'=','\0'};
 static const WCHAR fslashW[] = {'/','\0'};
 static const WCHAR onW[]  = {'O','N','\0'};
 static const WCHAR offW[] = {'O','F','F','\0'};
 static const WCHAR parmY[] = {'/','Y','\0'};
 static const WCHAR parmNoY[] = {'/','-','Y','\0'};
-static const WCHAR nullW[] = {'\0'};
 
 /**************************************************************************
  * WCMD_ask_confirm
diff --git a/programs/cmd/directory.c b/programs/cmd/directory.c
index 3634ded..03cb952 100644
--- a/programs/cmd/directory.c
+++ b/programs/cmd/directory.c
@@ -59,13 +59,6 @@ static BOOL orderReverse, orderGroupDirs, orderGroupDirsReverse, orderByCol;
 static BOOL paged_mode, recurse, wide, bare, lower, shortname, usernames, separator;
 static ULONG showattrs, attrsbits;
 
-static const WCHAR dotW[]    = {'.','\0'};
-static const WCHAR dotdotW[] = {'.','.','\0'};
-static const WCHAR starW[]   = {'*','\0'};
-static const WCHAR slashW[]  = {'\\','\0'};
-static const WCHAR emptyW[]  = {'\0'};
-static const WCHAR spaceW[]  = {' ','\0'};
-
 /*****************************************************************************
  * WCMD_strrev
  *
@@ -432,14 +425,14 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
 
             /* Note: WCMD_output uses wvsprintf which does not allow %*
                  so manually pad with spaces to appropriate width       */
-            strcpyW(temp, emptyW);
+            strcpyW(temp, nullW);
             while (padding > 0) {
-                strcatW(&temp[toWrite], spaceW);
+                strcatW(&temp[toWrite], space);
                 toWrite++;
                 if (toWrite > 99) {
                     WCMD_output(temp);
                     toWrite = 0;
-                    strcpyW(temp, emptyW);
+                    strcpyW(temp, nullW);
                 }
                 padding--;
             }
@@ -457,7 +450,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
         } else {
            if (!((strcmpW((fd+i)->cFileName, dotW) == 0) ||
                  (strcmpW((fd+i)->cFileName, dotdotW) == 0))) {
-              WCMD_output (fmt5, recurse?inputparms->dirName:emptyW, (fd+i)->cFileName);
+              WCMD_output (fmt5, recurse?inputparms->dirName:nullW, (fd+i)->cFileName);
            } else {
               addNewLine = FALSE;
            }
@@ -475,7 +468,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
            if (usernames) WCMD_output (fmt3, username);
            WCMD_output(fmt4,(fd+i)->cFileName);
         } else {
-           WCMD_output (fmt5, recurse?inputparms->dirName:emptyW, (fd+i)->cFileName);
+           WCMD_output (fmt5, recurse?inputparms->dirName:nullW, (fd+i)->cFileName);
         }
       }
      }
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index 205d31c..88b28c1 100644
--- a/programs/cmd/wcmd.h
+++ b/programs/cmd/wcmd.h
@@ -220,6 +220,13 @@ extern const WCHAR externals[NUM_EXTERNALS][10];
 
 /* Some standard messages */
 extern const WCHAR newline[];
+extern const WCHAR space[];
+extern const WCHAR nullW[];
+extern const WCHAR dotW[];
+extern const WCHAR dotdotW[];
+extern const WCHAR starW[];
+extern const WCHAR slashW[];
+extern const WCHAR equalW[];
 extern WCHAR anykey[];
 extern WCHAR version_string[];
 
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index b529672..e306d52 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -90,7 +90,7 @@ int defaultColor = 7;
 BOOL echo_mode = TRUE;
 static int opt_c, opt_k, opt_s;
 const WCHAR newline[] = {'\r','\n','\0'};
-static const WCHAR equalsW[] = {'=','\0'};
+const WCHAR space[]   = {' ','\0'};
 static const WCHAR closeBW[] = {')','\0'};
 WCHAR anykey[100];
 WCHAR version_string[100];
@@ -747,7 +747,7 @@ static WCHAR *WCMD_expand_envvar(WCHAR *start,
 
     /* search and replace manipulation */
     } else {
-      WCHAR *equalspos = strstrW(colonpos, equalsW);
+      WCHAR *equalspos = strstrW(colonpos, equalW);
       WCHAR *replacewith = equalspos+1;
       WCHAR *found       = NULL;
       WCHAR *searchIn;
@@ -1084,7 +1084,6 @@ void WCMD_run_program (WCHAR *command, int called) {
     WCHAR  thisDir[MAX_PATH] = {'\0'};
     WCHAR *pos               = NULL;
     BOOL  found             = FALSE;
-    static const WCHAR slashW[] = {'\\','\0'};
 
     /* Work on the first directory on the search path */
     pos = strchrW(pathposn, ';');
@@ -1332,7 +1331,7 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
       /* According to MSDN CreateProcess docs, special env vars record
          the current directory on each drive, in the form =C:
          so see if one specified, and if so go back to it             */
-      strcpyW(envvar, equalsW);
+      strcpyW(envvar, equalW);
       strcatW(envvar, cmd);
       if (GetEnvironmentVariableW(envvar, dir, MAX_PATH) == 0) {
         static const WCHAR fmt[] = {'%','s','\\','\0'};
@@ -1835,7 +1834,6 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
     if (context) handleExpansion(extraSpace, FALSE, NULL, NULL);
     /* Show prompt before batch line IF echo is on and in batch program */
     if (context && echo_mode && extraSpace[0] && (extraSpace[0] != '@')) {
-      static const WCHAR spc[]={' ','\0'};
       static const WCHAR echoDot[] = {'e','c','h','o','.'};
       static const WCHAR echoCol[] = {'e','c','h','o',':'};
       const DWORD len = sizeof(echoDot)/sizeof(echoDot[0]);
@@ -1850,7 +1848,7 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
           && CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
                          extraSpace, min_len, echoCol, len) != CSTR_EQUAL)
       {
-          WCMD_output_asis(spc);
+          WCMD_output_asis(space);
       }
       WCMD_output_asis(newline);
     }
-- 
1.7.7.2




More information about the wine-patches mailing list