-
- /* go through all attributes and add them to the attribute list */
- for (i=0; qa && qa[i]; i++)
- {
- struct ccl_rpn_attr *attr;
-
- for (attr = qa[i]; attr; attr = attr->next)
- if (attr->value > 0)
- { /* deal only with REAL attributes (positive) */
- switch (attr->type)
- {
- case CCL_BIB1_REL:
- if (relation_value != -1)
- continue;
- relation_value = attr->value;
- break;
- case CCL_BIB1_POS:
- if (position_value != -1)
- continue;
- position_value = attr->value;
- break;
- case CCL_BIB1_STR:
- if (structure_value != -1)
- continue;
- structure_value = attr->value;
- break;
- case CCL_BIB1_TRU:
- if (truncation_value != -1)
- continue;
- truncation_value = attr->value;
- left_trunc = right_trunc = mid_trunc = 0;
- break;
- case CCL_BIB1_COM:
- if (completeness_value != -1)
- continue;
- completeness_value = attr->value;
- break;
- }
- add_attr (p, attr->type, attr->value);
- }
- }
- /* len now holds the number of characters in the RPN term */
- /* no holds the number of CCL tokens (1 or more) */
-
- if (structure_value == -1 &&
- qual_val_type (qa, CCL_BIB1_STR, CCL_BIB1_STR_WP))
- { /* no structure attribute met. Apply either structure attribute
- WORD or PHRASE depending on number of CCL tokens */
- if (no == 1)
- add_attr (p, CCL_BIB1_STR, 2);
- else
- add_attr (p, CCL_BIB1_STR, 1);
- }
-
- /* make the RPN token */
- p->u.t.term = (char *)malloc (len);
- ccl_assert (p->u.t.term);
- p->u.t.term[0] = '\0';
- for (i = 0; i<no; i++)
- {
- const char *src_str = cclp->look_token->name;
- int src_len = cclp->look_token->len;
-
- if (i == 0 && left_trunc)
- {
- src_len--;
- src_str++;
- }
- else if (i == no-1 && right_trunc)
- src_len--;
- if (src_len)
- {
- int len = strlen(p->u.t.term);
- if (len &&
- !strchr("-+", *src_str) &&
- !strchr("-+", p->u.t.term[len-1]))
- {
- strcat (p->u.t.term, " ");
- }
- }
- strxcat (p->u.t.term, src_str, src_len);
- ADVANCE;
- }
- if (left_trunc && right_trunc)
- {
- if (!qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_BOTH))
- {
- cclp->error_code = CCL_ERR_TRUNC_NOT_BOTH;
- ccl_rpn_delete (p);
- return NULL;
- }
- add_attr (p, CCL_BIB1_TRU, 3);
- }
- else if (right_trunc)
- {
- if (!qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_RIGHT))
- {
- cclp->error_code = CCL_ERR_TRUNC_NOT_RIGHT;
- ccl_rpn_delete (p);
- return NULL;
- }
- add_attr (p, CCL_BIB1_TRU, 1);
- }
- else if (left_trunc)
- {
- if (!qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_LEFT))
- {
- cclp->error_code = CCL_ERR_TRUNC_NOT_LEFT;
- ccl_rpn_delete (p);
- return NULL;
- }
- add_attr (p, CCL_BIB1_TRU, 2);
- }
- else
- {
- if (qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_NONE))
- add_attr (p, CCL_BIB1_TRU, 100);
- }
+ if (len == 0)
+ break; /* no more terms . stop . */
+
+
+ if (p_top)
+ {
+ if (or_list)
+ p = mk_node (CCL_RPN_OR);
+ else if (and_list)
+ p = mk_node (CCL_RPN_AND);
+ else
+ p = mk_node (CCL_RPN_AND);
+ p->u.p[0] = p_top;
+ p_top = p;
+ }
+
+ /* create the term node, but wait a moment before adding the term */
+ p = mk_node (CCL_RPN_TERM);
+ p->u.t.attr_list = NULL;
+ p->u.t.term = NULL;
+
+ /* make the top node point to us.. */
+ if (p_top)
+ p_top->u.p[1] = p;
+ else
+ p_top = p;
+
+
+ /* go through all attributes and add them to the attribute list */
+ for (i=0; qa && qa[i]; i++)
+ {
+ struct ccl_rpn_attr *attr;
+
+ for (attr = qa[i]; attr; attr = attr->next)
+ if (attr->value > 0)
+ { /* deal only with REAL attributes (positive) */
+ switch (attr->type)
+ {
+ case CCL_BIB1_REL:
+ if (relation_value != -1)
+ continue;
+ relation_value = attr->value;
+ break;
+ case CCL_BIB1_POS:
+ if (position_value != -1)
+ continue;
+ position_value = attr->value;
+ break;
+ case CCL_BIB1_STR:
+ if (structure_value != -1)
+ continue;
+ structure_value = attr->value;
+ break;
+ case CCL_BIB1_TRU:
+ if (truncation_value != -1)
+ continue;
+ truncation_value = attr->value;
+ left_trunc = right_trunc = mid_trunc = 0;
+ break;
+ case CCL_BIB1_COM:
+ if (completeness_value != -1)
+ continue;
+ completeness_value = attr->value;
+ break;
+ }
+ add_attr (p, attr->set, attr->type, attr->value);
+ }
+ }
+ /* len now holds the number of characters in the RPN term */
+ /* no holds the number of CCL tokens (1 or more) */
+
+ if (structure_value == -1 &&
+ qual_val_type (qa, CCL_BIB1_STR, CCL_BIB1_STR_WP, &attset))
+ { /* no structure attribute met. Apply either structure attribute
+ WORD or PHRASE depending on number of CCL tokens */
+ if (no == 1 && no_spaces == 0)
+ add_attr (p, attset, CCL_BIB1_STR, 2);
+ else
+ add_attr (p, attset, CCL_BIB1_STR, 1);
+ }
+
+ /* make the RPN token */
+ p->u.t.term = (char *)xmalloc (len);
+ ccl_assert (p->u.t.term);
+ p->u.t.term[0] = '\0';
+ for (i = 0; i<no; i++)
+ {
+ const char *src_str = cclp->look_token->name;
+ int src_len = cclp->look_token->len;
+
+ if (i == 0 && left_trunc)
+ {
+ src_len--;
+ src_str++;
+ }
+ else if (i == no-1 && right_trunc)
+ src_len--;
+ if (src_len)
+ {
+ int len = strlen(p->u.t.term);
+ if (len &&
+ !strchr("-+", *src_str) &&
+ !strchr("-+", p->u.t.term[len-1]))
+ {
+ strcat (p->u.t.term, " ");
+ }
+ }
+ strxcat (p->u.t.term, src_str, src_len);
+ ADVANCE;
+ }
+ if (left_trunc && right_trunc)
+ {
+ if (!qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_BOTH,
+ &attset))
+ {
+ cclp->error_code = CCL_ERR_TRUNC_NOT_BOTH;
+ ccl_rpn_delete (p);
+ return NULL;
+ }
+ add_attr (p, attset, CCL_BIB1_TRU, 3);
+ }
+ else if (right_trunc)
+ {
+ if (!qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_RIGHT,
+ &attset))
+ {
+ cclp->error_code = CCL_ERR_TRUNC_NOT_RIGHT;
+ ccl_rpn_delete (p);
+ return NULL;
+ }
+ add_attr (p, attset, CCL_BIB1_TRU, 1);
+ }
+ else if (left_trunc)
+ {
+ if (!qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_LEFT,
+ &attset))
+ {
+ cclp->error_code = CCL_ERR_TRUNC_NOT_LEFT;
+ ccl_rpn_delete (p);
+ return NULL;
+ }
+ add_attr (p, attset, CCL_BIB1_TRU, 2);
+ }
+ else
+ {
+ if (qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_NONE,
+ &attset))
+ add_attr (p, attset, CCL_BIB1_TRU, 100);
+ }
+ if (!multi)
+ break;