-# $Id: Makefile.am,v 1.1 2003-01-06 08:20:27 adam Exp $
+# $Id: Makefile.am,v 1.2 2003-04-11 15:53:39 adam Exp $
AM_YFLAGS=-p cql_
AM_CPPFLAGS=-I$(top_srcdir)/include
cql2pqf_SOURCES = cql2pqf.c
cql2xcql_SOURCES = cql2xcql.c
-LDADD=libcql.la
+LDADD=libcql.la ../util/libutil.la
-/* $Id: cql.y,v 1.3 2003-02-14 18:49:23 adam Exp $
+/* $Id: cql.y,v 1.4 2003-04-11 15:53:39 adam Exp $
Copyright (C) 2002-2003
Index Data Aps
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <yaz/nmem.h>
#include <yaz/cql.h>
typedef struct {
struct cql_node *rel;
struct cql_node *cql;
- char buf[80];
+ char *buf;
size_t len;
- size_t max;
+ size_t size;
} token;
struct cql_parser {
int last_error;
int last_pos;
struct cql_node *top;
+ NMEM nmem;
};
#define YYSTYPE token
{
CQL_parser cp = (CQL_parser) malloc (sizeof(*cp));
+ cp->top = 0;
+ cp->getbyte = 0;
+ cp->ungetbyte = 0;
+ cp->client_data = 0;
+ cp->last_error = 0;
+ cp->last_pos = 0;
+ cp->nmem = nmem_create();
return cp;
}
void cql_parser_destroy(CQL_parser cp)
{
cql_node_destroy(cp->top);
+ nmem_destroy(cp->nmem);
free (cp);
}
-/* $Id: lexer.c,v 1.1 2003-01-06 08:20:27 adam Exp $
+/* $Id: lexer.c,v 1.2 2003-04-11 15:53:39 adam Exp $
Copyright (C) 2002-2003
Index Data Aps
See the file LICENSE.
*/
+
+static void putb(YYSTYPE *lval, CQL_parser cp, int c)
+{
+ if (lval->len >= lval->size)
+ {
+ char *nb = nmem_malloc(cp->nmem, (lval->size = lval->len * 2 + 20));
+ memcpy (nb, lval->buf, lval->len);
+ lval->buf = nb;
+ }
+ if (c)
+ lval->buf[lval->len++] = c;
+ lval->buf[lval->len] = '\0';
+}
+
/*
* bison lexer for CQL.
*/
} while (isspace(c));
lval->rel = 0;
lval->len = 0;
+ lval->size = 10;
+ lval->buf = nmem_malloc(cp->nmem, lval->size);
if (strchr("()=></", c))
{
int c1;
- lval->buf[lval->len++] = c;
+ putb(lval, cp, c);
if (c == '>')
{
c1 = cp->getbyte(cp->client_data);
if (c1 == '=')
{
- lval->buf[lval->len++] = c1;
- lval->buf[lval->len] = 0;
+ putb(lval, cp, c1);
return GE;
}
else
c1 = cp->getbyte(cp->client_data);
if (c1 == '=')
{
- lval->buf[lval->len++] = c1;
- lval->buf[lval->len] = 0;
+ putb(lval, cp, c1);
return LE;
}
else if (c1 == '>')
{
- lval->buf[lval->len++] = c1;
- lval->buf[lval->len] = 0;
+ putb(lval, cp, c1);
return NE;
}
else
cp->ungetbyte(c1, cp->client_data);
}
- lval->buf[lval->len] = 0;
return c;
}
if (c == '"')
{
if (c == '\\')
c = cp->getbyte(cp->client_data);
- lval->buf[lval->len++] = c;
+ putb(lval, cp, c);
}
- lval->buf[lval->len] = 0;
+ putb(lval, cp, 0);
}
else
{
- lval->buf[lval->len++] = c;
+ putb(lval, cp, c);
while ((c = cp->getbyte(cp->client_data)) != 0 &&
!strchr(" \n()=<>/", c))
{
if (c == '\\')
c = cp->getbyte(cp->client_data);
- lval->buf[lval->len++] = c;
+ putb(lval, cp, c);
}
- lval->buf[lval->len] = 0;
#if YYDEBUG
printf ("got %s\n", lval->buf);
#endif