summaryrefslogtreecommitdiff
path: root/test/tree-buf.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/tree-buf.c')
-rw-r--r--test/tree-buf.c38
1 files changed, 25 insertions, 13 deletions
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;