Changed CCL parser to be thread safe. New type, CCL-parser, declared
[yaz-moved-to-github.git] / include / ccl.h
index e40777d..d6ed51d 100644 (file)
  * CCL - header file
  *
  * $Log: ccl.h,v $
- * Revision 1.4  1996-10-11 15:02:26  adam
+ * Revision 1.8  1997-09-29 09:01:19  adam
+ * Changed CCL parser to be thread safe. New type, CCL-parser, declared
+ * and a create/destructor ccl_parser_create/ccl_parser_destroy has been
+ * added.
+ *
+ * Revision 1.7  1997/09/01 08:49:47  adam
+ * New windows NT/95 port using MSV5.0. To export DLL functions the
+ * YAZ_EXPORT modifier was added. Defined in yconfig.h.
+ *
+ * Revision 1.6  1997/05/14 06:53:37  adam
+ * C++ support.
+ *
+ * Revision 1.5  1997/04/30 08:52:08  quinn
+ * Null
+ *
+ * Revision 1.4  1996/10/11  15:02:26  adam
  * CCL parser from Europagate Email gateway 1.0.
  *
  * Revision 1.10  1996/01/08  08:41:22  adam
 #ifndef CCL_H
 #define CCL_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+    
 /* CCL error numbers */
 #define CCL_ERR_OK                0
 #define CCL_ERR_TERM_EXPECTED     1
 #define CCL_ERR_TRUNC_NOT_LEFT   10
 #define CCL_ERR_TRUNC_NOT_BOTH   11
 #define CCL_ERR_TRUNC_NOT_RIGHT  12
-
+    
 /* attribute pair (type, value) */
 struct ccl_rpn_attr {
     struct ccl_rpn_attr *next;
@@ -107,14 +126,16 @@ struct ccl_rpn_attr {
     int value;
 };
 
+#define CCL_RPN_AND 1
+#define CCL_RPN_OR 2
+#define CCL_RPN_NOT 3
+#define CCL_RPN_TERM 4
+#define CCL_RPN_SET 5
+#define CCL_RPN_PROX 6
+
 /* RPN tree structure */
 struct ccl_rpn_node {
-    enum rpn_node_kind {
-        CCL_RPN_AND, CCL_RPN_OR, CCL_RPN_NOT,
-        CCL_RPN_TERM,
-        CCL_RPN_SET,
-        CCL_RPN_PROX
-    } kind;
+    int kind;
     union {
        struct ccl_rpn_node *p[2];
        struct {
@@ -187,7 +208,7 @@ typedef struct ccl_qualifiers *CCL_bibset;
 /* CCL token */
 struct ccl_token {
     char kind;
-    char len;
+    size_t len;
     const char *name;
     struct ccl_token *next;
     struct ccl_token *prev;
@@ -200,9 +221,31 @@ struct ccl_qualifier {
     struct ccl_qualifier *next;
 };
 
+struct ccl_parser {
+/* current lookahead token */
+    struct ccl_token *look_token;
+    
+/* holds error code if error occur (and approx position of error) */
+    int error_code;
+    const char *error_pos;
+    
+/* current bibset */
+    CCL_bibset bibset;
+    
+    char *ccl_token_and;
+    char *ccl_token_or;
+    char *ccl_token_not;
+    char *ccl_token_set;
+    int ccl_case_sensitive;
+};
+    
+typedef struct ccl_parser *CCL_parser;
+    
 /* Generate tokens from command string - obeys all CCL opererators */
+struct ccl_token *ccl_parser_tokenize (CCL_parser cclp,
+                                      const char *command);
 struct ccl_token *ccl_tokenize (const char *command);
-
+    
 /* Generate tokens from command string - oebeys only simple tokens and 
    quoted strings */
 struct ccl_token *ccl_token_simple (const char *command);
@@ -242,15 +285,6 @@ CCL_bibset ccl_qual_mk (void);
 /* Delete CCL qualifier set */
 void ccl_qual_rm (CCL_bibset *b);
 
-/* Misc. reserved words */
-extern const char *ccl_token_and;
-extern const char *ccl_token_or;
-extern const char *ccl_token_not;
-extern const char *ccl_token_set;
-
-/* Whether the CCL parser is command sensitive */
-extern int ccl_case_sensitive;
-
 /* Char-to-upper function */
 extern int (*ccl_toupper)(int c);
 
@@ -259,6 +293,18 @@ int ccl_stricmp (const char *s1, const char *s2);
 int ccl_memicmp (const char *s1, const char *s2, size_t n);
 
 /* Search for qualifier 'name' in set 'b'. */
-struct ccl_rpn_attr *ccl_qual_search (CCL_bibset b, const char *name, int len);
+struct ccl_rpn_attr *ccl_qual_search (CCL_parser cclp, const char *name,
+                                      size_t len);
+
+/* Create CCL parser */
+CCL_parser ccl_parser_create (void);
+
+/* Destroy CCL parser */
+void ccl_parser_destroy (CCL_parser p);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif