Qualifiers are read from a file now.
[egate.git] / ccl / cclfind.c
index 76556a1..3288f87 100644 (file)
@@ -2,7 +2,10 @@
  * Europagate, 1995
  *
  * $Log: cclfind.c,v $
- * Revision 1.5  1995/02/14 14:12:41  adam
+ * Revision 1.6  1995/02/14 16:20:55  adam
+ * Qualifiers are read from a file now.
+ *
+ * Revision 1.5  1995/02/14  14:12:41  adam
  * Ranges for ordered qualfiers implemented (e.g. pd=1980-1990).
  *
  * Revision 1.4  1995/02/14  13:16:29  adam
@@ -45,6 +48,17 @@ static struct ccl_rpn_attr *qual_val (struct ccl_rpn_attr *list, int type)
     return NULL;
 }
 
+static int qual_val_type (struct ccl_rpn_attr *list, int type, int value)
+{
+    while (list)
+    {
+        if (list->type == type && list->value == value)
+            return 1;
+        list = list->next;
+    }
+    return 0;
+}
+
 static void strxcat (char *n, const char *src, int len)
 {
     while (*n)
@@ -122,6 +136,7 @@ static void add_attr (struct ccl_rpn_node *p, int type, int value)
 static struct ccl_rpn_node *search_term (struct ccl_rpn_attr **qa)
 {
     struct ccl_rpn_node *p;
+    struct ccl_rpn_attr *attr;
     struct ccl_token *lookahead = look_token;
     int len = 0;
     int no, i;
@@ -170,12 +185,11 @@ static struct ccl_rpn_node *search_term (struct ccl_rpn_attr **qa)
         if (i)
             strcat (p->u.t.term, " ");
        strxcat (p->u.t.term, src_str, src_len);
-       ADVANCE;
+        ADVANCE;
     }
     if (qa)
     {
         int i;
-        struct ccl_rpn_attr *attr;
         for (i=0; qa[i]; i++)
         {
             struct ccl_rpn_attr *attr;
@@ -184,21 +198,58 @@ static struct ccl_rpn_node *search_term (struct ccl_rpn_attr **qa)
                 if (attr->value > 0)
                     add_attr (p, attr->type, attr->value);
         }
-        if ((attr = qual_val (qa[0], CCL_BIB1_STR)) &&
-            attr->value == CCL_BIB1_STR_WP)
-        {
-            if (no == 1)
-                add_attr (p, CCL_BIB1_STR, 2);
-            else
-                add_attr (p, CCL_BIB1_STR, 1);
-        }
+        attr = qa[0];
+    }
+    else 
+        attr = ccl_qual_search (bibset, "term", 4);
+    if (attr && qual_val_type (attr, CCL_BIB1_STR, CCL_BIB1_STR_WP))
+    {
+        if (no == 1)
+            add_attr (p, CCL_BIB1_STR, 2);
+        else
+            add_attr (p, CCL_BIB1_STR, 1);
     }
     if (left_trunc && right_trunc)
+    {
+        if (attr && !qual_val_type (attr, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_BOTH))
+        {
+            ccl_error = CCL_ERR_TRUNC_NOT_BOTH;
+            if (qa)
+                free (qa);
+            ccl_rpn_delete (p);
+            return NULL;
+        }
         add_attr (p, CCL_BIB1_TRU, 3);
+    }
     else if (right_trunc)
+    {
+        if (attr && !qual_val_type (attr, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_RIGHT))
+        {
+            ccl_error = CCL_ERR_TRUNC_NOT_RIGHT;
+            if (qa)
+                free (qa);
+            ccl_rpn_delete (p);
+            return NULL;
+        }
         add_attr (p, CCL_BIB1_TRU, 1);
+    }
     else if (left_trunc)
+    {
+        if (attr && !qual_val_type (attr, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_LEFT))
+        {
+            ccl_error = CCL_ERR_TRUNC_NOT_LEFT;
+            if (qa)
+                free (qa);
+            ccl_rpn_delete (p);
+            return NULL;
+        }
         add_attr (p, CCL_BIB1_TRU, 2);
+    }
+    else
+    {
+        if (attr && qual_val_type (attr, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_NONE))
+            add_attr (p, CCL_BIB1_TRU, 100);
+    }
     return p;
 }
 
@@ -234,7 +285,8 @@ static struct ccl_rpn_node *qualifiers (struct ccl_token *la,
             ADVANCE;
     }
     ap[i] = NULL;
-    if (! (attr = qual_val (ap[0], CCL_BIB1_REL)) || attr->value == 3)
+    if (! (attr = qual_val (ap[0], CCL_BIB1_REL)) ||
+        attr->value != CCL_BIB1_REL_ORDER)
     {                
         /* unordered relation */
         struct ccl_rpn_node *p;