From 1b7116b57dee317a8ccc2d53401b629fabd8b9d8 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 22 Sep 2004 11:21:51 +0000 Subject: [PATCH] Added CCL utility ccl_qual_buf which parses one or more CCL spec lines in a buffer. --- NEWS | 3 +++ src/cclqfile.c | 27 ++++++++++++++++++++++++++- test/tstccl.c | 38 ++++++++++++++++++++++++++++++++------ 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 288195d..46454f2 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,9 @@ Possible compatibility problems with earlier versions marked with '*'. Macro YAZ_INIT in yaz.m4: option --with-yazconfig renamed to --with-yaz. +Added CCL utility ccl_qual_buf which parses one or more CCL +spec lines in a buffer. + Added CCL utility ccl_qual_line which adds CCL qualifier line consisting of name and value - ignoring empty lines and comments. diff --git a/src/cclqfile.c b/src/cclqfile.c index a637b75..d46b730 100644 --- a/src/cclqfile.c +++ b/src/cclqfile.c @@ -44,7 +44,7 @@ /* CCL qualifiers * Europagate, 1995 * - * $Id: cclqfile.c,v 1.2 2004-08-18 10:03:01 adam Exp $ + * $Id: cclqfile.c,v 1.3 2004-09-22 11:21:51 adam Exp $ * * Old Europagate Log: * @@ -214,6 +214,31 @@ void ccl_qual_fitem (CCL_bibset bibset, const char *cp, const char *qual_name) ccl_qual_field(bibset, cp, qual_name); } +void ccl_qual_buf(CCL_bibset bibset, const char *buf) +{ + const char *cp1 = buf; + char line[256]; + while (1) + { + const char *cp2 = cp1; + int len; + while (*cp2 && !strchr("\r\n", *cp2)) + cp2++; + len = cp2 - cp1; + if (len > 0) + { + if (len >= (sizeof(line)-1)) + len = sizeof(line)-1; + memcpy(line, cp1, len); + line[len] = '\0'; + ccl_qual_line(bibset, line); + } + if (!*cp2) + break; + cp1 = cp2+1; + } +} + void ccl_qual_line(CCL_bibset bibset, char *line) { int no_scan = 0; diff --git a/test/tstccl.c b/test/tstccl.c index 60c6502..9f8bb1b 100644 --- a/test/tstccl.c +++ b/test/tstccl.c @@ -2,7 +2,7 @@ * Copyright (c) 2002-2003, Index Data * See the file LICENSE for details. * - * $Id: tstccl.c,v 1.2 2004-08-11 12:01:22 adam Exp $ + * $Id: tstccl.c,v 1.3 2004-09-22 11:21:51 adam Exp $ */ /* CCL test */ @@ -26,15 +26,39 @@ static struct ccl_tst query_str[] = { {0, 0} }; -void tst1(void) +void tst1(int pass) { CCL_parser parser = ccl_parser_create (); CCL_bibset bibset = ccl_qual_mk(); int i; + char tstline[128]; - ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti"); - ccl_qual_fitem(bibset, "1=1016 s=al,pw", "term"); - ccl_qual_fitem(bibset, "1=/my/title", "dc.title"); + switch(pass) + { + case 0: + ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti"); + ccl_qual_fitem(bibset, "1=1016 s=al,pw", "term"); + ccl_qual_fitem(bibset, "1=/my/title", "dc.title"); + break; + case 1: + strcpy(tstline, "ti u=4 s=pw t=l,r"); + ccl_qual_line(bibset, tstline); + + strcpy(tstline, "term 1=1016 s=al,pw # default term"); + ccl_qual_line(bibset, tstline); + + strcpy(tstline, "dc.title 1=/my/title"); + ccl_qual_line(bibset, tstline); + break; + case 2: + ccl_qual_buf(bibset, "ti u=4 s=pw t=l,r\n" + "term 1=1016 s=al,pw\r\n" + "\n" + "dc.title 1=/my/title\n"); + break; + default: + exit(23); + } parser->bibset = bibset; @@ -80,6 +104,8 @@ void tst1(void) int main(int argc, char **argv) { - tst1(); + tst1(0); + tst1(1); + tst1(2); exit(0); } -- 1.7.10.4