From: Adam Dickmeiss Date: Sat, 6 Jun 2015 18:06:21 +0000 (+0200) Subject: CCL: re-factor and use internal utility ccl_rpn_node_mkbool X-Git-Tag: v5.14.0~4 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=e484d47e2e06b836878786d9772d01cb764913c7;p=yaz-moved-to-github.git CCL: re-factor and use internal utility ccl_rpn_node_mkbool --- diff --git a/src/cclfind.c b/src/cclfind.c index 13714d6..9403634 100644 --- a/src/cclfind.c +++ b/src/cclfind.c @@ -113,6 +113,23 @@ struct ccl_rpn_node *ccl_rpn_node_create(enum ccl_rpn_kind kind) return p; } +static struct ccl_rpn_node *ccl_rpn_node_mkbool(struct ccl_rpn_node *l, + struct ccl_rpn_node *r, + enum ccl_rpn_kind op) +{ + if (l && r) + { + struct ccl_rpn_node *tmp = ccl_rpn_node_create(op); + tmp->u.p[0] = l; + tmp->u.p[1] = r; + tmp->u.p[2] = 0; + return tmp; + } + else if (r) + return r; + return l; +} + static struct ccl_rpn_node *ccl_rpn_dup(struct ccl_rpn_node *rpn) { struct ccl_rpn_node *n; @@ -606,16 +623,7 @@ static struct ccl_rpn_node *ccl_term_multi_use(CCL_parser cclp, ccl_rpn_delete(p); return 0; } - if (!p) - p = tmp2; - else - { - struct ccl_rpn_node *tmp1; - tmp1 = ccl_rpn_node_create(CCL_RPN_OR); - tmp1->u.p[0] = p; - tmp1->u.p[1] = tmp2; - p = tmp1; - } + p = ccl_rpn_node_mkbool(p, tmp2, CCL_RPN_OR); } } if (!p) @@ -652,15 +660,7 @@ static struct ccl_rpn_node *split_recur(CCL_parser cclp, ccl_qualifier_t *qa, p1 = split_recur(cclp, qa, p2, ar + l, sz - l); else p1 = p2; - if (p_top) - { - struct ccl_rpn_node *tmp = ccl_rpn_node_create(CCL_RPN_OR); - tmp->u.p[0] = p_top; - tmp->u.p[1] = p1; - p_top = tmp; - } - else - p_top = p1; + p_top = ccl_rpn_node_mkbool(p_top, p1, CCL_RPN_OR); } assert(p_top); return p_top; @@ -764,25 +764,7 @@ static struct ccl_rpn_node *search_term_x(CCL_parser cclp, ADVANCE; if (!p) return 0; - /* make the top node point to us.. */ - if (p_top) - { - struct ccl_rpn_node *tmp; - - if (or_list) - tmp = ccl_rpn_node_create(CCL_RPN_OR); - else if (and_list) - tmp = ccl_rpn_node_create(CCL_RPN_AND); - else - tmp = ccl_rpn_node_create(CCL_RPN_AND); - tmp->u.p[0] = p_top; - tmp->u.p[1] = p; - - p_top = tmp; - } - else - p_top = p; - + p_top = ccl_rpn_node_mkbool(p_top, p, or_list ? CCL_RPN_OR : CCL_RPN_AND); if (!multi) break; } @@ -1070,16 +1052,7 @@ static struct ccl_rpn_node *qualifier_list(CCL_parser cclp, xfree(ap); return 0; } - if (node) - { - struct ccl_rpn_node *node_this = - ccl_rpn_node_create(CCL_RPN_OR); - node_this->u.p[0] = node; - node_this->u.p[1] = node_sub; - node = node_this; - } - else - node = node_sub; + node = ccl_rpn_node_mkbool(node, node_sub, CCL_RPN_OR); seq++; } if (seq == 0) @@ -1142,16 +1115,7 @@ static struct ccl_rpn_node *qualifier_list(CCL_parser cclp, ccl_rpn_delete(node); break; } - if (node) - { - struct ccl_rpn_node *node_this = - ccl_rpn_node_create(CCL_RPN_OR); - node_this->u.p[0] = node; - node_this->u.p[1] = node_sub; - node = node_this; - } - else - node = node_sub; + node = ccl_rpn_node_mkbool(node, node_sub, CCL_RPN_OR); seq++; } } @@ -1284,17 +1248,7 @@ static struct ccl_rpn_node *search_elements(CCL_parser cclp, ccl_rpn_delete(node); return 0; } - if (node) - { - struct ccl_rpn_node *node_this = - ccl_rpn_node_create(CCL_RPN_OR); - node_this->u.p[0] = node; - node_this->u.p[1] = node_sub; - node_this->u.p[2] = 0; - node = node_this; - } - else - node = node_sub; + node = ccl_rpn_node_mkbool(node, node_sub, CCL_RPN_OR); } if (!node) node = search_terms(cclp, 0); @@ -1310,7 +1264,7 @@ static struct ccl_rpn_node *search_elements(CCL_parser cclp, */ static struct ccl_rpn_node *find_spec(CCL_parser cclp, ccl_qualifier_t *qa) { - struct ccl_rpn_node *p1, *p2, *pn; + struct ccl_rpn_node *p1, *p2; if (!(p1 = search_elements(cclp, qa))) return NULL; while (1) @@ -1325,11 +1279,7 @@ static struct ccl_rpn_node *find_spec(CCL_parser cclp, ccl_qualifier_t *qa) ccl_rpn_delete(p1); return NULL; } - pn = ccl_rpn_node_create(CCL_RPN_AND); - pn->u.p[0] = p1; - pn->u.p[1] = p2; - pn->u.p[2] = 0; - p1 = pn; + p1 = ccl_rpn_node_mkbool(p1, p2, CCL_RPN_AND); continue; case CCL_TOK_OR: ADVANCE; @@ -1339,11 +1289,7 @@ static struct ccl_rpn_node *find_spec(CCL_parser cclp, ccl_qualifier_t *qa) ccl_rpn_delete(p1); return NULL; } - pn = ccl_rpn_node_create(CCL_RPN_OR); - pn->u.p[0] = p1; - pn->u.p[1] = p2; - pn->u.p[2] = 0; - p1 = pn; + p1 = ccl_rpn_node_mkbool(p1, p2, CCL_RPN_OR); continue; case CCL_TOK_NOT: ADVANCE; @@ -1353,11 +1299,7 @@ static struct ccl_rpn_node *find_spec(CCL_parser cclp, ccl_qualifier_t *qa) ccl_rpn_delete(p1); return NULL; } - pn = ccl_rpn_node_create(CCL_RPN_NOT); - pn->u.p[0] = p1; - pn->u.p[1] = p2; - pn->u.p[2] = 0; - p1 = pn; + p1 = ccl_rpn_node_mkbool(p1, p2, CCL_RPN_NOT); continue; } break;