From 4feb736e570d15bbc8254d593e0c44ed5066be85 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 15 Mar 2005 16:32:51 +0000 Subject: [PATCH] Fixed bug #272: Preserve spacing for CCL terms. The spacing is preserved for phrases by saving the prefix (leading) white-space for tokens. Added ws_prefix_{buf,len} in ccl_token to support it. --- NEWS | 2 ++ include/yaz/ccl.h | 8 +++++--- src/cclfind.c | 19 ++++++++----------- src/ccltoken.c | 5 ++++- test/tstccl.c | 10 +++++++--- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/NEWS b/NEWS index a2bed99..3ba5f3d 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ Possible compatibility problems with earlier versions marked with '*'. +Fixed bug #272: Preserve spacing for CCL terms. + --- 2.1.0 2005/03/14 Added support for virtual hosts and multiple backend servers for diff --git a/include/yaz/ccl.h b/include/yaz/ccl.h index d50792e..b827ae2 100644 --- a/include/yaz/ccl.h +++ b/include/yaz/ccl.h @@ -49,7 +49,7 @@ /* * CCL - header file * - * $Id: ccl.h,v 1.20 2004-10-15 00:18:59 adam Exp $ + * $Id: ccl.h,v 1.21 2005-03-15 16:32:52 adam Exp $ * * Old Europagate Log: * @@ -219,10 +219,12 @@ typedef struct ccl_qualifiers *CCL_bibset; /** CCL token */ struct ccl_token { char kind; - size_t len; - const char *name; + 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 */ diff --git a/src/cclfind.c b/src/cclfind.c index 6db1d84..9037887 100644 --- a/src/cclfind.c +++ b/src/cclfind.c @@ -56,7 +56,7 @@ /* CCL find (to rpn conversion) * Europagate, 1995 * - * $Id: cclfind.c,v 1.6 2004-10-15 00:18:59 adam Exp $ + * $Id: cclfind.c,v 1.7 2005-03-15 16:32:52 adam Exp $ * * Old Europagate log: * @@ -371,7 +371,7 @@ static struct ccl_rpn_node *search_term_x (CCL_parser cclp, else mid_trunc = 1; } - len += 1+lookahead->len; + len += 1+lookahead->len+lookahead->ws_prefix_len; lookahead = lookahead->next; } @@ -481,15 +481,12 @@ static struct ccl_rpn_node *search_term_x (CCL_parser cclp, } if (i == no-1 && right_trunc) src_len--; - if (src_len) - { - int len = strlen(p->u.t.term); - if (len && - !strchr("-+", *src_str) && - !strchr("-+", p->u.t.term[len-1])) - { - strcat (p->u.t.term, " "); - } + if (i && cclp->look_token->ws_prefix_len) + { + size_t len = strlen(p->u.t.term); + memcpy(p->u.t.term + len, cclp->look_token->ws_prefix_buf, + cclp->look_token->ws_prefix_len); + p->u.t.term[len + cclp->look_token->ws_prefix_len] = '\0'; } strxcat (p->u.t.term, src_str, src_len); ADVANCE; diff --git a/src/ccltoken.c b/src/ccltoken.c index 7584473..c4f0a60 100644 --- a/src/ccltoken.c +++ b/src/ccltoken.c @@ -48,7 +48,7 @@ /* CCL - lexical analysis * Europagate, 1995 * - * $Id: ccltoken.c,v 1.5 2004-10-15 00:19:00 adam Exp $ + * $Id: ccltoken.c,v 1.6 2005-03-15 16:32:52 adam Exp $ * * Old Europagate Log: * @@ -211,6 +211,7 @@ struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command) while (1) { + const unsigned char *cp0 = cp; while (*cp && strchr (" \t\r\n", *cp)) { cp++; @@ -229,6 +230,8 @@ struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command) last->next->prev = last; last = last->next; } + last->ws_prefix_buf = cp0; + last->ws_prefix_len = cp - cp0; last->next = NULL; last->name = (const char *) cp; last->len = 1; diff --git a/test/tstccl.c b/test/tstccl.c index 0142bc6..bf5b487 100644 --- a/test/tstccl.c +++ b/test/tstccl.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: tstccl.c,v 1.6 2005-02-01 17:23:36 adam Exp $ + * $Id: tstccl.c,v 1.7 2005-03-15 16:32:53 adam Exp $ */ /* CCL test */ @@ -37,6 +37,10 @@ static struct ccl_tst query_str[] = { { "x= -1980", "@attr 2=3 -1980 "}, { "x=234-1990", "@attr 2=3 234-1990 "}, { "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "}, + { "ti=a,b", "@attr 4=1 @attr 1=4 a,b "}, + { "ti=a, b", "@attr 4=1 @attr 1=4 a,\\ b "}, + { "ti=a-b", "@attr 4=2 @attr 1=4 a-b "}, + { "ti=a - b", "@attr 4=1 @attr 1=4 a\\ -\\ b "}, {0, 0} }; @@ -101,14 +105,14 @@ void tst1(int pass, int *number_of_errors) if (!query_str[i].result) { printf ("Failed %s\n", query_str[i].query); - printf (" got:%s:\n", wrbuf_buf(wrbuf)); + printf (" got: %s:\n", wrbuf_buf(wrbuf)); printf (" expected failure\n"); (*number_of_errors)++; } else if (strcmp(wrbuf_buf(wrbuf), query_str[i].result)) { printf ("Failed %s\n", query_str[i].query); - printf (" got:%s:\n", wrbuf_buf(wrbuf)); + printf (" got: %s:\n", wrbuf_buf(wrbuf)); printf (" expected:%s:\n", query_str[i].result); (*number_of_errors)++; } -- 1.7.10.4