--- cfg_node.c 2004/12/31 19:16:25 1.25
+++ cfg_node.c 2005/01/24 14:25:21 1.26
@@ -427,17 +427,21 @@
{
cfg_rc_t rc;
+#if 0
fprintf(stderr, " step3: (1) cpSel=\"%s\", nSel=%d, spec=\"%s\", nFilMin=%ld, nFilMax=%ld, nFound=%ld\n",
cpSel, nSel, spec, nFilMin, nFilMax, *nFound);
+#endif
if (spec[0] == '\0') {
/* end of selection, node found */
(*nFound)++;
+#if 0
fprintf(stderr, " step3: (2) found node!!\n");
fprintf(stderr, " step3: current node=0x%lx type=%s token=\"%s\"\n",
(unsigned long)node,
(node != NULL ? (node->type == CFG_NODE_TYPE_SEQ ? "SEQ" : (node->type == CFG_NODE_TYPE_DIR ? "DIR" : "ARG")) : "<NULL>/.."),
(node != NULL ? (node->token != NULL ? node->token : "<NULL>") : "<NULL>/.."));
+#endif
if (nFilMin <= *nFound && *nFound <= nFilMax) {
if (result_len != NULL) {
(*result_len)++;
@@ -474,61 +478,79 @@
cfg_node_t *node2;
cfg_node_type_t type;
+#if 0
fprintf(stderr, " step2: (1) cpSel=\"%.*s\", nSel=%d, spec=\"%s\", nFilMin=%ld, nFilMax=%ld, nFound=%ld\n",
nSel, cpSel, nSel, spec, nFilMin, nFilMax, *nFound);
fprintf(stderr, " step2: current node=0x%lx type=%s token=\"%s\"\n",
(unsigned long)node,
(node != NULL ? (node->type == CFG_NODE_TYPE_SEQ ? "SEQ" : (node->type == CFG_NODE_TYPE_DIR ? "DIR" : "ARG")) : "<NULL>/.."),
(node != NULL ? (node->token != NULL ? node->token : "<NULL>") : "<NULL>/.."));
+#endif
rc = CFG_OK;
if (nSel == 1 && strncmp(cpSel, ".", nSel) == 0) {
/* current node (no-op) */
+#if 0
fprintf(stderr, " step2: search current node, starting at node 0x%lx\n", (unsigned long)node);
+#endif
rc = cfg_node_select_step3(cfg, node, result_vec, result_len, spec, cpSel, nSel, nFilMin, nFilMax, nFound);
}
else if (nSel == 2 && strncmp(cpSel, "..", nSel) == 0) {
/* parent node */
+#if 0
fprintf(stderr, " step2: search parent node, starting at node 0x%lx\n", (unsigned long)node);
+#endif
if (cfg_node_get(cfg, node, CFG_NODE_ATTR_PARENT, &node) == CFG_OK && node != NULL)
rc = cfg_node_select_step3(cfg, node, result_vec, result_len, spec, cpSel, nSel, nFilMin, nFilMax, nFound);
}
else if (nSel == 4 && strncmp(cpSel, "....", nSel) == 0) {
/* anchestor nodes */
+#if 0
fprintf(stderr, " step2: search ancestor nodes, starting at node 0x%lx\n", (unsigned long)node);
+#endif
while (cfg_node_get(cfg, node, CFG_NODE_ATTR_PARENT, &node) == CFG_OK && node != NULL)
if ((rc = cfg_node_select_step3(cfg, node, result_vec, result_len, spec, cpSel, nSel, nFilMin, nFilMax, nFound)) != CFG_OK)
break;
}
else if (nSel == 1 && strncmp(cpSel, "-", nSel) == 0) {
/* previous sibling node */
+#if 0
fprintf(stderr, " step2: search previous sibling node, starting at node 0x%lx\n", (unsigned long)node);
+#endif
if ((rc = cfg_node_get(cfg, node, CFG_NODE_ATTR_LBROTH, &node)) == CFG_OK && node != NULL)
rc = cfg_node_select_step3(cfg, node, result_vec, result_len, spec, cpSel, nSel, nFilMin, nFilMax, nFound);
}
else if (nSel == 2 && strncmp(cpSel, "--", nSel) == 0) {
/* preceeding sibling nodes */
+#if 0
fprintf(stderr, " step2: search preceeding sibling nodes, starting at node 0x%lx\n", (unsigned long)node);
+#endif
while (cfg_node_get(cfg, node, CFG_NODE_ATTR_LBROTH, &node) == CFG_OK && node != NULL)
if ((rc = cfg_node_select_step3(cfg, node, result_vec, result_len, spec, cpSel, nSel, nFilMin, nFilMax, nFound)) != CFG_OK)
break;
}
else if (nSel == 1 && strncmp(cpSel, "+", nSel) == 0) {
/* next sibling node */
+#if 0
fprintf(stderr, " step2: search next sibling node, starting at node 0x%lx\n", (unsigned long)node);
+#endif
if ((rc = cfg_node_get(cfg, node, CFG_NODE_ATTR_RBROTH, &node)) == CFG_OK && node != NULL)
rc = cfg_node_select_step3(cfg, node, result_vec, result_len, spec, cpSel, nSel, nFilMin, nFilMax, nFound);
}
else if (nSel == 2 && strncmp(cpSel, "++", nSel) == 0) {
/* following sibling nodes */
+#if 0
fprintf(stderr, " step2: search following sibling nodes, starting at node 0x%lx\n", (unsigned long)node);
+#endif
while (cfg_node_get(cfg, node, CFG_NODE_ATTR_RBROTH, &node) == CFG_OK && node != NULL)
if ((rc = cfg_node_select_step3(cfg, node, result_vec, result_len, spec, cpSel, nSel, nFilMin, nFilMax, nFound)) != CFG_OK)
break;
}
else if (nSel == 0 /* "//" */) {
/* descendant nodes */
+#if 0
fprintf(stderr, " step2: search descendant nodes, starting at node 0x%lx\n", (unsigned long)node);
+#endif
#if 0 /* FIXME */
if ((rc = cfg_node_apply(cfg, node, NULL, NULL, cfg_node_select_step2_descendant, &descendant_ctx)
cfg_rc_t cfg_node_select_step2_descendant(cfg_t *cfg, cfg_node_t *node, void *_ctx));
@@ -545,7 +567,9 @@
}
else {
/* child node */
+#if 0
fprintf(stderr, " step2: search child nodes, starting at node 0x%lx\n", (unsigned long)node);
+#endif
if ((rc = cfg_node_get(cfg, node, CFG_NODE_ATTR_CHILD1, &node)) == CFG_OK && node != NULL) {
do {
if ((rc = cfg_node_get(cfg, node, CFG_NODE_ATTR_TOKEN, &token)) != CFG_OK)
@@ -558,7 +582,9 @@
}
if (token != NULL) {
size_t l = strlen(token);
+#if 0
fprintf(stderr, " step2: compare child node: token \"%s\"\n", token);
+#endif
if ( (l == 1 && nSel == 1 && token[0] == '*')
|| (l == nSel && strncmp(token, cpSel, nSel) == 0)) {
if ((rc = cfg_node_select_step3(cfg, node, result_vec, result_len, spec, cpSel, nSel, nFilMin, nFilMax, nFound)) != CFG_OK)
@@ -588,7 +614,9 @@
cfg_rc_t rc;
long nFound;
+#if 0
fprintf(stderr, " step1: (0) spec=\"%s\"\n", spec);
+#endif
/* stop processing if spec is empty */
if (spec[0] == '\0')
@@ -625,18 +653,24 @@
cp++;
spec = cp;
+#if 0
fprintf(stderr, " step1: (1) cpSel=\"%s\", nSel=%d, spec=\"%s\", nFilMin=%ld, nFilMax=%ld\n",
cpSel, nSel, spec, nFilMin, nFilMax);
+#endif
/* perform pre-selection if filter range is relative to last element */
if (nFilMin < 0 || nFilMax < 0) {
nFound = 0;
+#if 0
fprintf(stderr, " step1: pre-selection start\n");
+#endif
if ((rc = cfg_node_select_step2(cfg, node, NULL, NULL, spec, cpSel, nSel, 1, LONG_MAX, &nFound)) != CFG_OK)
return rc;
+#if 0
fprintf(stderr, " step1: (1b) cpSel=\"%s\", nSel=%d, spec=\"%s\", nFilMin=%ld, nFilMax=%ld nFound=%ld\n",
cpSel, nSel, spec, nFilMin, nFilMax, nFound);
fprintf(stderr, " step1: pre-selection end\n");
+#endif
if (nFound == 0)
return CFG_OK;
if (nFilMin < 0) {
@@ -651,16 +685,20 @@
}
}
+#if 0
fprintf(stderr, " step1: (2) cpSel=\"%s\", nSel=%d, spec=\"%s\", nFilMin=%ld, nFilMax=%ld\n",
cpSel, nSel, spec, nFilMin, nFilMax);
+#endif
/* perform real selection */
nFound = 0;
if ((rc = cfg_node_select_step2(cfg, node, result_vec, result_len, spec, cpSel, nSel, nFilMin, nFilMax, &nFound)) != CFG_OK)
return rc;
+#if 0
fprintf(stderr, " step1: (3) cpSel=\"%s\", nSel=%d, spec=\"%s\", nFilMin=%ld, nFilMax=%ld nFound=%ld\n",
cpSel, nSel, spec, nFilMin, nFilMax, nFound);
+#endif
return CFG_OK;
}
@@ -690,7 +728,9 @@
va_end(ap);
if (spec == NULL)
return CFG_ERR_FMT;
+#if 0
fprintf(stderr, "select: (1) spec=\"%s\"\n", spec);
+#endif
/* special cases for absolute (start from root-node) selection */
cp = spec;
@@ -705,7 +745,9 @@
/* <NULL, "..."> is same as <root, "..."> */
node = cfg->root;
}
+#if 0
fprintf(stderr, "select: (2) spec=\"%s\"\n", cp);
+#endif
/* initialize result node array */
result_len = 0;
@@ -718,7 +760,9 @@
free(*result_vec);
return rc;
}
+#if 0
fprintf(stderr, "select: (3) result_len=%ld\n", result_len);
+#endif
return CFG_OK;
}
|