Aric Stewart : hhctrl.ocx: Improve parsing of incoming file specs to HtmlHelp.

Alexandre Julliard julliard at winehq.org
Wed Jun 29 15:47:44 CDT 2011


Module: wine
Branch: master
Commit: 3414d0ea0e8fe8cbd5f4ee090e0673620ffd36ab
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3414d0ea0e8fe8cbd5f4ee090e0673620ffd36ab

Author: Aric Stewart <aric at codeweavers.com>
Date:   Wed Jun 29 10:51:05 2011 -0500

hhctrl.ocx: Improve parsing of incoming file specs to HtmlHelp.

---

 dlls/hhctrl.ocx/chm.c    |    2 +-
 dlls/hhctrl.ocx/hhctrl.c |   55 +++++++++++++++++++++++++++++++++------------
 dlls/hhctrl.ocx/hhctrl.h |    2 +
 3 files changed, 43 insertions(+), 16 deletions(-)

diff --git a/dlls/hhctrl.ocx/chm.c b/dlls/hhctrl.ocx/chm.c
index f0452fa..51d1685 100644
--- a/dlls/hhctrl.ocx/chm.c
+++ b/dlls/hhctrl.ocx/chm.c
@@ -282,7 +282,7 @@ done:
     return SUCCEEDED(hr);
 }
 
-static LPCWSTR skip_schema(LPCWSTR url)
+LPCWSTR skip_schema(LPCWSTR url)
 {
     static const WCHAR its_schema[] = {'i','t','s',':'};
     static const WCHAR msits_schema[] = {'m','s','-','i','t','s',':'};
diff --git a/dlls/hhctrl.ocx/hhctrl.c b/dlls/hhctrl.ocx/hhctrl.c
index 08dfc4e..33cc1f1 100644
--- a/dlls/hhctrl.ocx/hhctrl.c
+++ b/dlls/hhctrl.ocx/hhctrl.c
@@ -98,9 +98,41 @@ static const char *command_to_string(UINT command)
 #undef X
 }
 
-static BOOL resolve_filename(const WCHAR *filename, WCHAR *fullname, DWORD buflen)
+static BOOL resolve_filename(const WCHAR *filename, WCHAR *fullname, DWORD buflen, const WCHAR **index, const WCHAR **window)
 {
+    const WCHAR *extra;
+    WCHAR chm_file[MAX_PATH];
+
     static const WCHAR helpW[] = {'\\','h','e','l','p','\\',0};
+    static const WCHAR delimW[] = {':',':',0};
+    static const WCHAR delim2W[] = {'>',0};
+
+    filename = skip_schema(filename);
+
+    /* the format is "helpFile[::/index][>window]" */
+    if (index) *index = NULL;
+    if (window) *window = NULL;
+
+    extra = strstrW(filename, delim2W);
+    if (extra)
+    {
+        memcpy(chm_file, filename, (extra-filename)*sizeof(WCHAR));
+        chm_file[extra-filename] = 0;
+        filename = chm_file;
+        if (window)
+            *window = strdupW(extra+1);
+    }
+
+    extra = strstrW(filename, delimW);
+    if (extra)
+    {
+        if (filename != chm_file);
+            memcpy(chm_file, filename, (extra-filename)*sizeof(WCHAR));
+        chm_file[extra-filename] = 0;
+        filename = chm_file;
+        if (index)
+            *index = strdupW(extra+2);
+    }
 
     GetFullPathNameW(filename, buflen, fullname, NULL);
     if (GetFileAttributesW(fullname) == INVALID_FILE_ATTRIBUTES)
@@ -128,27 +160,16 @@ HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR dat
     case HH_DISPLAY_TOPIC:
     case HH_DISPLAY_TOC:
     case HH_DISPLAY_SEARCH:{
-        static const WCHAR delimW[] = {':',':',0};
         HHInfo *info;
         BOOL res;
-        WCHAR chm_file[MAX_PATH];
-        const WCHAR *index;
+        const WCHAR *index = NULL;
 
         FIXME("Not all HH cases handled correctly\n");
 
         if (!filename)
             return NULL;
 
-        index = strstrW(filename, delimW);
-        if (index)
-        {
-            memcpy(chm_file, filename, (index-filename)*sizeof(WCHAR));
-            chm_file[index-filename] = 0;
-            filename = chm_file;
-            index += 2; /* advance beyond "::" for calling NavigateToChm() later */
-        }
-
-        if (!resolve_filename(filename, fullname, MAX_PATH))
+        if (!resolve_filename(filename, fullname, MAX_PATH, &index, NULL))
         {
             WARN("can't find %s\n", debugstr_w(filename));
             return 0;
@@ -162,6 +183,10 @@ HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR dat
             index = info->WinType.pszFile;
 
         res = NavigateToChm(info, info->pCHMInfo->szFile, index);
+
+        if (index != info->WinType.pszFile)
+            heap_free((WCHAR*)index);
+
         if(!res)
         {
             ReleaseHelpViewer(info);
@@ -176,7 +201,7 @@ HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR dat
         if (!filename)
             return NULL;
 
-        if (!resolve_filename(filename, fullname, MAX_PATH))
+        if (!resolve_filename(filename, fullname, MAX_PATH, NULL, NULL))
         {
             WARN("can't find %s\n", debugstr_w(filename));
             return 0;
diff --git a/dlls/hhctrl.ocx/hhctrl.h b/dlls/hhctrl.ocx/hhctrl.h
index 1d45201..8e63545 100644
--- a/dlls/hhctrl.ocx/hhctrl.h
+++ b/dlls/hhctrl.ocx/hhctrl.h
@@ -189,6 +189,8 @@ BOOL NavigateToChm(HHInfo*,LPCWSTR,LPCWSTR) DECLSPEC_HIDDEN;
 void InitSearch(HHInfo *info, const char *needle) DECLSPEC_HIDDEN;
 void ReleaseSearch(HHInfo *info) DECLSPEC_HIDDEN;
 
+LPCWSTR skip_schema(LPCWSTR url) DECLSPEC_HIDDEN;
+
 /* memory allocation functions */
 
 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)




More information about the wine-cvs mailing list