- if ((p1 = get_xp_part(&pr, mem))) {
- if ((p2 = get_xp_part(&pr, mem))) {
- if (!strcmp (p2, "and") || !strcmp (p2, "or") || !strcmp (p2, "not")) {
- r1=nmem_malloc(mem, sizeof(struct xpath_predicate));
- r1->which = XPATH_PREDICATE_RELATION;
- r1->u.relation.name = p1;
- r1->u.relation.op = "";
- r1->u.relation.value = "";
-
- r2 = get_xpath_predicate (pr, mem);
-
- res = nmem_malloc(mem, sizeof(struct xpath_predicate));
- res->which = XPATH_PREDICATE_BOOLEAN;
- res->u.boolean.op = p2;
- res->u.boolean.left = r1;
- res->u.boolean.right = r2;
-
- return (res);
- }
-
- if (strchr("><=] ", *p2)) {
- r1 = nmem_malloc(mem, sizeof(struct xpath_predicate));
-
- r1->which = XPATH_PREDICATE_RELATION;
- r1->u.relation.name = p1;
- r1->u.relation.op = p2;
- r1->u.relation.value = "";
-
- if ((p3 = get_xp_part(&pr, mem))) {
- r1->u.relation.value = p3;
- } else {
- /* error */
- }
- }
-
- if ((p4 = get_xp_part(&pr, mem))) {
- if (!strcmp (p4, "and") || !strcmp (p4, "or") ||
- !strcmp (p4, "not"))
- {
-
- r2 = get_xpath_predicate (pr, mem);
-
- res = nmem_malloc(mem, sizeof(struct xpath_predicate));
- res->which = XPATH_PREDICATE_BOOLEAN;
- res->u.boolean.op = p4;
- res->u.boolean.left = r1;
- res->u.boolean.right = r2;
- return (res);
- } else {
- /* error */
- }
- } else {
- return (r1);
- }
-
- } else {
- r1 = nmem_malloc(mem, sizeof(struct xpath_predicate));
-
- r1->which = XPATH_PREDICATE_RELATION;
- r1->u.relation.name = p1;
- r1->u.relation.op = "";
- r1->u.relation.value = "";
-
- return (r1);
- }
+ while (*look && !*literal &&
+ (!strcmp(*look, "and") || !strcmp(*look, "or") ||
+ !strcmp(*look, "not")))
+ {
+ struct xpath_predicate *res, *right;
+
+ res = nmem_malloc(mem, sizeof(struct xpath_predicate));
+ res->which = XPATH_PREDICATE_BOOLEAN;
+ res->u.boolean.op = *look;
+ res->u.boolean.left = left;
+
+ *look = get_xp_part(pr, mem, literal); /* skip the boolean name */
+ right = get_xpath_relation(pr, mem, look, literal);
+
+ res->u.boolean.right = right;
+
+ left = res;