Implemented ccl_pquery to convert from CCL tree to prefix query.
[yaz-moved-to-github.git] / zutil / pquery.c
index a302244..6f35004 100644 (file)
@@ -4,7 +4,13 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: pquery.c,v $
- * Revision 1.1  1999-06-08 10:10:16  adam
+ * Revision 1.3  1999-12-20 15:20:13  adam
+ * Implemented ccl_pquery to convert from CCL tree to prefix query.
+ *
+ * Revision 1.2  1999/11/30 13:47:12  adam
+ * Improved installation. Moved header files to include/yaz.
+ *
+ * Revision 1.1  1999/06/08 10:10:16  adam
  * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
  *
  * Revision 1.22  1999/04/20 09:56:49  adam
 #include <string.h>
 #include <stdlib.h>
 
-#include <proto.h>
-#include <oid.h>
-
-#include <pquery.h>
+#include <yaz/proto.h>
+#include <yaz/oid.h>
+#include <yaz/pquery.h>
 
 static oid_value p_query_dfset = VAL_NONE;
 
@@ -397,6 +402,7 @@ static Z_RPNStructure *rpn_structure (struct lex_info *li, ODR o,
 {
     Z_RPNStructure *sz;
     const char *cp;
+    int i, attrtype;
 
     sz = (Z_RPNStructure *)odr_malloc (o, sizeof(*sz));
     switch (li->query_look)
@@ -443,9 +449,19 @@ static Z_RPNStructure *rpn_structure (struct lex_info *li, ODR o,
             else
                 attr_set[num_attr] = VAL_NONE;
         }
-        attr_list[2*num_attr] = atoi (li->lex_buf);
-        attr_list[2*num_attr+1] = atoi (cp+1);
-        num_attr++;
+        attrtype = atoi (li->lex_buf);
+        for (i = 0; i < num_attr; i++)
+           if (attrtype == attr_list[2*i])
+           {
+               attr_list[2*i+1] = atoi (cp+1);
+               break;
+           }
+       if (i == num_attr)
+       {
+           attr_list[2*num_attr] = attrtype;
+           attr_list[2*num_attr+1] = atoi (cp+1);
+           num_attr++;
+       }
         lex (li);
         return
             rpn_structure (li, o, proto, num_attr, max_attr, attr_list,