summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-04-16 00:35:48 (GMT)
committer John Mark Bell <jmb@netsurf-browser.org>2009-04-16 00:35:48 (GMT)
commit4d199c8f9a86f4188b6862786199c62648e1525a (patch)
tree8e7400360dd677b54229c57a40d7899f84e794b3
parent8f025108a574602e50d1090204ba30cf68047f54 (diff)
downloadlibhubbub-4d199c8f9a86f4188b6862786199c62648e1525a.tar.gz
libhubbub-4d199c8f9a86f4188b6862786199c62648e1525a.tar.bz2
A load of c89 compatibility fixes.
GCC 2.95 doesn't understand -Wno-unused-parameter svn path=/trunk/hubbub/; revision=7103
-rw-r--r--Makefile4
-rw-r--r--test/parser.c2
-rw-r--r--test/tokeniser2.c8
-rw-r--r--test/tokeniser3.c8
-rw-r--r--test/tree-buf.c38
-rw-r--r--test/tree.c13
-rw-r--r--test/tree2.c36
7 files changed, 69 insertions, 40 deletions
diff --git a/Makefile b/Makefile
index 37f5d70..a926773 100644
--- a/Makefile
+++ b/Makefile
@@ -46,7 +46,9 @@ ifeq ($(WANT_TEST),yes)
TESTLDFLAGS := $(TESTLDFLAGS) -ljson
endif
- TESTCFLAGS := $(TESTCFLAGS) -Wno-unused-parameter
+ ifneq ($(GCCVER),2)
+ TESTCFLAGS := $(TESTCFLAGS) -Wno-unused-parameter
+ endif
endif
# Extra installation rules
diff --git a/test/parser.c b/test/parser.c
index ca9a15c..1f7010a 100644
--- a/test/parser.c
+++ b/test/parser.c
@@ -25,7 +25,7 @@ static int run_test(int argc, char **argv, unsigned int CHUNK_SIZE)
hubbub_parser_optparams params;
FILE *fp;
size_t len, origlen;
- uint8_t buf[CHUNK_SIZE];
+ uint8_t *buf = alloca(CHUNK_SIZE);
const char *charset;
hubbub_charset_source cssource;
diff --git a/test/tokeniser2.c b/test/tokeniser2.c
index 59ea72f..82cbea0 100644
--- a/test/tokeniser2.c
+++ b/test/tokeniser2.c
@@ -149,14 +149,14 @@ void run_test(context *ctx)
if (ctx->last_start_tag != NULL) {
/* Fake up a start tag, in PCDATA state */
- uint8_t buf [strlen(ctx->last_start_tag) + 3];
+ size_t len = strlen(ctx->last_start_tag) + 3;
+ uint8_t *buf = alloca(len);
- snprintf((char *) buf, sizeof buf, "<%s>",
+ snprintf((char *) buf, len, "<%s>",
ctx->last_start_tag);
assert(parserutils_inputstream_append(stream,
- buf, strlen(ctx->last_start_tag) + 2) ==
- HUBBUB_OK);
+ buf, len - 1) == HUBBUB_OK);
assert(hubbub_tokeniser_run(tok) == HUBBUB_OK);
}
diff --git a/test/tokeniser3.c b/test/tokeniser3.c
index 95a5cbc..70e1e53 100644
--- a/test/tokeniser3.c
+++ b/test/tokeniser3.c
@@ -146,14 +146,14 @@ void run_test(context *ctx)
if (ctx->last_start_tag != NULL) {
/* Fake up a start tag, in PCDATA state */
- uint8_t buf [strlen(ctx->last_start_tag) + 3];
+ size_t len = strlen(ctx->last_start_tag) + 3;
+ uint8_t *buf = alloca(len);
- snprintf((char *) buf, sizeof buf, "<%s>",
+ snprintf((char *) buf, len, "<%s>",
ctx->last_start_tag);
assert(parserutils_inputstream_append(stream,
- buf, strlen(ctx->last_start_tag) + 2) ==
- HUBBUB_OK);
+ buf, len - 1) == HUBBUB_OK);
assert(hubbub_tokeniser_run(tok) == HUBBUB_OK);
}
diff --git a/test/tree-buf.c b/test/tree-buf.c
index 923573d..404c8f7 100644
--- a/test/tree-buf.c
+++ b/test/tree-buf.c
@@ -64,7 +64,7 @@ struct buf_t {
#define NUM_NAMESPACES 7
-const char const *ns_names[NUM_NAMESPACES] =
+const char * const ns_names[NUM_NAMESPACES] =
{ NULL, NULL /*html*/, "math", "svg", "xlink", "xml", "xmlns" };
@@ -199,6 +199,7 @@ int main(int argc, char **argv)
size_t *chunks;
size_t n_chunks;
hubbub_parser *parser;
+ uint32_t i;
buf_t got = { NULL, 0, 0 };
@@ -230,7 +231,7 @@ int main(int argc, char **argv)
chunks = malloc(n_chunks * sizeof(size_t));
assert(chunks != NULL);
- for (uint32_t i = 0; i < n_chunks; i++) {
+ for (i = 0; i < n_chunks; i++) {
assert(fgets(buf, sizeof(buf), fp) != NULL);
chunks[i] = atoi(buf);
}
@@ -240,7 +241,7 @@ int main(int argc, char **argv)
parser = setup_parser();
- for (uint32_t i = 0; i < n_chunks; i++) {
+ for (i = 0; i < n_chunks; i++) {
ssize_t bytes_read;
assert(chunks[i] <= sizeof(buf));
@@ -327,6 +328,7 @@ hubbub_error create_doctype(void *ctx, const hubbub_doctype *doctype,
hubbub_error create_element(void *ctx, const hubbub_tag *tag, void **result)
{
node_t *node = calloc(1, sizeof *node);
+ size_t i;
UNUSED(ctx);
@@ -342,7 +344,7 @@ hubbub_error create_element(void *ctx, const hubbub_tag *tag, void **result)
node->data.element.attrs = calloc(node->data.element.n_attrs,
sizeof *node->data.element.attrs);
- for (size_t i = 0; i < tag->n_attributes; i++) {
+ for (i = 0; i < tag->n_attributes; i++) {
attr_t *attr = &node->data.element.attrs[i];
assert(tag->attributes[i].ns < NUM_NAMESPACES);
@@ -553,6 +555,9 @@ hubbub_error clone_node(void *ctx, void *node, bool deep, void **result)
{
node_t *old_node = node;
node_t *new_node = calloc(1, sizeof *new_node);
+ node_t *last;
+ node_t *child;
+ size_t i;
new_node->type = old_node->type;
@@ -578,7 +583,7 @@ hubbub_error clone_node(void *ctx, void *node, bool deep, void **result)
new_node->data.element.attrs =
calloc(old_node->data.element.n_attrs,
sizeof *new_node->data.element.attrs);
- for (size_t i = 0; i < old_node->data.element.n_attrs; i++) {
+ for (i = 0; i < old_node->data.element.n_attrs; i++) {
attr_t *attr = &new_node->data.element.attrs[i];
attr->ns = old_node->data.element.attrs[i].ns;
@@ -602,9 +607,9 @@ hubbub_error clone_node(void *ctx, void *node, bool deep, void **result)
if (deep == false)
return 0;
- node_t *last = NULL;
+ last = NULL;
- for (node_t *child = old_node->child; child != NULL;
+ for (child = old_node->child; child != NULL;
child = child->next) {
node_t *n;
@@ -697,6 +702,7 @@ hubbub_error add_attributes(void *ctx, void *vnode,
{
node_t *node = vnode;
size_t old_elems = node->data.element.n_attrs;
+ size_t i;
UNUSED(ctx);
@@ -706,7 +712,7 @@ hubbub_error add_attributes(void *ctx, void *vnode,
node->data.element.n_attrs *
sizeof *node->data.element.attrs);
- for (size_t i = 0; i < n_attributes; i++) {
+ for (i = 0; i < n_attributes; i++) {
attr_t *attr = &node->data.element.attrs[old_elems + i];
assert(attributes[i].ns < NUM_NAMESPACES);
@@ -750,8 +756,11 @@ static int compare_attrs(const void *a, const void *b) {
static void indent(buf_t *buf, unsigned depth)
{
+ unsigned int i;
+
buf_add(buf, "| ");
- for (unsigned i = 0; i < depth; i++) {
+
+ for (i = 0; i < depth; i++) {
buf_add(buf, " ");
}
}
@@ -766,6 +775,8 @@ static void print_ns(buf_t *buf, hubbub_ns ns)
static void node_print(buf_t *buf, node_t *node, unsigned depth)
{
+ size_t i;
+
if (!node) return;
indent(buf, depth);
@@ -807,7 +818,7 @@ static void node_print(buf_t *buf, node_t *node, unsigned depth)
sizeof *node->data.element.attrs,
compare_attrs);
- for (size_t i = 0; i < node->data.element.n_attrs; i++) {
+ for (i = 0; i < node->data.element.n_attrs; i++) {
indent(buf, depth + 1);
print_ns(buf, node->data.element.attrs[i].ns);
buf_add(buf, node->data.element.attrs[i].name);
@@ -844,6 +855,9 @@ static void node_print(buf_t *buf, node_t *node, unsigned depth)
static void delete_node(node_t *node)
{
+ size_t i;
+ node_t *c, *d;
+
if (node == NULL)
return;
@@ -865,14 +879,12 @@ static void delete_node(node_t *node)
break;
case ELEMENT:
free(node->data.element.name);
- for (size_t i = 0; i < node->data.element.n_attrs; i++)
+ for (i = 0; i < node->data.element.n_attrs; i++)
delete_attr(&node->data.element.attrs[i]);
free(node->data.element.attrs);
break;
}
- node_t *c, *d;
-
for (c = node->child; c != NULL; c = d) {
d = c->next;
diff --git a/test/tree.c b/test/tree.c
index dee0893..9f48922 100644
--- a/test/tree.c
+++ b/test/tree.c
@@ -89,10 +89,11 @@ static int run_test(int argc, char **argv, unsigned int CHUNK_SIZE)
hubbub_parser_optparams params;
FILE *fp;
size_t len, origlen;
- uint8_t buf[CHUNK_SIZE];
+ uint8_t *buf = alloca(CHUNK_SIZE);
const char *charset;
hubbub_charset_source cssource;
bool passed = true;
+ uintptr_t n;
UNUSED(argc);
@@ -148,7 +149,7 @@ static int run_test(int argc, char **argv, unsigned int CHUNK_SIZE)
hubbub_parser_destroy(parser);
/* Ensure that all nodes have been released by the treebuilder */
- for (uintptr_t n = 1; n <= node_counter; n++) {
+ for (n = 1; n <= node_counter; n++) {
if (node_ref[n] != 0) {
printf("%" PRIuPTR " still referenced (=%u)\n", n, node_ref[n]);
passed = false;
@@ -232,11 +233,13 @@ hubbub_error create_doctype(void *ctx, const hubbub_doctype *doctype,
hubbub_error create_element(void *ctx, const hubbub_tag *tag, void **result)
{
+ uint32_t i;
+
printf("Creating (%" PRIuPTR ") [element '%.*s']\n", ++node_counter,
(int) tag->name.len, tag->name.ptr);
assert(memchr(tag->name.ptr, 0xff, tag->name.len) == NULL);
- for (uint32_t i = 0; i < tag->n_attributes; i++) {
+ for (i = 0; i < tag->n_attributes; i++) {
hubbub_attribute *attr = &tag->attributes[i];
assert(memchr(attr->name.ptr, 0xff, attr->name.len) == NULL);
@@ -382,13 +385,15 @@ hubbub_error form_associate(void *ctx, void *form, void *node)
hubbub_error add_attributes(void *ctx, void *node,
const hubbub_attribute *attributes, uint32_t n_attributes)
{
+ uint32_t i;
+
UNUSED(ctx);
UNUSED(attributes);
UNUSED(n_attributes);
printf("Adding attributes to %" PRIuPTR "\n", (uintptr_t) node);
- for (uint32_t i = 0; i < n_attributes; i++) {
+ for (i = 0; i < n_attributes; i++) {
const hubbub_attribute *attr = &attributes[i];
assert(memchr(attr->name.ptr, 0xff, attr->name.len) == NULL);
diff --git a/test/tree2.c b/test/tree2.c
index d6ae196..ee24655 100644
--- a/test/tree2.c
+++ b/test/tree2.c
@@ -64,7 +64,7 @@ struct buf_t {
#define NUM_NAMESPACES 7
-const char const *ns_names[NUM_NAMESPACES] =
+const char * const ns_names[NUM_NAMESPACES] =
{ NULL, NULL /*html*/, "math", "svg", "xlink", "xml", "xmlns" };
@@ -206,7 +206,7 @@ enum reading_state {
READING_DATA,
READING_DATA_AFTER_FIRST,
READING_ERRORS,
- READING_TREE,
+ READING_TREE
};
int main(int argc, char **argv)
@@ -406,6 +406,7 @@ hubbub_error create_doctype(void *ctx, const hubbub_doctype *doctype,
hubbub_error create_element(void *ctx, const hubbub_tag *tag, void **result)
{
+ size_t i;
node_t *node = calloc(1, sizeof *node);
UNUSED(ctx);
@@ -422,7 +423,7 @@ hubbub_error create_element(void *ctx, const hubbub_tag *tag, void **result)
node->data.element.attrs = calloc(node->data.element.n_attrs,
sizeof *node->data.element.attrs);
- for (size_t i = 0; i < tag->n_attributes; i++) {
+ for (i = 0; i < tag->n_attributes; i++) {
attr_t *attr = &node->data.element.attrs[i];
assert(tag->attributes[i].ns < NUM_NAMESPACES);
@@ -634,6 +635,9 @@ hubbub_error clone_node(void *ctx, void *node, bool deep, void **result)
{
node_t *old_node = node;
node_t *new_node = calloc(1, sizeof *new_node);
+ node_t *last;
+ node_t *child;
+ size_t i;
new_node->type = old_node->type;
@@ -659,7 +663,7 @@ hubbub_error clone_node(void *ctx, void *node, bool deep, void **result)
new_node->data.element.attrs =
calloc(old_node->data.element.n_attrs,
sizeof *new_node->data.element.attrs);
- for (size_t i = 0; i < old_node->data.element.n_attrs; i++) {
+ for (i = 0; i < old_node->data.element.n_attrs; i++) {
attr_t *attr = &new_node->data.element.attrs[i];
attr->ns = old_node->data.element.attrs[i].ns;
@@ -683,10 +687,9 @@ hubbub_error clone_node(void *ctx, void *node, bool deep, void **result)
if (deep == false)
return 0;
- node_t *last = NULL;
+ last = NULL;
- for (node_t *child = old_node->child; child != NULL;
- child = child->next) {
+ for (child = old_node->child; child != NULL; child = child->next) {
node_t *n;
clone_node(ctx, child, true, (void **) (void *) &n);
@@ -778,6 +781,7 @@ hubbub_error add_attributes(void *ctx, void *vnode,
{
node_t *node = vnode;
size_t old_elems = node->data.element.n_attrs;
+ size_t i;
UNUSED(ctx);
@@ -787,7 +791,7 @@ hubbub_error add_attributes(void *ctx, void *vnode,
node->data.element.n_attrs *
sizeof *node->data.element.attrs);
- for (size_t i = 0; i < n_attributes; i++) {
+ for (i = 0; i < n_attributes; i++) {
attr_t *attr = &node->data.element.attrs[old_elems + i];
assert(attributes[i].ns < NUM_NAMESPACES);
@@ -831,8 +835,11 @@ static int compare_attrs(const void *a, const void *b) {
static void indent(buf_t *buf, unsigned depth)
{
+ unsigned int i;
+
buf_add(buf, "| ");
- for (unsigned i = 0; i < depth; i++) {
+
+ for (i = 0; i < depth; i++) {
buf_add(buf, " ");
}
}
@@ -847,6 +854,8 @@ static void print_ns(buf_t *buf, hubbub_ns ns)
static void node_print(buf_t *buf, node_t *node, unsigned depth)
{
+ size_t i;
+
if (!node) return;
indent(buf, depth);
@@ -888,7 +897,7 @@ static void node_print(buf_t *buf, node_t *node, unsigned depth)
sizeof *node->data.element.attrs,
compare_attrs);
- for (size_t i = 0; i < node->data.element.n_attrs; i++) {
+ for (i = 0; i < node->data.element.n_attrs; i++) {
indent(buf, depth + 1);
print_ns(buf, node->data.element.attrs[i].ns);
buf_add(buf, node->data.element.attrs[i].name);
@@ -925,6 +934,9 @@ static void node_print(buf_t *buf, node_t *node, unsigned depth)
static void delete_node(node_t *node)
{
+ size_t i;
+ node_t *c, *d;
+
if (node == NULL)
return;
@@ -946,14 +958,12 @@ static void delete_node(node_t *node)
break;
case ELEMENT:
free(node->data.element.name);
- for (size_t i = 0; i < node->data.element.n_attrs; i++)
+ for (i = 0; i < node->data.element.n_attrs; i++)
delete_attr(&node->data.element.attrs[i]);
free(node->data.element.attrs);
break;
}
- node_t *c, *d;
-
for (c = node->child; c != NULL; c = d) {
d = c->next;