From 5912b0c92fc40ed748e41964d0dc32755b65abbc Mon Sep 17 00:00:00 2001 From: Erich Hoover Date: Wed, 27 Jan 2010 19:12:21 -0700 Subject: [PATCH] hhctrl.ocx: Separate the HTML Help stream reader code from the Contents tab. --- dlls/hhctrl.ocx/Makefile.in | 1 + dlls/hhctrl.ocx/content.c | 159 +--------------------------------- dlls/hhctrl.ocx/stream.c | 167 ++++++++++++++++++++++++++++++++++++ dlls/hhctrl.ocx/stream.h | 47 ++++++++++ 4 files changed, 216 insertions(+), 158 deletions(-) create mode 100644 dlls/hhctrl.ocx/stream.c create mode 100644 dlls/hhctrl.ocx/stream.h diff --git a/dlls/hhctrl.ocx/Makefile.in b/dlls/hhctrl.ocx/Makefile.in index 60f2c507ba2..b2c10d0b270 100644 --- a/dlls/hhctrl.ocx/Makefile.in +++ b/dlls/hhctrl.ocx/Makefile.in @@ -11,6 +11,7 @@ C_SRCS = \ help.c \ hhctrl.c \ regsvr.c \ + stream.c \ webbrowser.c RC_SRCS = \ diff --git a/dlls/hhctrl.ocx/content.c b/dlls/hhctrl.ocx/content.c index 10de54c3708..bfe25cf9453 100644 --- a/dlls/hhctrl.ocx/content.c +++ b/dlls/hhctrl.ocx/content.c @@ -20,13 +20,12 @@ #define NONAMELESSSTRUCT #include "hhctrl.h" +#include "stream.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp); -#define BLOCK_SIZE 0x1000 - typedef enum { INSERT_NEXT, INSERT_CHILD @@ -50,162 +49,6 @@ static void free_content_item(ContentItem *item) } } -typedef struct { - char *buf; - int size; - int len; -} strbuf_t; - -static void strbuf_init(strbuf_t *buf) -{ - buf->size = 8; - buf->len = 0; - buf->buf = heap_alloc(buf->size); -} - -static void strbuf_zero(strbuf_t *buf) -{ - buf->len = 0; -} - -static void strbuf_free(strbuf_t *buf) -{ - heap_free(buf->buf); -} - -static void strbuf_append(strbuf_t *buf, const char *data, int len) -{ - if(buf->len+len > buf->size) { - buf->size = buf->len+len; - buf->buf = heap_realloc(buf->buf, buf->size); - } - - memcpy(buf->buf+buf->len, data, len); - buf->len += len; -} - -typedef struct { - IStream *str; - char buf[BLOCK_SIZE]; - ULONG size; - ULONG p; -} stream_t; - -static void stream_init(stream_t *stream, IStream *str) -{ - memset(stream, 0, sizeof(stream_t)); - stream->str = str; -} - -static BOOL stream_chr(stream_t *stream, strbuf_t *buf, char c) -{ - BOOL b = TRUE; - ULONG i; - - while(b) { - for(i=stream->p; isize; i++) { - if(stream->buf[i] == c) { - b = FALSE; - break; - } - } - - if(buf && i > stream->p) - strbuf_append(buf, stream->buf+stream->p, i-stream->p); - stream->p = i; - - if(stream->p == stream->size) { - stream->p = 0; - IStream_Read(stream->str, stream->buf, sizeof(stream->buf), &stream->size); - if(!stream->size) - break; - } - } - - return stream->size != 0; -} - -static void get_node_name(strbuf_t *node, strbuf_t *name) -{ - const char *ptr = node->buf+1; - - strbuf_zero(name); - - while(*ptr != '>' && !isspace(*ptr)) - ptr++; - - strbuf_append(name, node->buf+1, ptr-node->buf-1); - strbuf_append(name, "", 1); -} - -static BOOL next_node(stream_t *stream, strbuf_t *buf) -{ - if(!stream_chr(stream, NULL, '<')) - return FALSE; - - if(!stream_chr(stream, buf, '>')) - return FALSE; - - strbuf_append(buf, ">", 2); - - return TRUE; -} - -/* - * Find the value of a named HTML attribute. - * - * Note: Attribute names are case insensitive, so it is necessary to - * put both the node text and the attribute name in the same case - * before attempting a string search. - */ -static const char *get_attr(const char *node, const char *name, int *len) -{ - const char *ptr, *ptr2; - int name_len, node_len; - char name_buf[32]; - char *node_buf; - int i; - - /* Create a lower case copy of the node */ - node_len = strlen(node)+1; - node_buf = heap_alloc(node_len*sizeof(char)); - if(!node_buf) - return NULL; - memcpy(node_buf, node, node_len); - for(i=0;isize = 8; + buf->len = 0; + buf->buf = heap_alloc(buf->size); +} + +void strbuf_zero(strbuf_t *buf) +{ + buf->len = 0; +} + +void strbuf_free(strbuf_t *buf) +{ + heap_free(buf->buf); +} + +void strbuf_append(strbuf_t *buf, const char *data, int len) +{ + if(buf->len+len > buf->size) { + buf->size = buf->len+len; + buf->buf = heap_realloc(buf->buf, buf->size); + } + + memcpy(buf->buf+buf->len, data, len); + buf->len += len; +} + +void stream_init(stream_t *stream, IStream *str) +{ + memset(stream, 0, sizeof(stream_t)); + stream->str = str; +} + +BOOL stream_chr(stream_t *stream, strbuf_t *buf, char c) +{ + BOOL b = TRUE; + ULONG i; + + while(b) { + for(i=stream->p; isize; i++) { + if(stream->buf[i] == c) { + b = FALSE; + break; + } + } + + if(buf && i > stream->p) + strbuf_append(buf, stream->buf+stream->p, i-stream->p); + stream->p = i; + + if(stream->p == stream->size) { + stream->p = 0; + IStream_Read(stream->str, stream->buf, sizeof(stream->buf), &stream->size); + if(!stream->size) + break; + } + } + + return stream->size != 0; +} + +void get_node_name(strbuf_t *node, strbuf_t *name) +{ + const char *ptr = node->buf+1; + + strbuf_zero(name); + + while(*ptr != '>' && !isspace(*ptr)) + ptr++; + + strbuf_append(name, node->buf+1, ptr-node->buf-1); + strbuf_append(name, "", 1); +} + +BOOL next_node(stream_t *stream, strbuf_t *buf) +{ + if(!stream_chr(stream, NULL, '<')) + return FALSE; + + if(!stream_chr(stream, buf, '>')) + return FALSE; + + strbuf_append(buf, ">", 2); + + return TRUE; +} + +/* + * Find the value of a named HTML attribute. + * + * Note: Attribute names are case insensitive, so it is necessary to + * put both the node text and the attribute name in the same case + * before attempting a string search. + */ +const char *get_attr(const char *node, const char *name, int *len) +{ + const char *ptr, *ptr2; + int name_len, node_len; + char name_buf[32]; + char *node_buf; + int i; + + /* Create a lower case copy of the node */ + node_len = strlen(node)+1; + node_buf = heap_alloc(node_len*sizeof(char)); + if(!node_buf) + return NULL; + memcpy(node_buf, node, node_len); + for(i=0;i