void xode_put_attrib(xode owner, const char* name, const char* value) { xode attrib; if(owner == NULL || name == NULL || value == NULL) return; /* If there are no existing attributes, allocate a new one to start the list */ if (owner->firstattrib == NULL) { attrib = _xode_new(owner->p, name, XODE_TYPE_ATTRIB); owner->firstattrib = attrib; owner->lastattrib = attrib; } else { attrib = _xode_search(owner->firstattrib, name, XODE_TYPE_ATTRIB); if(attrib == NULL) { attrib = _xode_appendsibling(owner->lastattrib, name, XODE_TYPE_ATTRIB); owner->lastattrib = attrib; } } /* Update the value of the attribute */ attrib->data_sz = strlen(value); attrib->data = xode_pool_strdup(owner->p, value); }
/* Internal routines */ static xode _xode_new(xode_pool p, const char* name, unsigned int type) { xode result = NULL; if (type > XODE_TYPE_LAST) return NULL; if (type != XODE_TYPE_CDATA && name == NULL) return NULL; if (p == NULL) { p = xode_pool_heap(1*1024); } /* Allocate & zero memory */ result = (xode)xode_pool_malloc(p, sizeof(_xode)); memset(result, '\0', sizeof(_xode)); /* Initialize fields */ if (type != XODE_TYPE_CDATA) result->name = xode_pool_strdup(p,name); result->type = type; result->p = p; return result; }
void xode_spool_add(xode_spool s, char *str) { struct xode_spool_node *sn; int len; if(str == NULL) return; len = strlen(str); if(len == 0) return; sn = xode_pool_malloc(s->p, sizeof(struct xode_spool_node)); sn->c = xode_pool_strdup(s->p, str); sn->next = NULL; s->len += len; if(s->last != NULL) s->last->next = sn; s->last = sn; if(s->first == NULL) s->first = sn; }
/* when move above, this one would actually return a new block */ char *xode_pool_strdupx(xode_pool p, const char *src) { return xode_pool_strdup(p, src); }