version 1.6, 2019/04/09 01:39:09 |
version 1.7, 2019/04/10 14:22:37 |
Line 78 attrval_parse(const char *name) |
|
Line 78 attrval_parse(const char *name) |
|
* Recursively free a node (NULL is ok). |
* Recursively free a node (NULL is ok). |
*/ |
*/ |
static void |
static void |
pnode_free(struct pnode *pn) |
pnode_free(struct pnode *n) |
{ |
{ |
struct pnode *pch; |
struct pnode *nc; |
struct pattr *ap; |
struct pattr *a; |
|
|
if (pn == NULL) |
if (n == NULL) |
return; |
return; |
|
|
while ((pch = TAILQ_FIRST(&pn->childq)) != NULL) { |
while ((nc = TAILQ_FIRST(&n->childq)) != NULL) { |
TAILQ_REMOVE(&pn->childq, pch, child); |
TAILQ_REMOVE(&n->childq, nc, child); |
pnode_free(pch); |
pnode_free(nc); |
} |
} |
while ((ap = TAILQ_FIRST(&pn->attrq)) != NULL) { |
while ((a = TAILQ_FIRST(&n->attrq)) != NULL) { |
TAILQ_REMOVE(&pn->attrq, ap, child); |
TAILQ_REMOVE(&n->attrq, a, child); |
free(ap->rawval); |
free(a->rawval); |
free(ap); |
free(a); |
} |
} |
free(pn->real); |
free(n->real); |
free(pn); |
free(n); |
} |
} |
|
|
/* |
/* |
* Unlink a node from its parent and pnode_free() it. |
* Unlink a node from its parent and pnode_free() it. |
*/ |
*/ |
void |
void |
pnode_unlink(struct pnode *pn) |
pnode_unlink(struct pnode *n) |
{ |
{ |
if (pn == NULL) |
if (n == NULL) |
return; |
return; |
if (pn->parent != NULL) |
if (n->parent != NULL) |
TAILQ_REMOVE(&pn->parent->childq, pn, child); |
TAILQ_REMOVE(&n->parent->childq, n, child); |
pnode_free(pn); |
pnode_free(n); |
} |
} |
|
|
/* |
/* |
* Unlink all children of a node and pnode_free() them. |
* Unlink all children of a node and pnode_free() them. |
*/ |
*/ |
void |
void |
pnode_unlinksub(struct pnode *pn) |
pnode_unlinksub(struct pnode *n) |
{ |
{ |
while (TAILQ_EMPTY(&pn->childq) == 0) |
while (TAILQ_EMPTY(&n->childq) == 0) |
pnode_unlink(TAILQ_FIRST(&pn->childq)); |
pnode_unlink(TAILQ_FIRST(&n->childq)); |
} |
} |
|
|
/* |
/* |
Line 127 pnode_unlinksub(struct pnode *pn) |
|
Line 127 pnode_unlinksub(struct pnode *pn) |
|
* Return ATTRVAL__MAX if the node has no such attribute. |
* Return ATTRVAL__MAX if the node has no such attribute. |
*/ |
*/ |
enum attrval |
enum attrval |
pnode_getattr(struct pnode *pn, enum attrkey key) |
pnode_getattr(struct pnode *n, enum attrkey key) |
{ |
{ |
struct pattr *ap; |
struct pattr *a; |
|
|
if (pn == NULL) |
if (n == NULL) |
return ATTRVAL__MAX; |
return ATTRVAL__MAX; |
TAILQ_FOREACH(ap, &pn->attrq, child) |
TAILQ_FOREACH(a, &n->attrq, child) |
if (ap->key == key) |
if (a->key == key) |
return ap->val; |
return a->val; |
return ATTRVAL__MAX; |
return ATTRVAL__MAX; |
} |
} |
|
|
Line 144 pnode_getattr(struct pnode *pn, enum attrkey key) |
|
Line 144 pnode_getattr(struct pnode *pn, enum attrkey key) |
|
* Return defval if the node has no such attribute. |
* Return defval if the node has no such attribute. |
*/ |
*/ |
const char * |
const char * |
pnode_getattr_raw(struct pnode *pn, enum attrkey key, const char *defval) |
pnode_getattr_raw(struct pnode *n, enum attrkey key, const char *defval) |
{ |
{ |
struct pattr *ap; |
struct pattr *a; |
|
|
if (pn == NULL) |
if (n == NULL) |
return defval; |
return defval; |
TAILQ_FOREACH(ap, &pn->attrq, child) |
TAILQ_FOREACH(a, &n->attrq, child) |
if (ap->key == key) |
if (a->key == key) |
return ap->val != ATTRVAL__MAX ? attrvals[ap->val] : |
return a->val != ATTRVAL__MAX ? attrvals[a->val] : |
ap->rawval != NULL ? ap->rawval : defval; |
a->rawval != NULL ? a->rawval : defval; |
return defval; |
return defval; |
} |
} |
|
|
Line 161 pnode_getattr_raw(struct pnode *pn, enum attrkey key, |
|
Line 161 pnode_getattr_raw(struct pnode *pn, enum attrkey key, |
|
* Recursively search and return the first instance of "node". |
* Recursively search and return the first instance of "node". |
*/ |
*/ |
struct pnode * |
struct pnode * |
pnode_findfirst(struct pnode *pn, enum nodeid node) |
pnode_findfirst(struct pnode *n, enum nodeid node) |
{ |
{ |
struct pnode *pch, *res; |
struct pnode *nc, *res; |
|
|
if (pn->node == node) |
if (n->node == node) |
return pn; |
return n; |
TAILQ_FOREACH(pch, &pn->childq, child) |
TAILQ_FOREACH(nc, &n->childq, child) |
if ((res = pnode_findfirst(pch, node)) != NULL) |
if ((res = pnode_findfirst(nc, node)) != NULL) |
return res; |
return res; |
return NULL; |
return NULL; |
} |
} |