ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

stream.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2007 Jacek Caban for CodeWeavers
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #include "hhctrl.h"
00020 #include "stream.h"
00021 
00022 #include "wine/debug.h"
00023 
00024 WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp);
00025 
00026 void strbuf_init(strbuf_t *buf)
00027 {
00028     buf->size = 8;
00029     buf->len = 0;
00030     buf->buf = heap_alloc(buf->size);
00031 }
00032 
00033 void strbuf_zero(strbuf_t *buf)
00034 {
00035     buf->len = 0;
00036 }
00037 
00038 void strbuf_free(strbuf_t *buf)
00039 {
00040     heap_free(buf->buf);
00041 }
00042 
00043 void strbuf_append(strbuf_t *buf, const char *data, int len)
00044 {
00045     if(buf->len+len > buf->size) {
00046         buf->size = buf->len+len;
00047         buf->buf = heap_realloc(buf->buf, buf->size);
00048     }
00049 
00050     memcpy(buf->buf+buf->len, data, len);
00051     buf->len += len;
00052 }
00053 
00054 void stream_init(stream_t *stream, IStream *str)
00055 {
00056     memset(stream, 0, sizeof(stream_t));
00057     stream->str = str;
00058 }
00059 
00060 BOOL stream_chr(stream_t *stream, strbuf_t *buf, char c)
00061 {
00062     BOOL b = TRUE;
00063     ULONG i;
00064 
00065     while(b) {
00066         for(i=stream->p; i<stream->size; i++) {
00067             if(stream->buf[i] == c) {
00068                 b = FALSE;
00069                 break;
00070             }
00071         }
00072 
00073         if(buf && i > stream->p)
00074             strbuf_append(buf, stream->buf+stream->p, i-stream->p);
00075         stream->p = i;
00076 
00077         if(stream->p == stream->size) {
00078             stream->p = 0;
00079             IStream_Read(stream->str, stream->buf, sizeof(stream->buf), &stream->size);
00080             if(!stream->size)
00081                 break;
00082         }
00083     }
00084 
00085     return stream->size != 0;
00086 }
00087 
00088 void get_node_name(strbuf_t *node, strbuf_t *name)
00089 {
00090     const char *ptr = node->buf+1;
00091 
00092     strbuf_zero(name);
00093 
00094     while(*ptr != '>' && !isspace(*ptr))
00095         ptr++;
00096 
00097     strbuf_append(name, node->buf+1, ptr-node->buf-1);
00098     strbuf_append(name, "", 1);
00099 }
00100 
00101 /* Return the stream content up to the next HTML tag.
00102  *
00103  * Note: the first returned character is the end of the last tag (>).
00104  */
00105 BOOL next_content(stream_t *stream, strbuf_t *buf)
00106 {
00107     if(!stream_chr(stream, buf, '<'))
00108         return FALSE;
00109 
00110     return TRUE;
00111 }
00112 
00113 BOOL next_node(stream_t *stream, strbuf_t *buf)
00114 {
00115     if(!stream_chr(stream, NULL, '<'))
00116         return FALSE;
00117 
00118     if(!stream_chr(stream, buf, '>'))
00119         return FALSE;
00120 
00121     strbuf_append(buf, ">", 2);
00122 
00123     return TRUE;
00124 }
00125 
00126 /*
00127  * Find the value of a named HTML attribute.
00128  *
00129  * Note: Attribute names are case insensitive, so it is necessary to
00130  * put both the node text and the attribute name in the same case
00131  * before attempting a string search.
00132  */
00133 const char *get_attr(const char *node, const char *name, int *len)
00134 {
00135     const char *ptr, *ptr2;
00136     int name_len, node_len;
00137     char name_buf[32];
00138     char *node_buf;
00139     int i;
00140 
00141     /* Create a lower case copy of the node */
00142     node_len = strlen(node)+1;
00143     node_buf = heap_alloc(node_len*sizeof(char));
00144     if(!node_buf)
00145         return NULL;
00146     memcpy(node_buf, node, node_len);
00147     for(i=0;i<node_len;i++)
00148         node_buf[i] = tolower(node_buf[i]);
00149     /* Create a lower case copy of the attribute name (search string) */
00150     name_len = strlen(name);
00151     memcpy(name_buf, name, name_len);
00152     for(i=0;i<name_len;i++)
00153         name_buf[i] = tolower(name_buf[i]);
00154     name_buf[name_len++] = '=';
00155     name_buf[name_len++] = '\"';
00156     name_buf[name_len] = 0;
00157 
00158     ptr = strstr(node_buf, name_buf);
00159     if(!ptr) {
00160         WARN("name not found\n");
00161         heap_free(node_buf);
00162         return NULL;
00163     }
00164 
00165     ptr += name_len;
00166     ptr2 = strchr(ptr, '\"');
00167     if(!ptr2)
00168     {
00169         heap_free(node_buf);
00170         return NULL;
00171     }
00172 
00173     *len = ptr2-ptr;
00174     /* Return the pointer offset within the original string */
00175     ptr = node+(ptr-node_buf);
00176 
00177     heap_free(node_buf);
00178     return ptr;
00179 }

Generated on Sun May 27 2012 04:23:51 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.