Mike McCormack : msi: Clean trailing and leading spaces from path segments.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Jan 6 06:16:58 CST 2006


Module: wine
Branch: refs/heads/master
Commit: b9d135a37b235ac4fedc6bd1924aa7351d655b72
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=b9d135a37b235ac4fedc6bd1924aa7351d655b72

Author: Mike McCormack <mike at codeweavers.com>
Date:   Fri Jan  6 12:19:22 2006 +0100

msi: Clean trailing and leading spaces from path segments.

---

 dlls/msi/helpers.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/dlls/msi/helpers.c b/dlls/msi/helpers.c
index 2b2ba06..ffdf3be 100644
--- a/dlls/msi/helpers.c
+++ b/dlls/msi/helpers.c
@@ -228,6 +228,45 @@ static LPWSTR get_source_root( MSIPACKAG
     return path;
 }
 
+/*
+ * clean_spaces_from_path()
+ *
+ * removes spaces from the beginning and end of path segments
+ * removes multiple \\ characters
+ */
+static void clean_spaces_from_path( LPWSTR p )
+{
+    LPWSTR q = p;
+    int n, len = 0;
+
+    while (1)
+    {
+        /* copy until the end of the string or a space */
+        while (*p != ' ' && (*q = *p))
+        {
+            p++, len++;
+            /* reduce many backslashes to one */
+            if (*p != '\\' || *q != '\\')
+                q++;
+        }
+
+        /* quit at the end of the string */
+        if (!*p)
+            break;
+
+        /* count the number of spaces */
+        n = 0;
+        while (p[n] == ' ')
+            n++;
+
+        /* if it's leading or trailing space, skip it */
+        if ( len == 0 || p[-1] == '\\' || p[n] == '\\' )
+            p += n;
+        else  /* copy n spaces */
+            while (n && (*q++ = *p++)) n--;
+    }
+}
+
 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source, 
                       BOOL set_prop, MSIFOLDER **folder)
 {
@@ -255,6 +294,7 @@ LPWSTR resolve_folder(MSIPACKAGE *packag
 
             /* correct misbuilt target dir */
             path = build_directory_name(2, check_path, NULL);
+            clean_spaces_from_path( path );
             if (strcmpiW(path,check_path)!=0)
                 MSI_SetPropertyW(package,cszTargetDir,path);
             msi_free(check_path);
@@ -307,6 +347,7 @@ LPWSTR resolve_folder(MSIPACKAGE *packag
             TRACE("   TargetDefault = %s\n", debugstr_w(f->TargetDefault));
 
             path = build_directory_name( 3, p, f->TargetDefault, NULL );
+            clean_spaces_from_path( path );
             f->ResolvedTarget = strdupW( path );
             TRACE("target -> %s\n", debugstr_w(path));
             if (set_prop)




More information about the wine-cvs mailing list