+Clean-up the CCL API. Moved some internal structures from ccl.h to
+private header cclp.h. Changed ccl_parser_create so that a Bibset must
+be supplied. Removed tokenize API from ccl.h - including ccl_parser_find.
+This is replaced by ccl_parser_find_str which takes a string instead.
+
Split YAZ library into two libs : libyaz.la and libyaz_server.la.
libyaz.la is the core of YAZ except the generic frontend server and
does not depend on POSIX threads anymore. libyaz_server.la is the
/*
* CCL - header file
*
- * $Id: ccl.h,v 1.23 2005-06-25 15:46:01 adam Exp $
+ * $Id: ccl.h,v 1.24 2007-04-25 20:52:18 adam Exp $
*
* Old Europagate Log:
*
#define CCL_BIB1_TRU_CAN_BOTH (-3)
#define CCL_BIB1_TRU_CAN_NONE (-4)
-#define CCL_TOK_EOL 0
-#define CCL_TOK_TERM 1
-#define CCL_TOK_REL 2
-#define CCL_TOK_EQ 3
-#define CCL_TOK_PROX 4
-#define CCL_TOK_LP 5
-#define CCL_TOK_RP 6
-#define CCL_TOK_COMMA 7
-#define CCL_TOK_AND 8
-#define CCL_TOK_OR 9
-#define CCL_TOK_NOT 10
-#define CCL_TOK_SET 11
-
-/** CCL token */
-struct ccl_token {
- char kind;
- size_t len; /* length of name below */
- const char *name; /* string / name of token */
- struct ccl_token *next;
- struct ccl_token *prev;
- const char *ws_prefix_buf; /* leading white space buf */
- size_t ws_prefix_len; /* leading white space len */
-};
-
-/** CCL Qualifier */
-struct ccl_qualifier {
- char *name;
- int no_sub;
- struct ccl_qualifier **sub;
- struct ccl_rpn_attr *attr_list;
- struct ccl_qualifier *next;
-};
-
-/** CCL parser structure */
-struct ccl_parser {
- /** current lookahead token */
- struct ccl_token *look_token;
-
- /** holds error code if error occur */
- int error_code;
- /** if error occurs, this holds position (starting from 0). */
- const char *error_pos;
-
- /** current bibset */
- CCL_bibset bibset;
-
- /** names of and operator */
- char *ccl_token_and;
- /** names of or operator */
- char *ccl_token_or;
- /** names of not operator */
- char *ccl_token_not;
- /** names of set operator */
- char *ccl_token_set;
- /** 1=CCL parser is case sensitive, 0=case insensitive */
- int ccl_case_sensitive;
-};
-
typedef struct ccl_parser *CCL_parser;
/**
- * Splits CCL command string into individual tokens using
- * a CCL parser.
- */
-YAZ_EXPORT
-struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command);
-
-/**
- * Splits CCL command string into tokens using temporary parser.
- *
- * Use ccl_parser_tokenize instead and provide a parser - it is
- * more flexible and efficient.
- */
-YAZ_EXPORT
-struct ccl_token *ccl_tokenize (const char *command);
-
-/**
- * Deletes token list
- */
-YAZ_EXPORT
-void ccl_token_del (struct ccl_token *list);
-
-/**
- * Add single token after a given onde.
- */
-YAZ_EXPORT
-struct ccl_token *ccl_token_add (struct ccl_token *at);
-
-/**
* Parses a CCL Find command in a simple C string. Returns CCL parse
* tree node describing RPN if parsing is successful. If parsing is
* unsuccesful, NULL is returned and error and pos is set accordingly.
struct ccl_rpn_node *ccl_find_str (CCL_bibset bibset,
const char *str, int *error, int *pos);
-/**
- * Parses CCL Find command from a list of CCL tokens. Otherwise similar to
- * ccl_find_str.
- */
YAZ_EXPORT
-struct ccl_rpn_node *ccl_find (CCL_bibset abibset, struct ccl_token *list,
- int *error, const char **pos);
-
-/**
- * Parses a CCL Find command from a list of CCL tokens and given a CCL
- * parser. Otherwise similar to ccl_find_str.
- */
-YAZ_EXPORT
-struct ccl_rpn_node *ccl_parser_find (CCL_parser cclp, struct ccl_token *list);
+struct ccl_rpn_node *ccl_parser_find_str(CCL_parser cclp, const char *str);
/** Set names for AND operator in parser */
YAZ_EXPORT
/** Create CCL parser */
YAZ_EXPORT
-CCL_parser ccl_parser_create (void);
+CCL_parser ccl_parser_create (CCL_bibset bibset);
/** Destroy CCL parser */
YAZ_EXPORT
/** Search for special qualifier */
YAZ_EXPORT
-const char *ccl_qual_search_special (CCL_bibset b,
- const char *name);
+const char *ccl_qual_search_special (CCL_bibset b, const char *name);
/** Pretty-print CCL RPN node tree to WRBUF */
YAZ_EXPORT
void ccl_pquery (WRBUF w, struct ccl_rpn_node *p);
+YAZ_EXPORT
+CCL_bibset ccl_parser_get_bibset(CCL_parser cclp);
+
+YAZ_EXPORT
+int ccl_parser_get_error(CCL_parser cclp, int *pos);
+
#ifndef ccl_assert
#define ccl_assert(x) ;
#endif
## This file is part of the YAZ toolkit.
## Copyright (C) 1995-2007, Index Data, All rights reserved.
-## $Id: Makefile.am,v 1.63 2007-04-18 08:08:02 adam Exp $
+## $Id: Makefile.am,v 1.64 2007-04-25 20:52:19 adam Exp $
YAZ_VERSION_INFO=3:0:0
otherinfo.c pquery.c sortspec.c charneg.c initopt.c \
zoom-c.c zoom-socket.c zoom-opt.c zoom-p.h \
grs1disp.c zgdu.c soap.c srw.c srwutil.c \
- opacdisp.c cclfind.c ccltoken.c cclerrms.c cclqual.c cclptree.c \
+ opacdisp.c cclfind.c ccltoken.c cclerrms.c cclqual.c cclptree.c cclp.h \
cclqfile.c cclstr.c cclxmlconfig.c \
cql.y cqlstdio.c cqltransform.c cqlutil.c xcqlutil.c cqlstring.c \
cqlstrer.c querytowrbuf.c \
/* CCL find (to rpn conversion)
* Europagate, 1995
*
- * $Id: cclfind.c,v 1.8 2005-06-25 15:46:03 adam Exp $
+ * $Id: cclfind.c,v 1.9 2007-04-25 20:52:19 adam Exp $
*
* Old Europagate log:
*
#include <stdlib.h>
#include <string.h>
-#include <yaz/ccl.h>
+#include "cclp.h"
/* returns type of current lookahead */
#define KIND (cclp->look_token->kind)
return p1;
}
-struct ccl_rpn_node *ccl_parser_find (CCL_parser cclp, struct ccl_token *list)
+struct ccl_rpn_node *ccl_parser_find_str(CCL_parser cclp, const char *str)
+{
+ struct ccl_rpn_node *p;
+ struct ccl_token *list = ccl_parser_tokenize(cclp, str);
+ p = ccl_parser_find_token(cclp, list);
+ ccl_token_del(list);
+ return p;
+}
+
+struct ccl_rpn_node *ccl_parser_find_token(CCL_parser cclp,
+ struct ccl_token *list)
{
struct ccl_rpn_node *p;
}
/**
- * ccl_find: Parse CCL find - token representation
- * bibset: Bibset to be used for the parsing
- * list: List of tokens
- * error: Pointer to integer. Holds error no. on completion.
- * pos: Pointer to char position. Holds approximate error position.
- * return: RPN tree on successful completion; NULL otherwise.
- */
-struct ccl_rpn_node *ccl_find (CCL_bibset bibset, struct ccl_token *list,
- int *error, const char **pos)
-{
- struct ccl_rpn_node *p;
- CCL_parser cclp = ccl_parser_create ();
-
- cclp->bibset = bibset;
-
- p = ccl_parser_find (cclp, list);
-
- *error = cclp->error_code;
- *pos = cclp->error_pos;
-
- ccl_parser_destroy (cclp);
-
- return p;
-}
-
-/**
* ccl_find_str: Parse CCL find - string representation
* bibset: Bibset to be used for the parsing
* str: String to be parsed
* pos: Pointer to char position. Holds approximate error position.
* return: RPN tree on successful completion; NULL otherwise.
*/
-struct ccl_rpn_node *ccl_find_str (CCL_bibset bibset, const char *str,
- int *error, int *pos)
+struct ccl_rpn_node *ccl_find_str(CCL_bibset bibset, const char *str,
+ int *error, int *pos)
{
- CCL_parser cclp = ccl_parser_create ();
+ CCL_parser cclp = ccl_parser_create (bibset);
struct ccl_token *list;
struct ccl_rpn_node *p;
- cclp->bibset = bibset;
-
list = ccl_parser_tokenize (cclp, str);
- p = ccl_parser_find (cclp, list);
+ p = ccl_parser_find_token(cclp, list);
*error = cclp->error_code;
if (*error)
--- /dev/null
+/*
+ * Copyright (C) 1995-2005, Index Data ApS
+ * See the file LICENSE for details.
+ *
+ * $Id: cclp.h,v 1.1 2007-04-25 20:52:19 adam Exp $
+ */
+
+#include <yaz/ccl.h>
+
+#define CCL_TOK_EOL 0
+#define CCL_TOK_TERM 1
+#define CCL_TOK_REL 2
+#define CCL_TOK_EQ 3
+#define CCL_TOK_PROX 4
+#define CCL_TOK_LP 5
+#define CCL_TOK_RP 6
+#define CCL_TOK_COMMA 7
+#define CCL_TOK_AND 8
+#define CCL_TOK_OR 9
+#define CCL_TOK_NOT 10
+#define CCL_TOK_SET 11
+
+
+/** CCL token */
+struct ccl_token {
+ char kind;
+ size_t len; /* length of name below */
+ const char *name; /* string / name of token */
+ struct ccl_token *next;
+ struct ccl_token *prev;
+ const char *ws_prefix_buf; /* leading white space buf */
+ size_t ws_prefix_len; /* leading white space len */
+};
+
+/** CCL parser structure */
+struct ccl_parser {
+ /** current lookahead token */
+ struct ccl_token *look_token;
+
+ /** holds error code if error occur */
+ int error_code;
+ /** start of CCL string buffer */
+ const char *start_pos;
+ /** if error occurs, this holds position (starting from 0). */
+ const char *error_pos;
+
+ /** current bibset */
+ CCL_bibset bibset;
+
+ /** names of and operator */
+ char *ccl_token_and;
+ /** names of or operator */
+ char *ccl_token_or;
+ /** names of not operator */
+ char *ccl_token_not;
+ /** names of set operator */
+ char *ccl_token_set;
+ /** 1=CCL parser is case sensitive, 0=case insensitive */
+ int ccl_case_sensitive;
+};
+
+/**
+ * Splits CCL command string into individual tokens using
+ * a CCL parser.
+ */
+YAZ_EXPORT
+struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command);
+
+/**
+ * Deletes token list
+ */
+YAZ_EXPORT
+void ccl_token_del (struct ccl_token *list);
+
+/**
+ * Add single token after a given onde.
+ */
+YAZ_EXPORT
+struct ccl_token *ccl_token_add (struct ccl_token *at);
+
+
+YAZ_EXPORT
+struct ccl_rpn_node *ccl_parser_find_token(CCL_parser cclp,
+ struct ccl_token *list);
+
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
/* CCL qualifiers
* Europagate, 1995
*
- * $Id: cclqfile.c,v 1.7 2005-06-25 15:46:03 adam Exp $
+ * $Id: cclqfile.c,v 1.8 2007-04-25 20:52:19 adam Exp $
*
* Old Europagate Log:
*
#include <yaz/ccl.h>
+#define MAX_QUAL 128
+
void ccl_qual_field (CCL_bibset bibset, const char *cp, const char *qual_name)
{
char qual_spec[128];
- int type_ar[128];
- int value_ar[128];
- char *svalue_ar[128];
- char *attsets[128];
+ int type_ar[MAX_QUAL];
+ int value_ar[MAX_QUAL];
+ char *svalue_ar[MAX_QUAL];
+ char *attsets[MAX_QUAL];
int pair_no = 0;
- while (pair_no < 128)
+ while (pair_no < MAX_QUAL)
{
char *qual_value, *qual_type;
char *split, *setp;
/* type=value ... */
qual_type = qual_spec;
}
- while (pair_no < 128)
+ while (pair_no < MAX_QUAL)
{
int type, value;
}
if (setp)
{
- attsets[pair_no] = (char*) xmalloc (strlen(qual_spec)+1);
- strcpy (attsets[pair_no], qual_spec);
+ attsets[pair_no] = xstrdup (qual_spec);
}
else
attsets[pair_no] = 0;
/* CCL qualifiers
* Europagate, 1995
*
- * $Id: cclqual.c,v 1.3 2005-06-25 15:46:03 adam Exp $
+ * $Id: cclqual.c,v 1.4 2007-04-25 20:52:19 adam Exp $
*
* Old Europagate Log:
*
#include <stdlib.h>
#include <string.h>
-#include <yaz/ccl.h>
+#include "cclp.h"
+
+/** CCL Qualifier */
+struct ccl_qualifier {
+ char *name;
+ int no_sub;
+ struct ccl_qualifier **sub;
+ struct ccl_rpn_attr *attr_list;
+ struct ccl_qualifier *next;
+};
+
/** Definition of CCL_bibset pointer */
struct ccl_qualifiers {
/* CCL - lexical analysis
* Europagate, 1995
*
- * $Id: ccltoken.c,v 1.9 2005-08-22 20:34:21 adam Exp $
+ * $Id: ccltoken.c,v 1.10 2007-04-25 20:52:19 adam Exp $
*
* Old Europagate Log:
*
#include <stdlib.h>
#include <ctype.h>
-#include <yaz/ccl.h>
+#include "cclp.h"
/*
* token_cmp: Compare token with keyword(s)
const unsigned char *cp = (const unsigned char *) command;
struct ccl_token *first = NULL;
struct ccl_token *last = NULL;
+ cclp->start_pos = command;
while (1)
{
return n;
}
-struct ccl_token *ccl_tokenize (const char *command)
-{
- CCL_parser cclp = ccl_parser_create ();
- struct ccl_token *list;
-
- list = ccl_parser_tokenize (cclp, command);
-
- ccl_parser_destroy (cclp);
- return list;
-}
-
/*
* ccl_token_del: delete CCL tokens
*/
return p;
}
-CCL_parser ccl_parser_create (void)
+CCL_parser ccl_parser_create (CCL_bibset bibset)
{
CCL_parser p = (CCL_parser)xmalloc (sizeof(*p));
if (!p)
p->look_token = NULL;
p->error_code = 0;
p->error_pos = NULL;
- p->bibset = NULL;
+ p->bibset = bibset;
p->ccl_token_and = ccl_strdup("and");
p->ccl_token_or = ccl_strdup("or");
if (p)
p->ccl_case_sensitive = case_sensitivity_flag;
}
+
+int ccl_parser_get_error(CCL_parser cclp, int *pos)
+{
+ if (pos && cclp->error_code)
+ *pos = cclp->error_pos - cclp->start_pos;
+ return cclp->error_code;
+}
+
/*
* Local variables:
* c-basic-offset: 4
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tstccl.c,v 1.15 2007-03-19 22:17:41 adam Exp $
+ * $Id: tstccl.c,v 1.16 2007-04-25 20:52:19 adam Exp $
*/
/* CCL test */
const char *query,
const char *result)
{
- CCL_parser parser = ccl_parser_create();
+ CCL_parser parser = ccl_parser_create(bibset);
int ret = 0;
if (parser && bibset)
{
- struct ccl_token *token_list;
struct ccl_rpn_node *rpn;
- parser->bibset = bibset;
-
- token_list = ccl_parser_tokenize(parser, query);
- rpn = ccl_parser_find(parser, token_list);
- ccl_token_del(token_list);
+ rpn = ccl_parser_find_str(parser, query);
if (rpn)
{
/* parse ok. check that result is there and match */
/* CCL shell.
* Europagate 1995
*
- * $Id: cclsh.c,v 1.5 2007-01-08 10:48:08 adam Exp $
+ * $Id: cclsh.c,v 1.6 2007-04-25 20:52:20 adam Exp $
*
* Old Europagate Log:
*
}
if (q_wrbuf)
{
- CCL_parser cclp = ccl_parser_create ();
- struct ccl_token *list;
+ CCL_parser cclp = ccl_parser_create(bibset);
int error;
struct ccl_rpn_node *rpn;
- cclp->bibset = bibset;
+ rpn = ccl_parser_find_str (cclp, wrbuf_cstr(q_wrbuf));
- list = ccl_parser_tokenize (cclp, wrbuf_cstr(q_wrbuf));
- rpn = ccl_parser_find (cclp, list);
-
- error = cclp->error_code;
+ error = ccl_parser_get_error(cclp, 0);
if (error)
{
printf ("\n");
}
}
- if (debug)
- {
- struct ccl_token *lp;
- for (lp = list; lp; lp = lp->next)
- printf ("%d %.*s\n", lp->kind, (int) (lp->len), lp->name);
- }
- ccl_token_del (list);
ccl_parser_destroy (cclp);
if (rpn)
ccl_rpn_delete(rpn);
while (1)
{
char buf[1000];
- int i, error, pos;
+ int i, error;
struct ccl_rpn_node *rpn;
#if HAVE_READLINE_READLINE_H
for (i = 0; i<1; i++)
{
- CCL_parser cclp = ccl_parser_create ();
- struct ccl_token *list;
-
- cclp->bibset = bibset;
+ CCL_parser cclp = ccl_parser_create(bibset);
+ int pos;
- list = ccl_parser_tokenize (cclp, buf);
- rpn = ccl_parser_find (cclp, list);
+ rpn = ccl_parser_find_str(cclp, buf);
- error = cclp->error_code;
- if (error)
- pos = cclp->error_pos - buf;
+ error = ccl_parser_get_error(cclp, &pos);
if (error)
{
printf ("\n");
}
}
- if (debug)
- {
- struct ccl_token *lp;
- for (lp = list; lp; lp = lp->next)
- printf ("%d %.*s\n", lp->kind, (int) (lp->len), lp->name);
- }
- ccl_token_del (list);
ccl_parser_destroy (cclp);
if (rpn)
ccl_rpn_delete(rpn);