winhelp

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



this patch solves a couple of issues with winhelp (see changelog)
A+
--
Eric Pouech
Name:          winhlp
ChangeLog:     
	- added some missing strings to resources
	- made the decompression code a bit more pedantic to avoid crashes
	- fixed startup without .HLP filename passed on command line
	- passed a few more commands from remote applications to the macros
License:       X11
GenDate:       2003/05/23 18:48:43 UTC
ModifiedFiles: programs/winhelp/Si.rc programs/winhelp/Sk.rc programs/winhelp/hlpfile.c programs/winhelp/winhelp.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/programs/winhelp/Si.rc,v
retrieving revision 1.2
diff -u -u -r1.2 Si.rc
--- programs/winhelp/Si.rc	21 Oct 2002 19:18:42 -0000	1.2
+++ programs/winhelp/Si.rc	21 Oct 2002 19:32:53 -0000
@@ -62,6 +62,7 @@
 STID_SEARCH, 		"&Iskanje"
 STID_BACK, 			"&Nazaj"
 STID_HISTORY, 		"&Zgodovina"
+STID_TOPICS,		"&Topics"
 STID_ALL_FILES, 		"Vse datiteke (*.*)"
 STID_HELP_FILES_HLP, 	"Datoteke s pomoèjo (*.hlp)"
 }
Index: programs/winhelp/Sk.rc
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/programs/winhelp/Sk.rc,v
retrieving revision 1.6
diff -u -u -r1.6 Sk.rc
--- programs/winhelp/Sk.rc	21 Oct 2002 19:18:42 -0000	1.6
+++ programs/winhelp/Sk.rc	21 Oct 2002 19:32:35 -0000
@@ -59,6 +59,7 @@
 STID_SEARCH,                "&H¾ada?"
 STID_BACK,                  "&Spä?"
 STID_HISTORY,               "&História"
+STID_TOPICS,		    "&Topics"
 STID_ALL_FILES,             "V?etky súbory (*.*)"
 STID_HELP_FILES_HLP,        "Súbory pomoci (*.hlp)"
 }
Index: programs/winhelp/hlpfile.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/programs/winhelp/hlpfile.c,v
retrieving revision 1.17
diff -u -u -r1.17 hlpfile.c
--- programs/winhelp/hlpfile.c	14 Jan 2003 23:43:41 -0000	1.17
+++ programs/winhelp/hlpfile.c	23 May 2003 18:48:39 -0000
@@ -85,7 +85,7 @@
 static BOOL  HLPFILE_AddParagraph(HLPFILE*, BYTE *, BYTE*, unsigned*);
 static void  HLPFILE_Uncompress2(const BYTE*, const BYTE*, BYTE*, const BYTE*);
 static BOOL  HLPFILE_Uncompress3(char*, const char*, const BYTE*, const BYTE*);
-static void  HLPFILE_UncompressRLE(const BYTE* src, unsigned sz, BYTE** dst);
+static void  HLPFILE_UncompressRLE(const BYTE* src, const BYTE* end, BYTE** dst, unsigned dstsz);
 static BOOL  HLPFILE_ReadFont(HLPFILE* hlpfile);
 
 /***********************************************************************
@@ -523,15 +523,15 @@
     {
     case 0: /* uncompressed */
         if (sz != csz)
-            WINE_WARN("Bogus gfx sizes: %u / %u\n", sz, csz);
+            WINE_WARN("Bogus gfx sizes (uncompressed): %u / %u\n", sz, csz);
         dst = src;
         break;
     case 1: /* RunLen */
         tmp = dst = HeapAlloc(GetProcessHeap(), 0, sz);
         if (!dst) return NULL;
-        HLPFILE_UncompressRLE(src, csz, &tmp);
+        HLPFILE_UncompressRLE(src, src + csz, &tmp, sz);
         if (tmp - dst != sz)
-            WINE_FIXME("Bogus gfx sizes: %u/%u\n", tmp - dst, sz);
+            WINE_FIXME("Bogus gfx sizes (RunLen): %u/%u\n", tmp - dst, sz);
         break;
     case 2: /* LZ77 */
         sz77 = HLPFILE_UncompressedLZ77_Size(src, src + csz);
@@ -539,18 +539,18 @@
         if (!dst) return NULL;
         HLPFILE_UncompressLZ77(src, src + csz, dst);
         if (sz77 != sz)
-            WINE_WARN("Bogus gfx sizes: %u / %u\n", sz77, sz);
+            WINE_WARN("Bogus gfx sizes (LZ77): %u / %u\n", sz77, sz);
         break;
     case 3: /* LZ77 then RLE */
         sz77 = HLPFILE_UncompressedLZ77_Size(src, src + csz);
-        tmp = HeapAlloc(GetProcessHeap(), 0, sz/*sz77*/);
+        tmp = HeapAlloc(GetProcessHeap(), 0, sz77);
         if (!tmp) return FALSE;
         HLPFILE_UncompressLZ77(src, src + csz, tmp);
         dst = tmp2 = HeapAlloc(GetProcessHeap(), 0, sz);
         if (!dst) return FALSE;
-        HLPFILE_UncompressRLE(tmp, sz77, &tmp2);
+        HLPFILE_UncompressRLE(tmp, tmp + sz77, &tmp2, sz);
         if (tmp2 - dst != sz)
-            WINE_WARN("Bogus gfx: %u / %u\n", tmp2 - dst, sz);
+            WINE_WARN("Bogus gfx sizes (LZ77+RunLen): %u / %u\n", tmp2 - dst, sz);
         HeapFree(GetProcessHeap(), 0, tmp);
         break;
     default:
@@ -592,6 +592,9 @@
     if (bi->bmiHeader.biBitCount > 32) WINE_FIXME("Unknown bit count %u\n", bi->bmiHeader.biBitCount);
     if (bi->bmiHeader.biPlanes != 1) WINE_FIXME("Unsupported planes %u\n", bi->bmiHeader.biPlanes);
     bi->bmiHeader.biSizeImage = (((bi->bmiHeader.biWidth * bi->bmiHeader.biBitCount + 31) & ~31) / 8) * bi->bmiHeader.biHeight;
+    WINE_TRACE("planes=%d bc=%d size=(%ld,%ld)\n",
+               bi->bmiHeader.biPlanes, bi->bmiHeader.biBitCount, 
+               bi->bmiHeader.biWidth, bi->bmiHeader.biHeight);
 
     csz = fetch_ulong(&ptr);
     fetch_ulong(&ptr); /* hotspot size */
@@ -1406,7 +1409,7 @@
                 wi->style = (flags & 0x0080) ? GET_USHORT(ptr, 84) : SW_SHOW;
                 wi->sr_color = (flags & 0x0100) ? GET_UINT(ptr, 86) : 0xFFFFFF;
                 wi->nsr_color = (flags & 0x0200) ? GET_UINT(ptr, 90) : 0xFFFFFF;
-                WINE_FIXME("System-Window: flags=%c%c%c%c%c%c%c%c type=%s name=%s caption=%s (%ld,%ld)x(%ld,%ld)\n",
+                WINE_TRACE("System-Window: flags=%c%c%c%c%c%c%c%c type=%s name=%s caption=%s (%ld,%ld)x(%ld,%ld)\n",
                            flags & 0x0001 ? 'T' : 't',
                            flags & 0x0002 ? 'N' : 'n',
                            flags & 0x0004 ? 'C' : 'c',
@@ -1715,7 +1718,8 @@
             else 
             {
                 len = phrases.offsets[idx + 1] - phrases.offsets[idx];
-                memcpy(dst, &phrases.buffer[phrases.offsets[idx]], len);
+                if (dst + len <= dst_end)
+                    memcpy(dst, &phrases.buffer[phrases.offsets[idx]], len);
             }
         }
         else if ((*src & 0x03) == 0x01)
@@ -1730,19 +1734,22 @@
             else
             {
                 len = phrases.offsets[idx + 1] - phrases.offsets[idx];
-                memcpy(dst, &phrases.buffer[phrases.offsets[idx]], len);
+                if (dst + len <= dst_end)
+                    memcpy(dst, &phrases.buffer[phrases.offsets[idx]], len);
             }
         }
         else if ((*src & 0x07) == 0x03)
         {
             len = (*src / 8) + 1;
-            memcpy(dst, src + 1, len);
+            if (dst + len <= dst_end)
+                memcpy(dst, src + 1, len);
             src += len;
         }
         else
         {
             len = (*src / 16) + 1;
-            memset(dst, ((*src & 0x0F) == 0x07) ? ' ' : 0, len);
+            if (dst + len <= dst_end)
+                memset(dst, ((*src & 0x0F) == 0x07) ? ' ' : 0, len);
         }
         dst += len;
     }
@@ -1756,27 +1763,37 @@
  *
  *
  */
-static void HLPFILE_UncompressRLE(const BYTE* src, unsigned sz, BYTE** dst)
+static void HLPFILE_UncompressRLE(const BYTE* src, const BYTE* end, BYTE** dst, unsigned dstsz)
 {
-    unsigned    i;
     BYTE        ch;
+    BYTE*       sdst = *dst + dstsz;
 
-    for (i = 0; i < sz; i++)
+    while (src < end)
     {
-        ch = src[i];
+        ch = *src++;
         if (ch & 0x80)
         {
             ch &= 0x7F;
-            memcpy(*dst, src + i + 1, ch);
-            i += ch;
+            if (ch == 0) WINE_FIXME("Null length 1, next is %u\n", *src);
+            if ((*dst) + ch < sdst)
+                memcpy(*dst, src, ch);
+            src += ch;
         }
         else
         {
-            memset(*dst, (char)src[i + 1], ch);
-            i++;
+            if ((*dst) + ch < sdst)
+                memset(*dst, (char)*src, ch);
+            src++;
+            if (ch == 0)
+            {
+                WINE_FIXME("Null length 2, next is %u\n", *src);
+            }
         }
         *dst += ch;
     }
+    if (*dst != sdst)
+        WINE_FIXME("Buffer X-flow: d(%u) instead of d(%u)\n",
+                   *dst - (sdst - dstsz), dstsz);
 }
 
 /******************************************************************
Index: programs/winhelp/winhelp.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/programs/winhelp/winhelp.c,v
retrieving revision 1.25
diff -u -u -r1.25 winhelp.c
--- programs/winhelp/winhelp.c	8 Jan 2003 21:09:25 -0000	1.25
+++ programs/winhelp/winhelp.c	23 May 2003 16:35:25 -0000
@@ -91,9 +91,10 @@
     if (!name || !name[0])
         name = Globals.active_win->lpszName;
 
-    for (i = 0; i < hlpfile->numWindows; i++)
-        if (!strcmp(hlpfile->windows[i].name, name))
-            return &hlpfile->windows[i];
+    if (hlpfile)
+        for (i = 0; i < hlpfile->numWindows; i++)
+            if (!strcmp(hlpfile->windows[i].name, name))
+                return &hlpfile->windows[i];
 
     if (strcmp(name, "main") != 0)
     {
@@ -196,9 +197,12 @@
 
     /* Create primary window */
     WINHELP_RegisterWinClasses();
-    hlpfile = WINHELP_LookupHelpFile(cmdline);
-    if (!hlpfile)
-        return 0;
+    if (*cmdline)
+    {
+        hlpfile = WINHELP_LookupHelpFile(cmdline);
+        if (!hlpfile) return 0;
+    }
+    else hlpfile = NULL;
     WINHELP_CreateHelpWindowByHash(hlpfile, lHash, 
                                    WINHELP_GetWindowInfo(hlpfile, "main"), show);
 
@@ -285,33 +289,60 @@
 
     if (wh)
     {
+        char*   ptr = (wh->ofsFilename) ? (LPSTR)wh + wh->ofsFilename : NULL;
+
         WINE_TRACE("Got[%u]: cmd=%u data=%08lx fn=%s\n", 
-                   wh->size, wh->command, wh->data,
-                   wh->ofsFilename ? (LPSTR)wh + wh->ofsFilename : "");
+                   wh->size, wh->command, wh->data, ptr);
         switch (wh->command)
         {
+        case HELP_CONTEXT:
+            if (ptr)
+            {
+                MACRO_JumpContext(ptr, "main", wh->data);
+            }
+            break;
         case HELP_QUIT:
             MACRO_Exit();
             break;
-        case HELP_FINDER:
-            /* in fact, should be the topic dialog box */
-            if (wh->ofsFilename)
+        case HELP_CONTENTS:
+            if (ptr)
             {
-                MACRO_JumpHash((LPSTR)wh + wh->ofsFilename, "main", 0);
+                MACRO_JumpContents(ptr, "main");
             }
             break;
-        case HELP_CONTEXT:
+        case HELP_HELPONHELP:
+            MACRO_HelpOn();
+            break;
+        /* case HELP_SETINDEX: */
         case HELP_SETCONTENTS:
-        case HELP_CONTENTS:
+            if (ptr)
+            {
+                MACRO_SetContents(ptr, wh->data);
+            }
+            break;
         case HELP_CONTEXTPOPUP:
-        case HELP_FORCEFILE:
-        case HELP_HELPONHELP:
-        case HELP_KEY:
-        case HELP_PARTIALKEY:
-        case HELP_COMMAND:
-        case HELP_MULTIKEY:
-        case HELP_SETWINPOS:
-            WINE_FIXME("NIY\n");
+            if (ptr)
+            {
+                MACRO_PopupContext(ptr, wh->data);
+            }
+            break;
+        /* case HELP_FORCEFILE:*/
+        /* case HELP_CONTEXTMENU: */
+        case HELP_FINDER:
+            /* in fact, should be the topic dialog box */
+            if (ptr)
+            {
+                MACRO_JumpHash(ptr, "main", 0);
+            }
+            break;
+        /* case HELP_WM_HELP: */
+        /* case HELP_SETPOPUP_POS: */
+        /* case HELP_KEY: */
+        /* case HELP_COMMAND: */
+        /* case HELP_PARTIALKEY: */
+        /* case HELP_MULTIKEY: */
+        /* case HELP_SETWINPOS: */
+            WINE_FIXME("Unknown command (%x) for remote winhelp control\n", wh->command);
             break;
         }
     }
@@ -478,6 +509,7 @@
             MACRO_ExecuteMacro(macro->lpszMacro);
     }
 
+    win->histIndex = win->backIndex = 0;
     /* Reuse existing window */
     if (!bPopup)
     {
@@ -488,13 +520,13 @@
                 return WINHELP_ReuseWindow(win, oldwin, page, nCmdShow);
             }
         }
-
-        win->histIndex = win->backIndex = 1;
-        win->history[0] = win->back[0] = page;
-        page->file->wRefCount += 2;
+        if (page)
+        {
+            win->histIndex = win->backIndex = 1;
+            win->history[0] = win->back[0] = page;
+            page->file->wRefCount += 2;
+        }
     }
-    else
-        win->histIndex = win->backIndex = 0;
 
     hWnd = CreateWindow(bPopup ? TEXT_WIN_CLASS_NAME : MAIN_WIN_CLASS_NAME,
                         wi->caption, wi->win_style,

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux