ReactOS 0.4.15-dev-7934-g1dc8d80
stream.c
Go to the documentation of this file.
1/*
2 * Copyright 2007 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#include "hhctrl.h"
20#include "stream.h"
21
22#include "wine/debug.h"
23
25
27{
28 buf->size = 8;
29 buf->len = 0;
30 buf->buf = heap_alloc(buf->size);
31}
32
34{
35 buf->len = 0;
36}
37
39{
40 heap_free(buf->buf);
41}
42
43static void strbuf_append(strbuf_t *buf, const char *data, int len)
44{
45 if(buf->len+len > buf->size) {
46 buf->size = buf->len+len;
47 buf->buf = heap_realloc(buf->buf, buf->size);
48 }
49
50 memcpy(buf->buf+buf->len, data, len);
51 buf->len += len;
52}
53
55{
56 memset(stream, 0, sizeof(stream_t));
57 stream->str = str;
58}
59
61{
62 BOOL b = TRUE;
63 ULONG i;
64
65 while(b) {
66 for(i=stream->p; i<stream->size; i++) {
67 if(stream->buf[i] == c) {
68 b = FALSE;
69 break;
70 }
71 }
72
73 if(buf && i > stream->p)
75 stream->p = i;
76
77 if(stream->p == stream->size) {
78 stream->p = 0;
79 IStream_Read(stream->str, stream->buf, sizeof(stream->buf), &stream->size);
80 if(!stream->size)
81 break;
82 }
83 }
84
85 return stream->size != 0;
86}
87
89{
90 const char *ptr = node->buf+1;
91
93
94 while(*ptr != '>' && !isspace(*ptr))
95 ptr++;
96
97 strbuf_append(name, node->buf+1, ptr-node->buf-1);
98 strbuf_append(name, "", 1);
99}
100
101/* Return the stream content up to the next HTML tag.
102 *
103 * Note: the first returned character is the end of the last tag (>).
104 */
106{
107 if(!stream_chr(stream, buf, '<'))
108 return FALSE;
109
110 return TRUE;
111}
112
114{
115 int tag_count = 0, b = buf->len;
116 char *p;
117
118 while(1)
119 {
120 if(!stream_chr(stream, buf, '>'))
121 return FALSE;
122 if(buf->len == 0)
123 break;
124 p = &buf->buf[b];
125 while((p = memchr(p+1, '"', buf->len-(p+1-buf->buf))) != NULL)
126 tag_count++;
127 b = buf->len;
128 if(tag_count % 2 != 0)
129 {
130 if(!stream_chr(stream, buf, '"'))
131 return FALSE;
132 tag_count++;
133 }
134 else
135 break;
136 }
137 return TRUE;
138}
139
141{
142 /* find the beginning of the next node */
143 if(!stream_chr(stream, NULL, '<'))
144 return FALSE;
145
146 /* read out the data of the next node */
148 return FALSE;
149
150 strbuf_append(buf, ">", 2);
151
152 return TRUE;
153}
154
155/*
156 * Find the value of a named HTML attribute.
157 *
158 * Note: Attribute names are case insensitive, so it is necessary to
159 * put both the node text and the attribute name in the same case
160 * before attempting a string search.
161 */
162const char *get_attr(const char *node, const char *name, int *len)
163{
164 const char *ptr, *ptr2;
165 int name_len, node_len;
166 char name_buf[32];
167 char *node_buf;
168 int i;
169
170 /* Create a lower case copy of the node */
171 node_len = strlen(node)+1;
172 node_buf = heap_alloc(node_len*sizeof(char));
173 if(!node_buf)
174 return NULL;
175 memcpy(node_buf, node, node_len);
176 for(i=0;i<node_len;i++)
177 node_buf[i] = tolower(node_buf[i]);
178 /* Create a lower case copy of the attribute name (search string) */
179 name_len = strlen(name);
180 memcpy(name_buf, name, name_len);
181 for(i=0;i<name_len;i++)
182 name_buf[i] = tolower(name_buf[i]);
183 name_buf[name_len++] = '=';
184 name_buf[name_len++] = '\"';
185 name_buf[name_len] = 0;
186
187 ptr = strstr(node_buf, name_buf);
188 if(!ptr) {
189 WARN("name not found\n");
190 heap_free(node_buf);
191 return NULL;
192 }
193
194 ptr += name_len;
195 ptr2 = strchr(ptr, '\"');
196 if(!ptr2)
197 {
198 heap_free(node_buf);
199 return NULL;
200 }
201
202 *len = ptr2-ptr;
203 /* Return the pointer offset within the original string */
204 ptr = node+(ptr-node_buf);
205
206 heap_free(node_buf);
207 return ptr;
208}
#define isspace(c)
Definition: acclib.h:69
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int tolower(int c)
Definition: utclib.c:902
char * strchr(const char *String, int ch)
Definition: utclib.c:501
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:71
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define WARN(fmt,...)
Definition: debug.h:112
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
const char * get_attr(const char *node, const char *name, int *len)
Definition: stream.c:162
void strbuf_free(strbuf_t *buf)
Definition: stream.c:38
void strbuf_init(strbuf_t *buf)
Definition: stream.c:26
static void strbuf_append(strbuf_t *buf, const char *data, int len)
Definition: stream.c:43
BOOL next_node(stream_t *stream, strbuf_t *buf)
Definition: stream.c:140
BOOL next_content(stream_t *stream, strbuf_t *buf)
Definition: stream.c:105
void strbuf_zero(strbuf_t *buf)
Definition: stream.c:33
static BOOL find_node_end(stream_t *stream, strbuf_t *buf)
Definition: stream.c:113
void stream_init(stream_t *stream, IStream *str)
Definition: stream.c:54
static BOOL stream_chr(stream_t *stream, strbuf_t *buf, char c)
Definition: stream.c:60
void get_node_name(strbuf_t *node, strbuf_t *name)
Definition: stream.c:88
unsigned int BOOL
Definition: ntddk_ex.h:94
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
const GLubyte * c
Definition: glext.h:8905
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define b
Definition: ke_i.h:79
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define memchr(s, c, n)
Definition: mkisofs.h:875
static PVOID ptr
Definition: dispmode.c:27
const WCHAR * str
Console I/O streams.
#define memset(x, y, z)
Definition: compat.h:39
Definition: name.c:39
Definition: parse.h:23
unsigned char * p
Definition: parse.h:24
unsigned int size
Definition: parse.h:27
uint32_t ULONG
Definition: typedefs.h:59
Definition: dlist.c:348