bf->alloc_buf_size = HEADER_SIZE;
else
bf->alloc_buf_size = bf->block_size;
-
+
hbuf = bf->alloc_buf = xmalloc(bf->alloc_buf_size);
/* fill-in default values */
zint pos = 0;
assert(bf->alloc_buf);
assert(bf->magic);
- sprintf(bf->alloc_buf, "%s %d " ZINT_FORMAT " " ZINT_FORMAT " ",
+ sprintf(bf->alloc_buf, "%s %d " ZINT_FORMAT " " ZINT_FORMAT " ",
bf->magic, version, bf->last_block, bf->free_list);
if (more_info)
strcat(bf->alloc_buf, more_info);
if ((ret = cf_read(bf->cf, no, offset, nbytes, buf)) == 0)
ret = mf_read(bf->mf, no, offset, nbytes, buf);
}
- else
+ else
ret = mf_read(bf->mf, no, offset, nbytes, buf);
zebra_lock_rdwr_runlock(&bf->rdwr_lock);
return ret;
memset(cf, 'Z', sizeof(*cf));
yaz_log(YLOG_DEBUG, "cf: open %s %s", fname, wflag ? "rdwr" : "rd");
-
+
cf->block_mf = 0;
cf->hash_mf = 0;
- cf->rmf = mf;
+ cf->rmf = mf;
assert(firstp);
cf->head.block_size = block_size;
cf->head.hash_size = 199;
hash_bytes = cf->head.hash_size * sizeof(zint);
- cf->head.flat_bucket = cf->head.next_bucket = cf->head.first_bucket =
+ cf->head.flat_bucket = cf->head.next_bucket = cf->head.first_bucket =
(hash_bytes+sizeof(cf->head))/HASH_BSIZE + 2;
cf->head.next_block = 1;
cf->array = (zint *) xmalloc(hash_bytes);
*p->h_prev = p->h_next;
if (p->h_next)
p->h_next->h_prev = p->h_prev;
-
+
--(cf->bucket_in_memory);
xfree(p);
}
cf->bucket_lru_front->lru_next = p;
else
cf->bucket_lru_back = p;
- cf->bucket_lru_front = p;
+ cf->bucket_lru_front = p;
pp = cf->parray + hno;
p->h_next = *pp;
yaz_log(YLOG_DEBUG, "cf: Moving to flat shadow: %s", cf->rmf->name);
yaz_log(YLOG_DEBUG, "cf: hits=%d miss=%d bucket_in_memory=" ZINT_FORMAT " total="
ZINT_FORMAT,
- cf->no_hits, cf->no_miss, cf->bucket_in_memory,
+ cf->no_hits, cf->no_miss, cf->bucket_in_memory,
cf->head.next_bucket - cf->head.first_bucket);
assert(cf->head.state == CFILE_STATE_HASH);
if (flush_bucket(cf, -1))
{
int hno = cf_hash(cf, no);
struct CFile_hash_bucket *hbprev = NULL, *hb = cf->parray[hno];
- zint *bucketpp = &cf->array[hno];
+ zint *bucketpp = &cf->array[hno];
int i;
zint vno = (cf->head.next_block)++;
-
+
for (hb = cf->parray[hno]; hb; hb = hb->h_next)
if (!hb->ph.vno[HASH_BUCKET-1])
for (i = 0; i<HASH_BUCKET; i++)
{
zint block;
int ret;
-
+
assert(cf);
zebra_mutex_lock(&cf->mutex);
ret = cf_lookup(cf, no, &block);
typedef struct CFile_struct
{
struct CFile_head head;
-
+
MFile block_mf; /**< block meta file */
MFile hash_mf; /**< hash or index file (depending on state) */
zint *array; /**< array for hash */
if (mf_write(m_p->cf->rmf, m_p->map[i].to, 0, 0,
m_p->buf + m_p->map[i].from * m_p->cf->head.block_size))
return -1;
- }
+ }
m_p->no = 0;
return 0;
}
#endif
static int cf_commit_hash (CFile cf)
-{
+{
int r = 0;
int i;
zint bucket_no;
/*
* If no definition is given, use current directory, unlimited.
*/
- char dirname[FILENAME_MAX+1];
+ char dirname[FILENAME_MAX+1];
mf_dir **dp = &ma->dirs, *dir = *dp;
if (!ad)
\retval -1 ERROR
\retval -2 OK, but file does not created (read-only)
*/
-
+
static zint file_position(MFile mf, zint pos, int offset)
{
zint off = 0, ps;
struct dirent *dent;
int fd, number;
char metaname[FILENAME_MAX+1], tmpnam[FILENAME_MAX+1];
-
+
yaz_log(YLOG_DEBUG, "mf_init(%s)", name);
strcpy(ma->name, name);
ma->mfiles = 0;
yaz_log(YLOG_FATAL, "mf_write: %s error (4) no more space",
mf->name);
for (dp = mf->ma->dirs; dp ; dp = dp->next) {
- yaz_log(YLOG_FATAL,"%s: max=" ZINT_FORMAT
- " used=" ZINT_FORMAT " available=" ZINT_FORMAT,
- dp->name, (zint)dp->max_bytes,
+ yaz_log(YLOG_FATAL,"%s: max=" ZINT_FORMAT
+ " used=" ZINT_FORMAT " available=" ZINT_FORMAT,
+ dp->name, (zint)dp->max_bytes,
(zint)(dp->max_bytes - dp->avail_bytes), (zint)dp->avail_bytes );
}
yaz_log(YLOG_FATAL,"Adjust the limits in your zebra.cfg");
yaz_log(YLOG_FATAL, "mf_write: %s error (5)", mf->name);
ret = -1;
goto out;
- }
+ }
}
else
{
return ret;
}
-/** \brief metafile area statistics
+/** \brief metafile area statistics
\param ma metafile area handle
\param no area number (0=first, 1=second, ..)
\param directory holds directory upon completion (if non-NULL)
MFile_area mf_init(const char *name, const char *spec, const char *base,
int only_shadow_files)
ZEBRA_GCC_ATTR((warn_unused_result));
-
+
/** \brief destroys metafile area handle
\param ma metafile area handle
*/
*/
MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag)
ZEBRA_GCC_ATTR((warn_unused_result));
-
+
/** \brief closes metafile
\param mf metafile handle
\retval 0 OK
*/
int mf_read(MFile mf, zint no, int offset, int nbytes, void *buf)
ZEBRA_GCC_ATTR((warn_unused_result));
-
+
/** \brief writes block to metafile
\param mf metafile handle
\param no block position
\retval -1 error (block not written)
*/
int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf)
- ZEBRA_GCC_ATTR((warn_unused_result));
-
+ ZEBRA_GCC_ATTR((warn_unused_result));
+
/** \brief reset all files in a metafile area (optionally delete them as well)
\param ma metafile area
\param unlink_flag if unlink_flag=1 all files are removed from FS
on same platform depending on whether 64-bit is enabled or not.
Note that if an area has unlimited size, that is represented
as max_bytes = -1.
-*/
+*/
int mf_area_directory_stat(MFile_area ma, int no, const char **directory,
double *bytes_used, double *bytes_max);
-
+
YAZ_END_CDECL
#endif
const char *more_info = 0;
bf_reset(bfs);
- bf = bf_xopen(bfs, "tst", /* block size */ 32,
+ bf = bf_xopen(bfs, "tst", /* block size */ 32,
/* wr */ 1, "tstmagic", &version, 0 /* more_info */);
YAZ_CHECK(bf);
if (!bf)
return;
bf_xclose(bf, version, "more info");
-
- bf = bf_xopen(bfs, "tst", /* block size */ 32,
+
+ bf = bf_xopen(bfs, "tst", /* block size */ 32,
/* wr */ 1, "tstmagic", &version, &more_info);
-
+
YAZ_CHECK(bf);
if (!bf)
return;
BFile bf;
bf_reset(bfs);
- bf = bf_xopen(bfs, "tst", /* block size */ 32,
+ bf = bf_xopen(bfs, "tst", /* block size */ 32,
/* wr */ 1, "tstmagic", &version, 0 /* more_info */);
YAZ_CHECK(bf);
if (!bf)
for(i = 0; i<BLOCKS; i++)
blocks[i] = 0;
- bf = bf_xopen(bfs, "tst", /* block size */ 32,
+ bf = bf_xopen(bfs, "tst", /* block size */ 32,
/* wr */ 1, "tstmagic", &version, 0 /* more_info */);
YAZ_CHECK(bf);
if (!bf)
else
{
bf_xclose(bf, version, 0);
- bf = bf_xopen(bfs, "tst", /* block size */ 32,
+ bf = bf_xopen(bfs, "tst", /* block size */ 32,
/* wr */ 1, "tstmagic", &version, 0 /* more_info */);
}
}
return;
YAZ_CHECK(max_block * block_size < 4 * 1000000); /* 4M */
-
+
r = mkdir("register", 0777);
YAZ_CHECK(r == 0 || (r == -1 && errno == EEXIST));
{
zint bno = 0;
int step = max_block / 50;
-
+
while (bno < max_block)
{
memset(buf, ' ', block_size);
YAZ_CHECK(f);
YAZ_CHECK_EQ(mf_read(f, 0, 0, 0, buf), 0);
-
+
memset(buf, 'a', BLOCK_SIZE);
YAZ_CHECK_EQ(mf_write(f, 0, 0, 0, buf), 0);
void *data1_hash_lookup(struct data1_hash_table *ht, const char *str)
{
struct data1_hash_entry **he = &ht->ar[data1_hash_calc(ht, str)];
-
+
for (; *he && yaz_matchstr(str, (*he)->str); he = &(*he)->next)
;
if (*he)
struct data1_systag *next;
};
-struct data1_absyn_cache_info
+struct data1_absyn_cache_info
{
char *name;
data1_absyn *absyn;
data1_absyn_cache next;
};
-struct data1_attset_cache_info
+struct data1_attset_cache_info
{
char *name;
data1_attset *attset;
return 0;
}
/* *ostrich*
- We need to destroy DFAs, in xp_element (xelm) definitions
+ We need to destroy DFAs, in xp_element (xelm) definitions
pop, 2002-12-13
*/
void data1_absyn_destroy (data1_handle dh)
{
data1_absyn_cache p = *data1_absyn_cache_get (dh);
-
+
while (p)
{
data1_absyn *abs = p->absyn;
data1_xpelement *xpe = abs->xp_elements;
while (xpe) {
yaz_log (YLOG_DEBUG,"Destroy xp element %s",xpe->xpath_expr);
- if (xpe->dfa)
+ if (xpe->dfa)
dfa_delete (&xpe->dfa);
xpe = xpe->next;
}
{
NMEM mem = data1_nmem_get (dh);
data1_attset *attset;
-
+
attset = data1_read_attset (dh, name);
if (!attset)
yaz_log (YLOG_WARN|YLOG_ERRNO, "Couldn't load attribute set %s", name);
data1_attset_cache p = (data1_attset_cache)
nmem_malloc (mem, sizeof(*p));
data1_attset_cache *pp = data1_attset_cache_get (dh);
-
+
attset->name = p->name = nmem_strdup(mem, name);
p->attset = attset;
p->next = *pp;
for (; r; r = r->next)
{
data1_name *n;
-
+
for (n = r->tag->names; n; n = n->next)
data1_hash_insert(ht, n->name, r, 0);
}
*/
-static const char * mk_xpath_regexp (data1_handle dh, const char *expr)
+static const char * mk_xpath_regexp (data1_handle dh, const char *expr)
{
const char *p = expr;
int abs = 1;
char *stack[32];
char *res_p, *res = 0;
size_t res_size = 1;
-
+
if (*p != '/')
return ("");
p++;
- if (*p == '/')
- {
+ if (*p == '/')
+ {
abs =0;
p++;
}
is_predicate=1;
else if (*pp == ']')
is_predicate=0;
- else
+ else
{
if (!is_predicate) {
- if (*pp == '*')
+ if (*pp == '*')
*s++ = '.';
*s++ = *pp;
}
}
if (!abs)
{
- sprintf(res_p, ".*");
+ sprintf(res_p, ".*");
res_p += 2;
}
sprintf (res_p, "$");
*tp = (data1_termlist *)
nmem_malloc(data1_nmem_get(dh), sizeof(**tp));
(*tp)->next = 0;
-
+
if (*attname == '!')
{
if (!xpelement && element_name)
source = "data"; /* ok: default is leaf data */
(*tp)->source = (char *)
nmem_strdup (data1_nmem_get (dh), source);
-
+
if (r < 2) /* is the structure qualified? */
(*tp)->structure = "w";
- else
+ else
(*tp)->structure = (char *)
nmem_strdup (data1_nmem_get (dh), structure);
tp = &(*tp)->next;
else
fieldtype = "datafield";
sprintf(buf, "/*/%s[@tag=\"%s\"]", fieldtype, field);
- if (*subfield)
+ if (*subfield)
sprintf(buf + strlen(buf), "/subfield[@code=\"%s\"]", subfield);
else if (field[0] != '0' || field[1] != '0')
strcat(buf, "/subfield");
char *p;
int argc;
int quoted = 0;
-
+
while ((p = fgets(line, len, f)))
{
(*lineno)++;
}
if (!p)
return 0;
-
+
for (argc = 0; *p ; argc++)
{
if (*p == '#') /* trailing comment */
char *argv[50], line[512];
f = data1_path_fopen(dh, file, "r");
-
+
res = (data1_absyn *) nmem_malloc(data1_nmem_get(dh), sizeof(*res));
res->name = 0;
res->oid = 0;
res->tagset = 0;
res->encoding = 0;
- res->xpath_indexing =
+ res->xpath_indexing =
(f ? DATA1_XPATH_INDEXING_DISABLE : default_xpath);
res->systags = 0;
systagsp = &res->systags;
cur_elements->elements = NULL;
cur_elements->name = "main";
res->sub_elements = cur_elements;
-
+
level = 0;
ppl[level] = &cur_elements->elements;
}
}
level = i;
new_element = *ppl[level-1] = data1_mk_element(dh);
-
+
tp = &new_element->termlists;
ppl[level-1] = &new_element->next;
ppl[level] = &new_element->children;
-
+
/* consider subtree (if any) ... */
if ((sub_p = strchr (p, ':')) && sub_p[1])
{
*sub_p++ = '\0';
new_element->sub_name =
- nmem_strdup (data1_nmem_get(dh), sub_p);
+ nmem_strdup (data1_nmem_get(dh), sub_p);
}
/* well-defined tag */
if (sscanf(p, "(%d,%d)", &type, &value) == 2)
nt->which = DATA1T_string;
nt->value.string = nmem_strdup(data1_nmem_get (dh), p);
nt->names = (data1_name *)
- nmem_malloc(data1_nmem_get(dh),
+ nmem_malloc(data1_nmem_get(dh),
sizeof(*new_element->tag->names));
nt->names->name = nt->value.string;
nt->names->next = 0;
/* *ostrich*
New code to support xelm directive
for each xelm a dfa is built. xelms are stored in res->xp_elements
-
+
maybe we should use a simple sscanf instead of dfa?
-
+
pop, 2002-12-13
Now [] predicates are supported. regexps and xpath structure is
char melm_xpath[128];
data1_xpelement *xp_ele = 0;
data1_xpelement *last_match = 0;
-
+
if (argc != 3)
{
yaz_log(YLOG_WARN, "%s:%d: Bad # of args to %s",
#if OPTIMIZE_MELM
(*cur_xpelement)->regexp = regexp;
#endif
- (*cur_xpelement)->xpath_expr = nmem_strdup(data1_nmem_get (dh),
- xpath_expr);
-
+ (*cur_xpelement)->xpath_expr = nmem_strdup(data1_nmem_get (dh),
+ xpath_expr);
+
if (dfa)
dfa_mkstate (dfa);
(*cur_xpelement)->dfa = dfa;
-
-#ifdef ENHANCED_XELM
+
+#ifdef ENHANCED_XELM
(*cur_xpelement)->xpath_len =
zebra_parse_xpath_str(
- xpath_expr,
+ xpath_expr,
(*cur_xpelement)->xpath, XPATH_STEP_COUNT,
data1_nmem_get(dh));
#endif
(*cur_xpelement)->termlists = 0;
tp = &(*cur_xpelement)->termlists;
-
+
/* parse termList definitions */
p = termlists;
if (*p != '-')
else if (!strcmp(cmd, "section"))
{
char *name;
-
+
if (argc < 2)
{
yaz_log(YLOG_WARN, "%s:%d: Bad # of args to section",
continue;
}
name = argv[1];
-
+
cur_elements = (data1_sub_elements *)
nmem_malloc(data1_nmem_get(dh), sizeof(*cur_elements));
cur_elements->next = res->sub_elements;
cur_elements->elements = NULL;
cur_elements->name = nmem_strdup (data1_nmem_get(dh), name);
res->sub_elements = cur_elements;
-
+
level = 0;
ppl[level] = &cur_elements->elements;
}
else if (!strcmp(cmd, "reference"))
{
char *name;
-
+
if (argc != 2)
{
yaz_log(YLOG_WARN, "%s:%d: Bad # of args to reference",
}
name = argv[1];
res->oid = yaz_string_to_oid_nmem(yaz_oid_std(),
- CLASS_SCHEMA, name,
+ CLASS_SCHEMA, name,
data1_nmem_get(dh));
if (!res->oid)
{
- yaz_log(YLOG_WARN, "%s:%d: Unknown tagset ref '%s'",
+ yaz_log(YLOG_WARN, "%s:%d: Unknown tagset ref '%s'",
file, lineno, name);
continue;
}
{
char *name;
data1_attset *attset;
-
+
if (argc != 2)
{
yaz_log(YLOG_WARN, "%s:%d: Bad # of args to attset",
}
name = argv[1];
fname = argv[2];
-
+
*esetpp = (data1_esetname *)
nmem_malloc(data1_nmem_get(dh), sizeof(**esetpp));
(*esetpp)->name = nmem_strdup(data1_nmem_get(dh), name);
else if (!strcmp(cmd, "maptab"))
{
char *name;
-
+
if (argc != 2)
{
yaz_log(YLOG_WARN, "%s:%d: Bad # of args for maptab",
else if (!strcmp(cmd, "marc"))
{
char *name;
-
+
if (argc != 2)
{
yaz_log(YLOG_WARN, "%s:%d: Bad # or args for marc",
}
else
{
- yaz_log(YLOG_WARN, "%s:%d: Unknown directive '%s'", file,
+ yaz_log(YLOG_WARN, "%s:%d: Unknown directive '%s'", file,
lineno, cmd);
continue;
}
}
if (f)
fclose(f);
-
+
for (cur_elements = res->sub_elements; cur_elements;
cur_elements = cur_elements->next)
{
{
data1_att *r;
data1_attset_child *c;
-
+
/* scan local set */
for (r = s->atts; r; r = r->next)
if (!data1_matchstr(r->name, name))
char *name;
char *endptr;
data1_att *t;
-
+
if (argc < 3)
{
yaz_log(YLOG_WARN, "%s:%d: Bad # of args to att", file, lineno);
continue;
}
name = argv[2];
-
+
t = *attp = (data1_att *)nmem_malloc(mem, sizeof(*t));
t->parent = res;
t->name = nmem_strdup(mem, name);
yaz_log(YLOG_WARN, "%s:%d: Include of attset %s failed",
file, lineno, name);
continue;
-
+
}
*childp = (data1_attset_child *)
nmem_malloc (mem, sizeof(**childp));
/** \file d1_doespec.c
* \brief handle Z39.50 variant-1 specs
- *
+ *
* See http://www.loc.gov/z3950/agency/defns/variant1.html
*/
#if HAVE_CONFIG_H
const Odr_oid *cur_oid = var->triples[i]->variantSetId;
if (!cur_oid)
cur_oid = var->globalVariantSetId;
- if (cur_oid && var_oid
+ if (cur_oid && var_oid
&& !oid_oidcmp(var_oid, cur_oid) && *var->triples[i]->type == type)
return var->triples[i];
}
{
int remove_flag = 0;
Z_Triple *r;
-
+
assert ((*c)->which == DATA1N_variant);
-
+
if ((*c)->u.variant.type->zclass->zclass == 4 &&
(*c)->u.variant.type->type == 1)
{
data1_tag *tag = 0;
if (c->u.tag.element)
tag = c->u.tag.element->tag;
-
+
*predicate = '\0';
sscanf(spec, "%63[^[]%c%63[^]]", elem, &dummy_ch, predicate);
if (data1_matchstr(elem, tag ? tag->value.string : c->u.tag.tag))
}
return 0;
}
-
+
static int match_children_here (data1_handle dh, data1_node *n,
Z_Espec1 *e, int i,
Z_ETagUnit **t, int num,
#if 1
if (!match_node_and_attr(c, str_val))
continue;
-#else
+#else
if (data1_matchstr(str_val,
tag ? tag->value.string : c->u.tag.tag))
continue;
/*
* 6,5: meta-data requested, variant list.
*/
- if (find_triple(vreq, e->defaultVariantSetId,
+ if (find_triple(vreq, e->defaultVariantSetId,
var_oid, 6, 5))
show_variantlist = 1;
/*
n = data1_get_root_tag (dh, n);
if (n && n->which == DATA1N_tag)
n->u.tag.node_selected = 1;
-
+
for (i = 0; i < e->num_elements; i++)
{
if (e->elements[i]->which != Z_ERequest_simpleElement)
{
Z_Occurrences *op = (Z_Occurrences *)nmem_malloc(nmem, sizeof(*op));
char *p;
-
+
if (!occ)
{
op->which = Z_Occurrences_values;
else
{
Z_OccurValues *ov = (Z_OccurValues *)nmem_malloc(nmem, sizeof(*ov));
-
+
if (!d1_isdigit(*occ))
{
yaz_log(YLOG_WARN, "%s:%d: Bad occurrences-spec %s",
int terms;
int type;
char value[512], occ[512];
-
+
if (*buf == '*')
{
u->which = Z_ETagUnit_wildPath;
Z_SpecificTag *t;
char *valp = value;
int force_string = 0;
-
+
if (*valp == '\'')
{
valp++;
int argc, size_esn = 0;
char *argv[50], line[512];
Z_Espec1 *res = (Z_Espec1 *)nmem_malloc(nmem, sizeof(*res));
-
+
if (!(f = data1_path_fopen(dh, file, "r")))
return 0;
-
+
res->num_elementSetNames = 0;
res->elementSetNames = 0;
res->defaultVariantSetId = 0;
res->defaultTagType = 0;
res->num_elements = 0;
res->elements = 0;
-
+
while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
if (!strcmp(argv[0], "elementsetnames"))
{
int nnames = argc-1, i;
-
+
if (!nnames)
{
yaz_log(YLOG_WARN, "%s:%d: Empty elementsetnames directive",
file, lineno);
continue;
}
-
+
res->elementSetNames =
(char **)nmem_malloc(nmem, sizeof(char**)*nnames);
for (i = 0; i < nnames; i++)
char *path = argv[1];
char *ep;
int num, i = 0;
-
+
if (!res->elements)
res->elements = (Z_ElementRequest **)
nmem_malloc(nmem, size_esn = 24*sizeof(er));
file, lineno, argv[0]);
continue;
}
-
+
res->elements[res->num_elements++] = er =
(Z_ElementRequest *)nmem_malloc(nmem, sizeof(*er));
er->which = Z_ERequest_simpleElement;
;
tp->tags = (Z_ETagUnit **)
nmem_malloc(nmem, sizeof(Z_ETagUnit*)*num);
-
+
for ((ep = strchr(path, '/')) ; path ;
(void)((path = ep) && (ep = strchr(path, '/'))))
{
Z_ETagUnit *tagunit;
if (ep)
ep++;
-
+
assert(i<num);
tagunit = read_tagunit(path, nmem, file, lineno);
if (!tagunit)
}
tp->tags[tp->num_tags++] = tagunit;
}
-
+
if (argc > 2 && !strcmp(argv[2], "variant"))
se->variantRequest=
read_variant(argc-3, argv+3, nmem, file, lineno);
*/
/*
- * This module converts data1 tree to Z39.50 Explain records
+ * This module converts data1 tree to Z39.50 Explain records
*/
#if HAVE_CONFIG_H
c = c->child;
if (!is_data_tag (eh, c) || c->u.data.len > 63)
return 0;
- yaz_snprintf(oidstr, sizeof(oidstr)-1,
+ yaz_snprintf(oidstr, sizeof(oidstr)-1,
"%.*s", c->u.data.len, c->u.data.data);
return yaz_string_to_oid_odr(yaz_oid_std(),
res[i++] = f_oid (eh, c, oclass);
return res;
}
-
+
char **f_string_seq (ExpHandle *eh, data1_node *n, int *num)
{
char **res;
*wp = Z_DatabaseInfo_approxNumber;
else
return 0;
- if (!c->child || c->child->which != DATA1N_data ||
+ if (!c->child || c->child->which != DATA1N_data ||
c->child->u.data.len >= sizeof(intbuf))
return 0;
sprintf(intbuf, "%.*s", c->child->u.data.len, c->child->u.data.data);
Z_ContactInfo *res = (Z_ContactInfo *)
odr_malloc (eh->o, sizeof(*res));
data1_node *c;
-
+
res->name = 0;
res->description = 0;
res->address = 0;
res->email = 0;
res->phone = 0;
-
+
for (c = n->child; c; c = c->next)
{
switch (is_numeric_tag (eh, c))
data1_node *c;
Z_DatabaseList *res;
int i = 0;
-
+
for (c = n->child; c; c = c->next)
{
- if (!is_numeric_tag (eh, c) != 102)
+ if (!is_numeric_tag (eh, c) != 102)
continue;
++i;
}
return NULL;
res = (Z_DatabaseList *)odr_malloc (eh->o, sizeof(*res));
-
+
res->num_databases = i;
res->databases = (char **)odr_malloc (eh->o, sizeof(*res->databases) * i);
i = 0;
Z_NetworkAddressIA *res = (Z_NetworkAddressIA *)
odr_malloc (eh->o, sizeof(*res));
data1_node *c;
-
+
res->hostAddress = 0;
res->port = 0;
return res;
}
-static Z_NetworkAddress **f_networkAddresses(ExpHandle *eh, data1_node *n,
+static Z_NetworkAddress **f_networkAddresses(ExpHandle *eh, data1_node *n,
int *num)
{
Z_NetworkAddress **res = NULL;
data1_node *c;
int i = 0;
-
+
*num = 0;
for (c = n->child; c; c = c->next)
{
if (*num)
res = (Z_NetworkAddress **) odr_malloc (eh->o, sizeof(*res) * (*num));
-
+
for (c = n->child; c; c = c->next)
{
switch (is_numeric_tag (eh, c))
}
if (res->num_categories)
res->categories =
- (Z_CategoryInfo **)odr_malloc (eh->o, res->num_categories
+ (Z_CategoryInfo **)odr_malloc (eh->o, res->num_categories
* sizeof(*res->categories));
for (n = c->child; n; n = n->next)
{
res->num_languages = 0;
res->languages = NULL;
res->commonAccessInfo = 0;
-
+
for (c = n->child; c; c = c->next)
{
int i = 0;
case 111: res->welcomeMessage = f_humstring(eh, c); break;
case 112: res->contactInfo = f_contactInfo(eh, c); break;
case 113: res->description = f_humstring(eh, c); break;
- case 114:
+ case 114:
res->num_nicknames = 0;
for (n = c->child; n; n = n->next)
{
}
if (res->num_nicknames)
res->nicknames =
- (char **)odr_malloc (eh->o, res->num_nicknames
+ (char **)odr_malloc (eh->o, res->num_nicknames
* sizeof(*res->nicknames));
for (n = c->child; n; n = n->next)
{
res->dbCombinations[i++] = f_databaseList (eh, n);
}
break;
- case 119:
+ case 119:
res->addresses =
f_networkAddresses (eh, c, &res->num_addresses);
break;
res->supplierContactInfo = 0;
res->submissionContactInfo = 0;
res->accessInfo = 0;
-
+
for (c = n->child; c; c = c->next)
{
int i = 0;
}
if (res->num_nicknames)
res->nicknames =
- (char **)odr_malloc (eh->o, res->num_nicknames
+ (char **)odr_malloc (eh->o, res->num_nicknames
* sizeof(*res->nicknames));
for (n = c->child; n; n = n->next)
{
}
if (res->num_keywords)
res->keywords =
- (Z_HumanString **)odr_malloc (eh->o, res->num_keywords
+ (Z_HumanString **)odr_malloc (eh->o, res->num_keywords
* sizeof(*res->keywords));
for (n = c->child; n; n = n->next)
{
odr_malloc(eh->o, sizeof(*res));
data1_node *c;
int i = 0;
-
+
res->name = 0;
res->description = 0;
res->attributeValue = 0;
Z_AttributeSetDetails *res = (Z_AttributeSetDetails *)
odr_malloc(eh->o, sizeof(*res));
data1_node *c;
-
+
res->attributeSet = 0;
res->num_attributesByType = 0;
res->attributesByType = 0;
res->which = Z_Explain_categoryList;
if (!(res->u.categoryList = f_categoryList(&eh, n)))
return 0;
- return res;
+ return res;
case 2:
res->which = Z_Explain_targetInfo;
if (!(res->u.targetInfo = f_targetInfo(&eh, n)))
res->which = Z_Explain_attributeSetInfo;
if (!(res->u.attributeSetInfo = f_attributeSetInfo(&eh, n)))
return 0;
- return res;
+ return res;
case 10:
res->which = Z_Explain_attributeDetails;
if (!(res->u.attributeDetails = f_attributeDetails(&eh, n)))
ODR o)
{
data1_node *c;
-
+
for (c = n->child; c; c = c->next)
if (c->which == DATA1N_data && level)
{
|| n->u.data.what == DATA1I_xmltext))
{
int i = n->u.data.len;
-
+
while (i > 0 && d1_isspace(n->u.data.data[i-1]))
i--;
if (i == 0)
{
char *tagstr;
- if (n->which == DATA1N_tag)
+ if (n->which == DATA1N_tag)
tagstr = n->u.tag.tag; /* tag at node */
- else if (tag)
+ else if (tag)
tagstr = tag->value.string; /* no take from well-known */
else
return 0;
{
if (!dh)
return;
-
+
/* *ostrich*
- We need to destroy DFAs, in xp_element (xelm) definitions
+ We need to destroy DFAs, in xp_element (xelm) definitions
pop, 2002-12-13
*/
data1_absyn_destroy(dh);
if (dh->map_buf)
xfree (dh->map_buf);
nmem_destroy (dh->mem);
-
+
xfree (dh);
}
return(**pPosInBuffer);
}
-/*
+/*
* Attempt to find a string value given the specified tagpath
- *
- * Need to make this safe by passing in a buffer.....
+ *
+ * Need to make this safe by passing in a buffer.....
*
*/
char *data1_getNodeValue(data1_node* node, char* pTagPath)
/* Max length of a tag */
#define MAX_TAG_SIZE 50
-/*
+/*
* data1_LookupNode : Try and find a node as specified by a tagpath
*/
data1_node *data1_LookupNode(data1_node* node, char* pTagPath)
/* See if we can find the . at the end of this clause */
sepchr = data1_ScanNextToken(pTagPath, &pCurrCharInPath, "."," ", Buffer);
}
-
+
}
yaz_log(YLOG_DEBUG,"search node for child like [%d,%d,%s,%d]",iTagType,iTagValue,StringTagVal,iOccurences);
-
+
/* OK.. We have extracted tagtype, Value and Occurence, see if we can find a node */
/* Under the current parent matching that description */
/**
\brief Count the number of occurences of the last instance on a tagpath.
\param node : The root of the tree we wish to look for occurences in
- \param pTagPath : The tagpath we want to count the occurences of...
+ \param pTagPath : The tagpath we want to count the occurences of...
*/
int data1_CountOccurences(data1_node* node, char* pTagPath)
{
}
mapp = &(*mapp)->next;
}
- else
+ else
yaz_log(YLOG_WARN, "%s:%d: Unknown directive '%s'",
file, lineno, argv[0]);
{
*last = *m = (data1_node *) nmem_malloc (mem, sizeof(**m));
memcpy (*m, n, sizeof(**m));
-
+
(*m)->parent = parent;
(*m)->root = parent->root;
(*m)->child = dup_child(dh, n->child, &(*m)->last_child, mem, *m);
{
cur = data1_mk_tag (
dh, mem, tag->names->name, 0, pn);
-
+
}
}
}
-
+
if (mt->next)
pn = cur;
else if (!m->no_data)
char line[512], *argv[50];
int lineno = 0;
int argc;
-
+
if (!(f = data1_path_fopen(dh, file, "r")))
return 0;
res->force_indicator_length = -1;
res->force_identifier_length = -1;
strcpy(res->user_systems, "z ");
-
+
while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
if (!strcmp(*argv, "name"))
{
continue;
}
res->oid = yaz_string_to_oid_nmem(yaz_oid_std(),
- CLASS_TAGSET, argv[1],
+ CLASS_TAGSET, argv[1],
mem);
if (!res->oid)
{
else if (n->which == DATA1N_data)
n = n->next;
else
- break;
+ break;
}
}
continue;
if (selected && !field->u.tag.node_selected)
continue;
-
+
subf = field->child;
if (!subf)
continue;
-
+
if (!yaz_matchstr(field->u.tag.tag, "mc?"))
continue;
else if (!strcmp(field->u.tag.tag, "leader"))
+ p->length_implementation;
if (!control_field)
- len += p->indicator_length;
+ len += p->indicator_length;
/* we'll allow no indicator if length is not 2 */
/* select when old XML format, since indicator is an element */
if (marc_xml == 0 && is_indicator (p, subf))
subf = subf->child;
-
+
for (; subf; subf = subf->next)
{
if (!control_field)
*buf = (char *)xmalloc(*size = len);
else if (*size <= len)
*buf = (char *)xrealloc(*buf, *size = len);
-
+
op = *buf;
/* we know the base address now */
/* copy temp leader to real output buf op */
memcpy (op, leader, 24);
memint (op, len, 5);
-
+
entry_p = 24;
data_p = base_address;
subf = field->child;
if (!subf)
continue;
-
+
if (!yaz_matchstr(field->u.tag.tag, "mc?"))
continue;
else if (!strcmp(field->u.tag.tag, "leader"))
if (strcmp(subf->u.tag.tag, "subfield"))
yaz_log(YLOG_WARN, "Unhandled tag %s",
subf->u.tag.tag);
-
+
for (xa = subf->u.tag.attributes; xa; xa = xa->next)
if (!strcmp(xa->name, "code"))
identifier = xa->value;
if (!tag || strlen(tag) != 3)
tag = "000";
memcpy (op + entry_p, tag, 3);
-
+
entry_p += 3;
memint (op + entry_p, data_p - data_0, p->length_data_entry);
entry_p += p->length_data_entry;
/*
- * This module reads "loose" SGML and converts it to data1 tree
+ * This module reads "loose" SGML and converts it to data1 tree
*/
#if HAVE_CONFIG_H
}
return n;
}
-
+
/*
* get the tag which is the immediate parent of this node (this may mean
* traversing intermediate things like variants and stuff.
{
data1_node *r = (data1_node *)nmem_malloc(m, sizeof(*r));
r->next = r->child = r->last_child = 0;
-
+
if (!parent)
r->root = r;
else
if (!absyn)
{
yaz_log(YLOG_WARN, "Unable to acquire abstract syntax " "for '%s'",
- name);
+ name);
/* It's now OK for a record not to have an absyn */
}
res = data1_mk_node2 (dh, nmem, DATA1N_root, 0);
}
*p = 0;
}
-
+
data1_node *data1_mk_preprocess (data1_handle dh, NMEM nmem,
const char *target,
const char **attr, data1_node *at)
data1_node *res = data1_mk_node2 (dh, nmem, DATA1N_preprocess, at);
res->u.preprocess.target = data1_insert_string_n (dh, res, nmem,
target, len);
-
+
data1_add_attrs(dh, nmem, attr, &res->u.preprocess.attributes);
return res;
}
data1_node *res = data1_insert_node (dh, nmem, DATA1N_preprocess, at);
res->u.preprocess.target = data1_insert_string_n (dh, res, nmem,
target, len);
-
+
data1_add_attrs(dh, nmem, attr, &res->u.preprocess.attributes);
return res;
}
-data1_node *data1_mk_tag_n (data1_handle dh, NMEM nmem,
+data1_node *data1_mk_tag_n (data1_handle dh, NMEM nmem,
const char *tag, size_t len, const char **attr,
data1_node *at)
{
data1_node *partag = get_parent_tag(dh, at);
data1_node *res = data1_mk_node2 (dh, nmem, DATA1N_tag, at);
data1_element *e = 0;
-
+
res->u.tag.tag = data1_insert_string_n (dh, res, nmem, tag, len);
-
+
if (!partag) /* top tag? */
e = data1_getelementbytagname (dh, at->root->u.root.absyn,
0 /* index as local */,
}
data1_node *data1_mk_tag (data1_handle dh, NMEM nmem,
- const char *tag, const char **attr, data1_node *at)
+ const char *tag, const char **attr, data1_node *at)
{
return data1_mk_tag_n (dh, nmem, tag, strlen(tag), attr, at);
}
return 0;
}
-data1_node *data1_mk_tag_uni (data1_handle dh, NMEM nmem,
+data1_node *data1_mk_tag_uni (data1_handle dh, NMEM nmem,
const char *tag, data1_node *at)
{
data1_node *node = data1_search_tag (dh, at->child, tag);
data1_node *res = data1_mk_node2 (dh, mem, DATA1N_data, parent);
res->u.data.what = DATA1I_text;
res->u.data.len = len;
-
+
res->u.data.data = data1_insert_string_n (dh, res, mem, buf, len);
return res;
}
data1_node *res = data1_mk_node2 (dh, mem, DATA1N_comment, parent);
res->u.data.what = DATA1I_text;
res->u.data.len = len;
-
+
res->u.data.data = data1_insert_string_n (dh, res, mem, buf, len);
return res;
}
if (!partag)
e = data1_getelementbytagname (dh, root->u.root.absyn, 0, tagname);
- else
+ else
{
e = partag->u.tag.element;
if (e)
NMEM nmem)
{
data1_node *node_data;
-
+
node_data = data1_mk_tag_data (dh, at, tag, nmem);
if (!node_data)
return 0;
data1_node *node_data;
char str[128], *p = str;
Odr_oid *ii;
-
+
node_data = data1_mk_tag_data (dh, at, tag, nmem);
if (!node_data)
return 0;
-
+
for (ii = oid; *ii >= 0; ii++)
{
if (ii != oid)
NMEM nmem)
{
data1_node *node_data;
-
+
node_data = data1_mk_tag_data (dh, at, tag, nmem);
if (!node_data)
return 0;
{
char ent[20];
int i = 0;
-
+
while (1)
{
c = (*get_byte)(fh);
if (c == ';')
{
ent[i] = 0;
-
+
c = ' ';
if (!strcmp (ent, "quot"))
c = '"';
pp = &p->next;
p->value = 0;
p->what = DATA1I_xmltext;
-
+
wrbuf_rewind(wrbuf);
while (c && c != '=' && c != '>' && c != '/' && !d1_isspace(c))
{
c = ampr (get_byte, fh, amp);
if (*amp == 0 && c == '"')
{
- c = ampr (get_byte, fh, amp);
+ c = ampr (get_byte, fh, amp);
wrbuf_rewind(wrbuf);
while (*amp || (c && c != '"'))
{
}
else if (*amp == 0 && c == '\'')
{
- c = ampr (get_byte, fh, amp);
+ c = ampr (get_byte, fh, amp);
wrbuf_rewind(wrbuf);
while (*amp || (c && c != '\''))
{
break;
}
}
- else
+ else
{
if (amp == 0 && c == quote_mode)
quote_mode = 0;
else if (amp == 0 && c == '!')
{
int c0, amp0;
-
+
wrbuf_rewind(wrbuf);
-
+
c0 = ampr (get_byte, fh, &0);
if (amp0 == 0 && c0 == '\0')
break;
c = ampr (get_byte, fh, &);
-
+
if (amp0 == 0 && c0 == '-' && amp == 0 && c == '-')
{
/* COMMENT: <!-- ... --> */
int no_dash = 0;
-
+
c = ampr (get_byte, fh, &);
while (amp || c)
{
else if (amp == 0 && c == '>' && no_dash >= 2)
{
if (level > 0)
- d1_stack[level] =
+ d1_stack[level] =
data1_mk_comment_n (
dh, m,
wrbuf_buf(wrbuf), wrbuf_len(wrbuf)-2,
}
else
{ /* DIRECTIVE: <! .. > */
-
+
int blevel = 0;
while (amp || c)
{
c = ampr (get_byte, fh, &);
/* End tag? */
- if (end_tag)
+ if (end_tag)
{
if (*tag == '\0')
--level; /* </> */
return d1_stack[0];
}
continue;
- }
- else if (!strcmp(tag, "var")
+ }
+ else if (!strcmp(tag, "var")
&& xattr && xattr->next && xattr->next->next
- && xattr->value == 0
+ && xattr->value == 0
&& xattr->next->value == 0
&& xattr->next->next->value == 0)
{
const char *type = xattr->next->name;
const char *value = xattr->next->name;
data1_vartype *tp;
-
+
yaz_log(YLOG_LOG, "Variant class=%s type=%s value=%s",
tclass, type, value);
if (!(tp =
tclass, type)))
continue;
/*
- * If we're the first variant in this group, create a parent
+ * If we're the first variant in this group, create a parent
* variant, and insert it before the current variant.
*/
if (parent->which != DATA1N_variant)
data1_insert_string (dh, res, m, value);
}
}
- else
+ else
{
-
+
/* tag .. acquire our element in the abstract syntax */
if (level == 0)
{
else /* != '<'... this is a body of text */
{
int len;
-
+
if (level == 0)
{
c = ampr (get_byte, fh, &);
res->u.data.what = DATA1I_xmltext;
res->u.data.formatted_text = 0;
d1_stack[level] = res;
-
+
wrbuf_rewind(wrbuf);
while (amp || (c && c != '<'))
res->u.data.data = (char*) nmem_malloc (m, len);
else
res->u.data.data = res->lbuf;
-
+
if (len)
memcpy (res->u.data.data, wrbuf_buf(wrbuf), len);
else
char **buf = data1_get_read_buf (dh, &size);
const char *bp;
int rd = 0, res;
-
+
if (!*buf)
*buf = (char *)xmalloc(*size = 4096);
-
+
for (;;)
{
if (rd + 2048 >= *size && !(*buf =(char *)xrealloc(*buf, *size *= 2)))
}
-static int conv_item(NMEM m, yaz_iconv_t t,
+static int conv_item(NMEM m, yaz_iconv_t t,
WRBUF wrbuf, char *inbuf, size_t inlen)
{
wrbuf_rewind(wrbuf);
== 0)
{
n->u.tag.tag =
- data1_insert_string_n (dh, n, m,
+ data1_insert_string_n (dh, n, m,
wrbuf->buf, wrbuf->pos);
}
if (n->u.tag.attributes)
}
int data1_iconv (data1_handle dh, NMEM m, data1_node *n,
- const char *tocode,
+ const char *tocode,
const char *fromcode)
{
if (yaz_matchstr (tocode, fromcode))
{
if (n->which == DATA1N_data)
{
-
+
int sz = n->u.data.len;
const char *ndata = n->u.data.data;
int off = 0;
-
+
for (off = 0; off < sz; off++)
if (!d1_isspace(ndata[off]))
break;
sz = sz - off;
ndata += off;
-
+
while (sz && d1_isspace(ndata[sz - 1]))
sz--;
n->u.data.data = nmem_malloc(m, sz);
n->u.data.len = sz;
memcpy(n->u.data.data, ndata, sz);
-
+
}
data1_chop_text(dh, m, n->child);
}
{
for (; n; n = n->next)
{
- if (n->which == DATA1N_data && n->next &&
+ if (n->which == DATA1N_data && n->next &&
n->next->which == DATA1N_data)
{
int sz = 0;
n->next = np;
if (!np && n->parent)
n->parent->last_child = n;
-
+
}
data1_concat_text(dh, m, n->child);
}
char buf[128];
wrbuf_rewind(b);
-
+
if (n->which != DATA1N_root)
return 0;
sprintf(buf, "@%s{\n", n->u.root.type);
int type, int value)
{
data1_tag *r;
-
+
for (; s; s = s->next)
{
/* scan local set */
fclose(f);
return 0;
}
-
+
/* read namelist */
nm = names;
npp = &rr->names;
else if (!strcmp(cmd, "reference"))
{
char *name;
-
+
if (argc != 2)
{
yaz_log(YLOG_WARN, "%s:%d: Bad # args to reference",
/* n is the only child */
if(! n->next){
- n->parent->last_child = 0;
+ n->parent->last_child = 0;
}
- }
+ }
/* n is one of the following childrens */
else {
data1_node * before;
-
+
/* need to find sibling before me */
before = n->parent->child;
while (before->next != n)
before = before->next;
-
+
before->next = n->next;
-
+
/* n is last child of many */
if ( n->parent->last_child == n){
n->parent->last_child = before;
if (!strcmp(n->u.tag.tag, "idzebra")){
if (n->u.tag.attributes){
data1_xattr *xattr = n->u.tag.attributes;
-
+
for (; xattr; xattr = xattr->next){
- if (!strcmp(xattr->name, "xmlns")
- & !strcmp(xattr->value,
+ if (!strcmp(xattr->name, "xmlns")
+ & !strcmp(xattr->value,
"http://www.indexdata.dk/zebra/"))
data1_remove_node (dh, n);
}
}
}
-
+
break;
/*
case DATA1N_data:
n->parent->last_child, n);
}
*/
-
+
}
if (!strcmp(argv[0], "class"))
{
data1_varclass *r;
-
+
if (argc != 3)
{
yaz_log(YLOG_WARN, "%s:%d: Bad # or args to class",
continue;
}
}
- else
+ else
yaz_log(YLOG_WARN, "%s:%d: Unknown directive '%s'",
file, lineno, argv[0]);
-
+
fclose(f);
return res;
}
while (l)
{
int wlen;
-
+
while (l && d1_isspace(*p))
p++, l--;
if (!l)
char *data1_nodetoidsgml (data1_handle dh, data1_node *n, int select, int *len)
{
WRBUF b = data1_get_wrbuf (dh);
-
+
wrbuf_rewind(b);
-
+
if (!data1_is_xmlmode (dh))
{
wrbuf_puts (b, "<");
break;
}
for (t=s->trans, i=s->tran_no; --i >= 0; t++)
- if ((unsigned) *p >= t->ch[0]
+ if ((unsigned) *p >= t->ch[0]
&& (unsigned) *p <= t->ch[1])
break;
p++;
#include <bset.h>
#include "imalloc.h"
-#define GET_BIT(s,m) (s[(m)/(sizeof(BSetWord)*8)]&(1<<(m&(sizeof(BSetWord)*8-1))))
+#define GET_BIT(s,m) (s[(m)/(sizeof(BSetWord)*8)]&(1<<(m&(sizeof(BSetWord)*8-1))))
#define SET_BIT(s,m) (s[(m)/(sizeof(BSetWord)*8)]|=(1<<(m&(sizeof(BSetWord)*8-1))))
BSetHandle *mk_BSetHandle (int size, int chunk)
{
- int wsize = 1+size/(sizeof(BSetWord)*8);
+ int wsize = 1+size/(sizeof(BSetWord)*8);
BSetHandle *sh;
if (chunk <= 1)
chunk = 32;
- sh = (BSetHandle *) imalloc (sizeof(BSetHandle) +
+ sh = (BSetHandle *) imalloc (sizeof(BSetHandle) +
chunk*sizeof(BSetWord)*wsize);
sh->size = size;
off = sh->offset;
if ((off + sh->wsize) > sh->chunk)
{
- sh1 = (BSetHandle *) imalloc (sizeof(BSetHandle) +
+ sh1 = (BSetHandle *) imalloc (sizeof(BSetHandle) +
sh->chunk*sizeof(BSetWord));
sh1->size = sh->size;
sh1->wsize = sh->wsize;
BSet charset);
static void term_Tnode (struct DFA_parse *parse_info);
-static void
- del_followpos (struct DFA_parse *parse_info),
- init_pos (struct DFA_parse *parse_info),
+static void
+ del_followpos (struct DFA_parse *parse_info),
+ init_pos (struct DFA_parse *parse_info),
del_pos (struct DFA_parse *parse_info),
mk_dfa_tran (struct DFA_parse *parse_info, struct DFA_states *dfas),
add_follow (struct DFA_parse *parse_info, DFASet lastpos, DFASet firstpos),
nextchar (struct DFA_parse *parse_info, int *esc),
read_charset (struct DFA_parse *parse_info);
-static const char
+static const char
*str_char (unsigned c);
#define L_LP 1
*expr_4 (struct DFA_parse *parse_info);
static struct Tnode *expr_1 (struct DFA_parse *parse_info)
-{
+{
struct Tnode *t1, *t2, *tn;
if (!(t1 = expr_2 (parse_info)))
lex (parse_info);
if (!(t2 = expr_2 (parse_info)))
return t2;
-
+
tn = mk_Tnode (parse_info);
tn->pos = OR;
tn->u.p[0] = t1;
static struct Tnode *expr_2 (struct DFA_parse *parse_info)
{
struct Tnode *t1, *t2, *tn;
-
+
if (!(t1 = expr_3 (parse_info)))
return t1;
while (parse_info->lookahead == L_WILD ||
{
if (!(t2 = expr_3 (parse_info)))
return t2;
-
+
tn = mk_Tnode (parse_info);
tn->pos = CAT;
tn->u.p[0] = t1;
t2 = mk_Tnode (parse_info);
t2->pos = ++parse_info->position;
t2->u.ch[1] = t2->u.ch[0] = '\n';
-
+
tn = mk_Tnode (parse_info);
tn->pos = CAT;
tn->u.p[0] = t1;
tn->u.p[1] = t2;
t1 = tn;
-
+
lex (parse_info);
}
}
t2->pos = ++parse_info->position;
t2->u.ch[0] = -(++parse_info->rule);
t2->u.ch[1] = start_anchor_flag ? 0 : -(parse_info->rule);
-
+
*tnp = mk_Tnode(parse_info);
(*tnp)->pos = CAT;
(*tnp)->u.p[0] = t1;
ch0 = nextchar_set (parse_info, &esc0);
}
/**
- ch0 is last met character
- ch1 is "next" char
+ ch0 is last met character
+ ch1 is "next" char
*/
while (ch0 != 0)
{
mapto = (*parse_info->cmap) (parse_info->cmap_data, &cp0, len);
assert (mapto);
-
+
parse_info->expr_ptr = (const unsigned char *) cp0;
parse_info->look_ch = ((unsigned char **) mapto)[i][0];
yaz_log (YLOG_DEBUG, "map from %c to %d", parse_info->expr_ptr[-1], parse_info->look_ch);
return map_l_char (parse_info);
else if (parse_info->look_ch == '[')
return read_charset(parse_info);
- else
+ else
{
const int *cc;
for (cc = parse_info->charMap; *cc; cc += 2)
static void init_pos (struct DFA_parse *parse_info)
{
- parse_info->posar = (struct Tnode **) imalloc (sizeof(struct Tnode*)
+ parse_info->posar = (struct Tnode **) imalloc (sizeof(struct Tnode*)
* (1+parse_info->position));
}
{
while (lastpos)
{
- parse_info->followpos[lastpos->value] =
+ parse_info->followpos[lastpos->value] =
union_DFASet (parse_info->poset,
parse_info->followpos[lastpos->value], firstpos);
lastpos = lastpos->next;
- }
+ }
}
static void dfa_trav (struct DFA_parse *parse_info, struct Tnode *n)
{
struct Tnode **posar = parse_info->posar;
DFASetType poset = parse_info->poset;
-
+
switch (n->pos)
{
case CAT:
pos_i = pos;
j = i = 0;
for (tran_set = dfa_from->set; tran_set; tran_set = tran_set->next)
- if ((c = posar[tran_set->value]->u.ch[0]) >= 0 && c <= max_char)
+ if ((c = posar[tran_set->value]->u.ch[0]) >= 0 && c <= max_char)
*pos_i++ = tran_set->value;
else if (c < 0)
{
{
char_0 = max_char+1;
for (pos_i = pos; (i = *pos_i) != -1; ++pos_i)
- if (posar[i]->u.ch[1] >= char_1
+ if (posar[i]->u.ch[1] >= char_1
&& (c=posar[i]->u.ch[0]) < char_0)
{
if (c < char_1)
break;
char_1 = max_char;
-
+
tran_set = mk_DFASet (poset);
for (pos_i = pos; (i = *pos_i) != -1; ++pos_i)
{
{
while ((cc[0] = cc[2]))
{
- cc[1] = cc[3];
+ cc[1] = cc[3];
cc += 2;
}
break;
static struct DFA_parse *dfa_parse_init (void)
{
- struct DFA_parse *parse_info =
+ struct DFA_parse *parse_info =
(struct DFA_parse *) imalloc (sizeof (struct DFA_parse));
parse_info->charset = mk_BSetHandle (255, 20);
#define INFBUF_SIZE 16384
-#define INLINE
+#define INLINE
static INLINE void set_bit (MatchContext *mc, MatchWord *m, int ch, int state)
{
mc->n = (dfa->no_states+WORD_BITS) / WORD_BITS;
mc->range = range;
mc->Sc = icalloc (sizeof(*mc->Sc) * 256 * mc->n);
-
+
for (i=0; i<dfa->no_states; i++)
{
int j;
int ch0 = state->trans[j].ch[0];
int ch1 = state->trans[j].ch[1];
assert (ch0 >= 0 && ch1 >= 0);
-
+
for (ch = ch0; ch <= ch1; ch++)
set_bit (mc, mc->Sc, ch, i);
}
while ((ch = getc (inf)) != EOF)
{
MatchWord *Rj_t;
-
+
infbuf[inf_ptr] = ch;
if (ch == '\n')
{
}
else
inf = stdin;
-
+
mc = mk_MatchContext (dfa, range);
go (mc, dfa, inf);
if (**++argv != '-' && **argv)
{
++no;
-
+
i = read_file (*argv, dfa);
if (i)
return i;
/* copy rest of line to output */
fputs (s, outf);
else
- {
+ {
/* preprocess regular expression */
- prep (&s);
+ prep (&s);
/* now parse regular expression */
sc = s;
i = dfa_parse (dfa, &sc);
struct DFA_states *dfas;
struct DFA_trans *tm;
int i;
-
+
dfas = (struct DFA_states *) imalloc (sizeof(struct DFA_states));
assert (dfas);
dfas->hasharray = (struct DFA_state **)
sb = (DFA_stateb *) imalloc (sizeof(*sb));
sb->next = dfas->statemem;
dfas->statemem = sb;
- sb->state_block = si = dfas->freelist =
+ sb->state_block = si = dfas->freelist =
(struct DFA_state *) imalloc (sizeof(struct DFA_state)*DFA_CHUNK);
for (i = 0; i<DFA_CHUNK-1; i++, si++)
si->next = si+1;
i = dfa_parse(dfa, &cp);
return i;
}
-
+
static void tst(int argc, char **argv)
{
struct DFA *dfa = dfa_init();
void *head_buf;
dict_bf_readp(dict->dbf, 0, &head_buf);
memcpy(head_buf, &dict->head, sizeof(dict->head));
- dict_bf_touch(dict->dbf, 0);
+ dict_bf_touch(dict->dbf, 0);
}
dict_bf_close(dict->dbf);
xfree(dict);
int dict_bf_close(Dict_BFile dbf)
{
dict_bf_flush_blocks(dbf, -1);
-
+
xfree(dbf->all_blocks);
xfree(dbf->all_data);
xfree(dbf->hash_array);
int i, slen, no = 0;
short *from_indxp, *to_indxp;
char *from_info, *to_info;
-
+
from_indxp = (short*) ((char*) from_p+DICT_bsize(from_p));
to_indxp = (short*) ((char*) to_p+DICT_bsize(to_p));
to_info = (char*) to_p + DICT_infoffset;
from_info += sizeof(Dict_ptr);
memcpy(&subchar, from_info, sizeof(subchar));
from_info += sizeof(Dict_char);
-
+
memcpy(to_info, &subptr, sizeof(Dict_ptr));
to_info += sizeof(Dict_ptr);
memcpy(to_info, &subchar, sizeof(Dict_char));
return -1;
map[0] = 0;
map[1] = dict_from->head.page_size;
-
+
for (i = 1; i < (int) (dict_from->head.last); i++)
{
void *buf;
#include "dict-p.h"
static void dict_del_subtree(Dict dict, Dict_ptr ptr,
- void *client,
+ void *client,
int (*f)(const char *, void *))
{
void *p = 0;
short *indxp;
int i, hi;
-
+
if (!ptr)
return;
-
+
dict_bf_readp(dict->dbf, ptr, &p);
indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
hi = DICT_nodir(p)-1;
else
{
Dict_ptr subptr;
-
+
/* Dict_ptr subptr */
/* Dict_char sub char */
/* unsigned char length of information */
/* char * information */
char *info = (char*)p - indxp[-i];
memcpy(&subptr, info, sizeof(Dict_ptr));
-
+
if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
{
if (f)
if (subptr)
{
dict_del_subtree(dict, subptr, client, f);
-
+
/* page may be gone. reread it .. */
dict_bf_readp(dict->dbf, ptr, &p);
indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
}
static int dict_del_string(Dict dict, const Dict_char *str, Dict_ptr ptr,
- int sub_flag, void *client,
+ int sub_flag, void *client,
int (*f)(const char *, void *))
{
int mid, lo, hi;
dict_bf_readp(dict->dbf, ptr, &p);
mid = lo = 0;
hi = DICT_nodir(p)-1;
- indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
+ indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
while (lo <= hi)
{
mid = (lo+hi)/2;
mid = lo = 0;
r = 1; /* signal deleted */
/* start again (may not be the most efficient way to go)*/
- continue;
+ continue;
}
}
else
subptr = 0; /* avoid dict_del_subtree (end of function)*/
if (r == 2)
{ /* subptr page became empty and is removed */
-
+
/* see if this entry is a real one or if it just
serves as pointer to subptr */
if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
{
int cache;
BFile bf;
-
+
struct Dict_file_block *all_blocks;
struct Dict_file_block *free_list;
struct Dict_file_block **hash_array;
-
+
struct Dict_file_block *lru_back, *lru_front;
int hash_size;
void *all_data;
-
+
int block_size;
int hits;
int misses;
dir[0..nodir-1]
ptr,info,string
*/
-
+
YAZ_END_CDECL
#endif
int no_of_new = 0, no_of_same = 0, no_of_change = 0;
int no_of_hits = 0, no_of_misses = 0, no_not_found = 0, no_of_deleted = 0;
int max_pos;
-
+
prog = argv[0];
if (argc < 2)
{
yaz_log (YLOG_FATAL|YLOG_ERRNO, "cannot open %s", inputfile);
exit (1);
}
-
+
while (fgets (ipf_buf, 1023, ipf))
{
char *ipf_ptr = ipf_buf;
}
if (rw)
{
- yaz_log (YLOG_LOG, "Iterations.... %d", no_of_iterations);
+ yaz_log (YLOG_LOG, "Iterations.... %d", no_of_iterations);
if (do_delete)
{
yaz_log (YLOG_LOG, "No of deleted. %d", no_of_deleted);
if (scan_the_thing)
{
char term_dict[1024];
-
+
int before = 1000000;
int after = 1000000;
yaz_log (YLOG_LOG, "dict_scan");
int cache, int rw)
{
Dict_BFile dbf;
-
+
dbf = (Dict_BFile) xmalloc(sizeof(*dbf));
dbf->bf = bf_open(bfs, name, block_size, rw);
if (!dbf->bf)
{
assert(p);
- /* remove from lru queue */
+ /* remove from lru queue */
if (p->lru_prev)
p->lru_prev->lru_next = p->lru_next;
else
effective_block, effective_offset,
p->nbytes);
#endif
-
+
}
else
{
if (*pp)
(*pp)->h_prev = &p->h_next;
*pp = p;
-
+
return p;
}
{
/* Already at front? */
if (!p->lru_next)
- return ;
+ return ;
/* Remove */
if (p->lru_prev)
best_indxp = indxp;
}
}
- else
+ else
{ /* new char prefix. restore */
prev_char = dc;
no_current = 1;
}
static void clean_page(Dict dict, Dict_ptr ptr, void *p, Dict_char *out,
- Dict_ptr subptr, char *userinfo)
+ Dict_ptr subptr, char *userinfo)
{
char *np = (char *) xmalloc(dict->head.page_size);
int i, slen, no = 0;
info2 += *userinfo + 1;
}
else
- *info2++ = 0;
- subptr = 0;
+ *info2++ = 0;
+ subptr = 0;
++no;
continue;
}
++no;
}
#if 1
- memcpy((char*)p+DICT_infoffset,
+ memcpy((char*)p+DICT_infoffset,
(char*)np+DICT_infoffset,
info2 - ((char*)np+DICT_infoffset));
memcpy((char*)p + ((char*)indxp2 - (char*)np),
void *p;
dict_bf_readp(dict->dbf, ptr, &p);
-
+
assert(p);
assert(ptr);
return dict_ins(dict, str-1, ptr,
userlen, userinfo);
}
- if (split_page(dict, ptr, p))
+ if (split_page(dict, ptr, p))
{
yaz_log(YLOG_FATAL, "Unable to split page %d\n", ptr);
assert(0);
#define WORD_BITS 32
#define MAX_LENGTH 1024
-/* This code is based
+/* This code is based
* Sun Wu and Udi Manber: Fast Text Searching Allowing Errors.
* Communications of the ACM, pp. 83-91, Vol. 35, No. 10, Oct. 1992, USA.
* PostScript version of the paper in its submitted form: agrep1.ps)
- * recommended reading to understand AGREP !
+ * recommended reading to understand AGREP !
*
* http://www.tgries.de/agrep/#AGREP1PS
* http://www.tgries.de/agrep/doc/agrep1ps.zip
MatchWord *match_mask; /* match_mask */
} MatchContext;
-#define INLINE
+#define INLINE
static INLINE void set_bit(MatchContext *mc, MatchWord *m, int ch, int state)
{
int off = state & (WORD_BITS-1);
int wno = state / WORD_BITS;
-
+
m[mc->n * ch + wno] |= 1<<off;
}
for (d = 1; d <= mc->range; d++)
{
or(mc, Rtmp, Rj, Rj1); /* 2,3 */
-
+
shift(mc, Rtmp_2, Rtmp, dfa);
mask_shift(mc, Rtmp, Rj+mc->n, dfa, ch); /* 1 */
-
+
or(mc, Rtmp, Rtmp_2, Rtmp); /* 1,2,3*/
Rj1 += mc->n;
-
+
or(mc, Rj1, Rtmp, Rj); /* 1,2,3,4 */
Rj += mc->n;
{
if (was_match)
{
- int ret = userfunc((char*) prefix,
+ int ret = userfunc((char*) prefix,
info+(j+1)*sizeof(Dict_char), client);
if (ret)
return ret;
info = (char*)p - indxp[-lo];
memcpy(&ch, info+sizeof(Dict_ptr), sizeof(Dict_char));
prefix[pos] = ch;
-
+
if (pos > *max_pos)
*max_pos = pos;
if (pos >= init_pos)
yaz_log(YLOG_DEBUG, " %2d %3d %c", i, pattern[i],
(pattern[i] > ' ' && pattern[i] < 127) ? pattern[i] : '?');
}
-
+
dfa_set_cmap(dfa, dict->grep_cmap_data, dict->grep_cmap);
i = dfa_parse(dfa, &this_pattern);
dict_bf_readp(dict->dbf, ptr, &p);
mid = lo = 0;
hi = DICT_nodir(p)-1;
- indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
+ indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
while (lo <= hi)
{
mid = (lo+hi)/2;
dict_bf_readp(dict->dbf, ptr, &p);
lo = 0;
hi = DICT_nodir(p)-1;
- indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
+ indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
while (lo <= hi)
{
if (indxp[-lo] > 0)
info = (char*)p - indxp[-lo];
memcpy(&ch, info+sizeof(Dict_ptr), sizeof(Dict_char));
prefix[pos] = ch;
-
+
sc = mi->s[ch & 255];
ri[1+range] = SH(ri[0]) & sc;
for (i=1; i<=range; i++)
lookup_ec(dict, subptr, mi, ri, pos+1,
userfunc, range, prefix);
dict_bf_readp(dict->dbf, ptr, &p);
- indxp = (short*) ((char*) p +
+ indxp = (short*) ((char*) p +
DICT_bsize(p)-sizeof(short));
}
}
if (!dict->head.root)
return 0;
-
+
mi = prepare_match((Dict_char*) pattern);
-
+
ri = (MatchWord *) xmalloc((dict_strlen((Dict_char*) pattern)+range+2)
* (range+1)*sizeof(*ri));
for (i = 0; i <= range; i++)
ri[i] = (2<<i)-1;
-
+
ret = lookup_ec(dict, dict->head.root, mi, ri, 0, userfunc,
range, prefix);
xfree(ri);
dict->head.freelist = 0;
dict->head.page_size = page_size;
dict->head.compact_flag = compact_flag;
-
+
/* create header with information (page 0) */
- if (dict->rw)
+ if (dict->rw)
dict_bf_newp(dict->dbf, 0, &head_buf, page_size);
}
#include "dict-p.h"
-static void scan_direction(Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
+static void scan_direction(Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
int start, int *count, void *client,
int (*userfunc)(char *, const char *, int, void *),
int dir)
else
lo = 0;
}
- indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
+ indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
while (lo <= hi && lo >= 0 && *count > 0)
{
}
if (*count>0 && subptr)
{
- scan_direction(dict, subptr, pos+1, str, -1, count,
+ scan_direction(dict, subptr, pos+1, str, -1, count,
client, userfunc, dir);
dict_bf_readp(dict->dbf, ptr, &p);
- indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
+ indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
}
if (*count>0 && dir<0 && info[sizeof(Dict_ptr)+sizeof(Dict_char)])
{
}
}
-void dict_scan_r(Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
+void dict_scan_r(Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
int *before, int *after, void *client,
int (*userfunc)(char *, const char *, int, void *))
{
{
if ((*userfunc)((char *) str, info+
(dict_strlen((Dict_char*) info)+1)
- *sizeof(Dict_char),
+ *sizeof(Dict_char),
*after, client))
{
*after = 0;
}
}
if (*after && subptr)
- scan_direction(dict, subptr, pos+1, str, -1,
+ scan_direction(dict, subptr, pos+1, str, -1,
after, client, userfunc, 1);
}
else
scan_direction(dict, ptr, pos, str, cmp ? mid : mid+1, after,
client, userfunc, 1);
if (*before && mid > 0)
- scan_direction(dict, ptr, pos, str, mid-1, before,
+ scan_direction(dict, ptr, pos, str, mid-1, before,
client, userfunc, -1);
}
const char **from, int *len, int first);
YAZ_EXPORT const char **chr_map_q_input(chrmaptab maptab,
const char **from, int len, int first);
-
+
YAZ_EXPORT const char *chr_map_output(chrmaptab t, const char **from, int len);
YAZ_END_CDECL
typedef struct data1_xpelement
{
char *xpath_expr;
-#ifdef ENHANCED_XELM
+#ifdef ENHANCED_XELM
struct xpath_location_step xpath[XPATH_STEP_COUNT];
int xpath_len;
#endif
- struct DFA *dfa;
+ struct DFA *dfa;
data1_termlist *termlists;
struct data1_xpelement *next;
#if OPTIMIZE_MELM
/** \file api.h
\brief Zebra API
-
+
Return codes:
Most functions has return type ZEBRA_RES, where ZEBRA_FAIL indicates
failure; ZEBRA_OK indicates success.
char *buf; /* record buffer (void pointer really) */
int len; /* length */
const Odr_oid *format; /* record syntax */
- char *base;
+ char *base;
zint sysno;
int score;
} ZebraRetrievalRecord;
/** \brief Creates a Zebra Service.
\param configName name of configuration file
-
+
This function is a simplified version of zebra_start_res.
*/
YAZ_EXPORT
\param configName name of configuration file
\param def_res default resources
\param over_res overriding resources
-
+
This function typically called once in a program. A Zebra Service
acts as a factory for Zebra session handles.
*/
/** \brief stops a Zebra service.
\param zs service handle
-
+
Frees resources used by the service.
*/
YAZ_EXPORT
/** \brief Creates a Zebra session handle within service.
\param zs service handle.
\param res resources to be used for the service (NULL for none)
-
+
There should be one handle for each thread doing something
- with zebra, be that searching or indexing. In simple apps
- one handle is sufficient
+ with zebra, be that searching or indexing. In simple apps
+ one handle is sufficient
*/
YAZ_EXPORT
ZebraHandle zebra_open(ZebraService zs, Res res
/** \brief Set limit before Zebra does approx hit count
\param zh session handle
\param approx_limit the limit
-
+
Results will be approximiate if hit count is greater than the
limit specified. By default there is a high-limit (no limit).
*/
const Odr_oid *input_format,
int num_recs,
ZebraRetrievalRecord *recs);
-/** \brief Deletes one or more resultsets
+/** \brief Deletes one or more resultsets
\param zh session handle
\param function Z_DeleteResultSetRequest_{list,all}
\param num_setnames number of result sets
\param zh session handle
\param setname result set name
\param num_terms number of terms returned in this integer
-
+
This function is used in conjunction with zebra_result_set_term_info.
If operation was successful, ZEBRA_OK is returned; otherwise
ZEBRA_FAIL is returned (typically non-existing setname)
\param zh session handle
\param setname result set name
\param no the term we want to know about (0=first, 1=second,..)
- \param count the number of occurrences of this term, aka hits (output)
+ \param count the number of occurrences of this term, aka hits (output)
\param approx about hits: 0=exact,1=approx (output)
\param termbuf buffer for term string (intput, output)
\param termlen size of termbuf (input=max, output=actual length)
\param term_ref_id if non-NULL *term_ref_id holds term reference
-
+
Returns information about one search term associated with result set.
Use zebra_result_set_term_no to read total number of terms associated
with result set. If this function can not return information,
\param zapt Attribute plus Term (start term)
\param attributeset Attributeset for Attribute plus Term
\param position input/output position
- \param num_entries number of terms requested / returned
+ \param num_entries number of terms requested / returned
\param entries list of resulting terms (ODR allocated)
\param is_partial upon return 1=partial, 0=complete
\param setname limit scan by this set (NULL means no limit)
\param stream ODR handle for result
\param query PQF scan query
\param position input/output position
- \param num_entries number of terms requested / returned
+ \param num_entries number of terms requested / returned
\param entries list of resulting terms (ODR allocated)
\param is_partial upon return 1=partial, 0=complete
\param setname limit scan by this set (NULL means no limit)
*/
YAZ_EXPORT
int zebra_string_norm(ZebraHandle zh, const char *index_type,
- const char *input_str,
+ const char *input_str,
int input_len, char *output_str, int output_len);
/** \brief Creates a database
ZEBRA_RES zebra_admin_import_begin(ZebraHandle zh, const char *database,
const char *record_type);
-YAZ_EXPORT
+YAZ_EXPORT
ZEBRA_RES zebra_admin_import_segment(ZebraHandle zh,
Z_Segment *segment);
-YAZ_EXPORT
+YAZ_EXPORT
ZEBRA_RES zebra_admin_import_end(ZebraHandle zh);
-YAZ_EXPORT
+YAZ_EXPORT
ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw
) ZEBRA_GCC_ATTR((warn_unused_result));
YAZ_EXPORT
ZEBRA_RES zebra_compact(ZebraHandle zh);
-YAZ_EXPORT
+YAZ_EXPORT
ZEBRA_RES zebra_repository_index(ZebraHandle zh, const char *path,
enum zebra_recctrl_action_t action);
-YAZ_EXPORT
+YAZ_EXPORT
ZEBRA_RES zebra_repository_update(ZebraHandle zh, const char *path);
-YAZ_EXPORT
+YAZ_EXPORT
ZEBRA_RES zebra_repository_delete(ZebraHandle zh, const char *path);
-YAZ_EXPORT
+YAZ_EXPORT
ZEBRA_RES zebra_repository_show(ZebraHandle zh, const char *path);
/** \brief Simple update record
This function is a simple wrapper or zebra_update_record with
action=action_update (insert or replace) .
*/
-YAZ_EXPORT
+YAZ_EXPORT
ZEBRA_RES zebra_add_record(ZebraHandle zh, const char *buf, int buf_size);
-
+
/** \brief Updates record
\param zh session handle
\param action (insert,replace,delete or update (replace/insert)
\param buf_size record buffer size
*/
YAZ_EXPORT
-ZEBRA_RES zebra_update_record(ZebraHandle zh,
+ZEBRA_RES zebra_update_record(ZebraHandle zh,
enum zebra_recctrl_action_t action,
const char *recordType,
zint *sysno, const char *match,
const char *fname,
const char *buf, int buf_size);
-YAZ_EXPORT
+YAZ_EXPORT
ZEBRA_RES zebra_sort(ZebraHandle zh, ODR stream,
int num_input_setnames,
const char **input_setnames,
const char *output_setname,
Z_SortKeySpecList *sort_sequence,
int *sort_status
- ) ZEBRA_GCC_ATTR((warn_unused_result));
+ ) ZEBRA_GCC_ATTR((warn_unused_result));
YAZ_EXPORT
-ZEBRA_RES zebra_select_databases(ZebraHandle zh, int num_bases,
+ZEBRA_RES zebra_select_databases(ZebraHandle zh, int num_bases,
const char **basenames
) ZEBRA_GCC_ATTR((warn_unused_result));
YAZ_EXPORT
void zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
YAZ_EXPORT
-const char *zebra_get_resource(ZebraHandle zh,
+const char *zebra_get_resource(ZebraHandle zh,
const char *name, const char *defaultvalue);
YAZ_EXPORT
ZebraMetaRecord *zebra_meta_records_create_range(ZebraHandle zh,
- const char *name,
+ const char *name,
zint start, int num);
YAZ_EXPORT
void zebra_meta_records_destroy(ZebraHandle zh, ZebraMetaRecord *records,
int num);
-YAZ_EXPORT
+YAZ_EXPORT
struct BFiles_struct *zebra_get_bfs(ZebraHandle zh);
YAZ_EXPORT
ZEBRA_RES zebra_set_limit(ZebraHandle zh, int complement_flag, zint *ids);
YAZ_EXPORT
-ZEBRA_RES zebra_set_break_handler(ZebraHandle zh,
+ZEBRA_RES zebra_set_break_handler(ZebraHandle zh,
int (*f)(void *client_data),
void *client_data);
YAZ_EXPORT
ZEBRA_RES zebra_register_check(ZebraHandle zh, const char *spec);
-YAZ_END_CDECL
+YAZ_END_CDECL
/** \mainpage Zebra
*
*
* \section res Resources
*
- * The resources system (res.h) is a manager of configuration
+ * The resources system (res.h) is a manager of configuration
* resources. The resources can be viewed as a simple database.
* Resources can be read from a configurtion file, they can be
* read or written by an application. Resources can also be written,
*
* Zebra has more than one ISAM system. The old and stable ISAM system
* is named isamc (see isamc.h). Another version isams is a write-once
- * isam system that is quite compact - suitable for CD-ROMs (isams.h).
+ * isam system that is quite compact - suitable for CD-ROMs (isams.h).
* The newest ISAM system, isamb, is implemented as a B-Tree (see isamb.h).
*
* \section data1 Data-1
/** \brief destroys a block files handle
\param bfiles block files handle
-
+
The files in the block files collection are not deleted. Only the
handle is freed.
*/
\param more_info more information to be stored in file (header)
\retval 0 success
\retval -1 failure (can never happen as the code is now)
-*/
+*/
YAZ_EXPORT
int bf_xclose(BFile bf, int version, const char *more_info);
on same platform depending on whether 64-bit is enabled or not.
Note that if a shadow area has unlimited size, that is represented
as max_bytes = -1.
-*/
+*/
YAZ_EXPORT
int bfs_shadow_directory_stat(BFiles bfs, int no, const char **directory,
double *used_bytes, double *max_bytes);
struct data1_attset;
-typedef struct data1_attset data1_attset;
+typedef struct data1_attset data1_attset;
typedef struct data1_att data1_att;
typedef struct data1_attset_child data1_attset_child;
int force_indicator_length;
int force_identifier_length;
- char leader[24]; /* Fixme! Need linear access to LEADER of MARC record */
+ char leader[24]; /* Fixme! Need linear access to LEADER of MARC record */
struct data1_marctab *next;
} data1_marctab;
typedef struct data1_node
{
/* the root of a record (containing global data) */
-#define DATA1N_root 1
+#define DATA1N_root 1
/* a tag */
-#define DATA1N_tag 2
+#define DATA1N_tag 2
/* some data under a leaf tag or variant */
#define DATA1N_data 3
/* variant specification (a triple, actually) */
struct data1_absyn *absyn; /* abstract syntax for this type */
} root;
- struct
+ struct
{
char *tag;
data1_element *element;
/* binary data inclusion */
#define DATA1I_incbin 2
/* text data */
-#define DATA1I_text 3
+#define DATA1I_text 3
/* numerical data */
#define DATA1I_num 4
/* object identifier */
YAZ_EXPORT data1_node *data1_read_nodex (data1_handle dh, NMEM m,
int (*get_byte)(void *fh), void *fh,
WRBUF wrbuf);
-YAZ_EXPORT data1_node *data1_read_record(data1_handle dh,
+YAZ_EXPORT data1_node *data1_read_record(data1_handle dh,
int (*rf)(void *, char *, size_t),
void *fh, NMEM m);
data1_tagset *s,
int type, int value);
YAZ_EXPORT data1_tagset *data1_empty_tagset (data1_handle dh);
-YAZ_EXPORT data1_tagset *data1_read_tagset(data1_handle dh,
+YAZ_EXPORT data1_tagset *data1_read_tagset(data1_handle dh,
const char *file,
int type);
-YAZ_EXPORT data1_element *data1_getelementbytagname(data1_handle dh,
+YAZ_EXPORT data1_element *data1_getelementbytagname(data1_handle dh,
data1_absyn *abs,
data1_element *parent,
const char *tagname);
char *zclass, char *type);
YAZ_EXPORT Z_Espec1 *data1_read_espec1(data1_handle dh, const char *file);
YAZ_EXPORT int data1_doespec1(data1_handle dh, data1_node *n, Z_Espec1 *e);
-YAZ_EXPORT data1_esetname *data1_getesetbyname(data1_handle dh,
+YAZ_EXPORT data1_esetname *data1_getesetbyname(data1_handle dh,
data1_absyn *a,
const char *name);
YAZ_EXPORT data1_element *data1_getelementbyname(data1_handle dh,
YAZ_EXPORT data1_node *data1_mk_node2(data1_handle dh, NMEM m,
int type, data1_node *parent);
-YAZ_EXPORT data1_node *data1_mk_tag (data1_handle dh, NMEM nmem,
+YAZ_EXPORT data1_node *data1_mk_tag (data1_handle dh, NMEM nmem,
const char *tag, const char **attr,
data1_node *at);
YAZ_EXPORT data1_node *data1_mk_tag_n (data1_handle dh, NMEM nmem,
YAZ_EXPORT data1_node *data1_search_tag (data1_handle dh, data1_node *n,
const char *tag);
-YAZ_EXPORT data1_node *data1_mk_tag_uni (data1_handle dh, NMEM nmem,
+YAZ_EXPORT data1_node *data1_mk_tag_uni (data1_handle dh, NMEM nmem,
const char *tag, data1_node *at);
YAZ_EXPORT data1_attset *data1_get_attset (data1_handle dh, const char *name);
YAZ_EXPORT data1_maptab *data1_read_maptab(data1_handle dh, const char *file);
YAZ_EXPORT Z_ExplainRecord *data1_nodetoexplain(data1_handle dh,
data1_node *n, int select,
ODR o);
-YAZ_EXPORT Z_BriefBib *data1_nodetosummary(data1_handle dh,
+YAZ_EXPORT Z_BriefBib *data1_nodetosummary(data1_handle dh,
data1_node *n, int select,
ODR o);
YAZ_EXPORT char *data1_nodetosoif(data1_handle dh, data1_node *n, int select,
YAZ_EXPORT data1_node *data1_get_root_tag (data1_handle dh, data1_node *n);
YAZ_EXPORT int data1_iconv (data1_handle dh, NMEM m, data1_node *n,
- const char *tocode,
+ const char *tocode,
const char *fromcode);
YAZ_EXPORT const char *data1_get_encoding (data1_handle dh, data1_node *n);
/** \file dict.h
\brief Zebra dictionary
-
+
The dictionary is a hash that maps a string to a value.
The value is opaque and is defined as a sequence of bytes
with a length in the range 0 to 255.
\param page_size page size of disc block
\returns dictionary handle
*/
-YAZ_EXPORT
+YAZ_EXPORT
Dict dict_open(BFiles bfs, const char *name, int cache, int rw,
int compact_flag, int page_size);
\param f function be called for each match (NULL for no call of f)
\retval 0 OK
\retval -1 error
-
+
Function f is called for each item matched.
*/
YAZ_EXPORT
\retval 0 Operation complete. Function f returned zero value always
\retval >0 Operation incomplete. Function f returned a non-zero value
\retval -1 error (such as bad regular expression)
-
+
The function f is called for each match. If function f returns
- non-zero value the grep operation is stopped and the returned
+ non-zero value the grep operation is stopped and the returned
non-zero value is also returned by dict_lookup_ec.
*/
YAZ_EXPORT
the scan operation is cancelled.
*/
YAZ_EXPORT
-int dict_scan(Dict dict, char *str,
+int dict_scan(Dict dict, char *str,
int *before, int *after, void *client,
int (*f)(char *name, const char *info, int pos, void *client));
\param dict dictionary handle
\param vp client data to be passed to cmap function handler
\param cmap function be called for each character
-
+
This function must be called prior to using dict_grep_lookup.
If vp is NULL, no character mapping takes place for dict_lookup_grep.
*/
-YAZ_EXPORT
+YAZ_EXPORT
void dict_grep_cmap(Dict dict, void *vp,
const char **(*cmap)(void *vp,
const char **from, int len));
YAZ_EXPORT
void dict_clean(Dict dict);
-/** \brief get number of lookup operations, since dict_open
+/** \brief get number of lookup operations, since dict_open
\param dict dictionary handle
\returns number of operatons
*/
YAZ_EXPORT
zint dict_get_no_lookup(Dict dict);
-/** \brief get number of insert operations, since dict_open
+/** \brief get number of insert operations, since dict_open
\param dict dictionary handle
\returns number of operatons
*/
YAZ_EXPORT
zint dict_get_no_insert(Dict dict);
-/** \brief get number of page split operations, since dict_open
+/** \brief get number of page split operations, since dict_open
\param dict dictionary handle
\returns number of operatons
*/
zint dict_get_no_split(Dict dict);
YAZ_END_CDECL
-
+
#endif
/*
* Local variables:
YAZ_EXPORT
int zebra_lock_r (ZebraLockHandle h);
-YAZ_EXPORT
+YAZ_EXPORT
void zebra_flock_init(void);
YAZ_END_CDECL
/**
isam.h - a generalized interface to the isam systems
-The isam system consists of a number of isam lists. Physically it is
-stored in a file, or a group of related files. It is typically used
-for storing all the occurrences of a given word, storing the document
-number and position for each occurrence.
+The isam system consists of a number of isam lists. Physically it is
+stored in a file, or a group of related files. It is typically used
+for storing all the occurrences of a given word, storing the document
+number and position for each occurrence.
An isam list is indentified by an isam_position. This is a number (zint).
It can be seen as a mapping from an isam_position to an ordered list of isam_
entries.
-An isam list consists of one or more isam entries. We do not know the
+An isam list consists of one or more isam entries. We do not know the
structure of those entries, but we know the (maximum) size of such, and
that they can be memcpy'ed around.
-The entries can be seen to consist of a key and a value, although we
+The entries can be seen to consist of a key and a value, although we
have no idea of their internal structure. We know that we have a compare
-function that can look at a part (or whole) of the isam entry (the 'key').
-The part not looked at (if any) will count as 'value' or 'payload'.
+function that can look at a part (or whole) of the isam entry (the 'key').
+The part not looked at (if any) will count as 'value' or 'payload'.
The entries are stored in increasing order (as defined by the compare
function), and no duplicates are allowed.
-There is an effective mass-insert routine that takes a stream of values,
+There is an effective mass-insert routine that takes a stream of values,
each accompanied by an insert/delete flag.
-For reading we have cursors, that can read through an isam list in order.
+For reading we have cursors, that can read through an isam list in order.
They have a fast-forward function to skip values we are not interested in.
-
+
*/
* key_control contains all there is to know about the keys (entries) stored
* in an isam, (and therefore operated by the rsets). Other than this info,
* all we assume is that all keys are the same size, and they can be
- * memcpy'd around.
+ * memcpy'd around.
*/
struct key_control {
/** (max) size of a key */
int key_size;
- /** Default for what level we operate on (book/chapter/verse).
- * for typical zebra, this is always 2 (sysno/seqno). Not used in
+ /** Default for what level we operate on (book/chapter/verse).
+ * for typical zebra, this is always 2 (sysno/seqno). Not used in
* isam context, but the rsets make use of this. */
- int scope;
+ int scope;
- /** Compare function, returning -1,0,1, if p1 is less/equal/greater
+ /** Compare function, returning -1,0,1, if p1 is less/equal/greater
* than p2 */
int (*cmp) (const void *p1, const void *p2);
/** Debug function to write a key in the log, with a message */
void (*key_logdump_txt) (int logmask, const void *p, const char *txt);
- /** Return the sequence number of a key, to see if we are on the same
+ /** Return the sequence number of a key, to see if we are on the same
* record. FIXME - this makes less sense with higher-scope keys. */
zint (*getseq)(const void *p);
/* FIXME - in zrpn.c, time being. Needs to be moved out */
-/** isam_data_stream is a callback function for the mass-insert (merge)
+/** isam_data_stream is a callback function for the mass-insert (merge)
* it provides another item to insert/delete, in proper order */
struct isam_data_stream {
int (*read_item)(void *clientData, char **dst, int *insertMode);
/** text description of the type, for debugging */
char *desc;
/** default filename, if none given to isam_open */
- const char *def_filename;
+ const char *def_filename;
/* there is an isam_open function, but it is not part of this */
/* dynamic table, as it is what provides this table */
/** close the isam system */
void (*f_close)(ISAM i);
- /** Insert an entry into the isam identified by pos. If pos==0,
+ /** Insert an entry into the isam identified by pos. If pos==0,
* create a new isam list */
ISAM_POS (*f_put)(ISAM is, ISAM_POS pos, const void *buf);
* do nothing, and return 0*/
int (*f_del)(ISAM is, ISAM_POS pos, const void *buf);
- /** Find an entry in the isam list. return 0 if not found. buf must
+ /** Find an entry in the isam list. return 0 if not found. buf must
* contain enough to identify the item, and will be overwritten by it */
int (*f_get)(ISAM is, ISAM_POS pos, void *buf );
/** Mass-insert data from incoming stream into the isam */
- ISAM_POS (*f_merge)(ISAM is, ISAM_POS pos, ISAM_DATA_STREAM *data);
+ ISAM_POS (*f_merge)(ISAM is, ISAM_POS pos, ISAM_DATA_STREAM *data);
/** Open a cursor to the isam list identified by pos */
- ISAM_CUR (*f_cur_open)(ISAM is, ISAM_POS pos);
+ ISAM_CUR (*f_cur_open)(ISAM is, ISAM_POS pos);
/** Read an item at the cursor (and forward to next). return 0 at eof */
int (*f_read)(ISAM_CUR cur, void *buf);
/** Delete the isam list from the isam system.*/
int (*f_unlink)(ISAM is, ISAM_POS pos);
-
+
};
/** ISAM_s is the generic isam structure */
/** Open the isam system */
-ISAM isam_open (BFiles bfs,
+ISAM isam_open (BFiles bfs,
const char *isamtype, /* usually "b" */
const char *filename, /* optional, use default from control ?? */
int flags, /* FIXME - define read/write, and some special ones */
YAZ_EXPORT
void isamb_close(ISAMB isamb);
-YAZ_EXPORT
+YAZ_EXPORT
void isamb_merge(ISAMB b, ISAM_P *pos, ISAMC_I *data);
YAZ_EXPORT
/** \brief record reader stream */
struct ZebraRecStream {
/** client data */
- void *fh;
+ void *fh;
/** \brief read function */
int (*readf)(struct ZebraRecStream *s, char *buf, size_t count);
/** \brief seek function */
off_t (*seekf)(struct ZebraRecStream *s, off_t offset);
/** \brief tell function */
- off_t (*tellf)(struct ZebraRecStream *s);
+ off_t (*tellf)(struct ZebraRecStream *s);
/** \brief set and get of record position */
- off_t (*endf)(struct ZebraRecStream *s, off_t *offset);
+ off_t (*endf)(struct ZebraRecStream *s, off_t *offset);
/** \brief close and destroy stream */
void (*destroy)(struct ZebraRecStream *s);
};
int recordSize; /* size of record in bytes */
char *fname; /* name of file (or NULL if internal) */
data1_handle dh;
-
+
/* response */
const Odr_oid * output_format; /* output format OID */
void * rec_buf;
int rec_len;
int diagnostic;
char * addinfo;
-
+
/* special fetch to be included in retrieved response (say snippets) */
void *handle;
int (*special_fetch)(void *handle, const char *esn,
#include <yaz/yaz-util.h>
/* unfortunately we need the isam includes here, for the arguments for */
/* rsisamX_create */
-#include <idzebra/isamb.h>
-#include <idzebra/isamc.h>
-#include <idzebra/isams.h>
+#include <idzebra/isamb.h>
+#include <idzebra/isamc.h>
+#include <idzebra/isams.h>
YAZ_BEGIN_CDECL
struct ord_list *ord_list_dup(NMEM nmem, struct ord_list *list);
void ord_list_print(struct ord_list *list);
-/**
- * rset_term is all we need to know of a term to do ranking etc.
+/**
+ * rset_term is all we need to know of a term to do ranking etc.
* As far as the rsets are concerned, it is just a dummy pointer to
* be passed around.
*/
struct ord_list *ol;
};
-typedef struct rset_term *TERMID;
+typedef struct rset_term *TERMID;
TERMID rset_term_create (const char *name, int length, const char *flags,
int type, NMEM nmem, struct ord_list *ol,
int reg_type, zint hits_limit, const char *ref_id);
};
-/**
+/**
* rset_control has function pointers to all the important functions
* of a rset. Each type of rset will have its own control block, pointing
* to the functions for that type. They all have their own create function
struct rset_control
{
/** text description of set type (for debugging) */
- char *desc;
+ char *desc;
/* RSET rs_something_create(const struct rset_control *sel, ...); */
void (*f_delete)(RSET ct);
void rset_get_one_term(RSET ct,TERMID *terms,int maxterms,int *curterm);
/**
- * key_control contains all there is to know about the keys stored in
+ * key_control contains all there is to know about the keys stored in
* an isam, and therefore operated by the rsets. Other than this info,
* all we assume is that all keys are the same size, and they can be
* memcpy'd around
zint hits_limit;
zint hits_count;
zint hits_round;
- int hits_approx;
+ int hits_approx;
} rset;
-/* rset is a "virtual base class", which will never exist on its own
+/* rset is a "virtual base class", which will never exist on its own
* all instances are rsets of some specific type, like rsisamb, or rsbool
* They keep their own stuff behind the priv pointer. */
* In more complex isams we can specify on what level we wish to do the
* matching and counting of hits. For example, we can have book / chapter /
* verse, and a seqno. Scope 2 means then "give me all verses that match",
- * 3 would be chapters, 4 books.
- * The resolution tells how much of the occurences we need to return. If we
+ * 3 would be chapters, 4 books.
+ * The resolution tells how much of the occurences we need to return. If we
* are doing some sort of proximity, we need to get the seqnos of all
* occurences, whereas if we are only counting hits, we do not need anything
* below the scope. Again 1 is seqnos, 2 sysnos (or verses), 3 books, etc.
RSFD rfd_create_base(RSET rs);
int rfd_is_last(RSFD rfd);
-RSET rset_create_base(const struct rset_control *sel,
+RSET rset_create_base(const struct rset_control *sel,
NMEM nmem,
struct rset_key_control *kcontrol,
int scope,
int scope, RSET rset_l, RSET rset_r);
RSET rset_create_between(NMEM nmem, struct rset_key_control *kcontrol,
- int scope, RSET rset_l, RSET rset_m, RSET rset_r,
+ int scope, RSET rset_l, RSET rset_m, RSET rset_r,
RSET rset_attr);
RSET rset_create_or(NMEM nmem, struct rset_key_control *kcontrol,
{
/* we have a use attribute and attribute set */
int r;
-
+
r = att_getentbyatt(zh, curAttributeSet, use_value, &use_string);
if (r == -2)
{
zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0);
return ZEBRA_FAIL;
}
- *ord = zebraExplain_lookup_attr_str(zh->reg->zei, cat,
+ *ord = zebraExplain_lookup_attr_str(zh->reg->zei, cat,
index_type, use_string);
if (*ord == -1)
{
- /* attribute 14=1 does not issue a diagnostic even
- 1) the attribute is numeric but listed in .att
+ /* attribute 14=1 does not issue a diagnostic even
+ 1) the attribute is numeric but listed in .att
2) the use attribute is string
*/
AttrType unsup;
if (relation_value == 103) /* always matches */
cat = zinfo_index_category_alwaysmatches;
-
+
if (!xpath_use)
{
res = zebra_attr_list_get_ord(zh, zapt->attributes,
/* use attribute not found. But it the relation is
always matches and the regulare index attribute is found
return a different diagnostic */
- if (res != ZEBRA_OK &&
+ if (res != ZEBRA_OK &&
relation_value == 103
&& zebra_attr_list_get_ord(
- zh, zapt->attributes,
+ zh, zapt->attributes,
zinfo_index_category_index, index_type,
curAttributeSet, ord) == ZEBRA_OK)
zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE, 103);
{
yaz_log(YLOG_LOG, "zebra_apt_get_ord OK xpath=%s index_type=%s",
xpath_use, index_type);
-
+
}
}
return res;
{
int errors = 0;
Res v = res_open(0, 0);
-
+
res_add(v, "attset", "");
res_add(v, "chdir", "");
res_add(v, "dbaccess", "");
res_add(v, "openRW", "p");
res_add(v, "facetNumRecs", "");
res_add(v, "facetMaxChunks", "");
-
+
errors = res_check(res, v);
-
+
res_close(v);
return errors;
}
size_t nmemb = 0;
while (e[nmemb].name)
nmemb++;
- qsort(e, nmemb, sizeof(*e), dir_cmp);
+ qsort(e, nmemb, sizeof(*e), dir_cmp);
}
void dir_free(struct dir_entry **e_p)
entry = ci->entries + ci->no_cur;
if (info[0] == sizeof(entry->sysno)+sizeof(entry->mtime))
{
- strcpy(entry->path, name + ci->prelen);
+ strcpy(entry->path, name + ci->prelen);
entry->kind = dirs_file;
memcpy(&entry->sysno, info+1, sizeof(entry->sysno));
- memcpy(&entry->mtime, info+1+sizeof(entry->sysno),
+ memcpy(&entry->mtime, info+1+sizeof(entry->sysno),
sizeof(entry->mtime));
ci->no_cur++;
- }
+ }
else if (info[0] == sizeof(entry->mtime))
{
strcpy(entry->path, name + ci->prelen);
info = dict_lookup(dict, path);
if (info && info[0] == sizeof(entry->sysno)+sizeof(entry->mtime))
{
- strcpy(entry->path, path);
+ strcpy(entry->path, path);
entry->kind = dirs_file;
memcpy(&entry->sysno, info+1, sizeof(entry->sysno));
- memcpy(&entry->mtime, info+1+sizeof(entry->sysno),
+ memcpy(&entry->mtime, info+1+sizeof(entry->sysno),
sizeof(entry->mtime));
p->no_cur++;
}
if (!(zh->records_processed % 1000))
{
yaz_log(YLOG_LOG, "Records: "ZINT_FORMAT" i/u/d "
- ZINT_FORMAT"/"ZINT_FORMAT"/"ZINT_FORMAT,
- zh->records_processed, zh->records_inserted,
+ ZINT_FORMAT"/"ZINT_FORMAT"/"ZINT_FORMAT,
+ zh->records_processed, zh->records_inserted,
zh->records_updated, zh->records_deleted);
}
}
}
-static void extract_add_index_string(RecWord *p,
+static void extract_add_index_string(RecWord *p,
zinfo_index_category_t cat,
const char *str, int length);
return ;
if (first)
- {
+ {
first = 0;
if (zebra_maps_is_first_in_field(zm))
{
assert(zh->reg->dh);
extractCtrl.dh = zh->reg->dh;
-
+
info.zh = zh;
info.snippets = sn;
extractCtrl.handle = &info;
extractCtrl.match_criteria[0] = '\0';
extractCtrl.staticrank = 0;
extractCtrl.action = action_insert;
-
+
init_extractCtrl(zh, &extractCtrl);
extractCtrl.setStoreData = 0;
assert(key.len <= IT_KEY_LEVEL_MAX && key.len > 2);
seqno = key.mem[key.len-1];
-
+
if (key.mem[0] == ch)
{
zint woff;
-
+
if (startSeq == -1)
startSeq = seqno;
woff = seqno - startSeq;
char attset_str[64], attname_str[64];
int i;
int first = 1;
-
+
for (s++; strchr(FILE_MATCH_BLANK, *s); s++)
;
- for (i = 0; *s && *s != ',' && *s != ')' &&
+ for (i = 0; *s && *s != ',' && *s != ')' &&
!strchr(FILE_MATCH_BLANK, *s); s++)
if (i+1 < sizeof(attset_str))
attset_str[i++] = *s;
attset_str[i] = '\0';
-
+
for (; strchr(FILE_MATCH_BLANK, *s); s++)
;
if (*s != ',')
{
for (s++; strchr(FILE_MATCH_BLANK, *s); s++)
;
- for (i = 0; *s && *s != ')' &&
+ for (i = 0; *s && *s != ')' &&
!strchr(FILE_MATCH_BLANK, *s); s++)
if (i+1 < sizeof(attname_str))
attname_str[i++] = *s;
searchRecordKey(zh, reckeys, attname_str, ws, 32);
if (0) /* for debugging */
- {
+ {
for (i = 0; i<32; i++)
{
if (ws[i])
}
else if (!strcmp(special, "type"))
spec_src = zh->m_record_type;
- else
+ else
spec_src = NULL;
if (spec_src)
{
\param ctrl record control
\param record_id custom record ID
\param sysno system record ID
-
+
This function serves two purposes.. It adds the always matches
entry and makes a pointer from the custom record ID (if defined)
back to the system record ID (sysno)
}
/* forward declaration */
-ZEBRA_RES zebra_extract_records_stream(ZebraHandle zh,
+ZEBRA_RES zebra_extract_records_stream(ZebraHandle zh,
struct ZebraRecStream *stream,
enum zebra_recctrl_action_t action,
const char *recordType,
void *recTypeClientData);
-ZEBRA_RES zebra_extract_file(ZebraHandle zh, zint *sysno, const char *fname,
+ZEBRA_RES zebra_extract_file(ZebraHandle zh, zint *sysno, const char *fname,
enum zebra_recctrl_action_t action)
{
ZEBRA_RES r = ZEBRA_OK;
*gprefix = '\0';
else
sprintf(gprefix, "%s.", zh->m_group);
-
+
yaz_log(log_level_extract, "zebra_extract_file %s", fname);
/* determine file extension */
}
else
strcpy(full_rep, fname);
-
+
if ((fd = open(full_rep, O_BINARY|O_RDONLY)) == -1)
{
yaz_log(YLOG_WARN|YLOG_ERRNO, "open %s", full_rep);
If sysno is provided, then it's used to identify the reocord.
If not, and match_criteria is provided, then sysno is guessed
If not, and a record is provided, then sysno is got from there
-
+
*/
-ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh,
+ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh,
const char *buf, size_t buf_size,
enum zebra_recctrl_action_t action,
const char *recordType,
"Record type explicitly specified: %s", recordType);
recType = recType_byName(zh->reg->recTypes, zh->res, recordType,
&clientData);
- }
+ }
else
{
if (!(zh->m_record_type))
zh->m_record_type, &clientData);
recordType = zh->m_record_type;
}
-
+
if (!recType)
{
yaz_log(YLOG_WARN, "No such record type: %s", recordType);
return res;
}
-static ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh,
+static ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh,
struct ZebraRecStream *stream,
enum zebra_recctrl_action_t action,
const char *recordType,
RecType recType,
void *recTypeClientData,
int *more)
-
+
{
zint sysno0 = 0;
RecordAttr *recordAttr;
Record rec;
off_t start_offset = 0, end_offset = 0;
const char *pr_fname = fname; /* filename to print .. */
- int show_progress = zh->records_processed + zh->records_skipped
+ int show_progress = zh->records_processed + zh->records_skipped
< zh->m_file_verbose_limit ? 1:0;
zebra_init_log_level();
if (zebraExplain_curDatabase(zh->reg->zei, zh->basenames[0]))
{
- if (zebraExplain_newDatabase(zh->reg->zei, zh->basenames[0],
+ if (zebraExplain_newDatabase(zh->reg->zei, zh->basenames[0],
zh->m_explain_database))
return ZEBRA_FAIL;
}
start_offset = stream->tellf(stream);
extractCtrl.first_record = start_offset ? 0 : 1;
-
+
stream->endf(stream, &null_offset);;
extractCtrl.init = extract_init;
init_extractCtrl(zh, &extractCtrl);
extract_set_store_data_prepare(&extractCtrl);
-
+
r = (*recType->extract)(recTypeClientData, &extractCtrl);
if (action == action_update)
{
action = extractCtrl.action;
}
-
+
switch (r)
{
case RECCTRL_EXTRACT_EOF:
yaz_log(YLOG_LOG, "skip %s %s " ZINT_FORMAT,
recordType, pr_fname, (zint) start_offset);
*more = 1;
-
+
end_offset = stream->endf(stream, 0);
if (end_offset)
stream->seekf(stream, end_offset);
/* test mode .. Do not perform match */
return ZEBRA_OK;
}
-
+
if (!sysno)
{
sysno = &sysno0;
-
+
if (match_criteria && *match_criteria)
matchStr = match_criteria;
else
{
if (zh->m_record_id && *zh->m_record_id)
{
- matchStr = get_match_from_spec(zh, zh->reg->keys, pr_fname,
+ matchStr = get_match_from_spec(zh, zh->reg->keys, pr_fname,
zh->m_record_id);
if (!matchStr)
{
}
}
}
- if (matchStr)
+ if (matchStr)
{
int db_ord = zebraExplain_get_database_ord(zh->reg->zei);
char *rinfo = dict_lookup_ord(zh->reg->matchDict, db_ord,
matchStr);
-
+
if (log_level_extract)
{
WRBUF w = wrbuf_hex_str(matchStr);
#endif
recordAttr->staticrank = extractCtrl.staticrank;
zh->records_inserted++;
- }
+ }
else
{
/* record already exists */
zebra_rec_keys_t sortKeys = zebra_rec_keys_open();
if (action == action_insert)
{
- yaz_log(YLOG_LOG, "skipped %s %s " ZINT_FORMAT,
+ yaz_log(YLOG_LOG, "skipped %s %s " ZINT_FORMAT,
recordType, pr_fname, (zint) start_offset);
logRecord(zh);
return ZEBRA_FAIL;
zebra_rec_keys_get_custom_record_id(zh->reg->keys),
*sysno);
}
-
+
recordAttr = rec_init_attr(zh->reg->zei, rec);
/* decrease total size */
#if FLUSH2
extract_flush_record_keys2(zh, *sysno, 0, recordAttr->staticrank,
delkeys, recordAttr->staticrank);
-#endif
+#endif
if (zebra_rec_keys_empty(delkeys))
{
yaz_log(YLOG_LOG, "delete %s %s " ZINT_FORMAT, recordType,
zh->reg->keys, extractCtrl.staticrank,
delkeys, recordAttr->staticrank);
#else
- extract_flush_record_keys(zh, *sysno, 1,
+ extract_flush_record_keys(zh, *sysno, 1,
zh->reg->keys, extractCtrl.staticrank);
#endif
recordAttr->staticrank = extractCtrl.staticrank;
/* update database name */
xfree(rec->info[recInfo_databaseName]);
rec->info[recInfo_databaseName] =
- rec_strdup(zh->basenames[0], &rec->size[recInfo_databaseName]);
+ rec_strdup(zh->basenames[0], &rec->size[recInfo_databaseName]);
/* update offset */
recordAttr->recordOffset = start_offset;
-
+
/* commit this record */
rec_put(zh->reg->records, &rec);
logRecord(zh);
\param recTypeClientData client data for record type
\returns ZEBRA_OK for success; ZEBRA_FAIL for failure
*/
-ZEBRA_RES zebra_extract_records_stream(ZebraHandle zh,
+ZEBRA_RES zebra_extract_records_stream(ZebraHandle zh,
struct ZebraRecStream *stream,
enum zebra_recctrl_action_t action,
const char *recordType,
extractCtrl.handle = handle;
extractCtrl.first_record = 1;
-
+
extract_set_store_data_prepare(&extractCtrl);
if (n)
if (rec->size[recInfo_delKeys])
{
zebra_rec_keys_t delkeys = zebra_rec_keys_open();
-
+
zebra_rec_keys_t sortkeys = zebra_rec_keys_open();
zebra_rec_keys_set_buf(delkeys, rec->info[recInfo_delKeys],
rec->size[recInfo_delKeys],
0);
#if FLUSH2
- extract_flush_record_keys2(zh, rec->sysno,
+ extract_flush_record_keys2(zh, rec->sysno,
zh->reg->keys, 0, delkeys, 0);
#else
extract_flush_record_keys(zh, rec->sysno, 0, delkeys, 0);
#if FLUSH2
extract_flush_record_keys2(zh, rec->sysno, zh->reg->keys, 0, 0, 0);
#else
- extract_flush_record_keys(zh, rec->sysno, 1, zh->reg->keys, 0);
+ extract_flush_record_keys(zh, rec->sysno, 1, zh->reg->keys, 0);
#endif
}
extract_flush_sort_keys(zh, rec->sysno, 1, zh->reg->sortKeys);
-
+
xfree(rec->info[recInfo_delKeys]);
zebra_rec_keys_get_buf(zh->reg->keys,
- &rec->info[recInfo_delKeys],
+ &rec->info[recInfo_delKeys],
&rec->size[recInfo_delKeys]);
xfree(rec->info[recInfo_sortKeys]);
const char *index_type;
int i;
const char *string_index;
-
+
zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type,
0/* db */, &string_index);
assert(index_type);
{
sprintf(keystr + strlen(keystr), ZINT_FORMAT " ", key->mem[i]);
}
-
+
if (*str < CHR_BASE_CHAR)
{
int i;
char dst_buf[200]; /* room for special chars */
-
+
strcpy(dst_buf , "?");
-
+
if (!strcmp(str, ""))
strcpy(dst_buf, "alwaysmatches");
if (!strcmp(str, FIRST_IN_FIELD_STR))
strcpy(dst_buf, "unknown");
else if (!strcmp(str, CHR_SPACE))
strcpy(dst_buf, "space");
-
+
for (i = 0; i<slen; i++)
{
sprintf(dst_buf + strlen(dst_buf), " %d", str[i] & 0xff);
}
yaz_log(level, "%s%s %s %s", keystr, index_type,
string_index, dst_buf);
-
+
}
else
yaz_log(level, "%s%s %s \"%s\"", keystr, index_type,
&ins_key_in);
if (del && ins && ins_rank == del_rank
- && !key_compare(&del_key_in, &ins_key_in)
+ && !key_compare(&del_key_in, &ins_key_in)
&& ins_slen == del_slen && !memcmp(del_str, ins_str, del_slen))
{
optimized++;
}
if (!del && !ins)
break;
-
+
normal++;
if (del)
- key_block_write(zh->reg->key_block, sysno,
+ key_block_write(zh->reg->key_block, sysno,
&del_key_in, 0, del_str, del_slen,
del_rank, zh->m_staticrank);
if (ins)
- key_block_write(zh->reg->key_block, sysno,
+ key_block_write(zh->reg->key_block, sysno,
&ins_key_in, 1, ins_str, ins_slen,
ins_rank, zh->m_staticrank);
}
struct it_key key_in;
while(zebra_rec_keys_read(reckeys, &str, &slen, &key_in))
{
- key_block_write(zh->reg->key_block, sysno,
+ key_block_write(zh->reg->key_block, sysno,
&key_in, cmd, str, slen,
staticrank, zh->m_staticrank);
}
zebra_snippets *snippets)
{
NMEM nmem = nmem_create();
- if (zebra_rec_keys_rewind(reckeys))
+ if (zebra_rec_keys_rewind(reckeys))
{
const char *str;
size_t slen;
assert(key.len <= IT_KEY_LEVEL_MAX && key.len > 2);
seqno = key.mem[key.len-1];
ord = CAST_ZINT_TO_INT(key.mem[0]);
-
+
zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type,
0/* db */, 0 /* string_index */);
assert(index_type);
assert(key.len <= IT_KEY_LEVEL_MAX && key.len > 2);
zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type, &db, 0);
-
+
seqno = key.mem[key.len-1];
-
+
zebra_term_untrans(zh, index_type, dst_buf, str);
-
- yaz_log(YLOG_LOG, "ord=%d seqno=" ZINT_FORMAT
- " term=%s", ord, seqno, dst_buf);
+
+ yaz_log(YLOG_LOG, "ord=%d seqno=" ZINT_FORMAT
+ " term=%s", ord, seqno, dst_buf);
}
}
}
{
WRBUF w = wrbuf_alloc();
-
+
wrbuf_write_escaped(w, string, length);
yaz_log(log_level_details, "extract_add_string: %s", wrbuf_cstr(w));
wrbuf_destroy(w);
int remain = p->term_len;
int first = 1;
const char **map = 0;
-
+
if (remain > 0)
map = zebra_maps_input(zm, &b, remain, 0);
return;
if (first)
- {
+ {
first = 0;
if (zebra_maps_is_first_in_field(zm))
{
extract_token_add
extract_add_{in}_complete / extract_add_icu
extract_add_string
-
+
extract_add_index_string
or
extract_add_sort_string
or
extract_add_staticrank_string
-
+
*/
static void extract_token_add(RecWord *p)
{
{
yaz_log(log_level_details, "extract_token_add "
"type=%s index=%s seqno=" ZINT_FORMAT " s=%.*s",
- p->index_type, p->index_name,
+ p->index_type, p->index_name,
p->seqno, p->term_len, p->term_buf);
}
if (zebra_maps_is_icu(zm))
(*e)->sysno = filter_sysno ? filter_sysno : sysno;
(*e)->section_id = section_id;
}
-
+
wrbuf_write((*e)->wrbuf, str, slen);
wrbuf_putc((*e)->wrbuf, '\0');
}
};
void getFnameTmp(Res res, char *fname, int no);
-
+
struct dirs_info *dirs_open(Dict dict, const char *rep, int rw);
struct dirs_info *dirs_fopen(Dict dict, const char *path, int rw);
struct dirs_entry *dirs_read(struct dirs_info *p);
struct zebra_register {
char *name;
-
+
ISAMS isams;
ISAMC isamc;
ISAMB isamb;
int partial_result;
#if HAVE_SYS_TIMES_H
struct tms tms1;
- struct tms tms2;
+ struct tms tms2;
#endif
int shadow_enable;
void resultSetInvalidate(ZebraHandle zh);
int zebra_record_fetch(ZebraHandle zh, const char *setname,
- zint sysno, int score,
+ zint sysno, int score,
ODR stream,
const Odr_oid *input_format, Z_RecordComposition *comp,
const Odr_oid **output_format, char **rec_bufp,
void zebra_index_merge(ZebraHandle zh);
-ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh,
+ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh,
const char *buf, size_t buf_size,
enum zebra_recctrl_action_t action,
const char *recordType,
void zebra_setError(ZebraHandle zh, int code, const char *addinfo);
void zebra_setError_zint(ZebraHandle zh, int code, zint i);
-int zebra_term_untrans_iconv(ZebraHandle zh, NMEM stream,
+int zebra_term_untrans_iconv(ZebraHandle zh, NMEM stream,
const char *index_type,
char **dst, const char *src);
const char **term_ref_id_str,
NMEM nmem);
-ZEBRA_RES zebra_result_recid_to_sysno(ZebraHandle zh,
+ZEBRA_RES zebra_result_recid_to_sysno(ZebraHandle zh,
const char *setname,
zint recid,
zint *sysnos, int *no_sysnos);
static inline_subfield *inline_mk_subfield(inline_subfield *parent)
{
inline_subfield *p = (inline_subfield *)xmalloc(sizeof(*p));
-
+
if (p)
{
memset(p, 0, sizeof(*p));
{
inline_field *pf = pif;
char *p = (char *)s;
-
+
if (!pf)
return -1;
-
+
if (pf->name[0] == '\0')
{
if ((sscanf(p, "%3s", pf->name)) != 1)
else
{
inline_subfield *psf = inline_mk_subfield(0);
-
+
sscanf(tag, "%1s", psf->name);
psf->data = xstrdup(p);
-
+
if (!pf->list)
{
pf->list = psf;
int dumpwords;
};
-#define SINGLETON_TYPE 8 /* the type to use for singletons that */
+#define SINGLETON_TYPE 8 /* the type to use for singletons that */
/* have no block and no block type */
static void print_dict_item (ZebraHandle zh, const char *s, zint count,
int level;
zint size;
zint blocks;
-
+
pp = isamb_pp_open_x(stat_info->zh->reg->isamb, isam_p, &level, 0);
while (isamb_pp_read(pp, &key))
fprintf (stdout, "%7d- %7d\n",
prev, stat_info.isam_occurrences[i]);
rec_prstat(zh->reg->records, 0);
- xmalloc_trav("unfreed"); /*! while hunting memory leaks */
+ xmalloc_trav("unfreed"); /*! while hunting memory leaks */
zebra_end_read (zh);
return 0;
}
kc->get_segment = 0;
}
- zebra_limit_for_rset(zh->m_limit,
+ zebra_limit_for_rset(zh->m_limit,
&kc->filter_func,
&cp->filter_destroy,
&kc->filter_data);
int c, d;
c = getc (f);
- switch (c & 192)
+ switch (c & 192)
{
case 0:
d = c;
op = key_info[0];
memcpy (&k, 1+key_info, sizeof(k));
- from += 2;
+ from += 2;
while (*from)
{
const char *res = zebra_maps_output (zm, reg_type, &from);
}
exit (0);
}
-#endif
+#endif
/*
* Local variables:
* c-basic-offset: 4
char v[100];
int h, i, j, k;
static const int incs[16] = { 1391376, 463792, 198768, 86961, 33936,
- 13776, 4592, 1968, 861, 336,
+ 13776, 4592, 1968, 861, 336,
112, 48, 21, 7, 3, 1 };
for ( k = 0; k < 16; k++)
for (h = incs[k], i = h; i < r; i++)
- {
+ {
memcpy (v, a+s*i, s);
j = i;
while (j > h && (*cmp)(a + s*(j-h), v) > 0)
j -= h;
}
memcpy (a+s*j, v, s);
- }
+ }
}
#endif
char *bp = i->buf, *bp0;
const char *src = (char *) &key;
size_t klen = strlen(k);
-
+
if (fwrite (k, klen+1, 1, outf) != 1)
{
yaz_log (YLOG_FATAL|YLOG_ERRNO, "fwrite");
}
static void encode_key_flush (struct encode_info *i, FILE *outf)
-{
+{
iscz1_stop(i->encode_handle);
iscz1_stop(i->decode_handle);
}
while (1)
{
pthread_mutex_lock(&p->mutex);
-
+
while (!p->is_sorting && !p->exit_flag)
pthread_cond_wait(&p->work_available, &p->mutex);
if (p->exit_flag)
break;
-
+
pthread_mutex_unlock(&p->mutex);
-
- key_block_flush_int(p, p->thread_key_buf,
+
+ key_block_flush_int(p, p->thread_key_buf,
p->thread_ptr_top, p->thread_ptr_i);
-
+
pthread_mutex_lock(&p->mutex);
p->is_sorting = 0;
pthread_cond_signal(&p->cond_sorting);
- pthread_mutex_unlock(&p->mutex);
+ pthread_mutex_unlock(&p->mutex);
}
pthread_mutex_unlock(&p->mutex);
return 0;
{
#if YAZ_POSIX_THREADS
pthread_mutex_lock(&p->mutex);
-
+
while (p->is_sorting)
pthread_cond_wait(&p->cond_sorting, &p->mutex);
-
+
p->exit_flag = 1;
-
+
pthread_cond_broadcast(&p->work_available);
-
+
pthread_mutex_unlock(&p->mutex);
pthread_join(p->thread_id, 0);
pthread_cond_destroy(&p->work_available);
pthread_cond_destroy(&p->cond_sorting);
pthread_mutex_destroy(&p->mutex);
-
+
#endif
xfree(p->alt_buf);
}
assert(p->ptr_i > 0);
(p->key_buf)[p->ptr_top - p->ptr_i] =
(char*)p->key_buf + p->key_buf_used;
-
+
/* key_in->mem[0] ord/ch */
/* key_in->mem[1] filter specified record ID */
-
+
/* encode the ordinal value (field/use/attribute) .. */
ch = CAST_ZINT_TO_INT(key_in->mem[0]);
p->key_buf_used +=
key_SU_encode(ch, (char*)p->key_buf +
p->key_buf_used);
-
+
/* copy the 0-terminated stuff from str to output */
memcpy((char*)p->key_buf + p->key_buf_used, str_buf, str_len);
p->key_buf_used += str_len;
((char*)p->key_buf)[(p->key_buf_used)++] = '\0';
-
+
/* the delete/insert indicator */
((char*)p->key_buf)[(p->key_buf_used)++] = cmd;
-
+
if (static_rank_enable)
{
assert(staticrank >= 0);
key_out.mem[j++] = staticrank;
}
-
+
if (key_in->mem[1]) /* filter specified record ID */
key_out.mem[j++] = key_in->mem[1];
else
for (i = 2; i < key_in->len; i++)
key_out.mem[j++] = key_in->mem[i];
key_out.len = j;
-
+
memcpy((char*)p->key_buf + p->key_buf_used,
&key_out, sizeof(key_out));
(p->key_buf_used) += sizeof(key_out);
if (ptr_i == 0)
return ;
-
+
(p->key_file_no)++;
yaz_log(YLOG_DEBUG, "sorting section %d", (p->key_file_no));
}
yaz_log(YLOG_DEBUG, "writing section %d", p->key_file_no);
prevcp = cp = (key_buf)[ptr_top - ptr_i];
-
+
encode_key_init (&encode_info);
encode_key_write (cp, &encode_info, outf);
-
+
while (--ptr_i > 0)
{
cp = (key_buf)[ptr_top - ptr_i];
{
#if YAZ_POSIX_THREADS
char **tmp;
-
+
pthread_mutex_lock(&p->mutex);
-
+
while (p->is_sorting)
pthread_cond_wait(&p->cond_sorting, &p->mutex);
-
+
p->is_sorting = 1;
-
+
p->thread_ptr_top = p->ptr_top;
p->thread_ptr_i = p->ptr_i;
p->thread_key_buf = p->key_buf;
-
+
tmp = p->key_buf;
p->key_buf = p->alt_buf;
p->alt_buf = tmp;
-
+
pthread_cond_signal(&p->work_available);
-
+
if (is_final)
{
while (p->is_sorting)
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
+
#if HAVE_CONFIG_H
#include <config.h>
#endif
void getFnameTmp(Res res, char *fname, int no)
{
const char *pre;
-
+
pre = res_get_def(res, "keyTmpDir", ".");
sprintf(fname, "%s/key%d.tmp", pre, no);
}
void extract_get_fname_tmp(ZebraHandle zh, char *fname, int no)
{
const char *pre;
-
+
pre = res_get_def(zh->res, "keyTmpDir", ".");
sprintf(fname, "%s/key%d.tmp", pre, no);
}
child++;
if ((*hi->cmp)(&hi->info.buf[hi->ptr[cur]],
&hi->info.buf[hi->ptr[child]]) > 0)
- {
+ {
key_heap_swap(hi, cur, child);
cur = child;
child = 2*cur;
(*dst) += p->sz_1;
return 1;
}
-
+
int heap_cread_item(void *vp, char **dst, int *insertMode)
{
struct heap_cread_info *p = (struct heap_cread_info *) vp;
if (!dict_delete(hi->reg->dict, this_name))
abort();
}
- else
+ else
{
hi->no_updates++;
if (isamc_p2 != isamc_p)
dict_insert(hi->reg->dict, this_name,
sizeof(ISAM_P), &isamc_p2);
}
- }
+ }
else
{
isamc_p = 0;
}
xfree(isamc_i);
return 0;
-}
+}
int heap_inpb(struct heap_cread_info *hci, struct heap_info *hi)
{
if (!dict_delete(hi->reg->dict, this_name))
abort();
}
- else
+ else
{
hi->no_updates++;
if (isamc_p2 != isamc_p)
dict_insert(hi->reg->dict, this_name,
sizeof(ISAM_P), &isamc_p2);
}
- }
+ }
else
{
isamc_p = 0;
}
xfree(isamc_i);
return 0;
-}
+}
int heap_inps(struct heap_cread_info *hci, struct heap_info *hi)
{
}
xfree(isams_i);
return 0;
-}
+}
struct progressInfo {
time_t startTime;
if (nkeys == 0)
return;
-
+
if (nkeys < 0)
{
char fname[1024];
}
hi = key_heap_init_file(zh, nkeys, key_qsort_compare);
hi->reg = zh->reg;
-
+
for (i = 1; i<=nkeys; i++)
if ((r = key_file_read(kf[i], rbuf)))
key_heap_insert(hi, rbuf, r, kf[i]);
if (1)
{
struct heap_cread_info hci;
-
+
hci.key = (char *) xmalloc(KEY_SIZE);
hci.key_1 = (char *) xmalloc(KEY_SIZE);
hci.key_2 = (char *) xmalloc(KEY_SIZE);
hci.first_in_list = 1;
hci.hi = hi;
hci.look_level = 0;
- hci.more = heap_read_one(hi, hci.cur_name, hci.key);
-
+ hci.more = heap_read_one(hi, hci.cur_name, hci.key);
+
if (zh->reg->isams)
heap_inps(&hci, hi);
if (zh->reg->isamc)
heap_inpc(&hci, hi);
if (zh->reg->isamb)
heap_inpb(&hci, hi);
-
+
xfree(hci.key);
xfree(hci.key_1);
xfree(hci.key_2);
}
-
+
for (i = 1; i<=nkeys; i++)
{
extract_get_fname_tmp (zh, rbuf, i);
xfree(kf);
if (hi->no_iterations)
{ /* do not log if nothing happened */
- yaz_log(YLOG_LOG, "Iterations: isam/dict "
+ yaz_log(YLOG_LOG, "Iterations: isam/dict "
ZINT_FORMAT "/" ZINT_FORMAT,
hi->no_iterations, hi->no_diffs);
yaz_log(YLOG_LOG, "Dict: inserts/updates/deletions: "
*filter_destroy = 0;
}
}
-
+
/*
* Local variables:
* c-basic-offset: 4
mc_context *mc_mk_context(const char *s)
{
mc_context *p=0;
-
+
if (s && strlen(s))
{
p = (mc_context*) xmalloc(sizeof(*p));
-
+
if (!p)
return 0;
-
+
memset(p, 0, sizeof(*p));
p->errcode = EMCOK;
p->data = s;
p->len = strlen(s);
p->crrtok = NOP;
}
-
+
return p;
}
void mc_destroy_context(mc_context *c)
case '[': c->crrtok = LINTERVAL; break;
case ']': c->crrtok = RINTERVAL; break;
default:
- if (isspace(*(unsigned char *) (c->data+c->offset))
+ if (isspace(*(unsigned char *) (c->data+c->offset))
|| *(c->data+c->offset) == '\n')
{
c->crrtok = NOP;
int mc_getdata(mc_context *c, char *s, int sz)
{
int i;
-
+
for (i=0; i<sz; i++)
{
if (mc_gettoken(c)!=REGULAR)
s[i] = mc_getval(c);
}
s[i] = '\0';
-
+
return i;
}
void mc_getinterval(mc_context *c, int *start, int *end)
{
char buf[6+1];
int start_pos, end_pos;
-
+
start_pos = end_pos = -1;
-
+
if (mc_gettoken(c) == LINTERVAL)
{
int i;
-
+
for (i=0;i<6;i++)
{
mc_token tok = mc_gettoken(c);
-
+
if (tok == RINTERVAL || tok == NOP)
break;
-
+
buf[i] = mc_getval(c);
}
-
+
buf[i] = '\0';
i = sscanf(buf, "%d-%d", &start_pos, &end_pos);
-
+
if (i == 1)
end_pos = start_pos;
else if ( i == 0)
p->interval.start = p->interval.end = -1;
}
return p;
-}
+}
void mc_destroy_field(mc_field *p)
{
if (!p)
return;
- if (p->name) xfree(p->name);
- if (p->ind1) xfree(p->ind1);
+ if (p->name) xfree(p->name);
+ if (p->ind1) xfree(p->ind1);
if (p->ind2) xfree(p->ind2);
if (p->list) mc_destroy_subfields_recursive(p->list);
xfree(p);
mc_field *pf;
pf = mc_mk_field();
-
+
if (!pf)
{
c->errcode = EMCNOMEM;
if (mc_getdata(c, pf->name, SZ_FNAME) == SZ_FNAME)
{
mc_token nexttok = mc_gettoken(c);
-
+
mc_ungettoken(c);
-
+
if (nexttok == LINTERVAL)
{
mc_getinterval(c, &pf->interval.start, &pf->interval.end);
pf->interval.end);
#endif
}
-
+
if ((mc_getdata(c, pf->ind1, SZ_IND) == SZ_IND) &&
(mc_getdata(c, pf->ind2, SZ_IND) == SZ_IND))
{
mc_destroy_field(pf);
return 0;
}
-
+
return pf;
}
mc_subfield *mc_mk_subfield(mc_subfield *parent)
{
if (!p)
return;
-
+
if (p->which == MC_SFGROUP || p->which == MC_SFVARIANT)
{
if (p->u.child)
if (p->u.in_line)
mc_destroy_field(p->u.in_line);
}
- if (p->name) xfree(p->name);
- if (p->prefix) xfree(p->prefix);
+ if (p->name) xfree(p->name);
+ if (p->prefix) xfree(p->prefix);
if (p->suffix) xfree(p->suffix);
if (p->parent) p->parent->next = p->next;
xfree(p);
return;
mc_destroy_subfields_recursive(p->next);
-
+
if (p->which == MC_SFGROUP || p->which == MC_SFVARIANT)
{
if (p->u.child)
if (p->u.in_line)
mc_destroy_field(p->u.in_line);
}
-
+
if (p->name) xfree(p->name);
if (p->prefix) xfree(p->prefix);
if (p->suffix) xfree(p->suffix);
{
mc_subfield *psf=0;
mc_token tok = mc_gettoken(c);
-
+
if (tok == NOP)
return 0;
-
+
if (tok == LGROUP)
{
if (!(psf = mc_mk_subfield(parent)))
psf->which = MC_SFGROUP;
psf->u.child = mc_getsubfields(c, psf);
-
+
if (mc_gettoken(c) == RGROUP)
psf->next = mc_getsubfields(c, psf);
else
psf->which = MC_SFVARIANT;
psf->u.child = mc_getsubfields(c, psf);
-
+
if (mc_gettoken(c) == RVARIANT)
psf->next = mc_getsubfields(c, psf);
else
mc_token tok = mc_gettoken(c);
mc_ungettoken(c);
-
+
if (tok == LINTERVAL)
{
mc_getinterval(c, &psf->interval.start, &psf->interval.end);
return 0;
}
}
-
+
if (mc_getdata(c, psf->suffix, SZ_SUFFIX) == SZ_SUFFIX)
{
psf->which = MC_SF;
return 0;
}
}
- }
+ }
return psf;
}
/*
typedef struct mc_context
{
int offset;
-
+
int crrval;
mc_token crrtok;
-
+
mc_errcode errcode;
-
+
int len;
const char *data;
} mc_context;
tinfo->schemas = 0;
#if YAZ_HAVE_EXSLT
- exsltRegisterAll();
+ exsltRegisterAll();
#endif
#if ENABLE_INPUT_CALLBACK
static int attr_content(struct _xmlAttr *attr, const char *name,
const char **dst_content)
{
- if (!XML_STRCMP(attr->name, name) && attr->children
+ if (!XML_STRCMP(attr->name, name) && attr->children
&& attr->children->type == XML_TEXT_NODE)
{
*dst_content = (const char *)(attr->children->content);
tinfo->schemas = 0;
xfree(tinfo->fname);
if (tinfo->doc)
- xmlFreeDoc(tinfo->doc);
+ xmlFreeDoc(tinfo->doc);
tinfo->doc = 0;
}
char tmp_full_name[1024];
xmlNodePtr ptr;
tinfo->fname = xstrdup(fname);
-
- if (yaz_filepath_resolve(tinfo->fname, tinfo->profile_path,
+
+ if (yaz_filepath_resolve(tinfo->fname, tinfo->profile_path,
NULL, tmp_full_name))
tinfo->full_name = xstrdup(tmp_full_name);
else
tinfo->full_name = xstrdup(tinfo->fname);
-
+
yaz_log(YLOG_LOG, "alvis filter: loading config file %s", tinfo->full_name);
-
+
tinfo->doc = xmlParseFile(tinfo->full_name);
-
+
if (!tinfo->doc)
{
- yaz_log(YLOG_WARN, "alvis filter: could not parse config file %s",
+ yaz_log(YLOG_WARN, "alvis filter: could not parse config file %s",
tinfo->full_name);
-
+
return ZEBRA_FAIL;
}
-
+
ptr = xmlDocGetRootElement(tinfo->doc);
- if (!ptr || ptr->type != XML_ELEMENT_NODE
+ if (!ptr || ptr->type != XML_ELEMENT_NODE
|| XML_STRCMP(ptr->name, "schemaInfo"))
{
- yaz_log(YLOG_WARN,
- "alvis filter: config file %s :"
- " expected root element <schemaInfo>",
- tinfo->full_name);
+ yaz_log(YLOG_WARN,
+ "alvis filter: config file %s :"
+ " expected root element <schemaInfo>",
+ tinfo->full_name);
return ZEBRA_FAIL;
}
if (ptr->type != XML_ELEMENT_NODE)
continue;
if (!XML_STRCMP(ptr->name, "schema"))
- {
+ {
struct _xmlAttr *attr;
struct filter_schema *schema = xmalloc(sizeof(*schema));
schema->name = 0;
attr_content(attr, "stylesheet", &schema->stylesheet);
attr_content(attr, "default", &schema->default_schema);
}
- /*yaz_log(YLOG_LOG, "XSLT add %s %s %s",
+ /*yaz_log(YLOG_LOG, "XSLT add %s %s %s",
schema->name, schema->identifier, schema->stylesheet); */
/* find requested schema */
if (schema->stylesheet)
{
char tmp_xslt_full_name[1024];
- if (!yaz_filepath_resolve(schema->stylesheet, tinfo->profile_path,
- NULL, tmp_xslt_full_name))
+ if (!yaz_filepath_resolve(schema->stylesheet, tinfo->profile_path,
+ NULL, tmp_xslt_full_name))
{
- yaz_log(YLOG_WARN,
+ yaz_log(YLOG_WARN,
"alvis filter: stylesheet %s not found in path %s",
schema->stylesheet, tinfo->profile_path);
return ZEBRA_FAIL;
}
- schema->stylesheet_xsp
+ schema->stylesheet_xsp
= xsltParseStylesheetFile((const xmlChar*) tmp_xslt_full_name);
if (!schema->stylesheet_xsp)
{
- yaz_log(YLOG_WARN,
- "alvis filter: could not parse xslt stylesheet %s",
+ yaz_log(YLOG_WARN,
+ "alvis filter: could not parse xslt stylesheet %s",
tmp_xslt_full_name);
return ZEBRA_FAIL;
}
{
const char *split_level_str = 0;
attr_content(attr, "level", &split_level_str);
- tinfo->split_level =
+ tinfo->split_level =
split_level_str ? atoi(split_level_str) : 0;
}
}
struct filter_schema *schema;
for (schema = tinfo->schemas; schema; schema = schema->next)
- {
+ {
/* find requested schema */
- if (est)
- {
+ if (est)
+ {
if (schema->identifier && !strcmp(schema->identifier, est))
return schema;
-
+
if (schema->name && !strcmp(schema->name, est))
return schema;
- }
+ }
/* or return default schema if defined */
else if (schema->default_schema)
return schema;
/* return first schema if no default schema defined */
if (tinfo->schemas)
return tinfo->schemas;
-
+
return 0;
}
if (tinfo->fname && !strcmp(args, tinfo->fname))
return ZEBRA_OK;
-
+
tinfo->profile_path = res_get(res, "profilePath");
yaz_log(YLOG_LOG, "alvis filter: profilePath %s", tinfo->profile_path);
else if (!strcmp("delete", type_str))
yaz_log(YLOG_WARN, "alvis filter delete: to be implemented");
else
- yaz_log(YLOG_WARN, "alvis filter: unknown record type '%s'",
+ yaz_log(YLOG_WARN, "alvis filter: unknown record type '%s'",
type_str);
}
-
+
static int extract_doc(struct filter_info *tinfo, struct recExtractCtrl *p,
xmlDocPtr doc)
{
if (schema && schema->stylesheet_xsp)
{
xmlNodePtr root_ptr;
- xmlDocPtr resDoc =
+ xmlDocPtr resDoc =
xsltApplyStylesheet(schema->stylesheet_xsp,
doc, params);
if (p->flagShowRecords)
if (p->setStoreData)
(*p->setStoreData)(p, buf_out, len_out);
xmlFree(buf_out);
-
+
xmlFreeDoc(doc);
return RECCTRL_EXTRACT_OK;
}
xmlFreeTextReader(tinfo->reader);
tinfo->reader = xmlReaderForIO(ioread_ex, ioclose_ex,
p /* I/O handler */,
- 0 /* URL */,
+ 0 /* URL */,
0 /* encoding */,
XML_PARSE_XINCLUDE
| XML_PARSE_NOENT
{
xmlNodePtr ptr2 = xmlCopyNode(ptr, 1);
xmlDocPtr doc = xmlNewDoc((const xmlChar*) "1.0");
-
+
xmlDocSetRootElement(doc, ptr2);
-
+
return extract_doc(tinfo, p, doc);
}
else
if (!root)
return RECCTRL_EXTRACT_ERROR_GENERIC;
} */
-
+
return extract_doc(tinfo, p, doc);
}
else
{
esn = p->comp->u.simple->u.generic;
}
- else if (p->comp->which == Z_RecordComp_complex
+ else if (p->comp->which == Z_RecordComp_complex
&& p->comp->u.complex->generic->elementSpec
&& p->comp->u.complex->generic->elementSpec->which ==
Z_ElementSpec_elementSetName)
{
p->diagnostic = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
}
- else if (!p->input_format
+ else if (!p->input_format
|| !oid_oidcmp(p->input_format, yaz_oid_recsyn_xml))
{
xmlChar *buf_out;
if (schema->stylesheet_xsp)
xsltSaveResultToString(&buf_out, &len_out, resDoc,
- schema->stylesheet_xsp);
+ schema->stylesheet_xsp);
else
- xmlDocDumpMemory(resDoc, &buf_out, &len_out);
+ xmlDocDumpMemory(resDoc, &buf_out, &len_out);
p->output_format = yaz_oid_recsyn_xml;
p->rec_len = len_out;
xsltSaveResultToString(&buf_out, &len_out, resDoc,
schema->stylesheet_xsp);
else
- xmlDocDumpMemory(resDoc, &buf_out, &len_out);
+ xmlDocDumpMemory(resDoc, &buf_out, &len_out);
p->output_format = yaz_oid_recsyn_sutrs;
p->rec_len = len_out;
p->rec_buf = odr_malloc(p->odr, p->rec_len);
memcpy(p->rec_buf, buf_out, p->rec_len);
-
+
xmlFree(buf_out);
}
else
} u;
struct filter_input *next;
};
-
+
struct filter_info {
char *fname;
char *full_name;
yaz_vsnprintf(buf, sizeof(buf)-1, fmt, ap);
if (ptr)
{
- yaz_log(level, "%s:%ld: %s", tinfo->fname ? tinfo->fname : "none",
+ yaz_log(level, "%s:%ld: %s", tinfo->fname ? tinfo->fname : "none",
xmlGetLineNo(ptr), buf);
}
else
tinfo->record_info_invoked = 0;
#if YAZ_HAVE_EXSLT
- exsltRegisterAll();
+ exsltRegisterAll();
#endif
return tinfo;
static int attr_content(struct _xmlAttr *attr, const char *name,
const char **dst_content)
{
- if (!XML_STRCMP(attr->name, name) && attr->children
+ if (!XML_STRCMP(attr->name, name) && attr->children
&& attr->children->type == XML_TEXT_NODE)
{
*dst_content = (const char *)(attr->children->content);
{
struct _xmlAttr *attr;
struct convert_s *p = nmem_malloc(tinfo->nmem_config, sizeof(*p));
-
+
p->next = 0;
p->which = convert_xslt_type;
p->u.xslt.stylesheet = 0;
p->u.xslt.stylesheet_xsp = 0;
-
+
for (attr = ptr->properties; attr; attr = attr->next)
if (attr_content(attr, "stylesheet", &p->u.xslt.stylesheet))
;
if (p->u.xslt.stylesheet)
{
char tmp_xslt_full_name[1024];
- if (!yaz_filepath_resolve(p->u.xslt.stylesheet,
+ if (!yaz_filepath_resolve(p->u.xslt.stylesheet,
tinfo->profile_path,
- NULL,
+ NULL,
tmp_xslt_full_name))
{
dom_log(YLOG_WARN, tinfo, 0,
"stylesheet %s not found in "
"path %s",
- p->u.xslt.stylesheet,
+ p->u.xslt.stylesheet,
tinfo->profile_path);
return ZEBRA_FAIL;
}
-
+
p->u.xslt.stylesheet_xsp
- = xsltParseStylesheetFile((const xmlChar*)
+ = xsltParseStylesheetFile((const xmlChar*)
tmp_xslt_full_name);
if (!p->u.xslt.stylesheet_xsp)
{
{
struct _xmlAttr *attr;
struct convert_s *p = nmem_malloc(tinfo->nmem_config, sizeof(*p));
-
+
p->next = 0;
p->which = convert_meta_type;
-
+
for (attr = ptr->properties; attr; attr = attr->next)
dom_log(YLOG_WARN, tinfo, ptr,
"bad attribute @%s", attr->name);
return ZEBRA_OK;
}
-static int process_meta(struct filter_info *tinfo, xmlDocPtr doc, xmlNodePtr node,
+static int process_meta(struct filter_info *tinfo, xmlDocPtr doc, xmlNodePtr node,
struct recRetrieveCtrl *retctr)
{
if (0 == XML_STRCMP(node->name, "meta"))
{
const char *element_set_name = 0;
-
- struct _xmlAttr *attr;
+
+ struct _xmlAttr *attr;
for (attr = node->properties; attr; attr = attr->next)
{
if (attr_content(attr, "name", &element_set_name))
const Odr_oid *input_format = yaz_oid_recsyn_xml;
const Odr_oid *output_format = 0;
int ret;
-
+
ret = retctr->special_fetch(retctr->handle,
element_set_name,
input_format, &output_format,
result, addinfo);
if (ret == 0)
{
- xmlDocPtr sub_doc =
+ xmlDocPtr sub_doc =
xmlParseMemory(wrbuf_buf(result), wrbuf_len(result));
if (sub_doc)
{
return 0;
}
-static ZEBRA_RES perform_convert(struct filter_info *tinfo,
+static ZEBRA_RES perform_convert(struct filter_info *tinfo,
struct recExtractCtrl *extctr,
struct recRetrieveCtrl *retctr,
struct convert_s *convert,
*doc, params);
if (last_xsp)
*last_xsp = convert->u.xslt.stylesheet_xsp;
-
+
if (!res_doc)
break;
-
+
/* now saving into buffer and re-reading into DOM to avoid annoing
XSLT problem with thrown-out indentation text nodes */
xsltSaveResultToString(&buf_out, &len_out, res_doc,
- convert->u.xslt.stylesheet_xsp);
+ convert->u.xslt.stylesheet_xsp);
xmlFreeDoc(res_doc);
-
+
xmlFreeDoc(*doc);
-
+
*doc = xmlParseMemory((const char *) buf_out, len_out);
-
+
/* writing debug info out */
if (extctr && extctr->flagShowRecords)
- yaz_log(YLOG_LOG, "%s: XSLT %s\n %.*s",
- tinfo->fname ? tinfo->fname : "(none)",
+ yaz_log(YLOG_LOG, "%s: XSLT %s\n %.*s",
+ tinfo->fname ? tinfo->fname : "(none)",
convert->u.xslt.stylesheet,
len_out, buf_out);
-
+
xmlFree(buf_out);
}
else if (convert->which == convert_meta_type)
yaz_iconv_t iconv = 0;
const char *input_charset = "marc-8";
struct _xmlAttr *attr;
-
+
for (attr = ptr->properties; attr; attr = attr->next)
{
if (attr_content(attr, "inputcharset", &input_charset))
iconv = yaz_iconv_open("utf-8", input_charset);
if (!iconv)
{
- dom_log(YLOG_WARN, tinfo, ptr,
+ dom_log(YLOG_WARN, tinfo, ptr,
"unsupported @charset '%s'", input_charset);
return ZEBRA_FAIL;
}
else
{
- struct filter_input *p
+ struct filter_input *p
= new_input(tinfo, DOM_INPUT_MARC);
p->u.marc.handle = yaz_marc_create();
p->u.marc.iconv = iconv;
-
+
yaz_marc_iconv(p->u.marc.handle, p->u.marc.iconv);
-
+
ptr = ptr->next;
-
+
parse_convert(tinfo, ptr, &p->convert);
}
break;
}
else if (!XML_STRCMP(ptr->name, "xmlreader"))
{
- struct filter_input *p
+ struct filter_input *p
= new_input(tinfo, DOM_INPUT_XMLREADER);
struct _xmlAttr *attr;
const char *level_str = 0;
}
if (level_str)
p->u.xmlreader.split_level = atoi(level_str);
-
+
ptr = ptr->next;
parse_convert(tinfo, ptr, &p->convert);
xmlDocPtr doc;
tinfo->fname = nmem_strdup(tinfo->nmem_config, fname);
-
- if (yaz_filepath_resolve(tinfo->fname, tinfo->profile_path,
+
+ if (yaz_filepath_resolve(tinfo->fname, tinfo->profile_path,
NULL, tmp_full_name))
tinfo->full_name = nmem_strdup(tinfo->nmem_config, tmp_full_name);
else
tinfo->full_name = nmem_strdup(tinfo->nmem_config, tinfo->fname);
-
+
yaz_log(YLOG_LOG, "%s dom filter: "
"loading config file %s", tinfo->fname, tinfo->full_name);
tinfo->fname, tinfo->full_name);
return ZEBRA_FAIL;
}
- /* save because we store ptrs to the content */
+ /* save because we store ptrs to the content */
tinfo->doc_config = doc;
-
+
ptr = xmlDocGetRootElement(doc);
- if (!ptr || ptr->type != XML_ELEMENT_NODE
+ if (!ptr || ptr->type != XML_ELEMENT_NODE
|| XML_STRCMP(ptr->name, "dom"))
{
dom_log(YLOG_WARN, tinfo, ptr,
- "bad root element <%s>, expected root element <dom>",
- ptr->name);
+ "bad root element <%s>, expected root element <dom>",
+ ptr->name);
return ZEBRA_FAIL;
}
struct _xmlAttr *attr;
struct filter_extract *f =
nmem_malloc(tinfo->nmem_config, sizeof(*f));
-
+
tinfo->extract = f;
f->name = 0;
f->convert = 0;
parse_convert(tinfo, ptr->children, &f->convert);
}
else if (!XML_STRCMP(ptr->name, "retrieve"))
- {
- /*
+ {
+ /*
<retrieve name="F">
<xslt stylesheet="some.xsl"/>
<xslt stylesheet="some.xsl"/>
struct filter_retrieve **fp = &tinfo->retrieve_list;
struct filter_retrieve *f =
nmem_malloc(tinfo->nmem_config, sizeof(*f));
-
+
while (*fp)
fp = &(*fp)->next;
for (attr = ptr->properties; attr; attr = attr->next)
{
- if (attr_content(attr, "identifier",
+ if (attr_content(attr, "identifier",
&f->identifier))
;
else if (attr_content(attr, "name", &f->name))
*/
struct filter_store *f =
nmem_malloc(tinfo->nmem_config, sizeof(*f));
-
+
tinfo->store = f;
f->convert = 0;
parse_convert(tinfo, ptr->children, &f->convert);
}
if (!tinfo->input_list)
{
- struct filter_input *p
+ struct filter_input *p
= new_input(tinfo, DOM_INPUT_XMLREADER);
p->u.xmlreader.split_level = 0;
p->u.xmlreader.reader = 0;
if (!est)
return f;
for (; f; f = f->next)
- {
+ {
/* find requested schema */
- if (est)
- {
+ if (est)
+ {
if (f->identifier && !strcmp(f->identifier, est))
return f;
if (f->name && !strcmp(f->name, est))
return f;
- }
+ }
}
return 0;
}
if (tinfo->fname && !strcmp(args, tinfo->fname))
return ZEBRA_OK;
-
+
tinfo->profile_path = res_get(res, "profilePath");
destroy_dom(tinfo);
/* DOM filter style indexing */
-static void index_value_of(struct filter_info *tinfo,
+static void index_value_of(struct filter_info *tinfo,
struct recExtractCtrl *extctr,
- RecWord* recword,
- xmlNodePtr node,
+ RecWord* recword,
+ xmlNodePtr node,
const char *index_p)
{
if (tinfo->record_info_invoked == 1)
{
xmlChar *text = xmlNodeGetContent(node);
size_t text_len = strlen((const char *)text);
-
+
/* if there is no text, we do not need to proceed */
if (text_len)
- {
+ {
/* keep seqno base so that all text will have
identical seqno's for multiple fields , e.g
<z:index name="title:w any:w title:p">.. */
-
+
zint seqno_base = recword->seqno;
zint seqno_max = recword->seqno;
-
+
const char *look = index_p;
const char *bval;
/* setting name and type to zero */
*index = '\0';
*type = '\0';
-
+
/* parsing one index name */
bval = look;
while (*look && ':' != *look && ' ' != *look)
eval = look;
strncpy((char *)index, (const char *)bval, eval - bval);
index[eval - bval] = '\0';
-
-
+
+
/* parsing one index type, if existing */
if (':' == *look)
{
look++;
-
+
bval = look;
while (*look && ' ' != *look)
{
/* writing debug out */
if (extctr->flagShowRecords)
- dom_log(YLOG_LOG, tinfo, 0,
- "INDEX '%s:%s' '%s'",
+ dom_log(YLOG_LOG, tinfo, 0,
+ "INDEX '%s:%s' '%s'",
(const char *) index,
- (const char *) type,
+ (const char *) type,
(const char *) text);
-
+
(extctr->tokenAdd)(recword);
if (seqno_max < recword->seqno)
if (*look && ' ' == *look)
{
look++;
- }
+ }
}
recword->seqno = seqno_max;
}
- xmlFree(text);
+ xmlFree(text);
}
}
/* DOM filter style indexing */
-static void set_record_info(struct filter_info *tinfo,
- struct recExtractCtrl *extctr,
- xmlNodePtr node,
- const char * id_p,
- const char * rank_p,
+static void set_record_info(struct filter_info *tinfo,
+ struct recExtractCtrl *extctr,
+ xmlNodePtr node,
+ const char * id_p,
+ const char * rank_p,
const char * type_p)
{
/* writing debug info out */
if (extctr && extctr->flagShowRecords)
dom_log(YLOG_LOG, tinfo, node,
- "RECORD id=%s rank=%s type=%s",
+ "RECORD id=%s rank=%s type=%s",
id_p ? (const char *) id_p : "(null)",
rank_p ? (const char *) rank_p : "(null)",
type_p ? (const char *) type_p : "(null)");
-
+
if (id_p && *id_p)
{
/* DOM filter style indexing */
-static void process_xml_element_zebra_node(struct filter_info *tinfo,
- struct recExtractCtrl *extctr,
- RecWord* recword,
+static void process_xml_element_zebra_node(struct filter_info *tinfo,
+ struct recExtractCtrl *extctr,
+ RecWord* recword,
xmlNodePtr node)
{
if (node->type == XML_ELEMENT_NODE && node->ns && node->ns->href
{
const char *index_p = 0;
- struct _xmlAttr *attr;
+ struct _xmlAttr *attr;
for (attr = node->properties; attr; attr = attr->next)
{
if (attr_content(attr, "name", &index_p))
{
index_value_of(tinfo, extctr, recword, node, index_p);
- }
+ }
else
{
dom_log(YLOG_WARN, tinfo, node,
}
}
set_record_info(tinfo, extctr, node, id_p, rank_p, type_p);
- }
+ }
else
{
dom_log(YLOG_WARN, tinfo, node,
}
/* DOM filter style indexing */
-static void process_xml_pi_node(struct filter_info *tinfo,
- struct recExtractCtrl *extctr,
+static void process_xml_pi_node(struct filter_info *tinfo,
+ struct recExtractCtrl *extctr,
xmlNodePtr node,
const char **index_pp)
{
{
xmlChar *pi_p = node->content;
const char *look = (const char *) node->content;
-
+
/* parsing PI record instructions */
if (0 == strncmp((const char *)look, "record", 6))
{
char id[256];
char rank[256];
char type[256];
-
+
*id = '\0';
*rank = '\0';
*type = '\0';
}
}
set_record_info(tinfo, extctr, node, id, rank, type);
- }
+ }
/* parsing index instruction */
else if (0 == strncmp((const char *)look, "index", 5))
{
look += 5;
-
+
/* eat whitespace */
while (*look && ' ' == *look)
look++;
/* export index instructions to outside */
*index_pp = look;
- }
- else
+ }
+ else
{
dom_log(YLOG_WARN, tinfo, node,
"content '%s', can not parse '%s'",
}
/* DOM filter style indexing */
-static void process_xml_element_node(struct filter_info *tinfo,
- struct recExtractCtrl *extctr,
- RecWord* recword,
+static void process_xml_element_node(struct filter_info *tinfo,
+ struct recExtractCtrl *extctr,
+ RecWord* recword,
xmlNodePtr node)
{
/* remember indexing instruction from PI to next element node */
const char *index_p = 0;
- /* check if we are an element node in the special zebra namespace
+ /* check if we are an element node in the special zebra namespace
and either set record data or index value-of node content*/
process_xml_element_zebra_node(tinfo, extctr, recword, node);
-
+
/* loop through kid nodes */
for (node = node->children; node; node = node->next)
{
/* DOM filter style indexing */
-static void extract_dom_doc_node(struct filter_info *tinfo,
- struct recExtractCtrl *extctr,
+static void extract_dom_doc_node(struct filter_info *tinfo,
+ struct recExtractCtrl *extctr,
xmlDocPtr doc)
{
/* only need to do the initialization once, reuse recword for all terms */
}
-static int convert_extract_doc(struct filter_info *tinfo,
+static int convert_extract_doc(struct filter_info *tinfo,
struct filter_input *input,
- struct recExtractCtrl *p,
+ struct recExtractCtrl *p,
xmlDocPtr doc)
{
xmlChar *buf_out;
xmlChar *buf_out;
int len_out;
xmlDocDumpMemory(doc, &buf_out, &len_out);
-#if 0
+#if 0
FILE *outf = fopen("extract.xml", "w");
fwrite(buf_out, 1, len_out, outf);
fclose(outf);
/* input conversion */
perform_convert(tinfo, p, 0, input->convert, params, &doc, 0);
-
+
if (tinfo->store)
{
/* store conversion */
perform_convert(tinfo, p, 0, tinfo->store->convert,
params, &store_doc, &last_xsp);
}
-
+
/* saving either store doc or original doc in case no store doc exists */
if (last_xsp)
- xsltSaveResultToString(&buf_out, &len_out,
+ xsltSaveResultToString(&buf_out, &len_out,
store_doc ? store_doc : doc, last_xsp);
else
xmlDocDumpMemory(store_doc ? store_doc : doc, &buf_out, &len_out);
-
+
if (p->setStoreData)
(*p->setStoreData)(p, buf_out, len_out);
xmlFree(buf_out);
extract_dom_doc_node(tinfo, p, doc);
xmlFreeDoc(doc);
}
-
+
/* there was nothing to index, so there is no inserted/updated record */
if (tinfo->record_info_invoked == 0)
return RECCTRL_EXTRACT_SKIP;
xmlFreeTextReader(input->u.xmlreader.reader);
input->u.xmlreader.reader = xmlReaderForIO(ioread_ex, ioclose_ex,
p /* I/O handler */,
- 0 /* URL */,
+ 0 /* URL */,
0 /* encoding */,
XML_PARSE_XINCLUDE
| XML_PARSE_NOENT
int type = xmlTextReaderNodeType(input->u.xmlreader.reader);
int depth = xmlTextReaderDepth(input->u.xmlreader.reader);
- if (type == XML_READER_TYPE_ELEMENT &&
+ if (type == XML_READER_TYPE_ELEMENT &&
input->u.xmlreader.split_level == depth)
{
xmlNodePtr ptr;
/* per default do not ingest record */
tinfo->record_info_invoked = 0;
-
+
ptr = xmlTextReaderExpand(input->u.xmlreader.reader);
if (ptr)
{
xmlNodePtr ptr2 = xmlCopyNode(ptr, 1);
xmlDocPtr doc = xmlNewDoc((const xmlChar*) "1.0");
-
+
xmlDocSetRootElement(doc, ptr2);
-
+
/* writing debug info out */
if (p->flagShowRecords)
{
xmlChar *buf_out = 0;
int len_out = 0;
xmlDocDumpMemory(doc, &buf_out, &len_out);
- yaz_log(YLOG_LOG, "%s: XMLREADER level: %i\n%.*s",
+ yaz_log(YLOG_LOG, "%s: XMLREADER level: %i\n%.*s",
tinfo->fname ? tinfo->fname : "(none)",
- depth, len_out, buf_out);
+ depth, len_out, buf_out);
xmlFree(buf_out);
}
-
+
return convert_extract_doc(tinfo, input, p, doc);
}
else
return RECCTRL_EXTRACT_EOF;
}
-static int extract_xml_full(struct filter_info *tinfo,
+static int extract_xml_full(struct filter_info *tinfo,
struct filter_input *input,
struct recExtractCtrl *p)
{
if (p->first_record) /* only one record per stream */
{
- xmlDocPtr doc = xmlReadIO(ioread_ex, ioclose_ex,
+ xmlDocPtr doc = xmlReadIO(ioread_ex, ioclose_ex,
p /* I/O handler */,
0 /* URL */,
0 /* encoding */,
{
xmlDocPtr rdoc;
xmlNode *root_ptr;
- yaz_marc_write_xml(input->u.marc.handle, &root_ptr,
+ yaz_marc_write_xml(input->u.marc.handle, &root_ptr,
"http://www.loc.gov/MARC21/slim", 0, 0);
rdoc = xmlNewDoc((const xmlChar*) "1.0");
xmlDocSetRootElement(rdoc, root_ptr);
- return convert_extract_doc(tinfo, input, p, rdoc);
+ return convert_extract_doc(tinfo, input, p, rdoc);
}
return RECCTRL_EXTRACT_OK;
}
if (!input)
return RECCTRL_EXTRACT_ERROR_GENERIC;
-
+
nmem_reset(tinfo->nmem_record);
if (p->setStoreData == 0)
{
esn = p->comp->u.simple->u.generic;
}
- else if (p->comp->which == Z_RecordComp_complex
+ else if (p->comp->which == Z_RecordComp_complex
&& p->comp->u.complex->generic->elementSpec
&& p->comp->u.complex->generic->elementSpec->which ==
Z_ElementSpec_elementSetName)
if (last_xsp)
xsltSaveResultToString(&buf_out, &len_out, doc, last_xsp);
else
- xmlDocDumpMemory(doc, &buf_out, &len_out);
+ xmlDocDumpMemory(doc, &buf_out, &len_out);
p->output_format = yaz_oid_recsyn_xml;
p->rec_len = len_out;
if (last_xsp)
xsltSaveResultToString(&buf_out, &len_out, doc, last_xsp);
else
- xmlDocDumpMemory(doc, &buf_out, &len_out);
-
+ xmlDocDumpMemory(doc, &buf_out, &len_out);
+
p->output_format = yaz_oid_recsyn_sutrs;
p->rec_len = len_out;
p->rec_buf = odr_malloc(p->odr, p->rec_len);
memcpy(p->rec_buf, buf_out, p->rec_len);
-
+
xmlFree(buf_out);
}
else
{
data1_node *lead;
const char *attr[] = { "xmlns", "http://www.loc.gov/MARC21/slim", 0};
-
+
res_top = data1_mk_tag (p->dh, p->mem, "record", attr, res_root);
lead = data1_mk_tag(p->dh, p->mem, "leader", 0, res_top);
res = parent;
else
res = data1_mk_tag_n (p->dh, p->mem, tag, 3, 0 /* attr */, parent);
-
+
#if MARC_DEBUG
fprintf (outf, "%s ", tag);
#endif
yaz_log(YLOG_WARN, "MARC: Bad offsets in data. Skipping rest");
break;
}
-
+
if (memcmp (tag, "00", 2) && indicator_length)
{
/* generate indicator node */
attr[0] = str1;
attr[1] = str2;
-
+
data1_tag_add_attr (p->dh, p->mem, res, attr);
}
}
#if MARC_DEBUG
int j;
#endif
- res = data1_mk_tag_n (p->dh, p->mem,
+ res = data1_mk_tag_n (p->dh, p->mem,
buf+i, indicator_length, 0 /* attr */, res);
#if MARC_DEBUG
for (j = 0; j<indicator_length; j++)
#endif
}
i += indicator_length;
- }
+ }
else
{
if (marc_xml)
{
const char *attr[10];
-
+
attr[0] = "tag";
attr[1] = tag;
attr[2] = 0;
-
+
res = data1_mk_tag(p->dh, p->mem, "controlfield", attr, res);
}
}
int j;
const char *attr[3];
char code[10];
-
+
for (j = 1; j<identifier_length && j < 9; j++)
code[j-1] = buf[i+j];
code[j-1] = 0;
else
{
res = data1_mk_tag_n (p->dh, p->mem,
- buf+i+1, identifier_length-1,
+ buf+i+1, identifier_length-1,
0 /* attr */, parent);
}
#if MARC_DEBUG
- fprintf (outf, " $");
+ fprintf (outf, " $");
for (j = 1; j<identifier_length; j++)
fprintf (outf, "%c", buf[j+i]);
fprintf (outf, " ");
else if (n->which == DATA1N_data)
n = n->next;
else
- break;
+ break;
}
r = "";
*len = strlen(r);
static data1_node *lookup_subfield(data1_node *node, const char *name)
{
data1_node *p;
-
+
for (p=node; p; p=p->next)
{
if (!yaz_matchstr(p->u.tag.tag, name))
const char *name)
{
inline_subfield *p;
-
+
for (p=pisf; p; p=p->next)
{
if (!yaz_matchstr(p->name, name))
inline_subfield *pisf)
{
mc_subfield *p;
-
+
for (p = psf; p && pisf; p = p->next)
{
if (p->which == MC_SF)
{
inline_subfield *found = lookup_inline_subfield(pisf, p->name);
-
+
if (found)
{
if (strcmp(p->prefix, "_"))
}
#if MARCOMP_DEBUG
yaz_log(YLOG_LOG, "cat_inline_subfield(): add subfield $%s", found->name);
-#endif
+#endif
pisf = found->next;
}
}
else if (p->which == MC_SFVARIANT)
{
inline_subfield *next;
-
+
do {
next = cat_inline_subfield(p->u.child, buf, pisf);
if (next == pisf)
{
mc_subfield *pp;
int found;
-
+
for (pp = p->u.child, found = 0; pp; pp = pp->next)
{
if (!yaz_matchstr(pisf->name, p->name))
}
}
}
- return pisf;
+ return pisf;
}
static void cat_inline_field(mc_field *pf, WRBUF buf, data1_node *subfield)
-{
+{
if (!pf || !subfield)
return;
int len;
inline_field *pif=NULL;
data1_node *psubf;
-
+
if (yaz_matchstr(subfield->u.tag.tag, "1"))
{
subfield = subfield->next;
continue;
}
-
+
psubf = subfield;
pif = inline_mk_field();
do
yaz_log(YLOG_WARN, "inline subfield ($%s): parse error",
psubf->u.tag.tag);
inline_destroy_field(pif);
- return;
+ return;
}
psubf = psubf->next;
} while (psubf && yaz_matchstr(psubf->u.tag.tag, "1"));
-
+
subfield = psubf;
-
+
if (pif && !yaz_matchstr(pif->name, pf->name))
{
if (!pf->list && pif->list)
ind1 = (pif->ind1[0] == ' ') ? '_':pif->ind1[0];
ind2 = (pif->ind2[0] == ' ') ? '_':pif->ind2[0];
-
+
if (((pf->ind1[0] == '.') || (ind1 == pf->ind1[0])) &&
((pf->ind2[0] == '.') || (ind2 == pf->ind2[0])))
{
cat_inline_subfield(pf->list, buf, pif->list);
-
+
/*
add separator for inline fields
*/
}
inline_destroy_field(pif);
}
-#if MARCOMP_DEBUG
+#if MARCOMP_DEBUG
yaz_log(YLOG_LOG, "cat_inline_field(): got buffer {%s}", buf);
#endif
}
data1_node *subfield)
{
mc_subfield *p;
-
+
for (p = psf; p && subfield; p = p->next)
{
if (p->which == MC_SF)
{
data1_node *found = lookup_subfield(subfield, p->name);
-
+
if (found)
{
int len;
-
+
if (strcmp(p->prefix, "_"))
{
wrbuf_puts(buf, " ");
wrbuf_puts(buf, p->prefix);
}
-
+
if (p->u.in_line)
{
cat_inline_field(p->u.in_line, buf, found);
wrbuf_puts(buf, p->suffix);
wrbuf_puts(buf, " ");
}
-#if MARCOMP_DEBUG
+#if MARCOMP_DEBUG
yaz_log(YLOG_LOG, "cat_subfield(): add subfield $%s", found->u.tag.tag);
-#endif
+#endif
subfield = found->next;
}
}
{
mc_subfield *pp;
int found;
-
+
for (pp = p->u.child, found = 0; pp; pp = pp->next)
{
if (!yaz_matchstr(subfield->u.tag.tag, pp->name))
{
data1_node *subfield;
int ind1, ind2;
-
+
if (!pf || !field)
return 0;
-
+
if (yaz_matchstr(field->u.tag.tag, pf->name))
return field->next;
subfield = field->child;
-
+
if (!subfield)
return field->next;
/*
check subfield without indicators
*/
-
+
if (!pf->list && subfield->which == DATA1N_data)
{
int len;
-
+
if (pf->interval.start == -1)
{
wrbuf_puts(buf, get_data(field, &len));
#endif
return field->next;
}
-
+
/*
check indicators
*/
ind1 = (subfield->u.tag.tag[0] == ' ') ? '_':subfield->u.tag.tag[0];
ind2 = (subfield->u.tag.tag[1] == ' ') ? '_':subfield->u.tag.tag[1];
-
+
if (!(
((pf->ind1[0] == '.') || (ind1 == pf->ind1[0])) &&
((pf->ind2[0] == '.') || (ind2 == pf->ind2[0]))
#endif
return field->next;
}
-
+
subfield = subfield->child;
-
+
if (!subfield)
return field->next;
cat_subfield(pf->list, buf, subfield);
-#if MARCOMP_DEBUG
+#if MARCOMP_DEBUG
yaz_log(YLOG_LOG, "cat_field(): got buffer {%s}", buf);
#endif
-
- return field->next;
+
+ return field->next;
}
static int is_empty(char *s)
{
char *p = s;
-
+
for (p = s; *p; p++)
{
if (!isspace(*(unsigned char *)p))
mc_context *c;
mc_field *pf;
WRBUF buf;
-
+
c = mc_mk_context(mc_stmnt+3);
-
+
if (!c)
return;
-
+
pf = mc_getfield(c);
-
+
if (!pf)
{
mc_destroy_context(c);
return;
}
buf = wrbuf_alloc();
-#if MARCOMP_DEBUG
+#if MARCOMP_DEBUG
yaz_log(YLOG_LOG, "parse_data1_tree(): statement -{%s}", mc_stmnt);
#endif
if (!yaz_matchstr(pf->name, "ldr"))
#if MARCOMP_DEBUG
yaz_log(YLOG_LOG,"parse_data1_tree(): try LEADER from {%d} to {%d} positions",
pf->interval.start, pf->interval.end);
-#endif
+#endif
if (marctab)
{
new = data1_mk_tag_n(p->dh, p->mem, mc_stmnt, strlen(mc_stmnt), 0, top);
else
{
field=top->child;
-
+
while(field)
{
if (!yaz_matchstr(field->u.tag.tag, pf->name))
{
data1_node *new;
char *pb;
-#if MARCOMP_DEBUG
+#if MARCOMP_DEBUG
yaz_log(YLOG_LOG, "parse_data1_tree(): try field {%s}", field->u.tag.tag);
-#endif
+#endif
wrbuf_rewind(buf);
wrbuf_puts(buf, "");
field = cat_field(p, pf, buf, field);
-
+
wrbuf_cstr(buf);
pb = wrbuf_buf(buf);
for (pb = strtok(pb, "\n"); pb; pb = strtok(NULL, "\n"))
if (!root)
return 0;
-
+
for (e = data1_absyn_getelements(p->dh, root); e; e=e->next)
{
data1_tag *tag = e->tag;
-
+
if (tag && tag->which == DATA1T_string &&
!yaz_matchstr(tag->value.string, "mc?"))
parse_data1_tree(p, tag->value.string, root);
if (!root)
return 0;
-
+
for (e = data1_absyn_getelements(p->dh, root); e; e=e->next)
{
data1_tag *tag = e->tag;
-
+
if (tag && tag->which == DATA1T_string &&
!yaz_matchstr(tag->value.string, "mc?"))
parse_data1_tree(p, tag->value.string, root);
&marcxml_type,
0,
};
-
+
/*
* Local variables:
* c-basic-offset: 4
};
struct lexRuleAction {
- int which;
+ int which;
union {
struct {
struct DFA *dfa; /* REGX_PATTERN */
data1_node **d1_stack;
int d1_level;
int stop_flag;
-
+
int *arg_start;
int *arg_end;
int arg_no;
{
int size;
char *buf;
-
+
if (*pos >= spec->f_win_start && *pos < spec->f_win_end)
return spec->f_win_buf[(*pos)++ - spec->f_win_start];
if (*pos == F_WIN_EOF)
if (p->tcl_obj)
Tcl_DecrRefCount (p->tcl_obj);
#endif
- xfree (p->str);
+ xfree (p->str);
xfree (p);
*pp = NULL;
}
{
struct lexSpec *p;
int i;
-
+
p = (struct lexSpec *) xmalloc (sizeof(*p));
p->name = (char *) xmalloc (strlen(name)+1);
strcpy (p->name, name);
}
if (!spec->context)
spec->context = lexContextCreate ("main");
-
+
switch (tok)
{
case REGX_BEGIN:
else
{
int addLine = 0;
-
+
while (1)
{
int c1 = c;
}
if (errors)
return -1;
-
+
return 0;
}
}
else if (elen > 0)
yaz_log (YLOG_LOG, "data(%d bytes) %.*s", elen, elen, ebuf);
- else
+ else
yaz_log (YLOG_LOG, "data(%d bytes)", elen);
#endif
-
+
if (spec->d1_level <= 1)
return;
nv[strlen(nv)+elen] = '\0';
(*ap)->value = nv;
}
- }
- else
+ }
+ else
{
- if ((res = spec->d1_stack[spec->d1_level]) &&
+ if ((res = spec->d1_stack[spec->d1_level]) &&
res->which == DATA1N_data)
org_len = res->u.data.len;
else
{
org_len = 0;
-
+
res = data1_mk_node2 (spec->dh, spec->m, DATA1N_data, parent);
res->u.data.what = DATA1I_text;
res->u.data.len = 0;
res->u.data.formatted_text = formatted_text;
res->u.data.data = 0;
-
+
if (spec->d1_stack[spec->d1_level])
spec->d1_stack[spec->d1_level]->next = res;
spec->d1_stack[spec->d1_level] = res;
if (org_len + elen >= spec->concatBuf[spec->d1_level].max)
{
char *old_buf, *new_buf;
-
+
spec->concatBuf[spec->d1_level].max = org_len + elen + 256;
new_buf = (char *) xmalloc (spec->concatBuf[spec->d1_level].max);
if ((old_buf = spec->concatBuf[spec->d1_level].buf))
static void tagDataRelease (struct lexSpec *spec)
{
data1_node *res;
-
+
if ((res = spec->d1_stack[spec->d1_level]) &&
- res->which == DATA1N_data &&
+ res->which == DATA1N_data &&
res->u.data.what == DATA1I_text)
{
assert (!res->u.data.data);
}
}
-static void variantBegin (struct lexSpec *spec,
+static void variantBegin (struct lexSpec *spec,
const char *class_str, int class_len,
const char *type_str, int type_len,
const char *value_str, int value_len)
memcpy (ttype, type_str, type_len);
ttype[type_len] = '\0';
-#if REGX_DEBUG
+#if REGX_DEBUG
yaz_log (YLOG_LOG, "variant begin(%s,%s,%d)", tclass, ttype,
spec->d1_level);
#endif
data1_getvartypeby_absyn(spec->dh, parent->root->u.root.absyn,
tclass, ttype)))
return;
-
+
if (parent->which != DATA1N_variant)
{
res = data1_mk_node2 (spec->dh, spec->m, DATA1N_variant, parent);
break;
}
-#if REGX_DEBUG
+#if REGX_DEBUG
yaz_log (YLOG_LOG, "variant node(%d)", spec->d1_level);
#endif
parent = spec->d1_stack[spec->d1_level-1];
res->lbuf[value_len] = '\0';
res->u.variant.value = res->lbuf;
-
+
if (spec->d1_stack[spec->d1_level])
tagDataRelease (spec);
spec->d1_stack[spec->d1_level] = res;
*len -= i;
}
-static void tagBegin (struct lexSpec *spec,
+static void tagBegin (struct lexSpec *spec,
const char *tag, int len)
{
if (spec->d1_level == 0)
if (spec->d1_stack[spec->d1_level])
tagDataRelease (spec);
-#if REGX_DEBUG
+#if REGX_DEBUG
yaz_log (YLOG_LOG, "begin tag(%.*s, %d)", len, tag, spec->d1_level);
#endif
yaz_log (YLOG_LOG, "begin record %s", absynName);
#endif
res = data1_mk_root (spec->dh, spec->m, absynName);
-
+
spec->d1_level = 0;
spec->d1_stack[spec->d1_level++] = res;
struct lexSpec *spec = (struct lexSpec *) clientData;
if (argc < 2)
return TCL_ERROR;
-
+
if (!strcmp (argv[1], "record"))
{
while (spec->d1_level)
const char *element = 0;
const char *attribute = 0;
struct lexSpec *spec = (struct lexSpec *) clientData;
-
+
while (argi < argc)
{
if (!strcmp("-text", argv[argi]))
#if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION > 0)
Tcl_DString ds;
char *native = Tcl_UtfToExternalDString(0, argv[argi], -1, &ds);
- execData (spec, native, strlen(native), textFlag, attribute,
+ execData (spec, native, strlen(native), textFlag, attribute,
attribute ? strlen(attribute) : 0);
Tcl_DStringFree (&ds);
#else
int argi = 1;
int offset = 0;
int no;
-
+
while (argi < argc)
{
if (!strcmp("-offset", argv[argi]))
}
static void execTcl (struct lexSpec *spec, struct regxCode *code)
-{
+{
int i;
int ret;
for (i = 0; i < spec->arg_no; i++)
{
char var_name[10], *var_buf;
int var_len, ch;
-
+
sprintf (var_name, "%d", i);
var_buf = f_win_get (spec, spec->arg_start[i], spec->arg_end[i],
- &var_len);
+ &var_len);
if (var_buf)
{
ch = var_buf[var_len];
if (ret != TCL_OK)
{
const char *err = Tcl_GetVar(spec->tcl_interp, "errorInfo", 0);
- yaz_log(YLOG_FATAL, "Tcl error, line=%d, \"%s\"\n%s",
+ yaz_log(YLOG_FATAL, "Tcl error, line=%d, \"%s\"\n%s",
spec->tcl_interp->errorLine,
spec->tcl_interp->result,
err ? err : "[NO ERRORINFO]");
const char *s = code->str;
int cmd_len, r;
const char *cmd_str;
-
+
r = execTok (spec, &s, &cmd_str, &cmd_len);
while (r)
{
char *p, ptmp[64];
-
+
if (r == 1)
{
r = execTok (spec, &s, &cmd_str, &cmd_len);
yaz_log (YLOG_LOG, "begin record %s", absynName);
#endif
res = data1_mk_root (spec->dh, spec->m, absynName);
-
+
spec->d1_level = 0;
spec->d1_stack[spec->d1_level++] = res;
continue;
tagBegin (spec, cmd_str, cmd_len);
r = execTok (spec, &s, &cmd_str, &cmd_len);
- }
+ }
else if (!strcmp (p, "variant"))
{
int class_len;
variantBegin (spec, class_str, class_len,
type_str, type_len, value_str, value_len);
-
-
+
+
r = execTok (spec, &s, &cmd_str, &cmd_len);
}
else if (!strcmp (p, "context"))
spec->context_stack[++(spec->context_stack_top)] = lc;
else
yaz_log (YLOG_WARN, "unknown context %s", p);
-
+
}
r = execTok (spec, &s, &cmd_str, &cmd_len);
}
if (spec->context_stack_top)
(spec->context_stack_top)--;
r = execTok (spec, &s, &cmd_str, &cmd_len);
- }
+ }
else
yaz_log (YLOG_WARN, "bad keyword '%s' after end", p);
}
const char *element_str = NULL;
int attribute_len;
const char *attribute_str = NULL;
-
+
while ((r = execTok (spec, &s, &cmd_str, &cmd_len)) == 3)
{
if (cmd_len==5 && !memcmp ("-text", cmd_str, cmd_len))
if (r < 2)
break;
}
- else if (cmd_len==10 && !memcmp ("-attribute", cmd_str,
+ else if (cmd_len==10 && !memcmp ("-attribute", cmd_str,
cmd_len))
{
r = execTok (spec, &s, &attribute_str, &attribute_len);
if (r < 2)
break;
}
- else
+ else
yaz_log (YLOG_WARN, "bad data option: %.*s",
cmd_len, cmd_str);
}
struct lexContext *lc = spec->context;
r = execTok (spec, &s, &cmd_str, &cmd_len);
p = regxStrz (cmd_str, cmd_len, ptmp);
-
+
while (lc && strcmp (p, lc->name))
lc = lc->next;
if (lc)
{
last_rule = state->rule_no;
last_ptr = *ptr;
- }
+ }
else if (state->rule_nno)
{
last_rule = state->rule_nno;
spec->stop_flag = 0;
spec->d1_level = 0;
- spec->context_stack_top = 0;
+ spec->context_stack_top = 0;
while (lt)
{
if (!strcmp (lt->name, context_name))
{
struct sgml_getc_info *p = (struct sgml_getc_info *) clientData;
int res;
-
+
if (p->off < p->size)
return p->buf[(p->off)++];
if (p->size < p->buf_size)
struct sgml_getc_info *sgi = (struct sgml_getc_info *) p->clientData;
data1_node *node;
int res;
-
+
sgi->moffset = p->stream->tellf(p->stream);
sgi->stream = p->stream;
sgi->off = 0;
attr_list[5] = standalone ? "yes" : "no";
attr_list[6] = 0;
-
+
data1_mk_preprocess (ui->dh, ui->nmem, "xml", attr_list,
ui->d1_stack[ui->level-1]);
#if 0
encoding ? encoding : "null");
#endif
}
-
+
static void cb_processing (void *user, const char *target,
const char *data)
{
data1_mk_preprocess (ui->dh, ui->nmem, target, 0,
ui->d1_stack[ui->level-1]);
data1_mk_text_nf (ui->dh, ui->nmem, data, strlen(data), res);
-
+
yaz_log (ui->loglevel, "decl processing target=%s data=%s",
target ? target : "null",
data ? data : "null");
" publicId=%s notationName=%s",
entityName, is_parameter_entity, value_length, value,
base, systemId, publicId, notationName);
-
+
}
static int cb_external_entity(XML_Parser pparser,
iconv_t t = iconv_open ("UNICODE", name);
if (t == (iconv_t) (-1))
return 0;
-
+
info->data = 0; /* signal that multibyte is not in use */
yaz_log (ui->loglevel, "Encoding handler of %s", name);
for (i = 0; i<256; i++)
int len = 2;
int j = 0;
info->map[i] = -1;
-
+
while (len <= 4)
{
char sbuf[80];
uinfo.nmem = m;
uinfo.d1_stack[0] = data1_mk_node2 (dh, m, DATA1N_root, 0);
uinfo.d1_stack[1] = 0; /* indicate no children (see end of routine) */
-
+
parser = XML_ParserCreate (0 /* encoding */);
-
+
XML_SetElementHandler (parser, cb_start, cb_end);
XML_SetCharacterDataHandler (parser, cb_chardata);
XML_SetXmlDeclHandler (parser, cb_decl);
attr_list[3] = "UTF-8"; /* encoding */
attr_list[4] = 0;
-
+
data1_insert_preprocess (uinfo.dh, uinfo.nmem, "xml", attr_list,
uinfo.d1_stack[0]);
}
&filter_type,
0,
};
-
+
#endif
/*
recWord.index_type = type_cstr;
if (tinfo->segments)
{
- if (sscanf(cp, ZINT_FORMAT " " ZINT_FORMAT " " ZINT_FORMAT
+ if (sscanf(cp, ZINT_FORMAT " " ZINT_FORMAT " " ZINT_FORMAT
ZINT_FORMAT " %39s %n",
- &recWord.record_id, &recWord.section_id,
+ &recWord.record_id, &recWord.section_id,
&recWord.segment,
&recWord.seqno,
field, &nor) < 5)
}
p->output_format = yaz_oid_recsyn_sutrs;
p->rec_buf = filter_buf;
- p->rec_len = filter_ptr;
+ p->rec_len = filter_ptr;
return 0;
}
do
{
int i = 0;
-
+
r = buf_getchar(tinfo, fi, w);
while (r > 0 && i < 511 && w[i] != '\n' && w[i] != '\r')
{
i++;
- r = buf_getchar(tinfo, fi, w + i);
+ r = buf_getchar(tinfo, fi, w + i);
}
if (i)
{
}
p->output_format = yaz_oid_recsyn_sutrs;
p->rec_buf = filter_buf;
- p->rec_len = filter_ptr;
+ p->rec_len = filter_ptr;
return 0;
}
char *name;
void *(*create)(ZebraHandle zh);
void (*destroy)(struct zebra_register *reg, void *class_handle);
- void *(*begin)(struct zebra_register *reg,
+ void *(*begin)(struct zebra_register *reg,
void *class_handle, RSET rset, NMEM nmem,
TERMID *terms, int numterms);
/* ### Could add parameters to begin:
}
/*
- * create: Creates/Initialises this rank handler. This routine is
+ * create: Creates/Initialises this rank handler. This routine is
* called exactly once. The routine returns the class_handle.
*/
static void *create(ZebraHandle zh)
{
- struct rank_class_info *ci =
+ struct rank_class_info *ci =
(struct rank_class_info *) xmalloc(sizeof(*ci));
if (!log_initialized)
* each result set. The returned handle is a "set handle" and
* will be used in each of the handlers below.
*/
-static void *begin(struct zebra_register *reg,
+static void *begin(struct zebra_register *reg,
void *class_handle, RSET rset, NMEM nmem,
TERMID *terms, int numterms)
{
- struct rank_set_info *si =
+ struct rank_set_info *si =
(struct rank_set_info *) nmem_malloc(nmem,sizeof(*si));
int i;
si->no_rank_entries = 0;
si->nmem=nmem;
si->entries = (struct rank_term_info *)
- nmem_malloc(si->nmem, sizeof(*si->entries)*numterms);
+ nmem_malloc(si->nmem, sizeof(*si->entries)*numterms);
for (i = 0; i < numterms; i++)
{
zint g = rset_count(terms[i]->rset);
- yaz_log(log_level, "i=%d flags=%s '%s'", i,
+ yaz_log(log_level, "i=%d flags=%s '%s'", i,
terms[i]->flags, terms[i]->name );
- if (!strncmp(terms[i]->flags, "rank,", 5))
+ if (!strncmp(terms[i]->flags, "rank,", 5))
{
const char *cp = strstr(terms[i]->flags+4, ",w=");
si->entries[i].rank_flag = 1;
si->entries[i].local_occur = 0; /* FIXME */
si->entries[i].global_occur = g;
si->entries[i].global_inv = 32 - log2_int(g);
- yaz_log(log_level, " global_inv = %d g = " ZINT_FORMAT,
+ yaz_log(log_level, " global_inv = %d g = " ZINT_FORMAT,
(int) (32-log2_int(g)), g);
si->entries[i].term = terms[i];
si->entries[i].term_index=i;
assert(ti);
si->last_pos = seqno;
ti->local_occur++;
- yaz_log(log_level, "rank-1 add seqno=%d term=%s count=%d",
+ yaz_log(log_level, "rank-1 add seqno=%d term=%s count=%d",
seqno, term->name,ti->local_occur);
}
/*
- * calc: Called for each document in a result. This handler should
+ * calc: Called for each document in a result. This handler should
* produce a score based on previous call(s) to the add handler. The
* score should be between 0 and 1000. If score cannot be obtained
* -1 should be returned.
int i, lo, divisor, score = 0;
struct rank_set_info *si = (struct rank_set_info *) set_handle;
- if (!si->no_rank_entries)
+ if (!si->no_rank_entries)
return -1; /* ranking not enabled for any terms */
for (i = 0; i < si->no_entries; i++)
add,
};
struct rank_control *rank_1_class = &rank_1_control;
-
+
static struct rank_control rank_2_control = {
"rank-2",
create,
calc_2,
add,
};
-
+
struct rank_control *rank_2_class = &rank_2_control;
/*
* Local variables:
static void ranksimilar_rec_reset(struct ranksimilarity_set_info *si)
{
int i;
-
+
for (i = 0; i < si->no_terms_query; i++)
{
si->entries[i].freq_term_docfield = 0;
/*
- * create: Creates/Initialises this rank handler. This routine is
+ * create: Creates/Initialises this rank handler. This routine is
* called exactly once. The routine returns the class_handle.
*/
static void *create (ZebraHandle zh)
{
- struct ranksimilarity_class_info *ci =
+ struct ranksimilarity_class_info *ci =
(struct ranksimilarity_class_info *) xmalloc (sizeof(*ci));
if (!log_initialized)
*/
static void destroy (struct zebra_register *reg, void *class_handle)
{
- struct ranksimilarity_class_info *ci
+ struct ranksimilarity_class_info *ci
= (struct ranksimilarity_class_info *) class_handle;
yaz_log(log_level, "destroy()");
xfree (ci);
* each result set. The returned handle is a "set handle" and
* will be used in each of the handlers below.
*/
-static void *begin (struct zebra_register *reg,
+static void *begin (struct zebra_register *reg,
void *class_handle, RSET rset, NMEM nmem,
TERMID *terms, int numterms)
{
- struct ranksimilarity_set_info *si =
+ struct ranksimilarity_set_info *si =
(struct ranksimilarity_set_info *) nmem_malloc (nmem, sizeof(*si));
int i;
-
+
yaz_log(log_level, "begin() numterms=%d", numterms);
-
+
/* setting database global statistics */
si->no_docs_database = -1; /* TODO */
si->no_terms_database = -1; /* TODO */
/* setting internal data structures */
si->nmem=nmem;
si->entries = (struct ranksimilarity_term_info *)
- nmem_malloc (si->nmem, sizeof(*si->entries)*numterms);
+ nmem_malloc (si->nmem, sizeof(*si->entries)*numterms);
/* reset the counts for the next term */
ranksimilar_rec_reset(si);
/* adding to number of rank entries */
- if (strncmp (terms[i]->flags, "rank,", 5))
+ if (strncmp (terms[i]->flags, "rank,", 5))
{
si->entries[i].rank_flag = 0;
- yaz_log(log_level, "begin() terms[%d]: '%s' flags=%s not ranked",
+ yaz_log(log_level, "begin() terms[%d]: '%s' flags=%s not ranked",
i, terms[i]->name, terms[i]->flags);
- }
- else
+ }
+ else
{
const char *cp = strstr(terms[i]->flags+4, ",w=");
zint no_docs_fieldindex = 0;
zint no_terms_fieldindex = 0;
-
- yaz_log(log_level, "begin() terms[%d]: '%s' flags=%s",
+
+ yaz_log(log_level, "begin() terms[%d]: '%s' flags=%s",
i, terms[i]->name, terms[i]->flags);
(si->no_ranked_terms_query)++;
ol = terms[i]->ol;
si->entries[i].rank_flag = 1;
- /* notice that the call to rset_count(rset) has he side-effect
+ /* notice that the call to rset_count(rset) has he side-effect
of setting rset->hits_limit = rset_count(rset) ??? */
si->entries[i].freq_term_resset = rset_count(terms[i]->rset);
si->entries[i].no_docs_resset = terms[i]->rset->hits_count;
/*
- yaz_log(log_level, "begin() rset_count(terms[%d]->rset) = "
- ZINT_FORMAT, i, rset_count(terms[i]->rset));
+ yaz_log(log_level, "begin() rset_count(terms[%d]->rset) = "
+ ZINT_FORMAT, i, rset_count(terms[i]->rset));
yaz_log(log_level, "begin() terms[%d]->rset->hits_limit = "
- ZINT_FORMAT, i, terms[i]->rset->hits_limit);
+ ZINT_FORMAT, i, terms[i]->rset->hits_limit);
yaz_log(log_level, "begin() terms[%d]->rset->hits_count = "
- ZINT_FORMAT, i, terms[i]->rset->hits_count);
+ ZINT_FORMAT, i, terms[i]->rset->hits_count);
yaz_log(log_level, "begin() terms[%d]->rset->hits_round = "
- ZINT_FORMAT, i, terms[i]->rset->hits_round);
- yaz_log(log_level, "begin() terms[%d]->rset->hits_approx = %d",
+ ZINT_FORMAT, i, terms[i]->rset->hits_round);
+ yaz_log(log_level, "begin() terms[%d]->rset->hits_approx = %d",
i, terms[i]->rset->hits_approx);
*/
-
+
/* looping indexes where term terms[i] is found */
-
+
for (; ol; ol = ol->next)
{
const char *index_type = 0;
zebraExplain_lookup_ord(reg->zei,
ol->ord, &index_type, &db,
&string_index);
-
- no_docs_fieldindex
+
+ no_docs_fieldindex
+= zebraExplain_ord_get_doc_occurrences(reg->zei, ol->ord);
- no_terms_fieldindex
+ no_terms_fieldindex
+= zebraExplain_ord_get_term_occurrences(reg->zei, ol->ord);
if (string_index)
- yaz_log(log_level,
+ yaz_log(log_level,
"begin() index: ord=%d type=%s db=%s str-index=%s",
ol->ord, index_type, db, string_index);
else
- yaz_log(log_level,
+ yaz_log(log_level,
"begin() index: ord=%d type=%s db=%s",
ol->ord, index_type, db);
}
-
+
si->entries[i].no_docs_fieldindex = no_docs_fieldindex;
si->entries[i].no_terms_fieldindex = no_terms_fieldindex;
}
-
+
si->entries[i].term = terms[i];
si->entries[i].term_index=i;
-
+
/* setting next entry in term */
terms[i]->rankpriv = &(si->entries[i]);
}
-
+
return si;
}
*/
static void add (void *set_handle, int seqno, TERMID term)
{
- struct ranksimilarity_set_info *si
+ struct ranksimilarity_set_info *si
= (struct ranksimilarity_set_info *) set_handle;
- struct ranksimilarity_term_info *ti;
+ struct ranksimilarity_term_info *ti;
assert(si);
if (!term)
{
assert(ti);
si->last_pos = seqno;
ti->freq_term_docfield++;
- /*yaz_log(log_level, "add() seqno=%d term=%s freq_term_docfield=%d",
+ /*yaz_log(log_level, "add() seqno=%d term=%s freq_term_docfield=%d",
seqno, term->name, ti->freq_term_docfield); */
}
/*
- * calc: Called for each document in a result. This handler should
+ * calc: Called for each document in a result. This handler should
* produce a score based on previous call(s) to the add handler. The
* score should be between 0 and 1000. If score cannot be obtained
* -1 should be returned.
int *stop_flag)
{
int i, score = 0;
- struct ranksimilarity_set_info *si
+ struct ranksimilarity_set_info *si
= (struct ranksimilarity_set_info *) set_handle;
-
-
+
+
yaz_log(log_level, "calc() sysno = " ZINT_FORMAT, sysno);
yaz_log(log_level, "calc() staticrank = " ZINT_FORMAT, staticrank);
-
- yaz_log(log_level, "calc() si->no_terms_query = %d",
+
+ yaz_log(log_level, "calc() si->no_terms_query = %d",
si->no_terms_query);
- yaz_log(log_level, "calc() si->no_ranked_terms_query = %d",
+ yaz_log(log_level, "calc() si->no_ranked_terms_query = %d",
si->no_ranked_terms_query);
- yaz_log(log_level, "calc() si->no_docs_database = " ZINT_FORMAT,
- si->no_docs_database);
- yaz_log(log_level, "calc() si->no_terms_database = " ZINT_FORMAT,
- si->no_terms_database);
+ yaz_log(log_level, "calc() si->no_docs_database = " ZINT_FORMAT,
+ si->no_docs_database);
+ yaz_log(log_level, "calc() si->no_terms_database = " ZINT_FORMAT,
+ si->no_terms_database);
+
-
if (!si->no_ranked_terms_query)
return -1; /* ranking not enabled for any terms */
-
+
/* if we set *stop_flag = 1, we stop processing (of result set list) */
/* you may use all the gathered statistics here */
for (i = 0; i < si->no_terms_query; i++)
{
- yaz_log(log_level, "calc() entries[%d] termid %p",
+ yaz_log(log_level, "calc() entries[%d] termid %p",
i, si->entries[i].term);
if (si->entries[i].term){
- yaz_log(log_level, "calc() entries[%d] term '%s' flags=%s",
+ yaz_log(log_level, "calc() entries[%d] term '%s' flags=%s",
i, si->entries[i].term->name, si->entries[i].term->flags);
- yaz_log(log_level, "calc() entries[%d] rank_flag %d",
+ yaz_log(log_level, "calc() entries[%d] rank_flag %d",
i, si->entries[i].rank_flag );
- yaz_log(log_level, "calc() entries[%d] fieldindex_weight %d",
+ yaz_log(log_level, "calc() entries[%d] fieldindex_weight %d",
i, si->entries[i].fieldindex_weight );
- yaz_log(log_level, "calc() entries[%d] freq_term_docfield %d",
+ yaz_log(log_level, "calc() entries[%d] freq_term_docfield %d",
i, si->entries[i].freq_term_docfield );
yaz_log(log_level, "calc() entries[%d] freq_term_resset " ZINT_FORMAT,
i, si->entries[i].freq_term_resset );
- yaz_log(log_level, "calc() entries[%d] no_docs_resset " ZINT_FORMAT,
+ yaz_log(log_level, "calc() entries[%d] no_docs_resset " ZINT_FORMAT,
i, si->entries[i].no_docs_resset );
- yaz_log(log_level, "calc() entries[%d] no_docs_fieldindex "
- ZINT_FORMAT,
+ yaz_log(log_level, "calc() entries[%d] no_docs_fieldindex "
+ ZINT_FORMAT,
i, si->entries[i].no_docs_fieldindex );
- yaz_log(log_level, "calc() entries[%d] no_terms_fieldindex "
- ZINT_FORMAT,
+ yaz_log(log_level, "calc() entries[%d] no_terms_fieldindex "
+ ZINT_FORMAT,
i, si->entries[i].no_terms_fieldindex );
}
}
-
+
/* reset the counts for the next term */
ranksimilar_rec_reset(si);
-
+
/* staticrank = 0 is highest, MAXINT lowest */
if (staticrank >= INT_MAX)
/* debugging statistics output */
- yaz_log(log_level, "calc() statistics: score = %d", score);
+ yaz_log(log_level, "calc() statistics: score = %d", score);
return score;
}
calc,
add,
};
-
+
struct rank_control *rank_similarity_class = &rank_control;
/*
* Local variables:
};
/*
- * create: Creates/Initialises this rank handler. This routine is
+ * create: Creates/Initialises this rank handler. This routine is
* called exactly once. The routine returns the class_handle.
*/
static void *create (ZebraHandle zh)
* each result set. The returned handle is a "set handle" and
* will be used in each of the handlers below.
*/
-static void *begin (struct zebra_register *reg,
+static void *begin (struct zebra_register *reg,
void *class_handle, RSET rset, NMEM nmem,
TERMID *terms, int numterms)
{
- struct rank_set_info *si =
+ struct rank_set_info *si =
(struct rank_set_info *) nmem_malloc (nmem, sizeof(*si));
int i;
{
struct ord_list *ol = terms[i]->ol;
- yaz_log(log_level, "i=%d flags=%s '%s'", i,
+ yaz_log(log_level, "i=%d flags=%s '%s'", i,
terms[i]->flags, terms[i]->name );
for (; ol; ol = ol->next)
yaz_log(log_level, " ord=%d index_type=%s db=%s set=%d use=%d",
ol->ord, index_type, db, set, use);
}
- if (!strncmp (terms[i]->flags, "rank,", 5))
+ if (!strncmp (terms[i]->flags, "rank,", 5))
(si->no_rank_entries)++;
}
return si;
}
/*
- * calc: Called for each document in a result. This handler should
+ * calc: Called for each document in a result. This handler should
* produce a score based on previous call(s) to the add handler. The
* score should be between 0 and 1000. If score cannot be obtained
* -1 should be returned.
calc,
add,
};
-
+
struct rank_control *rank_static_class = &rank_control;
/*
* Local variables:
if (dir)
{
struct dirent *de;
-
+
while ((de = readdir(dir)))
{
size_t dlen = strlen(de->d_name);
const char *err = dlerror();
yaz_log(YLOG_WARN, "dlopen failed %s %s",
fname, err ? err : "none");
-
+
}
}
}
const char *comp_ptr;
char comp[FILENAME_MAX+1];
size_t len;
-
+
len = yaz_filepath_comp(&module_path, &comp_ptr);
if (!len || len >= FILENAME_MAX)
break;
-
+
memcpy(comp, comp_ptr, len);
comp[len] = '\0';
{
struct recTypeClass *r = (struct recTypeClass *)
nmem_malloc (nmem, sizeof(*r));
-
+
r->next = *rts;
*rts = r;
RecTypes rts = (RecTypes) nmem_malloc(data1_nmem_get(dh), sizeof(*rts));
struct recTypeInstance **rti = &rts->entries;
-
+
rts->dh = dh;
for (; rtc; rtc = rtc->next)
{
int start, len;
RecWord tmp_w;
-
+
/* ( */
sp_lex(sp);
if (sp->lookahead != '(')
return 0;
sp_lex(sp); /* skip ( */
-
+
/* 1st arg: string */
if (!sp_expr(sp, n, wrd))
return 0;
-
+
if (sp->lookahead != ',')
- return 0;
+ return 0;
sp_lex(sp); /* skip , */
-
+
/* 2nd arg: start */
if (!sp_expr(sp, n, &tmp_w))
return 0;
start = atoi_n(tmp_w.term_buf, tmp_w.term_len);
-
+
if (sp->lookahead == ',')
{
sp_lex(sp); /* skip , */
-
+
/* 3rd arg: length */
if (!sp_expr(sp, n, &tmp_w))
return 0;
}
else
len = wrd->term_len;
-
+
/* ) */
if (sp->lookahead != ')')
- return 0;
+ return 0;
sp_lex(sp);
-
+
if (wrd->term_buf)
{
if (start >= wrd->term_len)
RecWord search_w;
int i;
sp_lex(sp); /* skip , */
-
+
if (!sp_expr(sp, n, &search_w))
return 0;
for (i = 0; i<wrd->term_len; i++)
else if (sp->len == 3 && !memcmp(sp->tok, "tag", sp->len))
{
if (n->which == DATA1N_tag)
- {
+ {
wrd->term_buf = n->u.tag.tag;
wrd->term_len = strlen(n->u.tag.tag);
}
if (!sp_expr(sp, n, &tmp_w))
return 0;
-
+
wrd->term_buf = "";
wrd->term_len = 0;
if (n->which == DATA1N_tag)
{
data1_xattr *p = n->u.tag.attributes;
- while (p && strlen(p->name) != tmp_w.term_len &&
+ while (p && strlen(p->name) != tmp_w.term_len &&
memcmp (p->name, tmp_w.term_buf, tmp_w.term_len))
p = p->next;
if (p)
wrd->term_buf = b;
sp_lex(sp);
}
- else
+ else
{
wrd->term_buf = "";
wrd->term_len = 0;
nmem_destroy(sp->nmem);
xfree(sp);
}
-
-static int sp_parse(struct source_parser *sp,
+
+static int sp_parse(struct source_parser *sp,
data1_node *n, RecWord *wrd, const char *src)
{
sp->len = 0;
int res = 1;
char *attname;
data1_xattr *attr;
-
+
if (!p) {
return 1;
} else {
if (p->which == XPATH_PREDICATE_RELATION) {
if (p->u.relation.name[0]) {
if (*p->u.relation.name != '@') {
- yaz_log(YLOG_WARN,
+ yaz_log(YLOG_WARN,
" Only attributes (@) are supported in xelm xpath predicates");
yaz_log(YLOG_WARN, "predicate %s ignored", p->u.relation.name);
return 1;
if (!strcmp(attr->name, attname)) {
if (p->u.relation.op[0]) {
if (*p->u.relation.op != '=') {
- yaz_log(YLOG_WARN,
+ yaz_log(YLOG_WARN,
"Only '=' relation is supported (%s)",p->u.relation.op);
yaz_log(YLOG_WARN, "predicate %s ignored", p->u.relation.name);
res = 1; break;
} else {
if (!strcmp(attr->value, p->u.relation.value)) {
res = 1; break;
- }
+ }
}
} else {
/* attribute exists, no value specified */
} else {
return 1;
}
- }
+ }
else if (p->which == XPATH_PREDICATE_BOOLEAN) {
if (!strcmp(p->u.boolean.op,"and")) {
- return d1_check_xpath_predicate(n, p->u.boolean.left)
- && d1_check_xpath_predicate(n, p->u.boolean.right);
+ return d1_check_xpath_predicate(n, p->u.boolean.left)
+ && d1_check_xpath_predicate(n, p->u.boolean.right);
}
else if (!strcmp(p->u.boolean.op,"or")) {
- return (d1_check_xpath_predicate(n, p->u.boolean.left)
- || d1_check_xpath_predicate(n, p->u.boolean.right));
+ return (d1_check_xpath_predicate(n, p->u.boolean.left)
+ || d1_check_xpath_predicate(n, p->u.boolean.right));
} else {
yaz_log(YLOG_WARN, "Unknown boolean relation %s, ignored",p->u.boolean.op);
return 1;
int i;
const char *p = text;
unsigned char c;
-
+
for (c = *p++, t = s->trans, i = s->tran_no; --i >= 0; t++)
{
if (c >= t->ch[0] && c <= t->ch[1])
}
/* *ostrich*
-
+
New function, looking for xpath "element" definitions in abs, by
tagpath, using a kind of ugly regxp search.The DFA was built while
parsing abs, so here we just go trough them and try to match
data1_xpelement *xpe = 0;
data1_node *nn;
-#ifdef ENHANCED_XELM
+#ifdef ENHANCED_XELM
struct xpath_location_step *xp;
#endif
char *pexpr = xmalloc(strlen(tagpath)+5);
-
+
sprintf(pexpr, "/%s\n", tagpath);
for (xpe = abs->xp_elements; xpe; xpe = xpe->next)
}
assert(ok == 0 || ok == 1);
if (ok) {
-#ifdef ENHANCED_XELM
+#ifdef ENHANCED_XELM
/* we have to check the perdicates up to the root node */
xp = xpe->xpath;
-
+
/* find the first tag up in the node structure */
for (nn = n; nn && nn->which != DATA1N_tag; nn = nn->parent)
;
-
+
/* go from inside out in the node structure, while going
backwards trough xpath location steps ... */
for (i = xpe->xpath_len - 1; i>0; i--)
ok = 0;
break;
}
-
+
if (nn->which == DATA1N_tag)
nn = nn->parent;
}
if (ok)
break;
}
- }
-
+ }
+
xfree(pexpr);
-
+
if (xpe) {
return xpe->termlists;
} else {
*ostrich*
Now, if there is a matching xelm described in abs, for the
- indexed element or the attribute, then the data is handled according
+ indexed element or the attribute, then the data is handled according
to those definitions...
modified by pop, 2002-12-13
wrd->term_buf = tag_path;
wrd->term_len = strlen(tag_path);
(*p->tokenAdd)(wrd);
-
+
if (value) {
wrd->index_name = ZEBRA_XPATH_ATTR_CDATA;
wrd->index_type = "w";
}
tag_path_full[flen] = 0;
}
-
+
static void index_xpath(struct source_parser *sp, data1_node *n,
struct recExtractCtrl *p,
int termlist_only = 1;
data1_termlist *tl;
- if (!n->root->u.root.absyn
- ||
+ if (!n->root->u.root.absyn
+ ||
n->root->u.root.absyn->xpath_indexing == DATA1_XPATH_INDEXING_ENABLE)
{
termlist_only = 0;
wrd->term_len = n->u.data.len;
mk_tag_path_full(tag_path_full, sizeof(tag_path_full), n);
-
+
/* If we have a matching termlist... */
- if (n->root->u.root.absyn &&
+ if (n->root->u.root.absyn &&
(tl = xpath_termlist_by_tagpath(tag_path_full, n)))
{
zint max_seqno = 0;
}
if (max_seqno)
wrd->seqno = max_seqno;
-
+
}
- /* xpath indexing is done, if there was no termlist given,
+ /* xpath indexing is done, if there was no termlist given,
or no ! in the termlist, and default indexing is enabled... */
if (!p->flagShowRecords && !termlist_only)
{
if (!termlist_only)
(*p->tokenAdd)(wrd); /* index element pag (AKA tag path) */
-
+
if (xpath_is_start == 1) /* only for the starting tag... */
{
#define MAX_ATTR_COUNT 50
data1_termlist *tll[MAX_ATTR_COUNT];
-
+
int i = 0;
for (xp = n->u.tag.attributes; xp; xp = xp->next) {
char comb[512];
- char attr_tag_path_full[1024];
-
+ char attr_tag_path_full[1024];
+
/* this could be cached as well */
sprintf(attr_tag_path_full, "@%s/%s",
xp->name, tag_path_full);
tll[i] = xpath_termlist_by_tagpath(attr_tag_path_full,n);
-
+
if (!termlist_only)
{
/* attribute (no value) */
wrd->index_name = ZEBRA_XPATH_ATTR_NAME;
wrd->term_buf = xp->name;
wrd->term_len = strlen(xp->name);
-
+
wrd->seqno--;
(*p->tokenAdd)(wrd);
-
- if (xp->value
+
+ if (xp->value
&&
strlen(xp->name) + strlen(xp->value) < sizeof(comb)-2)
{
strcpy(comb, xp->name);
strcat(comb, "=");
strcat(comb, xp->value);
-
+
wrd->index_name = ZEBRA_XPATH_ATTR_NAME;
wrd->index_type = "0";
wrd->term_buf = comb;
wrd->term_len = strlen(comb);
wrd->seqno--;
-
+
(*p->tokenAdd)(wrd);
}
- }
+ }
i++;
}
-
+
i = 0;
for (xp = n->u.tag.attributes; xp; xp = xp->next) {
data1_termlist *tl;
char attr_tag_path_full[1024];
int xpdone = 0;
-
+
sprintf(attr_tag_path_full, "@%s/%s",
xp->name, tag_path_full);
if ((tl = tll[i]))
xpdone = 1;
} else {
/* index attribute value (only path/@attr) */
- if (xp->value)
+ if (xp->value)
{
wrd->index_name = tl->index_name;
wrd->index_type = tl->structure;
}
}
}
- /* if there was no termlist for the given path,
- or the termlist didn't have a ! element, index
+ /* if there was no termlist for the given path,
+ or the termlist didn't have a ! element, index
the attribute as "w" */
if (!xpdone && !termlist_only)
{
* this has the effect of indexing locally defined tags with
* the attribute of their ancestor in the record.
*/
-
+
while (!par->u.tag.element)
if (!par->parent || !(par=get_parent_tag(p->dh, par->parent)))
break;
index_termlist(sp, n, n, p, level, wrd);
/* index start tag */
if (n->root->u.root.absyn)
- index_xpath(sp, n, p, level, wrd, ZEBRA_XPATH_ELM_BEGIN,
+ index_xpath(sp, n, p, level, wrd, ZEBRA_XPATH_ELM_BEGIN,
1 /* is start */);
}
if (par)
index_termlist(sp, par, n, p, level, wrd);
- index_xpath(sp, n, p, level, wrd, ZEBRA_XPATH_CDATA,
+ index_xpath(sp, n, p, level, wrd, ZEBRA_XPATH_CDATA,
0 /* is start */);
}
if (n->which == DATA1N_tag)
{
/* index end tag */
- index_xpath(sp, n, p, level, wrd, ZEBRA_XPATH_ELM_END,
+ index_xpath(sp, n, p, level, wrd, ZEBRA_XPATH_ELM_END,
0 /* is start */);
}
(*p->schemaAdd)(p, n->u.root.absyn->oid);
(*p->init)(p, &wrd);
- /* data1_pr_tree(p->dh, n, stdout); */
+ /* data1_pr_tree(p->dh, n, stdout); */
return dumpkeys(n, p, &wrd);
}
}
/* Add Zebra info in separate namespace ...
- <root
+ <root
...
<metadata xmlns="http://www.indexdata.dk/zebra/">
<size>359</size>
data1_mk_text(p->dh, mem, "\n", top);
data1_mk_text(p->dh, mem, i4, n);
-
+
data1_mk_tag_data_int(p->dh, n, "size", p->recordSize, mem);
if (p->score != -1)
const Odr_oid *requested_schema = 0;
data1_marctab *marctab;
int dummy;
-
+
mem = nmem_create();
gri.stream = p->stream;
gri.mem = mem;
sprintf(dnew->u.data.data, "%d", p->recordSize);
dnew->u.data.len = strlen(dnew->u.data.data);
}
-
+
tagname = data1_systag_lookup(node->u.root.absyn, "rank", "rank");
if (tagname && p->score >= 0 &&
(dnew = data1_mk_tag_data_wd(p->dh, top, tagname, mem)))
yaz_log(YLOG_DEBUG, "grs_retrieve: %s", tagname);
dnew->u.data.what = DATA1I_text;
dnew->u.data.data = dnew->lbuf;
-
+
sprintf(dnew->u.data.data, ZINT_FORMAT, p->localno);
dnew->u.data.len = strlen(dnew->u.data.data);
}
requested_schema = p->comp->u.complex->generic->schema.oid;
}
/* If schema has been specified, map if possible, then check that
- * we got the right one
+ * we got the right one
*/
if (requested_schema)
{
break;
}
}
- if (node->u.root.absyn
+ if (node->u.root.absyn
&& oid_oidcmp(requested_schema, node->u.root.absyn->oid))
{
p->diagnostic = YAZ_BIB1_RECORD_NOT_AVAILABLE_IN_REQUESTED_SYNTAX;
}
}
yaz_log(YLOG_DEBUG, "grs_retrieve: schemaIdentifier");
- if (node->u.root.absyn && node->u.root.absyn->oid
+ if (node->u.root.absyn && node->u.root.absyn->oid
&& !oid_oidcmp(p->input_format, yaz_oid_recsyn_grs_1))
{
char oid_str[OID_STR_MAX];
char *dot_str = oid_oid_to_dotstring(node->u.root.absyn->oid, oid_str);
-
- if (dot_str && (dnew = data1_mk_tag_data_wd(p->dh, top,
+
+ if (dot_str && (dnew = data1_mk_tag_data_wd(p->dh, top,
"schemaIdentifier", mem)))
{
dnew->u.data.what = DATA1I_oid;
{
/* ensure our data1 tree is UTF-8 */
data1_iconv(p->dh, mem, node, "UTF-8", data1_get_encoding(p->dh, node));
-
+
if (!(p->rec_buf = data1_nodetoexplain(p->dh, node, selected,
p->odr)))
p->diagnostic = YAZ_BIB1_RECORD_NOT_AVAILABLE_IN_REQUESTED_SYNTAX;
memcpy(&ent, (const char *)b + sizeof(sys) + 1, len);
yaz_log(YLOG_LOG, "%s " ZINT_FORMAT " next=" ZINT_FORMAT " sz=%d", txt, sys,
ent.next, ent.size);
-
+
}
else
yaz_log(YLOG_LOG, "%s " ZINT_FORMAT, txt, sys);
recindex_t p = xmalloc(sizeof(*p));
p->index_BFile = 0;
p->isamb = 0;
-
+
p->index_fname = "reci";
p->index_BFile = bf_open(bfs, p->index_fname, RIDX_CHUNK, rw);
if (p->index_BFile == NULL)
xfree(p);
return 0;
}
-
+
if (use_isamb)
{
int isam_block_size = 4096;
assert(p);
assert(p->index_BFile);
-
+
r = bf_write(p->index_BFile, 0, 0, len, buf);
if (r)
{
return ZEBRA_OK;
}
-int recindex_read_indx(recindex_t p, zint sysno, void *buf, int itemsize,
+int recindex_read_indx(recindex_t p, zint sysno, void *buf, int itemsize,
int ignoreError)
{
int r = 0;
char item[256];
char *st = item;
char untilbuf[sizeof(zint) + 1];
-
+
ISAMB_PP isam_pp = isamb_pp_open(p->isamb, p->isam_p, 1);
-
+
memcpy(untilbuf, &sysno, sizeof(sysno));
untilbuf[sizeof(sysno)] = 0;
r = isamb_pp_forward(isam_pp, st, untilbuf);
-
+
isamb_pp_close(isam_pp);
if (!r)
return 0;
-
+
if (item[sizeof(sysno)] != itemsize)
{
yaz_log(YLOG_WARN, "unexpected entry size %d != %d",
zint pos = (sysno-1)*itemsize;
int off = CAST_ZINT_TO_INT(pos%RIDX_CHUNK);
int sz1 = RIDX_CHUNK - off; /* sz1 is size of buffer to read.. */
-
+
if (sz1 > itemsize)
sz1 = itemsize; /* no more than itemsize bytes */
-
+
r = bf_read(p->index_BFile, 1+pos/RIDX_CHUNK, off, sz1, buf);
if (r == 1 && sz1 < itemsize) /* boundary? - must read second part */
r = bf_read(p->index_BFile, 2+pos/RIDX_CHUNK, 0, itemsize - sz1,
#if 0
{
struct record_index_entry *ep = buf;
- yaz_log(YLOG_LOG, "read r=%d sysno=" ZINT_FORMAT " next=" ZINT_FORMAT
+ yaz_log(YLOG_LOG, "read r=%d sysno=" ZINT_FORMAT " next=" ZINT_FORMAT
" sz=%d", r, sysno, ep->next, ep->size);
}
#endif
int bt_code_read(void *vp, char **dst, int *insertMode)
{
struct code_read_data *s = (struct code_read_data *) vp;
-
+
if (s->no == 0)
return 0;
(s->no)--;
-
+
memcpy(*dst, &s->sysno, sizeof(zint));
*dst += sizeof(zint);
**dst = s->itemsize;
zint pos = (sysno-1)*itemsize;
int off = CAST_ZINT_TO_INT(pos%RIDX_CHUNK);
int sz1 = RIDX_CHUNK - off; /* sz1 is size of buffer to read.. */
-
+
if (sz1 > itemsize)
sz1 = itemsize; /* no more than itemsize bytes */
-
+
bf_write(p->index_BFile, 1+pos/RIDX_CHUNK, off, sz1, buf);
if (sz1 < itemsize) /* boundary? must write second part */
bf_write(p->index_BFile, 2+pos/RIDX_CHUNK, 0, itemsize - sz1,
/** \brief opens records system
\param bfs block file storage
\param rw read-write flag(0=read only, 1=write)
- \param compression_method REC_COMPRESS_ type
+ \param compression_method REC_COMPRESS_ type
*/
Records rec_open(BFiles bfs, int rw, int compression_method);
#define REC_COMPRESS_ZLIB 2
-enum {
- recInfo_fileType,
- recInfo_filename,
- recInfo_delKeys,
+enum {
+ recInfo_fileType,
+ recInfo_filename,
+ recInfo_delKeys,
recInfo_databaseName,
recInfo_storeData,
recInfo_attr,
int recindex_read_head(recindex_t p, void *buf);
const char *recindex_get_fname(recindex_t p);
ZEBRA_RES recindex_write_head(recindex_t p, const void *buf, size_t len);
-int recindex_read_indx(recindex_t p, zint sysno, void *buf, int itemsize,
+int recindex_read_indx(recindex_t p, zint sysno, void *buf, int itemsize,
int ignoreError);
void recindex_write_indx(recindex_t p, zint sysno, void *buf, int itemsize);
p->buf = 0;
p->owner_of_buffer = 1;
p->encode_handle = iscz1_start();
- p->decode_handle = iscz1_start();
+ p->decode_handle = iscz1_start();
p->custom_record_id = 0;
p->nmem = nmem_create();
}
p->owner_of_buffer = copy_buf;
}
-
+
void zebra_rec_keys_get_buf(zebra_rec_keys_t p, char **buf, size_t *sz)
{
*buf = p->buf;
{
if (!p)
return;
-
+
if (p->owner_of_buffer)
xfree(p->buf);
if (p->encode_handle)
xfree(p);
}
-int zebra_rec_keys_add_hash(zebra_rec_keys_t keys,
+int zebra_rec_keys_add_hash(zebra_rec_keys_t keys,
const char *str, size_t slen,
const struct it_key *key)
{
return 1;
}
-void zebra_rec_keys_write(zebra_rec_keys_t keys,
+void zebra_rec_keys_write(zebra_rec_keys_t keys,
const char *str, size_t slen,
const struct it_key *key)
{
char *dst;
const char *src = (char*) key;
-
+
assert(keys->owner_of_buffer);
if (key->mem[1]) /* record_id custom */
{
assert(keys);
keys->buf_used = 0;
-
+
iscz1_reset(keys->encode_handle);
init_hash(keys);
{
const char *src = keys->buf + keys->fetch_offset;
char *dst = (char*) key;
-
+
assert (keys->fetch_offset < keys->buf_used);
/* store the destination key */
iscz1_decode(keys->decode_handle, &dst, &src);
-
+
/* store pointer to string and length of it */
*str = src;
*slen = strlen(src);
src += *slen + 1;
-
+
keys->fetch_offset = src - keys->buf;
}
return 1;
void zebra_rec_keys_close(zebra_rec_keys_t p);
-void zebra_rec_keys_write(zebra_rec_keys_t keys,
+void zebra_rec_keys_write(zebra_rec_keys_t keys,
const char *str, size_t slen,
const struct it_key *key);
void zebra_rec_keys_reset(zebra_rec_keys_t keys);
* ref_count (2 bytes)
* block (500 bytes)
*
- * Format of subsequent blocks
+ * Format of subsequent blocks
* next (8 bytes)
* block (502 bytes)
*
/* the list of blocks can all be removed (ref == 0) */
first = 0;
}
-
+
if (bf_write(p->data_BFile[dst_type], freeblock, 0, sizeof(freeblock),
&p->head.block_free[dst_type]))
{
cptr = p->tmp_buf + no_written;
}
block_prev = block_free;
- no_written += CAST_ZINT_TO_INT(p->head.block_size[dst_type])
+ no_written += CAST_ZINT_TO_INT(p->head.block_size[dst_type])
- sizeof(zint);
p->head.block_used[dst_type]++;
}
}
if (rw)
{
- if (recindex_write_head(p->recindex,
+ if (recindex_write_head(p->recindex,
&p->head, sizeof(p->head)) != ZEBRA_OK)
ret = ZEBRA_FAIL;
}
}
if (i == 0)
{
- rec_encode_zint(rec_sysno_to_int(rec->sysno),
+ rec_encode_zint(rec_sysno_to_int(rec->sysno),
(unsigned char *) *out_buf + *out_offset, &len);
(*out_offset) += len;
}
#endif
break;
case REC_COMPRESS_BZIP2:
-#if HAVE_BZLIB_H
+#if HAVE_BZLIB_H
csize = out_offset + (out_offset >> 6) + 620;
rec_tmp_expand(p, csize);
#ifdef BZ_CONFIG_ERROR
- i = BZ2_bzBuffToBuffCompress
+ i = BZ2_bzBuffToBuffCompress
#else
- i = bzBuffToBuffCompress
+ i = bzBuffToBuffCompress
#endif
(p->tmp_buf+sizeof(zint)+sizeof(short)+
sizeof(char),
case REC_COMPRESS_NONE:
break;
}
- if (!csize)
+ if (!csize)
{
/* either no compression or compression not supported ... */
csize = out_offset;
memcpy(p->tmp_buf + sizeof(zint), &ref_count, sizeof(ref_count));
memcpy(p->tmp_buf + sizeof(zint)+sizeof(short),
&compression_method, sizeof(compression_method));
-
+
/* -------- compression */
if (rec_write_tmp_buf(p, csize + sizeof(short) + sizeof(char), sysnos)
!= ZEBRA_OK)
{
struct record_cache_entry *e = p->record_cache + i;
rec_free(&e->rec);
- }
+ }
/* i still being used ... */
for (j = 0; j<saveCount; j++, i++)
memcpy(p->record_cache+j, p->record_cache+i,
freeblock = entry.next / 8;
assert(freeblock > 0);
-
+
rec_tmp_expand(p, entry.size);
cptr = p->tmp_buf;
zint tmp;
cptr += p->head.block_size[dst_type] - sizeof(freeblock);
-
+
memcpy(&tmp, cptr, sizeof(tmp));
r = bf_read(p->data_BFile[dst_type], freeblock, 0, 0, cptr);
if (r < 0)
(const Bytef *) in_buf, in_size);
if (i == Z_OK)
{
- bz_size = destLen;
+ bz_size = destLen;
break;
}
yaz_log(YLOG_LOG, "failed");
{
int i;
zint total_bytes = 0;
-
+
yaz_log (YLOG_LOG,
"Total records %8" ZINT_FORMAT0,
records->head.no_records);
NMEM nmem;
};
-static int zebra_create_record_stream(ZebraHandle zh,
+static int zebra_create_record_stream(ZebraHandle zh,
Record *rec,
struct ZebraRecStream *stream)
{
RecordAttr *recordAttr = rec_init_attr(zh->reg->zei, *rec);
- if ((*rec)->size[recInfo_storeData] > 0
+ if ((*rec)->size[recInfo_storeData] > 0
|| (*rec)->info[recInfo_filename] == 0)
zebra_create_stream_mem(stream, (*rec)->info[recInfo_storeData],
(*rec)->size[recInfo_storeData]);
{
char full_rep[1024];
int fd;
-
+
if (zh->path_reg && !yaz_is_abspath((*rec)->info[recInfo_filename])){
strcpy(full_rep, zh->path_reg);
strcat(full_rep, "/");
}
else
strcpy(full_rep, (*rec)->info[recInfo_filename]);
-
+
if ((fd = open(full_rep, O_BINARY|O_RDONLY)) == -1){
yaz_log(YLOG_WARN|YLOG_ERRNO, "Retrieve fail; missing file: %s",
full_rep);
}
return 0;
}
-
+
struct index_spec {
const char *index_name;
{
cp++;
cp0 = cp;
-
+
while (*cp != '\0' && *cp != ',' && *cp != ':')
cp++;
spec->index_type = nmem_strdupn(nmem, cp0, cp - cp0);
{
cp++;
cp0 = cp;
-
+
while (*cp != '\0' && *cp != ',' && *cp != ':')
cp++;
spec->extra = nmem_strdupn(nmem, cp0, cp - cp0);
WRBUF wrbuf_result = result;
int off = 0;
- zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type, &db,
+ zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type, &db,
&string_index);
if (!oid_oidcmp(input_format, yaz_oid_recsyn_xml))
{
}
else
{
- yaz_log(YLOG_WARN, "unsupported format for element set zebra::%s",
+ yaz_log(YLOG_WARN, "unsupported format for element set zebra::%s",
elemsetname);
*output_format = 0;
wrbuf_destroy(wrbuf_str);
assert(off < wrbuf_len(wrbuf_str));
zebra_term_untrans(zh, index_type, dst_buf,
wrbuf_buf(wrbuf_str)+off);
-
+
if (!oid_oidcmp(input_format, yaz_oid_recsyn_xml))
{
- wrbuf_printf(wrbuf_result, " <index name=\"%s\"",
+ wrbuf_printf(wrbuf_result, " <index name=\"%s\"",
string_index);
wrbuf_printf(wrbuf_result, " type=\"%s\">", index_type);
wrbuf_xmlputs(wrbuf_result, dst_buf);
return 0;
}
}
-
+
static int special_index_fetch(
struct special_fetch_s *fi, const char *elemsetname,
const Odr_oid *input_format,
ZebraHandle zh = fi->zh;
struct index_spec *spec, *spec_list;
int error;
-
+
/* set output variables before processing possible error states */
/* *rec_lenp = 0; */
if (oid_oidcmp(input_format, yaz_oid_recsyn_xml)
&& oid_oidcmp(input_format, yaz_oid_recsyn_sutrs))
{
- yaz_log(YLOG_WARN, "unsupported format for element set zebra::%s",
+ yaz_log(YLOG_WARN, "unsupported format for element set zebra::%s",
elemsetname);
*output_format = 0;
return YAZ_BIB1_NO_SYNTAXES_AVAILABLE_FOR_THIS_REQUEST;
const char *string_index = 0;
char dst_buf[IT_MAX_WORD];
int match = 0;
-
+
zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type, &db,
&string_index);
if (!spec_list)
{
if (zebra_term_untrans(zh, index_type, dst_buf, str))
*dst_buf = '\0'; /* untrans failed */
-
+
if (!oid_oidcmp(input_format, yaz_oid_recsyn_xml))
{
- wrbuf_printf(wrbuf, " <index name=\"%s\"",
+ wrbuf_printf(wrbuf, " <index name=\"%s\"",
string_index);
-
+
wrbuf_printf(wrbuf, " type=\"%s\"", index_type);
-
- wrbuf_printf(wrbuf, " seq=\"" ZINT_FORMAT "\">",
+
+ wrbuf_printf(wrbuf, " seq=\"" ZINT_FORMAT "\">",
key_in.mem[key_in.len -1]);
wrbuf_xmlputs(wrbuf, dst_buf);
wrbuf_printf(wrbuf, "</index>\n");
}
- else
+ else
{
wrbuf_printf(wrbuf, "%s ", string_index);
-
+
wrbuf_printf(wrbuf, "%s", index_type);
-
+
for (i = 1; i < key_in.len; i++)
- wrbuf_printf(wrbuf, " " ZINT_FORMAT,
+ wrbuf_printf(wrbuf, " " ZINT_FORMAT,
key_in.mem[i]);
-
+
wrbuf_printf(wrbuf, " %s", dst_buf);
-
+
wrbuf_printf(wrbuf, "\n");
}
}
const char *index_type;
const char *db = 0;
const char *string_index = 0;
-
- zebraExplain_lookup_ord(zh->reg->zei, w->ord,
+
+ zebraExplain_lookup_ord(zh->reg->zei, w->ord,
&index_type, &db, &string_index);
/* only report for same index type */
if (!strcmp(w_index_type, index_type))
const char *db = 0;
const char *string_index = 0;
- zebraExplain_lookup_ord(zh->reg->zei, doc_w->ord,
+ zebraExplain_lookup_ord(zh->reg->zei, doc_w->ord,
&index_type, &db, &string_index);
if (mark_state == 0)
{
-
+
wrbuf_printf(wrbuf, " <snippet name=\"%s\"", string_index);
wrbuf_printf(wrbuf, " type=\"%s\"", index_type);
snippet_check_fields(zh, wrbuf, doc, doc_w, index_type);
if (doc_w->match)
wrbuf_puts(wrbuf, "<s>");
/* not printing leading ws */
- if (mark_state || !doc_w->ws || doc_w->match)
+ if (mark_state || !doc_w->ws || doc_w->match)
wrbuf_xmlputs(wrbuf, doc_w->term);
if (doc_w->match)
wrbuf_puts(wrbuf, "</s>");
yaz_log(YLOG_LOG, "HIT SNIPPET:");
zebra_snippets_log(hit_snippet, YLOG_LOG, 1);
#endif
-
+
zebra_snippets_ring(rec_snippets, hit_snippet, 5, 5);
-
+
#if 0
yaz_log(YLOG_LOG, "---------------------------");
yaz_log(YLOG_LOG, "RING SNIPPET:");
zebra_snippets_log(rec_snippets, YLOG_LOG, 1);
#endif
snippet_xml_record(zh, wrbuf, rec_snippets);
-
+
*output_format = yaz_oid_recsyn_xml;
-
+
zebra_snippets_destroy(hit_snippet);
}
zebra_snippets_destroy(rec_snippets);
char *info;
zint hits = 0;
NMEM nmem = nmem_create();
-
+
strcpy(ord_buf + ord_len, term);
-
+
info = dict_lookup(zh->reg->dict, ord_buf);
if (info)
{
ISAM_P isam_p;
RSET rsets[2], rset;
memcpy(&isam_p, info+1, sizeof(ISAM_P));
-
+
rsets[0] = zebra_create_rset_isam(zh, nmem, kc, kc->scope, isam_p, 0);
rsets[1] = rset_dup(rset_set);
-
+
rset = rset_create_and(nmem, kc, kc->scope, 2, rsets);
zebra_count_set(zh, rset, &hits, zh->approx_limit);
qsort(col, no_terms_collect, sizeof(*col), term_qsort_handle);
}
-static struct term_collect *term_collect_create(zebra_strmap_t sm,
+static struct term_collect *term_collect_create(zebra_strmap_t sm,
int no_terms_collect,
NMEM nmem)
{
void *data_buf;
size_t data_len;
zebra_strmap_it it;
- struct term_collect *col = nmem_malloc(nmem,
+ struct term_collect *col = nmem_malloc(nmem,
sizeof *col *no_terms_collect);
int i;
for (i = 0; i < no_terms_collect; i++)
int oc = *(int*) data_buf;
int j = 0;
/* insertion may be slow but terms terms will be "infrequent" and
- thus number of iterations should be small below
+ thus number of iterations should be small below
*/
while (j < no_terms_collect && oc > col[j].oc)
j++;
- if (j)
+ if (j)
{ /* oc <= col[j] and oc > col[j-1] */
--j;
memmove(col, col+1, sizeof(*col) * j);
{
if (!poset[rec_i].sysno)
continue;
-
+
zebra_sort_sysno(zh->reg->sort_index, poset[rec_i].sysno);
zebra_sort_type(zh->reg->sort_index, ord_array[ord_i]);
-
+
wrbuf_rewind(w);
if (zebra_sort_read(zh->reg->sort_index, 0, w))
{
zebra_rec_keys_t keys = zebra_rec_keys_open();
zebra_rec_keys_set_buf(keys, rec->info[recInfo_delKeys],
rec->size[recInfo_delKeys], 0);
-
- yaz_log(YLOG_DEBUG, "rec %d " ZINT_FORMAT " %s",
+
+ yaz_log(YLOG_DEBUG, "rec %d " ZINT_FORMAT " %s",
j, sysnos[j], zebra_rec_keys_empty(keys) ? "empty" : "non-empty");
if (zebra_rec_keys_rewind(keys))
{
{
int ord_i;
struct index_spec *spec;
- for (spec = spec_list, ord_i = 0; ord_i < no_ord;
+ for (spec = spec_list, ord_i = 0; ord_i < no_ord;
ord_i++, spec = spec->next)
{
int ord = CAST_ZINT_TO_INT(key_in.mem[0]);
- if (ord == ord_array[ord_i] &&
+ if (ord == ord_array[ord_i] &&
str[0] != FIRST_IN_FIELD_CHAR)
{
int *freq;
zebra_strmap_t sm = map_array[ord_i];
-
+
freq = zebra_strmap_lookup(sm, str, 0, 0);
if (freq)
(*freq)++;
return 0;
}
-static int perform_facet(ZebraHandle zh,
+static int perform_facet(ZebraHandle zh,
struct special_fetch_s *fi,
WRBUF result,
int num_recs, ZebraMetaRecord *poset,
NMEM nmem = nmem_create();
struct term_collect *col;
int no_collect_terms = 20;
-
+
if (spec->extra)
no_collect_terms = atoi(spec->extra);
if (no_collect_terms < 1)
no_collect_terms = 1;
col = term_collect_create(map_array[i], no_collect_terms, nmem);
term_collect_freq(zh, col, no_collect_terms, ord_array[i],
- resultSetRef(zh, fi->setname),
+ resultSetRef(zh, fi->setname),
cat == zinfo_index_category_sort ? 1.0 : -1.0);
-
+
if (use_xml)
wrbuf_printf(wr, " <facet type=\"%s\" index=\"%s\">\n",
spec->index_type, spec->index_name);
{
wrbuf_printf(wr, " <term coccur=\"%d\"", col[j].oc);
if (col[j].set_occur)
- wrbuf_printf(wr, " occur=\"" ZINT_FORMAT "\"",
+ wrbuf_printf(wr, " occur=\"" ZINT_FORMAT "\"",
col[j].set_occur);
wrbuf_printf(wr, ">");
wrbuf_xmlputs(wr, dst_buf);
{
wrbuf_printf(wr, "term %d", col[j].oc);
if (col[j].set_occur)
- wrbuf_printf(wr, " " ZINT_FORMAT,
+ wrbuf_printf(wr, " " ZINT_FORMAT,
col[j].set_occur);
wrbuf_printf(wr, ": %s\n", dst_buf);
}
use_xml = 1;
spec_list = parse_index_spec(elemsetname, fi->nmem, &error);
-
+
if (!spec_list || error)
{
return YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_;
- }
-
+ }
+
for (spec = spec_list; spec; spec = spec->next)
{
if (!spec->index_type)
if (ord == -1)
break;
ord_array[i] = ord;
-
+
}
}
if (spec)
struct special_fetch_s *fi = (struct special_fetch_s *) handle;
ZebraHandle zh = fi->zh;
zint sysno = fi->sysno;
-
+
/* processing zebra::facet */
if (elemsetname && 0 == strncmp(elemsetname, "facet", 5))
{
- return facet_fetch(fi, elemsetname + 5,
+ return facet_fetch(fi, elemsetname + 5,
input_format, output_format,
result, addinfo);
}
{
wrbuf_printf(result, ZINT_FORMAT, fi->sysno);
*output_format = input_format;
- }
+ }
else if (!oid_oidcmp(input_format, yaz_oid_recsyn_xml))
{
wrbuf_printf(result, ZEBRA_XML_HEADER_STR
return YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
}
- /* processing special elementsetnames zebra::data */
+ /* processing special elementsetnames zebra::data */
if (elemsetname && 0 == strcmp(elemsetname, "data"))
{
struct ZebraRecStream stream;
- RecordAttr *recordAttr = rec_init_attr(zh->reg->zei, rec);
+ RecordAttr *recordAttr = rec_init_attr(zh->reg->zei, rec);
char *b;
zebra_create_record_stream(zh, &rec, &stream);
if (elemsetname && 0 == strcmp(elemsetname, "meta"))
{
int ret = 0;
- RecordAttr *recordAttr = rec_init_attr(zh->reg->zei, rec);
+ RecordAttr *recordAttr = rec_init_attr(zh->reg->zei, rec);
if (!oid_oidcmp(input_format, yaz_oid_recsyn_xml))
{
*output_format = input_format;
-
+
wrbuf_printf(result, ZEBRA_XML_HEADER_STR
" sysno=\"" ZINT_FORMAT "\"", sysno);
retrieve_puts_attr(result, "base", rec->info[recInfo_databaseName]);
retrieve_puts_attr(result, "type", rec->info[recInfo_fileType]);
if (fi->score >= 0)
retrieve_puts_attr_int(result, "score", fi->score);
-
+
wrbuf_printf(result,
" rank=\"" ZINT_FORMAT "\""
" size=\"%i\""
const char *res_buf;
size_t res_len;
zebra_map_tokenize_start(zm, term_utf8, strlen(term_utf8));
-
+
if (zebra_map_tokenize_next(zm, &res_buf, &res_len, 0, 0))
{
memcpy(termz, res_buf, res_len);
int i = 0;
const char *space_map = NULL;
int len;
-
+
while ((len = (cp_end - cp)) > 0)
{
map = zebra_maps_input(zm, &cp, len, 0);
return ZEBRA_OK;
}
-static void get_first_snippet_from_rset(ZebraHandle zh,
- RSET rset, zebra_snippets *snippets,
+static void get_first_snippet_from_rset(ZebraHandle zh,
+ RSET rset, zebra_snippets *snippets,
zint *sysno)
{
struct it_key key;
struct rset_key_control *kc,
Z_AttributesPlusTerm *zapt,
RSET limit_set,
- const char *term,
+ const char *term,
const char *index_type,
struct scan2_info_entry *ar, int ord_no,
ZebraScanEntry *glist, int pos)
AttrType global_hits_limit_attr;
int l;
attr_init_APT(&global_hits_limit_attr, zapt, 12);
-
+
l = attr_find(&global_hits_limit_attr, NULL);
if (l != -1)
approx_limit = l;
-
+
for (i = 0; i < ord_no; i++)
{
if (ar[i].isam_p && strcmp(wrbuf_cstr(ar[i].term), term) == 0)
{
struct ord_list *ol = ord_list_create(nmem);
RSET rset_t;
-
+
ol = ord_list_append(nmem, ol, ar[i].ord);
-
+
assert(ol);
rset_t = rset_trunc(
zh, &ar[i].isam_p, 1,
wrbuf_buf(ar[i].term), wrbuf_len(ar[i].term),
- NULL, 1, zapt->term->which, nmem,
- kc, kc->scope, ol, index_type,
+ NULL, 1, zapt->term->which, nmem,
+ kc, kc->scope, ol, index_type,
0 /* hits_limit_value */,
0 /* term_ref_id_str */);
if (!rset)
else
{
RSET rsets[2];
-
+
rsets[0] = rset;
rsets[1] = rset_t;
rset = rset_create_or(nmem, kc, kc->scope, 0 /* termid */,
RSET rsets[2];
rsets[0] = rset;
rsets[1] = rset_dup(limit_set);
-
+
rset = rset_create_and(nmem, kc, kc->scope, 2, rsets);
}
/* count it */
glist[pos].term = 0;
glist[pos].display_term = 0;
-
+
get_first_snippet_from_rset(zh, rset, hit_snippets, &sysno);
if (sysno)
{
int code = zebra_get_rec_snippets(zh, sysno, rec_snippets);
if (code == 0)
{
- const struct zebra_snippet_word *w =
+ const struct zebra_snippet_word *w =
zebra_snippets_lookup(rec_snippets, hit_snippets);
if (w)
{
static ZEBRA_RES rpn_scan_norm(ZebraHandle zh, ODR stream, NMEM nmem,
struct rset_key_control *kc,
Z_AttributesPlusTerm *zapt,
- int *position, int *num_entries,
+ int *position, int *num_entries,
ZebraScanEntry **list,
int *is_partial, RSET limit_set,
const char *index_type,
{
char termz[IT_MAX_WORD+20];
int prefix_len = 0;
-
+
prefix_len = key_SU_encode(ords[i], termz);
termz[prefix_len] = 0;
strcpy(ar[i].prefix, termz);
-
- if (trans_scan_term(zh, zapt, termz+prefix_len, zm) ==
+
+ if (trans_scan_term(zh, zapt, termz+prefix_len, zm) ==
ZEBRA_FAIL)
{
for (i = 0; i < ord_no; i++)
/* get maximum after scan */
for (i = 0; i < ord_no; i++)
{
- if (ar[i].isam_p
+ if (ar[i].isam_p
&& (hi == 0 || strcmp(wrbuf_cstr(ar[i].term), hi) > 0))
hi = wrbuf_cstr(ar[i].term);
}
{
char termz[IT_MAX_WORD+20];
int prefix_len = 0;
-
+
prefix_len = key_SU_encode(ords[i], termz);
termz[prefix_len] = 0;
strcpy(ar[i].prefix, termz);
-
- if (trans_scan_term(zh, zapt, termz+prefix_len, zm) ==
+
+ if (trans_scan_term(zh, zapt, termz+prefix_len, zm) ==
ZEBRA_FAIL)
return ZEBRA_FAIL;
wrbuf_rewind(ar[i].term);
/* get minimum after scan */
for (i = 0; i < ord_no; i++)
{
- if (ar[i].isam_p
+ if (ar[i].isam_p
&& (lo == 0 || strcmp(wrbuf_cstr(ar[i].term), lo) < 0))
lo = wrbuf_cstr(ar[i].term);
}
{
char resname[32];
sprintf(resname, "%d", termset_value_numeric);
- set_name = odr_strdup(stream, resname);
+ set_name = odr_strdup(stream, resname);
}
else
set_name = odr_strdup(stream, termset_value_string);
if (set_name)
{
limit_set = resultSetRef(zh, set_name);
-
+
if (!limit_set)
{
- zebra_setError(zh,
+ zebra_setError(zh,
YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
set_name);
return ZEBRA_FAIL;
yaz_log(YLOG_DEBUG, "position = %d, num = %d",
*position, *num_entries);
-
+
if (zebra_maps_attr(zh->reg->zebra_maps, zapt, &index_type, &search_type,
rank_type, &complete_flag, &sort_flag))
{
*num_entries = 0;
return ZEBRA_FAIL;
}
- if (zebra_apt_get_ord(zh, zapt, index_type, 0, attributeset, &ord)
+ if (zebra_apt_get_ord(zh, zapt, index_type, 0, attributeset, &ord)
!= ZEBRA_OK)
continue;
ords[ord_no++] = ord;
dict_grep_cmap(reg->dict, map_info, rpn_char_map_handler);
}
-#define TERM_COUNT
-
-struct grep_info {
-#ifdef TERM_COUNT
- int *term_no;
-#endif
+#define TERM_COUNT
+
+struct grep_info {
+#ifdef TERM_COUNT
+ int *term_no;
+#endif
ISAM_P *isam_p_buf;
- int isam_p_size;
+ int isam_p_size;
int isam_p_indx;
int trunc_max;
ZebraHandle zh;
const char *index_type;
ZebraSet termset;
-};
+};
static int add_isam_p(const char *name, const char *info,
struct grep_info *p)
if (p->isam_p_indx == p->isam_p_size)
{
ISAM_P *new_isam_p_buf;
-#ifdef TERM_COUNT
- int *new_term_no;
+#ifdef TERM_COUNT
+ int *new_term_no;
#endif
p->isam_p_size = 2*p->isam_p_size + 100;
new_isam_p_buf = (ISAM_P *) xmalloc(sizeof(*new_isam_p_buf) *
int ord = 0;
const char *index_name;
int len = key_SU_decode(&ord, (const unsigned char *) name);
-
+
zebra_term_untrans (p->zh, p->index_type, term_tmp, name+len);
yaz_log(log_level_rpn, "grep: %d %c %s", ord, name[len], term_tmp);
zebraExplain_lookup_ord(p->zh->reg->zei,
ord, 0 /* index_type */, &db, &index_name);
yaz_log(log_level_rpn, "grep: db=%s index=%s", db, index_name);
-
+
resultSetAddTerm(p->zh, p->termset, name[len], db,
index_name, term_tmp);
}
{
char tmpbuf[80];
esc_str(tmpbuf, sizeof(tmpbuf), map[0], strlen(map[0]));
-
+
wrbuf_puts(term_dict, map[0]);
}
}
wrbuf_putc(term_dict, '\\');
if (res_buf[i] < 32)
wrbuf_putc(term_dict, '\x01');
-
+
wrbuf_putc(term_dict, res_buf[i]);
}
wrbuf_write(display_term, display_buf, display_len);
}
if (*s1 == '\0')
break;
-
+
wrbuf_putc(term_dict, *s1);
wrbuf_putc(display_term, *s1);
while (*s0 == ' ')
s0++;
-
+
if (*s0 == '\0')
return 0;
-
+
if (space_split)
{
s1 = s0;
*src = s1;
zebra_map_tokenize_start(zm, s0, s1 - s0);
-
+
if (!zebra_map_tokenize_next(zm, &res_buf, &res_len,
&display_buf, &display_len))
{
{
/* ICU sort keys seem to be of the form
basechars \x01 accents \x01 length
- For now we'll just right truncate from basechars . This
+ For now we'll just right truncate from basechars . This
may give false hits due to accents not being used.
*/
i = res_len;
wrbuf_putc(term_dict, '\\');
if (res_buf[i] < 32)
wrbuf_putc(term_dict, '\x01');
-
+
wrbuf_putc(term_dict, res_buf[i]);
}
if (mode & 1)
wrbuf_putc(display_term, *space_start);
wrbuf_putc(term_dict, *space_start);
space_start++;
-
+
}
/* and reset */
space_start = space_end = 0;
}
}
*src = s0;
-
+
return i;
}
/* term_104: handle term, process ?n * # */
-static int term_104(zebra_map_t zm, const char **src,
+static int term_104(zebra_map_t zm, const char **src,
WRBUF term_dict, int space_split, WRBUF display_term)
{
const char *s0;
}
/* term_105/106: handle term, process * ! and possibly right_truncate */
-static int term_105(zebra_map_t zm, const char **src,
+static int term_105(zebra_map_t zm, const char **src,
WRBUF term_dict, int space_split,
WRBUF display_term, int right_truncate)
{
strcpy(dst, "(-[0-9]+|(");
else
strcpy(dst, "((");
- }
+ }
else
{
if (!islt)
if (d == '0')
continue;
d--;
- }
+ }
else
{
if (d == '9')
d++;
}
}
-
+
strcpy(dst + dst_p, numstr);
dst_p = strlen(dst) - pos - 1;
else
{
if (d != '9')
- {
+ {
dst[dst_p++] = '[';
dst[dst_p++] = d;
dst[dst_p++] = '-';
static int string_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
const char **term_sub, WRBUF term_dict,
const Odr_oid *attributeSet,
- zebra_map_t zm, int space_split,
+ zebra_map_t zm, int space_split,
WRBUF display_term,
int *error_code)
{
return 0;
}
yaz_log(log_level_rpn, "Relation <");
-
+
wrbuf_putc(term_dict, '(');
for (i = 0; i < wrbuf_len(term_component); )
{
int j = 0;
-
+
if (i)
wrbuf_putc(term_dict, '|');
while (j < i)
wrbuf_putc(term_dict, '[');
wrbuf_putc(term_dict, '^');
-
+
wrbuf_putc(term_dict, 1);
wrbuf_putc(term_dict, FIRST_IN_FIELD_CHAR);
-
+
string_rel_add_char(term_dict, term_component, &i);
wrbuf_putc(term_dict, '-');
-
+
wrbuf_putc(term_dict, ']');
wrbuf_putc(term_dict, '.');
wrbuf_putc(term_dict, '*');
while (j < i)
string_rel_add_char(term_dict, term_component, &j);
wrbuf_putc(term_dict, '[');
-
+
wrbuf_putc(term_dict, '^');
wrbuf_putc(term_dict, '-');
string_rel_add_char(term_dict, term_component, &i);
}
static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- const char **term_sub,
+ const char **term_sub,
WRBUF term_dict,
const Odr_oid *attributeSet, NMEM stream,
struct grep_info *grep_info,
AttrType hits_limit_attr;
int term_ref_id_int;
zint hits_limit_from_attr;
-
+
attr_init_APT(&hits_limit_attr, zapt, 11);
hits_limit_from_attr = attr_find(&hits_limit_attr, NULL);
*/
static ZEBRA_RES search_term(ZebraHandle zh,
Z_AttributesPlusTerm *zapt,
- const char **term_sub,
+ const char **term_sub,
const Odr_oid *attributeSet,
zint hits_limit, NMEM stream,
struct grep_info *grep_info,
const char *index_type, int complete_flag,
- const char *rank_type,
+ const char *rank_type,
const char *xpath_use,
NMEM rset_nmem,
RSET *rset,
yaz_log(log_level_rpn, "term: %s", wrbuf_cstr(display_term));
*rset = rset_trunc(zh, grep_info->isam_p_buf,
grep_info->isam_p_indx, wrbuf_buf(display_term),
- wrbuf_len(display_term), rank_type,
+ wrbuf_len(display_term), rank_type,
1 /* preserve pos */,
zapt->term->which, rset_nmem,
kc, kc->scope, ol, index_type, hits_limit_value,
}
static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- const char **term_sub,
+ const char **term_sub,
WRBUF term_dict,
const Odr_oid *attributeSet, NMEM stream,
struct grep_info *grep_info,
yaz_log(log_level_rpn, "truncation value %d", truncation_value);
termp = *term_sub; /* start of term for each database */
-
+
if (zebra_apt_get_ord(zh, zapt, index_type, xpath_use,
attributeSet, &ord) != ZEBRA_OK)
{
*term_sub = 0;
return ZEBRA_FAIL;
}
-
+
wrbuf_rewind(term_dict); /* new dictionary regexp term */
-
+
*ol = ord_list_append(stream, *ol, ord);
ord_len = key_SU_encode(ord, ord_buf);
-
+
wrbuf_putc(term_dict, '(');
-
+
for (i = 0; i<ord_len; i++)
{
wrbuf_putc(term_dict, 1); /* our internal regexp escape char */
wrbuf_putc(term_dict, ord_buf[i]);
}
wrbuf_putc(term_dict, ')');
-
+
prefix_len = wrbuf_len(term_dict);
if (zebra_maps_is_icu(zm))
{
int relation_value;
AttrType relation;
-
+
attr_init_APT(&relation, zapt, 2);
relation_value = attr_find(&relation, NULL);
if (relation_value == 103) /* always matches */
*term_sub = 0;
return ZEBRA_OK;
}
- break;
+ break;
case 1: /* right truncation */
if (!term_100_icu(zm, &termp, term_dict, space_split, display_term, 1))
{
wrbuf_destroy(pr_wr);
}
r = dict_lookup_grep(zh->reg->dict, wrbuf_cstr(term_dict), regex_range,
- grep_info, &max_pos,
+ grep_info, &max_pos,
ord_len /* number of "exact" chars */,
grep_handle);
if (r == 1)
const char *termset_name = 0;
if (termset_value_numeric != -2)
{
-
+
sprintf(resname, "%d", termset_value_numeric);
termset_name = resname;
}
struct grep_info grep_info;
const char *termp = termz;
int alloc_sets = 0;
-
+
*num_result_sets = 0;
if (grep_info_prepare(zh, zapt, &grep_info, index_type) == ZEBRA_FAIL)
return ZEBRA_FAIL;
while (1)
- {
+ {
ZEBRA_RES res;
if (alloc_sets == *num_result_sets)
{
int add = 10;
- RSET *rnew = (RSET *) nmem_malloc(stream, (alloc_sets+add) *
+ RSET *rnew = (RSET *) nmem_malloc(stream, (alloc_sets+add) *
sizeof(*rnew));
if (alloc_sets)
memcpy(rnew, *result_sets, alloc_sets * sizeof(*rnew));
grep_info_delete(&grep_info);
return ZEBRA_OK;
}
-
+
/**
\brief Create result set(s) for list of terms
\param zh Zebra Handle
char *val;
ISAM_P isam_p;
zebra_map_t zm = zebra_map_get_or_add(zh->reg->zebra_maps, index_type);
-
+
attr_init_APT(&position, zapt, 3);
position_value = attr_find(&position, NULL);
switch(position_value)
assert(*val == sizeof(ISAM_P));
memcpy(&isam_p, val+1, sizeof(isam_p));
- *rset = zebra_create_rset_isam(zh, rset_nmem, kc, kc->scope,
+ *rset = zebra_create_rset_isam(zh, rset_nmem, kc, kc->scope,
isam_p, 0);
}
return ZEBRA_OK;
rank_type, xpath_use,
rset_nmem,
&result_sets, &num_result_sets, kc);
-
+
if (res != ZEBRA_OK)
return res;
if (num_result_sets > 0)
{
RSET first_set = 0;
- res = search_position(zh, zapt, attributeSet,
+ res = search_position(zh, zapt, attributeSet,
index_type,
rset_nmem, &first_set,
kc);
}
}
if (num_result_sets == 0)
- *rset = rset_create_null(rset_nmem, kc, 0);
+ *rset = rset_create_null(rset_nmem, kc, 0);
else if (num_result_sets == 1)
*rset = result_sets[0];
else
const Odr_oid *attributeSet,
zint hits_limit,
NMEM stream,
- const char *index_type,
+ const char *index_type,
int complete_flag,
const char *rank_type,
const char *xpath_use,
for (i = 0; i<num_result_sets; i++)
{
RSET first_set = 0;
- res = search_position(zh, zapt, attributeSet,
+ res = search_position(zh, zapt, attributeSet,
index_type,
rset_nmem, &first_set,
kc);
tmp_set[0] = first_set;
tmp_set[1] = result_sets[i];
-
+
result_sets[i] = rset_create_prox(
rset_nmem, kc, kc->scope,
2, tmp_set,
}
}
if (num_result_sets == 0)
- *rset = rset_create_null(rset_nmem, kc, 0);
+ *rset = rset_create_null(rset_nmem, kc, 0);
else if (num_result_sets == 1)
*rset = result_sets[0];
else
const Odr_oid *attributeSet,
zint hits_limit,
NMEM stream,
- const char *index_type,
+ const char *index_type,
int complete_flag,
- const char *rank_type,
+ const char *rank_type,
const char *xpath_use,
NMEM rset_nmem,
RSET *rset,
for (i = 0; i<num_result_sets; i++)
{
RSET first_set = 0;
- res = search_position(zh, zapt, attributeSet,
+ res = search_position(zh, zapt, attributeSet,
index_type,
rset_nmem, &first_set,
kc);
tmp_set[0] = first_set;
tmp_set[1] = result_sets[i];
-
+
result_sets[i] = rset_create_prox(
rset_nmem, kc, kc->scope,
2, tmp_set,
if (num_result_sets == 0)
- *rset = rset_create_null(rset_nmem, kc, 0);
+ *rset = rset_create_null(rset_nmem, kc, 0);
else if (num_result_sets == 1)
*rset = result_sets[0];
else
case 1:
yaz_log(log_level_rpn, "Relation <");
if (!term_100(zm, term_sub, term_num, 1, display_term))
- {
+ {
wrbuf_destroy(term_num);
return 0;
}
if (!term_100(zm, term_sub, term_num, 1, display_term))
{
wrbuf_destroy(term_num);
- return 0;
+ return 0;
}
term_value = atoi(wrbuf_cstr(term_num));
wrbuf_printf(term_dict, "(0*%d)", term_value);
break;
default:
*error_code = YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE;
- wrbuf_destroy(term_num);
+ wrbuf_destroy(term_num);
return 0;
}
- r = dict_lookup_grep(zh->reg->dict, wrbuf_cstr(term_dict),
+ r = dict_lookup_grep(zh->reg->dict, wrbuf_cstr(term_dict),
0, grep_info, max_pos, 0, grep_handle);
if (r == 1)
}
static ZEBRA_RES numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- const char **term_sub,
+ const char **term_sub,
WRBUF term_dict,
const Odr_oid *attributeSet, NMEM stream,
struct grep_info *grep_info,
int ord, ord_len, i;
char ord_buf[32];
zebra_map_t zm = zebra_map_get_or_add(zh->reg->zebra_maps, index_type);
-
+
*ol = ord_list_create(stream);
rpn_char_map_prepare(zh->reg, zm, &rcmi);
termp = *term_sub;
-
+
if (zebra_apt_get_ord(zh, zapt, index_type, xpath_use,
attributeSet, &ord) != ZEBRA_OK)
{
return ZEBRA_FAIL;
}
-
+
wrbuf_rewind(term_dict);
-
+
*ol = ord_list_append(stream, *ol, ord);
-
+
ord_len = key_SU_encode(ord, ord_buf);
-
+
wrbuf_putc(term_dict, '(');
for (i = 0; i < ord_len; i++)
{
wrbuf_putc(term_dict, ord_buf[i]);
}
wrbuf_putc(term_dict, ')');
-
+
if (!numeric_relation(zh, zapt, &termp, term_dict,
attributeSet, grep_info, &max_pos, zm,
display_term, &relation_error))
return ZEBRA_OK;
}
-
+
static ZEBRA_RES rpn_search_APT_numeric(ZebraHandle zh,
Z_AttributesPlusTerm *zapt,
const char *termz,
const Odr_oid *attributeSet,
zint hits_limit,
NMEM stream,
- const char *index_type,
+ const char *index_type,
int complete_flag,
- const char *rank_type,
+ const char *rank_type,
const char *xpath_use,
NMEM rset_nmem,
RSET *rset,
if (grep_info_prepare(zh, zapt, &grep_info, index_type) == ZEBRA_FAIL)
return ZEBRA_FAIL;
while (1)
- {
+ {
struct ord_list *ol;
WRBUF term_dict = wrbuf_alloc();
WRBUF display_term = wrbuf_alloc();
if (alloc_sets == num_result_sets)
{
int add = 10;
- RSET *rnew = (RSET *) nmem_malloc(stream, (alloc_sets+add) *
+ RSET *rnew = (RSET *) nmem_malloc(stream, (alloc_sets+add) *
sizeof(*rnew));
if (alloc_sets)
memcpy(rnew, result_sets, alloc_sets * sizeof(*rnew));
grep_info.isam_p_indx, wrbuf_buf(display_term),
wrbuf_len(display_term), rank_type,
0 /* preserve position */,
- zapt->term->which, rset_nmem,
+ zapt->term->which, rset_nmem,
kc, kc->scope, ol, index_type,
hits_limit_value,
term_ref_id_str);
{
Record rec;
zint sysno = atozint(termz);
-
+
if (sysno <= 0)
sysno = 0;
rec = rec_get(zh->reg->records, sysno);
*rset = rset_create_temp(rset_nmem, kc, kc->scope,
res_get(zh->res, "setTmpDir"), 0);
rsfd = rset_open(*rset, RSETF_WRITE);
-
+
key.mem[0] = sysno;
key.mem[1] = 1;
key.len = 2;
Z_SortKeySpec *sks;
Z_SortKey *sk;
char termz[20];
-
+
attr_init_APT(&sort_relation_type, zapt, 7);
sort_relation_value = attr_find(&sort_relation_type, &attributeSet);
*sks->sortRelation = Z_SortKeySpec_ascending;
else if (sort_relation_value == 2)
*sks->sortRelation = Z_SortKeySpec_descending;
- else
+ else
*sks->sortRelation = Z_SortKeySpec_ascending;
sks->caseSensitivity = (Odr_int *)
const Odr_oid *curAttributeSet = attributeSet;
AttrType use;
const char *use_string = 0;
-
+
attr_init_APT(&use, zapt, 1);
attr_find_ex(&use, &curAttributeSet, &use_string);
return zebra_parse_xpath_str(use_string, xpath, max, mem);
}
-
-
+
+
static RSET xpath_trunc(ZebraHandle zh, NMEM stream,
- const char *index_type, const char *term,
+ const char *index_type, const char *term,
const char *xpath_use,
NMEM rset_nmem,
struct rset_key_control *kc)
{
struct grep_info grep_info;
- int ord = zebraExplain_lookup_attr_str(zh->reg->zei,
+ int ord = zebraExplain_lookup_attr_str(zh->reg->zei,
zinfo_index_category_index,
index_type, xpath_use);
if (grep_info_prepare(zh, 0 /* zapt */, &grep_info, "0") == ZEBRA_FAIL)
return rset_create_null(rset_nmem, kc, 0);
-
+
if (ord < 0)
return rset_create_null(rset_nmem, kc, 0);
else
}
wrbuf_putc(term_dict, ')');
wrbuf_puts(term_dict, term);
-
+
grep_info.isam_p_indx = 0;
dict_lookup_grep(zh->reg->dict, wrbuf_cstr(term_dict), 0,
&grep_info, &max_pos, 0, grep_handle);
/a/b[@c = y] val range(b/a/,freetext(w,1016,val),b/a/,@c = y)
/a[@c = y]/b val range(a/,range(b/a/,freetext(w,1016,val),b/a/),a/,@c = y)
/a[@c = x]/b[@c = y] range(a/,range(b/a/,freetext(w,1016,val),b/a/,@c = y),a/,@c = x)
-
+
*/
dict_grep_cmap(zh->reg->dict, 0, 0);
-
+
{
int level = xpath_len;
int first_path = 1;
-
+
while (--level >= 0)
{
WRBUF xpath_rev = wrbuf_alloc();
{
const char *cp = xpath[level].predicate->u.relation.value;
wrbuf_putc(wbuf, '=');
-
+
while (*cp)
{
if (strchr(REGEX_CHARS, *cp))
}
}
rset_attr = xpath_trunc(
- zh, stream, "0", wrbuf_cstr(wbuf),
- ZEBRA_XPATH_ATTR_NAME,
+ zh, stream, "0", wrbuf_cstr(wbuf),
+ ZEBRA_XPATH_ATTR_NAME,
rset_nmem, kc);
wrbuf_destroy(wbuf);
- }
- else
+ }
+ else
{
if (!first_path)
{
continue;
}
}
- yaz_log(log_level_rpn, "xpath_rev (%d) = %s", level,
+ yaz_log(log_level_rpn, "xpath_rev (%d) = %s", level,
wrbuf_cstr(xpath_rev));
if (wrbuf_len(xpath_rev))
{
- rset_start_tag = xpath_trunc(zh, stream, "0",
+ rset_start_tag = xpath_trunc(zh, stream, "0",
wrbuf_cstr(xpath_rev),
- ZEBRA_XPATH_ELM_BEGIN,
+ ZEBRA_XPATH_ELM_BEGIN,
rset_nmem, kc);
if (always_matches)
rset = rset_start_tag;
else
{
- rset_end_tag = xpath_trunc(zh, stream, "0",
+ rset_end_tag = xpath_trunc(zh, stream, "0",
wrbuf_cstr(xpath_rev),
- ZEBRA_XPATH_ELM_END,
+ ZEBRA_XPATH_ELM_END,
rset_nmem, kc);
-
+
rset = rset_create_between(rset_nmem, kc, kc->scope,
rset_start_tag, rset,
rset_end_tag, rset_attr);
#define MAX_XPATH_STEPS 10
-static ZEBRA_RES rpn_search_database(ZebraHandle zh,
+static ZEBRA_RES rpn_search_database(ZebraHandle zh,
Z_AttributesPlusTerm *zapt,
const Odr_oid *attributeSet,
zint hits_limit, NMEM stream,
const Odr_oid *attributeSet,
zint hits_limit, NMEM stream,
Z_SortKeySpecList *sort_sequence,
- int num_bases, const char **basenames,
+ int num_bases, const char **basenames,
NMEM rset_nmem,
RSET *rset,
struct rset_key_control *kc)
rset_delete(rsets[i]);
*rset = 0;
}
- else
+ else
{
if (num_bases == 1)
*rset = rsets[0];
else if (num_bases == 0)
- *rset = rset_create_null(rset_nmem, kc, 0);
+ *rset = rset_create_null(rset_nmem, kc, 0);
else
*rset = rset_create_or(rset_nmem, kc, kc->scope, 0 /* TERMID */,
num_bases, rsets);
return res;
}
-static ZEBRA_RES rpn_search_database(ZebraHandle zh,
+static ZEBRA_RES rpn_search_database(ZebraHandle zh,
Z_AttributesPlusTerm *zapt,
const Odr_oid *attributeSet,
zint hits_limit, NMEM stream,
}
zebra_maps_attr(zh->reg->zebra_maps, zapt, &index_type, &search_type,
rank_type, &complete_flag, &sort_flag);
-
+
yaz_log(YLOG_DEBUG, "index_type=%s", index_type);
yaz_log(YLOG_DEBUG, "complete_flag=%d", complete_flag);
yaz_log(YLOG_DEBUG, "search_type=%s", search_type);
return rpn_sort_spec(zh, zapt, attributeSet, stream, sort_sequence,
rank_type, rset_nmem, rset, kc);
/* consider if an X-Path query is used */
- xpath_len = rpn_check_xpath(zh, zapt, attributeSet,
+ xpath_len = rpn_check_xpath(zh, zapt, attributeSet,
xpath, MAX_XPATH_STEPS, stream);
if (xpath_len >= 0)
{
- if (xpath[xpath_len-1].part[0] == '@')
+ if (xpath[xpath_len-1].part[0] == '@')
xpath_use = ZEBRA_XPATH_ATTR_CDATA; /* last step is attribute */
else
- xpath_use = ZEBRA_XPATH_CDATA; /* searching for cdata */
+ xpath_use = ZEBRA_XPATH_CDATA; /* searching for cdata */
if (1)
{
if (relation_value == 103) /* alwaysmatches */
{
*rset = 0; /* signal no "term" set */
- return rpn_search_xpath(zh, stream, rank_type, *rset,
+ return rpn_search_xpath(zh, stream, rank_type, *rset,
xpath_len, xpath, rset_nmem, rset, kc);
}
}
/* search using one of the various search type strategies
termz is our UTF-8 search term
- attributeSet is top-level default attribute set
+ attributeSet is top-level default attribute set
stream is ODR for search
reg_id is the register type
complete_flag is 1 for complete subfield, 0 for incomplete
return res;
if (!*rset)
return ZEBRA_FAIL;
- return rpn_search_xpath(zh, stream, rank_type, *rset,
+ return rpn_search_xpath(zh, stream, rank_type, *rset,
xpath_len, xpath, rset_nmem, rset, kc);
}
Z_AttributesPlusTerm *zapt = zs->u.simple->u.attributesPlusTerm;
AttrType global_hits_limit_attr;
int l;
-
+
attr_init_APT(&global_hits_limit_attr, zapt, 12);
-
+
l = attr_find(&global_hits_limit_attr, NULL);
if (l != -1)
*approx_limit = l;
}
ZEBRA_RES rpn_search_top(ZebraHandle zh, Z_RPNStructure *zs,
- const Odr_oid *attributeSet,
+ const Odr_oid *attributeSet,
zint hits_limit,
NMEM stream, NMEM rset_nmem,
Z_SortKeySpecList *sort_sequence,
res = rpn_search_structure(zh, zs, attributeSet, hits_limit,
stream, rset_nmem,
- sort_sequence,
+ sort_sequence,
num_bases, basenames,
&result_sets, &num_result_sets,
0 /* no parent op */,
/* make a new list of result for all children */
*num_result_sets = num_result_sets_l + num_result_sets_r;
- *result_sets = nmem_malloc(stream, *num_result_sets *
+ *result_sets = nmem_malloc(stream, *num_result_sets *
sizeof(**result_sets));
- memcpy(*result_sets, result_sets_l,
+ memcpy(*result_sets, result_sets_l,
num_result_sets_l * sizeof(**result_sets));
- memcpy(*result_sets + num_result_sets_l, result_sets_r,
+ memcpy(*result_sets + num_result_sets_l, result_sets_r,
num_result_sets_r * sizeof(**result_sets));
if (!parent_op || parent_op->which != zop->which
case Z_Operator_prox:
if (zop->u.prox->which != Z_ProximityOperator_known)
{
- zebra_setError(zh,
+ zebra_setError(zh,
YAZ_BIB1_UNSUPP_PROX_UNIT_CODE,
0);
return ZEBRA_FAIL;
{
rset = rset_create_prox(rset_nmem, kc,
kc->scope,
- *num_result_sets, *result_sets,
+ *num_result_sets, *result_sets,
*zop->u.prox->ordered,
- (!zop->u.prox->exclusion ?
+ (!zop->u.prox->exclusion ?
0 : *zop->u.prox->exclusion),
*zop->u.prox->relationType,
*zop->u.prox->distance );
return ZEBRA_FAIL;
}
*num_result_sets = 1;
- *result_sets = nmem_malloc(stream, *num_result_sets *
+ *result_sets = nmem_malloc(stream, *num_result_sets *
sizeof(**result_sets));
(*result_sets)[0] = rset;
}
rset = resultSetRef(zh, zs->u.simple->u.resultSetId);
if (!rset)
{
- zebra_setError(zh,
+ zebra_setError(zh,
YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
zs->u.simple->u.resultSetId);
return ZEBRA_FAIL;
return ZEBRA_FAIL;
}
*num_result_sets = 1;
- *result_sets = nmem_malloc(stream, *num_result_sets *
+ *result_sets = nmem_malloc(stream, *num_result_sets *
sizeof(**result_sets));
(*result_sets)[0] = rset;
}
*/
/** \file
- \brief factory function for RSET from ISAM
+ \brief factory function for RSET from ISAM
*/
#if HAVE_CONFIG_H
#include <config.h>
#if HAVE_CONFIG_H
#include <config.h>
#endif
-#include <assert.h>
+#include <assert.h>
#include <string.h>
#include <yaz/log.h>
return 0;
(s->no)--;
-
+
*insertMode = s->insert_flag;
memcpy(*dst, &s->st, sizeof(s->st));
*dst += sizeof(s->st);
case ZEBRA_SORT_TYPE_ISAMB:
method.codec.encode = sort_term_encode1;
method.codec.decode = sort_term_decode1;
-
+
sprintf(fname, "sortb%d", id);
sf->u.isamb = isamb_open2(si->bfs, fname, si->write_flag, &method,
/* cache */ 0,
isam_block_size = 32768;
method.codec.encode = sort_term_encode2;
method.codec.decode = sort_term_decode2;
-
+
sprintf(fname, "sortm%d", id);
sf->u.isamb = isamb_open2(si->bfs, fname, si->write_flag, &method,
/* cache */ 0,
s.st.section_id = section_id;
s.st.length = 0;
s.st.term[0] = '\0';
-
+
s.no = 1;
s.insert_flag = 0;
isamc_i.clientData = &s;
isamc_i.read_item = sort_term_code_read;
-
+
isamb_merge(sf->u.isamb, &sf->isam_p, &isamc_i);
sf->no_deleted++;
}
len = strlen(wrbuf_buf(wrbuf));
if (len > SORT_IDX_ENTRYSIZE)
len = SORT_IDX_ENTRYSIZE;
-
+
memcpy(si->entry_buf, wrbuf_buf(wrbuf), len);
if (len < SORT_IDX_ENTRYSIZE-len)
memset(si->entry_buf+len, 0, SORT_IDX_ENTRYSIZE-len);
s.insert_flag = 1;
isamc_i.clientData = &s;
isamc_i.read_item = sort_term_code_read;
-
+
isamb_merge(sf->u.isamb, &sf->isam_p, &isamc_i);
sf->no_inserted++;
}
s.insert_flag = 1;
isamc_i.clientData = &s;
isamc_i.read_item = sort_term_code_read;
-
+
isamb_merge(sf->u.isamb, &sf->isam_p, &isamc_i);
sf->no_inserted++;
}
fc->fd = fd;
fc->record_offset = start_offset;
fc->offset_end = 0;
-
+
stream->fh = fc;
stream->readf = zebra_ext_read;
stream->seekf = zebra_ext_seek;
int cmp_border = preserve_position ? 0 : 1;
NMEM rset_nmem_sub = nmem_create(); /* all sub rsets not needed
after this */
-
+
rset = (RSET *) xmalloc(sizeof(*rset) * rsmax);
rsfd = (RSFD *) xmalloc(sizeof(*rsfd) * rsmax);
-
+
for (i = from; i < to; i += i_add)
{
if (i_add <= to - i)
rset[rscur] = rset_trunc_r(zi, term, length, flags,
isam_p, i, i+i_add,
merge_chunk, preserve_position,
- term_type, rset_nmem_sub,
+ term_type, rset_nmem_sub,
kctrl, scope, 0);
else
rset[rscur] = rset_trunc_r(zi, term, length, flags,
isam_p, i, to,
merge_chunk, preserve_position,
- term_type, rset_nmem_sub,
+ term_type, rset_nmem_sub,
kctrl, scope, 0);
rscur++;
}
termid = rset_term_create(term, length, flags, term_type, rset_nmem, ol,
*index_type, hits_limit, term_ref_id);
-
+
if (no < 1)
return rset_create_null(rset_nmem, kctrl, termid);
else if (no == 1)
return 0;
}
-int zebra_term_untrans_iconv(ZebraHandle zh, NMEM stream,
+int zebra_term_untrans_iconv(ZebraHandle zh, NMEM stream,
const char *index_type,
char **dst, const char *src)
{
char term_src[IT_MAX_WORD];
char term_dst[IT_MAX_WORD];
int r;
-
+
r = zebra_term_untrans (zh, index_type, term_src, src);
if (r)
return r;
char *outbuf = term_dst;
size_t outleft = sizeof(term_dst)-1;
size_t ret;
-
+
ret = yaz_iconv (zh->iconv_from_utf8, &inbuf, &inleft,
&outbuf, &outleft);
if (ret == (size_t)(-1))
int before = 10;
int after = 1000;
char term[1000];
-
+
strcpy(term, "0");
dict_scan(dict, term, &before, &after, 0, dump_file_dict_func);
}
sprintf(tmppath, "%s%s", base, dst->path);
zebra_extract_file(zh, &dst->sysno, tmppath, action_delete);
strcpy(tmppath, dst->path);
- dst = dirs_read(di);
+ dst = dirs_read(di);
dirs_del(di, tmppath);
break;
case dirs_dir:
static void file_update_r(ZebraHandle zh,
struct dirs_info *di, struct dirs_entry *dst,
- const char *base, char *src,
+ const char *base, char *src,
int level)
{
struct dir_entry *e_src;
src[src_len] = '/';
src[++src_len] = '\0';
}
- dst = dirs_read(di);
+ dst = dirs_read(di);
}
dir_sort(e_src);
{
strcpy(src + src_len, e_src[i_src].name);
sprintf(tmppath, "%s%s", base, src);
-
+
switch(e_src[i_src].kind)
{
case dirs_file:
yaz_log(YLOG_DEBUG, "last is %s", dst ? dst->path : "null");
break;
default:
- dst = dirs_read(di);
+ dst = dirs_read(di);
}
i_src++;
}
{
case dirs_file:
if (zebra_extract_file(zh, &sysno, tmppath, action_update) == ZEBRA_OK)
- dirs_add(di, src, sysno, e_src[i_src].mtime);
+ dirs_add(di, src, sysno, e_src[i_src].mtime);
break;
case dirs_dir:
file_update_r(zh, di, dst, base, src, level+1);
if (ret == -1)
{
yaz_log(YLOG_WARN|YLOG_ERRNO, "Cannot access path %s", src);
- }
+ }
else if (S_ISREG(sbuf.st_mode))
{
struct dirs_entry *e_dst;
ZEBRA_RES zebra_remove_file_match(ZebraHandle zh)
{
Dict dict;
-
+
if (zebra_open_fmatch(zh, &dict) != ZEBRA_OK)
return ZEBRA_FAIL;
}
if (zebra_open_fmatch(zh, &dict) != ZEBRA_OK)
return ZEBRA_FAIL;
-
+
if (!strcmp(path, "") || !strcmp(path, "-"))
{
char src[1024];
rep[rep_len] = '/';
else
--rep_len;
-
+
for (i=0; e[i].name; i++)
{
char *ecp;
yaz_log(YLOG_FATAL, "dict_open fail of %s", FMATCH_DICT);
return;
}
-
+
strncpy(src, path, sizeof(src)-1);
src[sizeof(src)-1]='\0';
src_len = strlen(src);
-
+
if (src_len && src[src_len-1] != '/')
{
src[src_len] = '/';
src[++src_len] = '\0';
}
-
+
di = dirs_open(dict, src, zh->m_flag_rw);
-
+
while ((dst = dirs_read(di)))
yaz_log(YLOG_LOG, "%s", dst->path);
dirs_free(&di);
}
-ZEBRA_RES zebra_update_from_path(ZebraHandle zh, const char *path,
+ZEBRA_RES zebra_update_from_path(ZebraHandle zh, const char *path,
enum zebra_recctrl_action_t action)
{
if (!strcmp(path, "") || !strcmp(path, "-"))
{
char src[1024];
-
+
while (scanf("%1020s", src) == 1)
repositoryExtract(zh, src, action);
}
return ZEBRA_OK;
}
-static struct zebra_register *zebra_register_open(ZebraService zs,
+static struct zebra_register *zebra_register_open(ZebraService zs,
const char *name,
int rw, int useshadow,
Res res,
zh->destroyed = 0;
zh->errCode = 0;
zh->errString = 0;
- zh->res = 0;
+ zh->res = 0;
zh->session_res = res_open(zs->global_res, res);
zh->user_perm = 0;
zh->dbaccesslist = 0;
zh = xmalloc(sizeof(*zh));
zh->global_res = res;
zh->sessions = 0;
-
+
if (zebra_chdir(zh))
{
xfree(zh);
return 0;
}
-
+
zebra_mutex_cond_init(&zh->session_lock);
passwd_plain = res_get(zh->global_res, "passwd");
passwd_encrypt = res_get(zh->global_res, "passwd.c");
if (!passwd_plain && !passwd_encrypt)
zh->passwd_db = NULL;
- else
+ else
{
zh->passwd_db = passwd_db_open();
if (!zh->passwd_db)
ZEBRA_RES ret = ZEBRA_OK;
ASSERTZS;
-
+
reg = xmalloc(sizeof(*reg));
assert(name);
yaz_log(YLOG_DEBUG, "zebra_register_open rw=%d useshadow=%d p=%p n=%s rp=%s",
rw, useshadow, reg, name, reg_path ? reg_path : "(none)");
-
+
reg->dh = data1_create();
if (!reg->dh)
{
reg->isamc = 0;
reg->isamb = 0;
reg->zei = 0;
-
+
/* installing rank classes */
zebraRankInstall(reg, rank_1_class);
zebraRankInstall(reg, rank_2_class);
ret = ZEBRA_FAIL;
}
-
+
if (res_get_match(res, "sortindex", "f", "f"))
sort_type = ZEBRA_SORT_TYPE_FLAT;
else if (res_get_match(res, "sortindex", "i", "f"))
if (res_get_match(res, "isam", "b", ISAM_DEFAULT))
{
struct ISAMC_M_s isamc_m;
-
+
if (!(reg->isamb = isamb_open(reg->bfs, "isamb",
rw, key_isamc_m(res, &isamc_m), 0)))
{
if (res_get_match(res, "isam", "bc", ISAM_DEFAULT))
{
struct ISAMC_M_s isamc_m;
-
+
if (!(reg->isamb = isamb_open(reg->bfs, "isamb",
rw, key_isamc_m(res, &isamc_m), 1)))
{
if (res_get_match(res, "isam", "null", ISAM_DEFAULT))
{
struct ISAMC_M_s isamc_m;
-
+
if (!(reg->isamb = isamb_open(reg->bfs, "isamb",
rw, key_isamc_m(res, &isamc_m), -1)))
{
ret = ZEBRA_FAIL;
}
}
-
+
if (ret != ZEBRA_OK)
{
zebra_register_close(zs, reg);
yaz_log(YLOG_DEBUG, "zebra_register_close p=%p", reg);
reg->stop_flag = 0;
zebra_chdir(zs);
-
+
zebraExplain_close(reg->zei);
dict_close(reg->dict);
if (reg->matchDict)
{
zebra_close(zs->sessions);
}
-
+
zebra_mutex_cond_destroy(&zs->session_lock);
if (zs->passwd_db)
yaz_timing_get_real(zs->timing),
yaz_timing_get_user(zs->timing),
yaz_timing_get_sys(zs->timing));
-
+
yaz_timing_destroy(&zs->timing);
xfree(zs);
ZEBRA_CHECK_HANDLE(zh);
zh->errCode = 0;
-
+
zs = zh->service;
yaz_log(YLOG_DEBUG, "zebra_close zh=%p", zh);
resultSetDestroy(zh, -1, 0, 0);
zh->path_reg = 0;
if (zh->service->path_root)
{
- zh->path_reg = xmalloc(strlen(zh->service->path_root) +
+ zh->path_reg = xmalloc(strlen(zh->service->path_root) +
strlen(zh->reg_name) + 3);
strcpy(zh->path_reg, zh->service->path_root);
if (*zh->reg_name)
}
}
zebra_open_res(zh);
-
+
if (zh->lock_normal)
zebra_lock_destroy(zh->lock_normal);
zh->lock_normal = 0;
{
char fname[512];
const char *lock_area = res_get(zh->res, "lockDir");
-
+
if (!lock_area && zh->path_reg)
res_set(zh->res, "lockDir", zh->path_reg);
sprintf(fname, "norm.%s.LCK", zh->reg_name);
zh->lock_normal =
zebra_lock_create(res_get(zh->res, "lockDir"), fname);
-
+
sprintf(fname, "shadow.%s.LCK", zh->reg_name);
zh->lock_shadow =
zebra_lock_create(res_get(zh->res, "lockDir"), fname);
}
if (zh->res)
{
- if (res_get_int(zh->res, "segment", &zh->m_segment_indexing) ==
+ if (res_get_int(zh->res, "segment", &zh->m_segment_indexing) ==
ZEBRA_OK)
{
yaz_log(YLOG_DEBUG, "segment indexing set and is %d",
assert(value);
assert(name);
assert(vp);
-
+
no =
sscanf(value, "%127s %127s %127s %127s %127s %127s %127s %127s %127s",
fromdb, todb[0], todb[1], todb[2], todb[3], todb[4],
{
if (p->new_num_bases == p->new_num_max)
return;
- p->new_basenames[(p->new_num_bases)++] =
+ p->new_basenames[(p->new_num_bases)++] =
nmem_strdup(p->mem, todb[i]);
}
return;
info.mem = stream->mem;
res_trav(zh->session_res, "mapdb", &info, map_basenames_func);
-
+
for (i = 0; i<p->num_bases; i++)
if (p->basenames[i] && p->new_num_bases < p->new_num_max)
{
- p->new_basenames[(p->new_num_bases)++] =
+ p->new_basenames[(p->new_num_bases)++] =
nmem_strdup(p->mem, p->basenames[i]);
}
*num_bases = info.new_num_bases;
yaz_log(log_level, "zebra_select_databases n=%d [0]=%s",
num_bases,basenames[0]);
zh->errCode = 0;
-
+
if (num_bases < 1)
{
zh->errCode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP;
for (i = 0; i < zh->num_basenames; i++)
xfree(zh->basenames[i]);
xfree(zh->basenames);
-
+
zh->num_basenames = num_bases;
zh->basenames = xmalloc(zh->num_basenames * sizeof(*zh->basenames));
for (i = 0; i < zh->num_basenames; i++)
int *partial_resultset)
{
ZEBRA_RES r;
-
+
ZEBRA_CHECK_HANDLE(zh);
assert(o);
if (zebra_begin_read(zh) == ZEBRA_FAIL)
return ZEBRA_FAIL;
- r = resultSetAddRPN(zh, odr_extract_mem(o), query,
+ r = resultSetAddRPN(zh, odr_extract_mem(o), query,
zh->num_basenames, zh->basenames, setname,
hits, estimated_hit_count);
setname);
return ZEBRA_FAIL;
}
-
+
if (zebra_begin_read(zh) == ZEBRA_FAIL)
return ZEBRA_FAIL;
/* we disable hit snippets for now. It does not work well
and it slows retrieval down a lot */
#if 0
- zebra_snippets_hit_vector(zh, setname, poset[i].sysno,
+ zebra_snippets_hit_vector(zh, setname, poset[i].sysno,
hit_snippet);
#endif
wrbuf_rewind(addinfo_w);
stream, input_format, comp,
&recs[i].format, &buf, &len,
&recs[i].base, addinfo_w);
-
+
if (wrbuf_len(addinfo_w))
recs[i].errString =
odr_strdup(stream, wrbuf_cstr(addinfo_w));
Z_AttributesPlusTerm *zapt;
Odr_oid *attributeSet;
ZEBRA_RES res;
-
+
if (!(zapt = yaz_pqf_scan(pqf_parser, stream, &attributeSet, query)))
{
res = ZEBRA_FAIL;
return zh->errCode;
}
yaz_log(log_level, "zebra_errCode: o");
- return 0;
+ return 0;
}
const char *zebra_errString(ZebraHandle zh)
ZEBRA_CHECK_HANDLE(zh);
zs = zh->service;
-
+
sprintf(u, "perm.%.30s", user ? user : "anonymous");
p = res_get(zs->global_res, u);
xfree(zh->user_perm);
/* users that don't require a password .. */
if (zh->user_perm && strchr(zh->user_perm, 'a'))
return ZEBRA_OK;
-
+
if (!zs->passwd_db || !passwd_db_auth(zs->passwd_db, user, pass))
return ZEBRA_OK;
return ZEBRA_FAIL;
ZEBRA_RES zebra_admin_import_begin(ZebraHandle zh, const char *database,
const char *record_type)
{
- yaz_log(log_level, "zebra_admin_import_begin db=%s rt=%s",
+ yaz_log(log_level, "zebra_admin_import_begin db=%s rt=%s",
database, record_type);
if (zebra_select_database(zh, database) == ZEBRA_FAIL)
return ZEBRA_FAIL;
{
Odr_oct *oct = fragment->u.notExternallyTagged;
sysno = 0;
-
+
if(zebra_update_record(
- zh,
+ zh,
action_update,
0, /* record Type */
&sysno,
assert(zh->reg->isamb);
assert(zh->reg->records);
dict_delete_subtree(zh->reg->dict, ord_buf,
- zh,
+ zh,
!strcmp(string_index, "_ALLRECORDS") ?
delete_w_all_handle : delete_w_handle);
return 0;
return ZEBRA_FAIL;
/* announce database */
- if (zebraExplain_newDatabase(zh->reg->zei, db, 0
+ if (zebraExplain_newDatabase(zh->reg->zei, db, 0
/* explainDatabase */))
{
if (zebra_end_trans(zh) != ZEBRA_OK)
\param zh Zebra handle
\param val state
\param seqno sequence number
-
+
val is one of:
d=writing to shadow(shadow enabled); writing to register (shadow disabled)
o=reading only
if (!f)
{
yaz_log(YLOG_FATAL|YLOG_ERRNO, "open %s w", state_fname);
- exit(1);
+ exit(1);
}
yaz_log(YLOG_DEBUG, "zebra_set_state: %c %d %ld", val, seqno, p);
fprintf(f, "%c %d %ld\n", val, seqno, p);
const char *group = res_get(zh->res, "group");
const char *v;
/* FIXME - do we still use groups ?? */
-
+
zh->m_group = group;
v = res_get_prefix(zh->res, "followLinks", group, "1");
zh->m_follow_links = atoi(v);
int seqno = 0;
char val = '?';
const char *rval = 0;
-
+
(zh->trans_no++);
if (zh->trans_w_no)
{
zh->records_deleted = 0;
zh->records_processed = 0;
zh->records_skipped = 0;
-
+
#if HAVE_SYS_TIMES_H
times(&zh->tms1);
#endif
/* lock */
if (zh->shadow_enable)
rval = res_get(zh->res, "shadow");
-
+
if (rval)
{
zebra_lock_r(zh->lock_normal);
}
zebra_set_state(zh, 'd', seqno);
-
+
zh->reg = zebra_register_open(zh->service, zh->reg_name,
1, rval ? 1 : 0, zh->res,
zh->path_reg);
int dirty = 0;
char val;
int seqno;
-
+
(zh->trans_no)++;
-
+
if (zh->trans_no != 1)
{
return zebra_flush_reg(zh);
zebra_get_state(zh, &val, &seqno);
if (val == 'd')
val = 'o';
-
+
if (!zh->reg)
dirty = 1;
else if (seqno != zh->reg->seqno)
}
if (!dirty)
return ZEBRA_OK;
-
+
if (val == 'c')
zebra_lock_r(zh->lock_shadow);
else
zebra_lock_r(zh->lock_normal);
-
+
if (zh->reg)
{
resultSetInvalidate(zh);
{ /* release write lock */
zh->trans_no--;
zh->trans_w_no = 0;
-
+
yaz_log(YLOG_DEBUG, "zebra_end_trans");
rval = res_get(zh->res, "shadow");
-
+
zebraExplain_runNumberIncrement(zh->reg->zei, 1);
-
+
zebra_flush_reg(zh);
-
+
resultSetInvalidate(zh);
zebra_register_close(zh->service, zh->reg);
zh->reg = 0;
-
+
yaz_log(YLOG_LOG, "Records: "ZINT_FORMAT" i/u/d "
- ZINT_FORMAT"/"ZINT_FORMAT"/"ZINT_FORMAT,
+ ZINT_FORMAT"/"ZINT_FORMAT"/"ZINT_FORMAT,
zh->records_processed, zh->records_inserted,
zh->records_updated, zh->records_deleted);
-
+
status->processed = zh->records_processed;
status->inserted = zh->records_inserted;
status->updated = zh->records_updated;
status->deleted = zh->records_deleted;
-
+
zebra_get_state(zh, &val, &seqno);
if (val != 'd')
{
zebra_set_state(zh, 'o', seqno);
zebra_unlock(zh->lock_shadow);
zebra_unlock(zh->lock_normal);
-
+
}
#if HAVE_SYS_TIMES_H
times(&zh->tms2);
yaz_log(log_level, "user/system: %ld/%ld",
(long) (zh->tms2.tms_utime - zh->tms1.tms_utime),
(long) (zh->tms2.tms_stime - zh->tms1.tms_stime));
-
+
status->utime = (long) (zh->tms2.tms_utime - zh->tms1.tms_utime);
status->stime = (long) (zh->tms2.tms_stime - zh->tms1.tms_stime);
#endif
zh->errCode = YAZ_BIB1_DATABASE_UNAVAILABLE;
return ZEBRA_FAIL;
}
- rval = res_get(zh->res, "shadow");
+ rval = res_get(zh->res, "shadow");
if (!rval)
{
yaz_log(YLOG_WARN, "Cannot perform commit - No shadow area defined");
else
{
zebra_set_state(zh, 'c', seqno);
-
+
yaz_log(log_level, "commit start");
if (bf_commitExec(bfs))
res = ZEBRA_FAIL;
{
seqno++;
zebra_set_state(zh, 'o', seqno);
-
+
zebra_unlock(zh->lock_shadow);
zebra_unlock(zh->lock_normal);
-
+
zebra_lock_w(zh->lock_shadow);
bf_commitClean(bfs, rval);
zebra_unlock(zh->lock_shadow);
}
if (rval && *rval)
bf_cache(bfs, rval);
-
+
bf_reset(bfs);
bfs_destroy(bfs);
zebra_set_state(zh, 'o', 0);
zebra_rec_keys_t keys = zebra_rec_keys_open();
zebra_rec_keys_set_buf(keys, rec->info[recInfo_delKeys],
rec->size[recInfo_delKeys], 0);
-
+
*no_keys = 0;
if (!zebra_rec_keys_rewind(keys))
{
continue;
}
memcpy(ord_buf + ord_len, str, slen);
- ord_buf[ord_len + slen] = '\0';
+ ord_buf[ord_len + slen] = '\0';
if (ord_len + slen >= IT_MAX_WORD)
{
res = ZEBRA_FAIL;
if (*no_long_dict_entries <= message_limit)
{
do_fail = 1;
- yaz_log(YLOG_WARN, "Record " ZINT_FORMAT
+ yaz_log(YLOG_WARN, "Record " ZINT_FORMAT
": long dictionary entry %d + %d",
rec->sysno, (int) ord_len, (int) slen);
}
if (*no_invalid_dict_infos <= message_limit)
{
do_fail = 1;
- yaz_log(YLOG_WARN, "Record " ZINT_FORMAT
+ yaz_log(YLOG_WARN, "Record " ZINT_FORMAT
": long dictionary entry %d + %d",
rec->sysno, (int) ord_len, (int) slen);
}
if (*no_invalid_isam_entries <= message_limit)
{
do_fail = 1;
- yaz_log(YLOG_WARN, "Record " ZINT_FORMAT
+ yaz_log(YLOG_WARN, "Record " ZINT_FORMAT
": isamb_pp_open entry " ZINT_FORMAT
" not found",
rec->sysno, pos);
struct it_key isam_key;
int r;
int i = 0;
-
+
until_key.len = key_in.len - 1;
for (i = 0; i < until_key.len; i++)
until_key.mem[i] = key_in.mem[i+1];
-
+
if (until_key.mem[0] == 0)
until_key.mem[0] = rec->sysno;
r = isamb_pp_forward(ispt, &isam_key, &until_key);
if (*no_invalid_isam_entries <= message_limit)
{
do_fail = 1;
- yaz_log(YLOG_WARN, "Record " ZINT_FORMAT
+ yaz_log(YLOG_WARN, "Record " ZINT_FORMAT
": isamb_pp_forward " ZINT_FORMAT
" returned no entry",
rec->sysno, pos);
{
do_fail = 1;
yaz_log(YLOG_WARN, "Record "
- ZINT_FORMAT
+ ZINT_FORMAT
": isamb_pp_forward "
ZINT_FORMAT
" returned different entry",
ZEBRA_RES res = ZEBRA_FAIL;
unsigned flags = 0;
int message_limit = 10;
-
+
if (!spec || *spec == '\0'
|| !strcmp(spec, "dict") || !strcmp(spec, "default"))
flags = ZEBRA_CHECK_DICT;
if (zh->reg)
{
Record rec = rec_get_root(zh->reg->records);
-
+
zint no_long_dict_entries = 0;
zint no_failed_dict_lookups = 0;
zint no_invalid_keys = 0;
yaz_iconv_close(zh->iconv_to_utf8);
if (zh->iconv_from_utf8 != 0)
yaz_iconv_close(zh->iconv_from_utf8);
-
+
zh->iconv_to_utf8 =
yaz_iconv_open("UTF-8", encoding);
if (zh->iconv_to_utf8 == 0)
ZEBRA_RES zebra_add_record(ZebraHandle zh,
const char *buf, int buf_size)
{
- return zebra_update_record(zh, action_update,
+ return zebra_update_record(zh, action_update,
0 /* record type */,
0 /* sysno */ ,
- 0 /* match */,
+ 0 /* match */,
0 /* fname */,
buf, buf_size);
}
-ZEBRA_RES zebra_update_record(ZebraHandle zh,
+ZEBRA_RES zebra_update_record(ZebraHandle zh,
enum zebra_recctrl_action_t action,
const char *recordType,
zint *sysno, const char *match,
if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL)
return ZEBRA_FAIL;
- res = zebra_buffer_extract_record(zh, buf, buf_size,
+ res = zebra_buffer_extract_record(zh, buf, buf_size,
action,
recordType,
- sysno,
- match,
+ sysno,
+ match,
fname);
if (zebra_end_trans(zh) != ZEBRA_OK)
{
yaz_log(YLOG_WARN, "zebra_end_trans failed");
res = ZEBRA_FAIL;
}
- return res;
+ return res;
}
/* ---------------------------------------------------------------------------
- Searching
+ Searching
*/
ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
assert(setname);
yaz_log(log_level, "zebra_search_PQF s=%s q=%s", setname, pqf_query);
-
+
query = p_query_rpn(odr, pqf_query);
-
+
if (!query)
{
yaz_log(YLOG_WARN, "bad query %s\n", pqf_query);
}
else
res = zebra_search_RPN(zh, odr, query, setname, &lhits);
-
+
odr_destroy(odr);
yaz_log(log_level, "Hits: " ZINT_FORMAT, lhits);
int zebra_sort_by_specstr(ZebraHandle zh, ODR stream,
const char *sort_spec,
const char *output_setname,
- const char **input_setnames)
+ const char **input_setnames)
{
int num_input_setnames = 0;
int sort_status = 0;
zh->errCode = YAZ_BIB1_CANNOT_SORT_ACCORDING_TO_SEQUENCE;
return -1;
}
-
- /* we can do this, since the perl typemap code for char** will
+
+ /* we can do this, since the perl typemap code for char** will
put a NULL at the end of list */
while (input_setnames[num_input_setnames]) num_input_setnames++;
if (zebra_begin_read(zh))
return -1;
-
+
resultSetSort(zh, stream->mem, num_input_setnames, input_setnames,
output_setname, sort_sequence, &sort_status);
-
+
zebra_end_read(zh);
return sort_status;
}
void zebra_lock_prefix(Res res, char *path)
{
const char *lock_dir = res_get_def(res, "lockDir", "");
-
+
strcpy(path, lock_dir);
if (*path && path[strlen(path)-1] != '/')
strcat(path, "/");
char *database = 0;
Res res = res_open(0, 0);
Res default_res = res_open(0, 0);
-
+
int trans_started = 0;
#ifndef WIN32
char nbuf[100];
{
yaz_log(YLOG_FATAL, "Cannot read config %s", config);
exit(1);
- }
+ }
zh = zebra_open(zs, 0);
zebra_shadow_enable(zh, enable_commit);
}
const char *add = zebra_errAdd(zh);
yaz_log(YLOG_FATAL, "Operation failed: %s %s",
zebra_errString(zh), add ? add : "");
-
+
if (trans_started)
if (zebra_end_trans(zh) != ZEBRA_OK)
yaz_log(YLOG_WARN, "zebra_end_trans failed");
*/
-/*
+/*
zebrash.c - command-line interface to zebra API
*/
#endif
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
+#include <string.h>
#include <ctype.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_READLINE_READLINE_H
-#include <readline/readline.h>
+#include <readline/readline.h>
#endif
#if HAVE_READLINE_HISTORY_H
#include <readline/history.h>
* Help functions
*/
-
+
static int split_args( char *line, char** args )
-{ /* splits line into individual null-terminated strings,
+{ /* splits line into individual null-terminated strings,
* returns pointers to them in args */
/* FIXME - do we need to handle quoted args ?? */
char *p=line;
while (*p==' ' || *p=='\t' || *p=='\n')
p++;
if (*p=='#') /* skip comments */
- break;
+ break;
args[i++]=p;
args[i]=0;
while (*p && *p!=' ' && *p!='\t' && *p!='\n' && *p!='#')
return args[0]+skiplen;
}
-int onecommand( char *line, WRBUF outbuff, const char *prevout);
+int onecommand( char *line, WRBUF outbuff, const char *prevout);
/**************************************
* Simple support commands
wrbuf_printf(outbuff,"%s\n",restargs(args,1));
return 0;
}
-
+
int cmd_quit( char *args[], WRBUF outbuff)
{
if (zs)
/**************************************
* Tests for starting and stopping zebra, etc
*/
-
-static int cmd_help( char *args[], WRBUF outbuff);
-
+
+static int cmd_help( char *args[], WRBUF outbuff);
+
static int cmd_zebra_start( char *args[], WRBUF outbuff)
{
char *conf=args[1];
}
return 0; /* ok */
}
-
+
static int cmd_zebra_stop( char *args[], WRBUF outbuff)
{
if (!zs)
static int cmd_logf( char *args[], WRBUF outbuff)
{
int lev = defargint(args[1],0);
- int i=1;
+ int i=1;
if (lev)
i=2;
else
yaz_log( lev, "%s", restargs(args,i));
return 0; /* ok */
}
-
+
/****************
- * Error handling
+ * Error handling
*/
static int cmd_err ( char *args[], WRBUF outbuff)
{
wrbuf_printf(outbuff, "errCode: %d \nerrStr: %s\nerrAdd: %s \n",
zebra_errCode (zh),
- zebra_errString (zh),
+ zebra_errString (zh),
zebra_errAdd (zh) );
return 0; /* ok */
}
static int cmd_erradd ( char *args[], WRBUF outbuff)
{
wrbuf_printf(outbuff, "errAdd: %s \n",
- zebra_errAdd (zh) );
+ zebra_errAdd (zh) );
return 0; /* ok */
}
wrbuf_printf(outbuff,"Selecting database '%s'\n",db);
return zebra_select_database(zh, db);
}
-
+
static int cmd_create_database( char *args[], WRBUF outbuff)
{
char *db=defarg(args[1],DEFAULTDATABASE);
wrbuf_printf(outbuff,"Creating database '%s'\n",db);
-
+
return zebra_create_database(zh, db);
}
zint sysno = 0;
int rc;
char *rec=restargs(args,1);
-
+
rc = zebra_update_record(zh,
action_insert,
0, /* record type */
*/
/**************************************)
- * Command table, parser, and help
+ * Command table, parser, and help
*/
struct cmdstruct
int (*testfunc)(char *args[], WRBUF outbuff);
} ;
-
+
struct cmdstruct cmds[] = {
/* special cases:
* if text is 0, does not list the command
* if cmd is "", adds the args (and newline) in command listing
*/
{ "", "Starting and stopping:", "", 0 },
- { "zebra_start",
- "[configfile]",
+ { "zebra_start",
+ "[configfile]",
"starts the zebra service. You need to call this first\n"
- "if no configfile is given, assumes " DEFAULTCONFIG,
+ "if no configfile is given, assumes " DEFAULTCONFIG,
cmd_zebra_start },
- { "zebra_stop", "",
- "stops the zebra service",
+ { "zebra_stop", "",
+ "stops the zebra service",
cmd_zebra_stop },
- { "zebra_open", "",
+ { "zebra_open", "",
"starts a zebra session. Once you have called zebra_start\n"
- "you can call zebra_open to start working",
+ "you can call zebra_open to start working",
cmd_zebra_open },
- { "zebra_close", "",
- "closes a zebra session",
- cmd_zebra_close },
- { "quickstart", "[configfile]",
- "Does a zebra_start, zebra_open, and sets up the log",
- cmd_quickstart },
-
- { "", "Log file:","", 0},
- { "yaz_log_file",
+ { "zebra_close", "",
+ "closes a zebra session",
+ cmd_zebra_close },
+ { "quickstart", "[configfile]",
+ "Does a zebra_start, zebra_open, and sets up the log",
+ cmd_quickstart },
+
+ { "", "Log file:","", 0},
+ { "yaz_log_file",
"[filename]",
"Directs the log to filename (or stderr)",
cmd_yaz_log_file },
- { "yaz_log_level",
+ { "yaz_log_level",
"[level]",
"Sets the logging level (or returns to default)",
cmd_yaz_log_level },
- { "yaz_log_prefix",
+ { "yaz_log_prefix",
"[prefix]",
"Sets the log prefix",
- cmd_yaz_log_prefix},
- { "yaz_log",
+ cmd_yaz_log_prefix},
+ { "yaz_log",
"[level] text...",
"writes an entry in the log",
- cmd_logf},
+ cmd_logf},
{ "", "Error handling:","", 0},
{ "err", "",
"Displays zebra's error status (code, str, add)",
- cmd_err},
+ cmd_err},
{ "errcode", "",
"Displays zebra's error code",
- cmd_errcode},
+ cmd_errcode},
{ "errstr", "",
"Displays zebra's error string",
- cmd_errstr},
+ cmd_errstr},
{ "erradd", "",
"Displays zebra's additional error message",
- cmd_erradd},
-
- { "", "Admin:","", 0},
+ cmd_erradd},
+
+ { "", "Admin:","", 0},
{ "init", "",
"Initializes the zebra database, destroying all data in it",
- cmd_init},
+ cmd_init},
{ "select_database", "basename",
"Selects a database",
- cmd_select_database},
+ cmd_select_database},
{ "create_database", "basename",
"Create database",
cmd_create_database},
{ "sort","sortspec",
"sorts a result set. (example spec: 1=4 >)",
cmd_sort},
-
- { "", "Misc:","", 0},
- { "echo", "string",
- "ouputs the string",
+
+ { "", "Misc:","", 0},
+ { "echo", "string",
+ "ouputs the string",
cmd_echo },
- { "q", "",
- "exits the program",
+ { "q", "",
+ "exits the program",
cmd_quit },
- { "quit", "",
- "exits the program",
+ { "quit", "",
+ "exits the program",
cmd_quit },
- { "help", "[command]",
- "Gives help on command, or lists them all",
+ { "help", "[command]",
+ "Gives help on command, or lists them all",
cmd_help },
- { "", "help [command] gives more info on command", "",0 },
-
+ { "", "help [command] gives more info on command", "",0 },
+
{0,0,0,0} /* end marker */
};
-
-int onecommand(
+
+int onecommand(
char *line, /* input line */
WRBUF outbuff, /* output goes here */
const char *prevout) /* prev output, for 'expect' */
argbuf[MAX_ARG_LEN-1]='\0'; /* just to be sure */
/*memset(args,'\0',MAX_NO_ARGS*sizeof(char *));*/
nargs=split_args(argbuf, args);
-
+
#if 0
for (i = 0; i <= n; i++)
{
if (0==nargs)
return -90; /* no command on line, too bad */
- if (0==strcmp(args[0],"expect"))
+ if (0==strcmp(args[0],"expect"))
{
char *rest;
if (nargs>1) /* args[0] is not yet set, can't use restargs */
if (0==strstr(prevout,rest))
{
printf( "Failed expectation, '%s' not found\n", rest);
- exit(9);
+ exit(9);
}
return 0;
}
for (i=0;cmds[i].cmd;i++)
- if (0==strcmp(cmds[i].cmd, args[0]))
+ if (0==strcmp(cmds[i].cmd, args[0]))
{
if (nargs>1)
args[0]= line + (args[1]-argbuf); /* rest of the line */
else
- args[0]="";
+ args[0]="";
return ((cmds[i].testfunc)(args,outbuff));
}
wrbuf_printf(outbuff, "Unknown command '%s'. Try help\n",args[0]);
yaz_log(log_level,"Unknown command");
- return -90;
+ return -90;
}
-
+
static int cmd_help( char *args[], WRBUF outbuff)
-{
+{
int i;
int linelen;
- if (args[1])
- { /* help for a single command */
+ if (args[1])
+ { /* help for a single command */
for (i=0;cmds[i].cmd;i++)
- if (0==strcmp(cmds[i].cmd, args[1]))
+ if (0==strcmp(cmds[i].cmd, args[1]))
{
wrbuf_printf(outbuff,"%s %s\n%s\n",
- cmds[i].cmd, cmds[i].args,
+ cmds[i].cmd, cmds[i].args,
cmds[i].explanation);
return 0;
}
wrbuf_printf(outbuff, "Unknown command '%s'", args[1]);
}
- else
+ else
{ /* list all commands */
linelen=9999;
for (i=0;cmds[i].cmd;i++)
}
return 0;
}
-
+
/* If Zebra reports an error after an operation,
* append it to the outbuff and log it */
static void Zerrors (WRBUF outbuff)
}
}
-/**************************************
+/**************************************
* The shell
*/
-
+
void shell(void)
{
int rc=0;
}
#endif
/* line_in != NULL if readine is present and input is a tty */
-
- printf (PROMPT);
+
+ printf (PROMPT);
fflush (stdout);
if (line_in)
{
strcpy(buf,line_in);
free (line_in);
}
- else
+ else
{
if (!fgets (buf, MAX_ARG_LEN-1, stdin))
- break;
+ break;
}
-
+
/* get rid of \n in line */
if ((nl_cp = strchr(buf, '\n')))
*nl_cp = '\0';
else if (rc>-90)
{
wrbuf_printf(outbuff, " command returned %d\n",rc);
- }
+ }
Zerrors(outbuff);
printf("%s\n", wrbuf_cstr(outbuff));
} /* while */
exit(1);
}
/**************************************
- * Main
+ * Main
*/
int main (int argc, char ** argv)
yaz_get_proposal_charneg(nmem, q->charneg_request,
&charsets, &num_charsets,
&langs, &num_langs, &selected);
-
+
for (i = 0; i < num_charsets; i++)
{
const char *right_name = "";
* because a lot servers in Russia to use own in during
* character set and language negotiation still.
*/
-
+
if (!yaz_matchstr(charsets[i], "win")) {
right_name = "WINDOWS-1251";
} else if (!yaz_matchstr(charsets[i], "koi")) {
&count, &approx, outbuf, &len,
&term_ref_id);
se = sr->elements[i] = odr_malloc(r->stream, sizeof(**sr->elements));
- se->subqueryId = term_ref_id ?
+ se->subqueryId = term_ref_id ?
odr_strdup(r->stream, term_ref_id) : 0;
-
+
se->fullQuery = odr_booldup(r->stream, 0);
- se->subqueryExpression =
+ se->subqueryExpression =
odr_malloc(r->stream, sizeof(Z_QueryExpression));
- se->subqueryExpression->which =
+ se->subqueryExpression->which =
Z_QueryExpression_term;
se->subqueryExpression->u.term =
odr_malloc(r->stream, sizeof(Z_QueryExpressionTerm));
static int break_handler(void *client_data)
{
- bend_association assoc =(bend_association) client_data;
+ bend_association assoc =(bend_association) client_data;
if (!bend_assoc_is_alive(assoc))
return 1;
return 0;
int num_arg;
int ascending = 1;
nmem_strsplitx(odr_getmem(o), ",", sortspec[i], &arg, &num_arg, 0);
-
+
if (num_arg > 5 || num_arg < 1)
{
yaz_log(YLOG_WARN, "Invalid sort spec '%s' num_arg=%d",
}
if (num_arg > 2 && arg[2][0])
ascending = atoi(arg[2]);
-
+
if (i < num_sortspec-1)
wrbuf_puts(w, " @or");
wrbuf_puts(w, " @attr 1=");
else
{
Z_RPNStructure *s = nquery->RPNStructure;
-
+
if (s->which != Z_RPNStructure_complex)
{
yaz_log(YLOG_WARN, "query_add_sortkeys: not complex operand");
ZEBRA_RES res;
retrievalRecord.position = r->number;
-
+
r->last_in_set = 0;
res = zebra_records_retrieve(zh, r->stream, r->setname, r->comp,
r->request_format, 1, &retrievalRecord);
int is_partial, i;
ZEBRA_RES res;
- res = zebra_select_databases(zh, r->num_bases,
+ res = zebra_select_databases(zh, r->num_bases,
(const char **) r->basenames);
if (res != ZEBRA_OK)
{
res = zebra_scan(zh, r->stream, r->term,
r->attributeset,
&r->term_position,
- &r->num_entries, &entries, &is_partial,
+ &r->num_entries, &entries, &is_partial,
0 /* setname */);
if (res == ZEBRA_OK)
{
int bend_esrequest(void *handle, bend_esrequest_rr *rr)
{
ZebraHandle zh = (ZebraHandle) handle;
-
+
yaz_log(YLOG_LOG, "function: " ODR_INT_PRINTF, *rr->esr->function);
if (rr->esr->packageName)
yaz_log(YLOG_LOG, "packagename: %s", rr->esr->packageName);
Z_IUUpdateEsRequest *esRequest = up->u.esRequest;
Z_IUOriginPartToKeep *toKeep = esRequest->toKeep;
Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep;
-
+
yaz_log(YLOG_LOG, "action");
if (toKeep->action)
{
rr->errstring = "unsupported ES Update action";
break;
}
-
+
if (opaque_recid)
{
size_t l = opaque_recid->len;
yaz_log(YLOG_WARN, "Unknown Extended Service(%d)",
rr->esr->taskSpecificParameters->which);
rr->errcode = YAZ_BIB1_ES_EXTENDED_SERVICE_TYPE_UNSUPP;
-
+
}
return 0;
}
exit(1);
}
#ifdef WIN32
-
+
#else
- if (!sob->inetd && !sob->background)
+ if (!sob->inetd && !sob->background)
{
char pidfname[4096];
struct flock area;
else
{
char pidstr[30];
-
+
sprintf(pidstr, "%ld", (long) getpid());
if (write(fd, pidstr, strlen(pidstr)) != strlen(pidstr))
{
#ifdef WIN32
#else
- if (!sob->inetd && !sob->background && sob->handle)
+ if (!sob->inetd && !sob->background && sob->handle)
{
char pidfname[4096];
zebra_pidfname(sob->handle, pidfname);
if (!rec)
return 0;
*sysno = rec->sysno;
-
+
rec->info[recInfo_fileType] =
rec_strdup("grs.sgml", &rec->size[recInfo_fileType]);
rec->info[recInfo_databaseName] =
rec_strdup("IR-Explain-1",
- &rec->size[recInfo_databaseName]);
+ &rec->size[recInfo_databaseName]);
}
return rec;
}
len = 63;
memcpy(str, np->child->u.data.data, len);
str[len] = '\0';
-
+
oid = odr_getoidbystr_nmem(zei->nmem, str);
for (ao = *op; ao; ao = ao->next)
zebAccessInfo *accessInfo)
{
data1_node *np;
-
+
if (!n)
{
*accessInfo = (zebAccessInfo)
zei->records = records;
zei->nmem = nmem;
zei->dh = dh;
-
+
data1_get_absyn(zei->dh, "explain", DATA1_XPATH_INDEXING_DISABLE);
zei->attsets = 0;
node_aid = np2->child;
}
assert(node_id && node_name && node_aid);
-
- *zdip =(struct zebDatabaseInfoB *)
+
+ *zdip =(struct zebDatabaseInfoB *)
nmem_malloc(zei->nmem, sizeof(**zdip));
(*zdip)->readFlag = 1;
(*zdip)->dirty = 0;
np = np->child;
assert(np && np->which == DATA1N_data);
zei->ordinalSU = atoi_n(np->u.data.data, np->u.data.len);
-
+
np = data1_search_tag(zei->dh, node_zebra->child,
"ordinalDatabase");
np = np->child;
rec_strdup("grs.sgml", &trec->size[recInfo_fileType]);
trec->info[recInfo_databaseName] =
rec_strdup("IR-Explain-1", &trec->size[recInfo_databaseName]);
-
+
sgml_buf = data1_nodetoidsgml(dh, zei->data1_target, 0, &sgml_len);
trec->info[recInfo_storeData] = (char *) xmalloc(sgml_len);
memcpy(trec->info[recInfo_storeData], sgml_buf, sgml_len);
trec->size[recInfo_storeData] = sgml_len;
-
+
rec_put(records, &trec);
rec_free(&trec);
}
-
+
zebraExplain_newDatabase(zei, "IR-Explain-1", 0);
-
+
if (!zei->categoryList->dirty)
{
struct zebraCategoryListInfo *zcl = zei->categoryList;
data1_node *node_cl;
-
+
zcl->dirty = 1;
zcl->data1_categoryList =
data1_read_sgml(zei->dh, zei->nmem,
"<explain><categoryList>CategoryList\n"
"</></>\n");
-
+
if (zcl->data1_categoryList)
{
node_cl = data1_search_tag(zei->dh, zcl->data1_categoryList,
nmem_malloc(zei->nmem, sizeof(**zsuip));
if (node_type && node_type->u.data.len > 0)
- (*zsuip)->info.index_type =
+ (*zsuip)->info.index_type =
nmem_strdupn(zei->nmem,
node_type->u.data.data,
node_type->u.data.len);
cat = zinfo_index_category_index;
else if (!strncmp(np->u.data.data, "sort", np->u.data.len))
cat = zinfo_index_category_sort;
- else if (!strncmp(np->u.data.data, "alwaysmatches",
+ else if (!strncmp(np->u.data.data, "alwaysmatches",
np->u.data.len))
cat = zinfo_index_category_alwaysmatches;
- else if (!strncmp(np->u.data.data, "anchor",
+ else if (!strncmp(np->u.data.data, "anchor",
np->u.data.len))
cat = zinfo_index_category_anchor;
else
rec = rec_get(zei->records, zdi->sysno);
zdi->data1_database = read_sgml_rec(zei->dh, zei->nmem, rec);
-
+
node_dbinfo = data1_search_tag(zei->dh, zdi->data1_database,
"/databaseInfo");
assert(node_dbinfo);
"zebraInfo");
if (node_zebra
&& (np = data1_search_tag(zei->dh, node_zebra->child,
- "recordBytes"))
+ "recordBytes"))
&& np->child && np->child->which == DATA1N_data)
zdi->recordBytes = atoi_zn(np->child->u.data.data,
np->child->u.data.len);
if (node_zebra
&& (np = data1_search_tag(zei->dh, node_zebra->child,
- "ordinalDatabase"))
+ "ordinalDatabase"))
&& np->child && np->child->which == DATA1N_data)
zdi->ordinalDatabase = atoi_n(np->child->u.data.data,
np->child->u.data.len);
{
/* remove attribute details keys and delete it */
zebAttributeDetails zad = zdi->attributeDetails;
-
+
rec = rec_get(zei->records, zad->sysno);
(*zei->updateFunc)(zei->updateHandle, rec, 0);
rec_del(zei->records, &rec);
database_n++;
else
database_n = database;
-
+
assert(zei);
if (zei->curDatabaseInfo &&
!STRCASECMP(zei->curDatabaseInfo->databaseName, database))
data1_node *c = data1_search_tag(zei->dh, n->child, "accessInfo");
data1_node *d;
zebAccessObject p;
-
+
if (!c)
{
data1_pr_tree(zei->dh, n, stdout);
zdi->ordinalDatabase = zei->ordinalDatabase++;
zebraExplain_mergeAccessInfo(zei, 0, &zdi->accessInfo);
-
+
assert(zei->dh);
assert(zei->nmem);
zdi->data1_database =
- data1_read_sgml(zei->dh, zei->nmem,
+ data1_read_sgml(zei->dh, zei->nmem,
"<explain><databaseInfo>DatabaseInfo\n"
"</></>\n");
if (!zdi->data1_database)
data1_mk_tag_data_text(zei->dh, node_dbinfo, "name",
database, zei->nmem);
-
+
if (explain_database)
data1_mk_tag_data_text(zei->dh, node_dbinfo, "explainDatabase",
"", zei->nmem);
-
+
data1_mk_tag_data_text(zei->dh, node_dbinfo, "userFee",
"0", zei->nmem);
-
+
data1_mk_tag_data_text(zei->dh, node_dbinfo, "available",
"1", zei->nmem);
-
+
#if ZINFO_DEBUG
data1_pr_tree(zei->dh, zdi->data1_database, stderr);
#endif
drec = createRecord(zei->records, &sysno);
if (!drec)
return;
-
+
node_ci = data1_search_tag(zei->dh, node_categoryList,
"/categoryList");
assert (node_ci);
node_ci = data1_mk_tag(zei->dh, zei->nmem, "categories", 0 /* attr */,
node_ci);
assert (node_ci);
-
+
for (i = 0; category[i]; i++)
{
data1_node *node_cat = data1_mk_tag(zei->dh, zei->nmem, "category",
drec->info[recInfo_storeData] = (char *) xmalloc(sgml_len);
memcpy(drec->info[recInfo_storeData], sgml_buf, sgml_len);
drec->size[recInfo_storeData] = sgml_len;
-
+
rec_put(zei->records, &drec);
}
Record drec;
data1_node *node_adinfo, *node_list, *node_zebra;
struct zebSUInfoB *zsui;
-
+
if (!zad->dirty)
return;
-
+
zad->dirty = 0;
#if ZINFO_DEBUG
- yaz_log(YLOG_LOG, "zebraExplain_writeAttributeDetails");
+ yaz_log(YLOG_LOG, "zebraExplain_writeAttributeDetails");
data1_pr_tree(zei->dh, zad->data1_tree, stderr);
#endif
drec->info[recInfo_storeData] = (char *) xmalloc(sgml_len);
memcpy(drec->info[recInfo_storeData], sgml_buf, sgml_len);
drec->size[recInfo_storeData] = sgml_len;
-
+
rec_put(zei->records, &drec);
}
int sgml_len;
Record drec;
data1_node *node_dbinfo, *node_count, *node_zebra;
-
+
if (!zdi->dirty)
return;
drec->info[recInfo_storeData] = (char *) xmalloc(sgml_len);
memcpy(drec->info[recInfo_storeData], sgml_buf, sgml_len);
drec->size[recInfo_storeData] = sgml_len;
-
+
rec_put(zei->records, &drec);
}
for (atts = attset->atts; atts; atts = atts->next)
{
data1_node *node_value;
-
+
node_value = data1_mk_tag(zei->dh, zei->nmem, "attributeValue",
0 /* attr */, node_values);
data1_mk_tag_data_text(zei->dh, node_value, "name",
if (o->oid)
attset = data1_attset_search_id(zei->dh, o->oid);
-
+
#if ZINFO_DEBUG
yaz_log(YLOG_LOG, "zebraExplain_writeAttributeSet %s",
- attset ? attset->name : "<unknown>");
+ attset ? attset->name : "<unknown>");
#endif
drec = createRecord(zei->records, &o->sysno);
if (attset && attset->name)
data1_mk_tag_data_text(zei->dh, node_attinfo,
"name", attset->name, zei->nmem);
-
+
node_attributes = data1_mk_tag_uni(zei->dh, zei->nmem,
"attributes", node_attinfo);
node_atttype = data1_mk_tag_uni(zei->dh, zei->nmem,
drec->info[recInfo_storeData] = (char *) xmalloc(sgml_len);
memcpy(drec->info[recInfo_storeData], sgml_buf, sgml_len);
drec->size[recInfo_storeData] = sgml_len;
-
+
rec_put(zei->records, &drec);
}
trec->info[recInfo_storeData] = (char *) xmalloc(sgml_len);
memcpy(trec->info[recInfo_storeData], sgml_buf, sgml_len);
trec->size[recInfo_storeData] = sgml_len;
-
+
rec_put(zei->records, &trec);
}
-int zebraExplain_lookup_attr_str(ZebraExplainInfo zei,
+int zebraExplain_lookup_attr_str(ZebraExplainInfo zei,
zinfo_index_category_t cat,
const char *index_type,
const char *str)
assert(zei->curDatabaseInfo);
for (zsui = &zei->curDatabaseInfo->attributeDetails->SUInfo;
*zsui; zsui = &(*zsui)->next)
- if ( (index_type == 0
+ if ( (index_type == 0
|| !strcmp((*zsui)->info.index_type, index_type))
&& (*zsui)->info.cat == cat
&& !yaz_matchstr((*zsui)->info.str, str))
if ((*zsui)->info.ordinal == ord)
{
struct zebSUInfoB *zsui_this = *zsui;
-
+
/* take it out of the list and move to front */
*zsui = (*zsui)->next;
zsui_this->next = zdb->attributeDetails->SUInfo;
}
int zebraExplain_lookup_ord(ZebraExplainInfo zei, int ord,
- const char **index_type,
+ const char **index_type,
const char **db,
const char **string_index)
{
Odr_oid *oid)
{
zebAccessObject ao;
-
+
for (ao = *op; ao; ao = ao->next)
if (!oid_oidcmp(oid, ao->oid))
break;
return zsui;
}
-int zebraExplain_add_attr_str(ZebraExplainInfo zei,
+int zebraExplain_add_attr_str(ZebraExplainInfo zei,
zinfo_index_category_t cat,
const char *index_type,
const char *index_name)
memset(recordAttr, '\0', sizeof(*recordAttr));
rec->info[recInfo_attr] = (char *) recordAttr;
rec->size[recInfo_attr] = sizeof(*recordAttr);
-
+
recordAttr->recordSize = 0;
recordAttr->recordOffset = 0;
recordAttr->runNumber = zei->runNumber;
adds attributeSet (in AccessInfo area) to DatabaseInfo if it doesn't
exist for the database.
- If the database doesn't exist globally (in TargetInfo) an
+ If the database doesn't exist globally (in TargetInfo) an
AttributeSetInfo must be added (globally).
*/
/*
zinfo_index_category_alwaysmatches,
zinfo_index_category_anchor
} zinfo_index_category_t;
-
+
typedef ZEBRA_RES ZebraExplainUpdateFunc(void *handle,
- Record drec,
+ Record drec,
data1_node *n);
typedef struct zebraExplainInfo *ZebraExplainInfo;
int zebraExplain_add_attr_su(ZebraExplainInfo zei, int index_type,
int set, int use);
-/** \brief lookup ordinal from string index + index type
+/** \brief lookup ordinal from string index + index type
\param zei explain info
\param cat category
\param index_type index type
\param str index string
\returns -1 no such index+type exist; ordinal otherwise
*/
-
-int zebraExplain_lookup_attr_str(ZebraExplainInfo zei,
+
+int zebraExplain_lookup_attr_str(ZebraExplainInfo zei,
zinfo_index_category_t cat,
const char *index_type,
const char *str);
-int zebraExplain_add_attr_str(ZebraExplainInfo zei,
+int zebraExplain_add_attr_str(ZebraExplainInfo zei,
zinfo_index_category_t cat,
const char *index_type,
const char *str);
sizeof(*sort_sequence->specs));
for (i = 0; i<sort_sequence->num_specs; i++)
sort_sequence->specs[i] = 0;
-
+
rpn_get_top_approx_limit(zh, rpn->RPNStructure, &sset->approx_limit);
res = rpn_search_top(zh, rpn->RPNStructure, rpn->attributeSetId,
zebraSet->locked = 1;
zebraSet->rpn = 0;
zebraSet->nmem = m;
- zebraSet->rset_nmem = nmem_create();
+ zebraSet->rset_nmem = nmem_create();
zebraSet->num_bases = num_bases;
- zebraSet->basenames =
+ zebraSet->basenames =
nmem_malloc(zebraSet->nmem, num_bases * sizeof(*zebraSet->basenames));
for (i = 0; i<num_bases; i++)
zebraSet->basenames[i] = nmem_strdup(zebraSet->nmem, basenames[i]);
}
void resultSetAddTerm(ZebraHandle zh, ZebraSet s, int reg_type,
- const char *db, const char *index_name,
+ const char *db, const char *index_name,
const char *term)
{
assert(zh); /* compiler shut up */
int i;
s->term_entries_max = 1000;
s->term_entries =
- nmem_malloc(s->nmem, s->term_entries_max *
+ nmem_malloc(s->nmem, s->term_entries_max *
sizeof(*s->term_entries));
for (i = 0; i < s->term_entries_max; i++)
s->term_entries[i].term = 0;
for (s = zh->sets; s; s = s->next)
if (!strcmp(s->name, name))
break;
-
+
if (!log_level_set)
loglevels();
if (s)
void resultSetInvalidate(ZebraHandle zh)
{
ZebraSet s = zh->sets;
-
+
yaz_log(log_level_resultsets, "invalidating result sets");
for (; s; s = s->next)
{
{
ZebraSet * ss = &zh->sets;
int i;
-
+
if (statuses)
for (i = 0; i<num; i++)
statuses[i] = Z_DeleteStatus_resultSetDidNotExist;
if (i < 0)
{
*ss = s->next;
-
+
xfree(s->sort_info->all_entries);
xfree(s->sort_info->entries);
xfree(s->sort_info);
-
+
if (s->nmem)
nmem_destroy(s->nmem);
if (s->rset)
}
ZebraMetaRecord *zebra_meta_records_create_range(ZebraHandle zh,
- const char *name,
+ const char *name,
zint start, int num)
{
zint pos_small[10];
if (num > 10)
pos = xmalloc(sizeof(*pos) * num);
-
+
for (i = 0; i<num; i++)
pos[i] = start+i;
mr = zebra_meta_records_create(zh, name, num, pos);
-
+
if (num > 10)
xfree(pos);
return mr;
}
-ZebraMetaRecord *zebra_meta_records_create(ZebraHandle zh, const char *name,
+ZebraMetaRecord *zebra_meta_records_create(ZebraHandle zh, const char *name,
int num, zint *positions)
{
ZebraSet sset;
if (sort_info)
{
zint position;
-
+
for (i = 0; i<num; i++)
{
position = positions[i];
zint psysno = 0;
RSFD rfd;
struct it_key key;
-
+
if (sort_info)
position = sort_info->num_entries;
while (num_i < num && positions[num_i] <= position)
num_i++;
-
+
if (sset->cache_rfd &&
num_i < num && positions[num_i] > sset->cache_position)
{
{
char *this_entry_buf = tmp_cmp_buf[i];
memset(this_entry_buf, '\0', SORT_IDX_ENTRYSIZE);
-
+
if (criteria[i].ord[database_no] != -1)
{
yaz_log(log_level_sort, "pre zebra_sort_type ord is %d",
for (j = 0; j<num_criteria; j++)
{
char *this_entry_buf = tmp_cmp_buf[j];
- char *other_entry_buf =
+ char *other_entry_buf =
cmp_buf[j] + i * SORT_IDX_ENTRYSIZE;
if (criteria[j].numerical[database_no])
{
zebra_term_untrans(zh, index_type, other_entry_org,
other_entry_buf);
diff = atof(this_entry_org) - atof(other_entry_org);
-
+
if (diff > 0.0)
rel = 1;
else if (diff < 0.0)
rel = memcmp(this_entry_buf, other_entry_buf,
SORT_IDX_ENTRYSIZE);
}
- /* when the compare is equal, continue to next criteria,
+ /* when the compare is equal, continue to next criteria,
else break out */
if (rel)
break;
- }
+ }
if (!rel)
break;
if (criteria[j].relation == 'A')
--j;
else
j = (sort_info->num_entries)++;
-
+
new_entry = sort_info->entries[j];
while (j != i)
{
nset->nmem = nmem_create();
nset->num_bases = rset->num_bases;
- nset->basenames =
+ nset->basenames =
nmem_malloc(nset->nmem, nset->num_bases * sizeof(*rset->basenames));
for (i = 0; i<rset->num_bases; i++)
nset->basenames[i] = nmem_strdup(nset->nmem, rset->basenames[i]);
TERMID *terms;
int numTerms = 0;
size_t sysno_mem_index = 0;
-
+
int numbases = zh->num_basenames;
yaz_log(log_level_sort, "searching %d databases",numbases);
{
Z_SortKeySpec *sks = sort_sequence->specs[i];
Z_SortKey *sk;
-
+
sort_criteria[i].ord = (int *)
nmem_malloc(nmem, sizeof(int)*numbases);
sort_criteria[i].numerical = (int *)
nmem_malloc(nmem, sizeof(int)*numbases);
-
+
/* initialize ord and numerical for each database */
for (ib = 0; ib < numbases; ib++)
{
{
zebra_setError(zh, YAZ_BIB1_SORT_ILLEGAL_SORT, 0);
return ZEBRA_FAIL;
- }
+ }
sk = sks->sortElement->u.generic;
switch (sk->which)
{
{
zebraExplain_curDatabase(zh->reg->zei, zh->basenames[ib]);
sort_criteria[i].numerical[ib] = 0;
- sort_criteria[i].ord[ib] =
+ sort_criteria[i].ord[ib] =
zebraExplain_lookup_attr_str(zh->reg->zei,
zinfo_index_category_sort,
0, sk->u.sortField);
zebraExplain_curDatabase(zh->reg->zei, zh->basenames[ib]);
if (zebra_sort_get_ord(zh, sk->u.sortAttributes,
&sort_criteria[i].ord[ib],
- &sort_criteria[i].numerical[ib]) !=
+ &sort_criteria[i].numerical[ib]) !=
ZEBRA_OK && sks->which != Z_SortKeySpec_null)
return ZEBRA_FAIL;
}
}
yaz_log(log_level_sort, ZINT_FORMAT " keys, " ZINT_FORMAT " sysnos, sort",
- kno, sset->hits);
+ kno, sset->hits);
for (i = 0; i < numTerms; i++)
yaz_log(log_level_sort, "term=\"%s\" type=%s count=" ZINT_FORMAT,
terms[i]->name, terms[i]->flags, terms[i]->rset->hits_count);
kno++;
if (log_level_searchhits)
key_logdump_txt(log_level_searchhits, &key, termid->name);
- if (this_sys != psysno)
+ if (this_sys != psysno)
{ /* new record .. */
if (!(rfd->counted_items & 255) && zh->break_handler_func)
{
TERMID *term_array = xmalloc(num_terms * sizeof(*term_array));
zint *hits_array = xmalloc(num_terms * sizeof(*hits_array));
int *approx_array = xmalloc(num_terms * sizeof(*approx_array));
-
+
trav_rset_for_termids(sset->rset, term_array,
hits_array, approx_array);
{
char *outbuf = termbuf;
size_t ret;
-
+
ret = yaz_iconv(zh->iconv_from_utf8, &inbuf, &inleft,
&outbuf, &outleft);
if (ret == (size_t)(-1))
*termlen = 0;
else
{
- yaz_iconv(zh->iconv_from_utf8, 0, 0,
+ yaz_iconv(zh->iconv_from_utf8, 0, 0,
&outbuf, &outleft);
*termlen = outbuf - termbuf;
}
NMEM nmem = nmem_create();
struct it_key key;
RSET rsets[2], rset_comb;
- RSET rset_temp = rset_create_temp(nmem, kc, kc->scope,
+ RSET rset_temp = rset_create_temp(nmem, kc, kc->scope,
res_get(zh->res, "setTmpDir"),0 );
-
+
TERMID termid;
RSFD rsfd = rset_open(rset_temp, RSETF_WRITE);
-
+
key.mem[0] = sysno;
key.mem[1] = 0;
key.mem[2] = 0;
rsets[0] = rset_temp;
rsets[1] = rset_dup(sset->rset);
-
+
rset_comb = rset_create_and(nmem, kc, kc->scope, 2, rsets);
rsfd = rset_open(rset_comb, RSETF_READ);
}
}
rset_close(rsfd);
-
+
rset_delete(rset_comb);
nmem_destroy(nmem);
kc->dec(kc);
return ZEBRA_OK;
}
-static ZEBRA_RES zebra_recid_to_sysno(ZebraHandle zh,
+static ZEBRA_RES zebra_recid_to_sysno(ZebraHandle zh,
const char **basenames, int num_bases,
zint recid,
zint *sysnos, int *no_sysnos)
ZEBRA_RES res = ZEBRA_OK;
int sysnos_offset = 0;
int i;
-
+
if (!zh->reg->isamb || !zh->m_segment_indexing)
{
if (sysnos_offset < *no_sysnos)
char ord_buf[32];
int ord_len = key_SU_encode(ord, ord_buf);
char *info;
-
+
ord_buf[ord_len] = '\0';
-
+
info = dict_lookup(zh->reg->dict, ord_buf);
if (info)
{
struct it_key key_until, key_found;
int i = 0;
int r;
-
+
memcpy(&isam_p, info+1, sizeof(ISAM_P));
-
+
pt = isamb_pp_open(zh->reg->isamb, isam_p, 2);
if (!pt)
res = ZEBRA_FAIL;
key_until.mem[i++] = 0; /* segment */
key_until.mem[i++] = 0;
key_until.len = i;
-
+
r = isamb_pp_forward(pt, &key_found, &key_until);
while (r && key_found.mem[0] == recid)
{
if (sysnos_offset < *no_sysnos)
- sysnos[sysnos_offset++] =
+ sysnos[sysnos_offset++] =
key_found.mem[key_found.len-1];
r = isamb_pp_read(pt, &key_found);
}
return res;
}
-ZEBRA_RES zebra_result_recid_to_sysno(ZebraHandle zh,
+ZEBRA_RES zebra_result_recid_to_sysno(ZebraHandle zh,
const char *setname,
zint recid,
zint *sysnos, int *no_sysnos)
rset_close(rfd);
*count = rset->hits_count;
}
-
+
/*
* Local variables:
if (b->current_entry >= b->no_entries)
return 0;
-
+
t = b->ar[b->current_entry];
b->current_entry++;
-
+
key.len = 3;
key.mem[0] = t->word_id;
key.mem[1] = t->docid;
zint number_of_int_splits = isamb_get_int_splits(isb);
zint number_of_leaf_splits = isamb_get_leaf_splits(isb);
zint number_of_dict_splits = dict_get_no_split(dict);
-
+
b->ar = xmalloc(sizeof(*b->ar) * b->no_entries);
for (i = 0; i < b->no_entries; i++, t = t->next)
{
b->ar[i] = t;
}
assert(!t);
-
+
qsort(b->ar, b->no_entries, sizeof(*b->ar), cmp_ar);
tim_dict = yaz_timing_create();
#if 0
}
}
dict_insert(dict, "_w", sizeof(word_id_seq), &word_id_seq);
-
+
yaz_timing_stop(tim_dict);
tim_isamb = yaz_timing_create();
if (b->no_entries)
{
ISAMC_I isamc_i;
-
+
isamc_i.clientData = b;
isamc_i.read_item = code_read;
}
b->round++;
printf("%5d %9.6f %9.6f %5.2f %5.2f %9.6f %5.2f %5.2f "
- "%6" ZINT_FORMAT0 " %6" ZINT_FORMAT0
+ "%6" ZINT_FORMAT0 " %6" ZINT_FORMAT0
" %8d %8d %6d %6d" " %5" ZINT_FORMAT0 "\n",
b->round,
yaz_timing_get_real(tim_dict) + yaz_timing_get_real(tim_isamb),
{ /* continuation line */
for (i = 0; i<4 && *cp; i++, cp++)
;
- }
+ }
}
nl = 0;
if (*cp == '\n')
sz++;
}
cp++;
- }
+ }
}
if (sz)
index_term(b, term, docid, &seqno);
long off = ftell(inf) - 5;
if (verbose || print_offset)
printf("<!-- Skipping bad byte %d (0x%02X) at offset "
- "%ld (0x%lx) -->\n",
+ "%ld (0x%lx) -->\n",
*buf & 0xff, *buf & 0xff,
off, off);
for (i = 0; i<4; i++)
if (r < rlen)
break;
yaz_marc_read_iso2709(mt, buf, len);
-
+
if (yaz_marc_write_line(mt, wrbuf))
break;
}
break;
case 'c':
- if (sscanf(arg, "%d:%d", &dict_cache_size, &isam_cache_size)
+ if (sscanf(arg, "%d:%d", &dict_cache_size, &isam_cache_size)
!= 2)
{
fprintf(stderr, "bad cache sizes for -c\n");
exit_usage();
}
}
-
+
if (fname)
{
inf = fopen(fname, "rb");
}
if (!strcmp(type, "iso2709"))
- index_marc_from_file(isb_postings, dict, &docid_seq, inf, memory,
+ index_marc_from_file(isb_postings, dict, &docid_seq, inf, memory,
0 /* verbose */ , 0 /* print_offset */);
else if (!strcmp(type, "line"))
index_marc_line_records(isb_postings, dict, &docid_seq, inf, memory);
yaz_timing_get_real(tim),
yaz_timing_get_user(tim),
yaz_timing_get_sys(tim));
-
+
yaz_timing_destroy(&tim);
exit(0);
ri.step = 1;
ri.insertMode = 1;
ri.sz = sizeof(int) + 1 + extra_size;
-
+
for (round = 0; round < number_of_rounds; round++)
{
yaz_timing_t t = yaz_timing_create();
/* insert a number of entries */
ri.no = 0;
-
+
ri.val = (rand());
- if (RAND_MAX < 65536)
+ if (RAND_MAX < 65536)
ri.val = ri.val + 65536*rand();
// ri.val = number_of_elements * round;
ri.max = number_of_elements;
-
+
isamc_i.clientData = &ri;
isamc_i.read_item = code_read;
-
+
isamb_merge (isb, &isamc_p[i] , &isamc_i);
if (0)
int number_of_isams = 1000;
int extra_size = 0;
yaz_timing_t t = 0;
-
+
while ((ret = options("z:r:n:i:", argv, argc, &arg)) != -2)
{
switch(ret)
exit_usage();
}
}
-
+
/* setup method (attributes) */
method.compare_item = compare_item;
method.log_item = log_item;
method.codec.stop = code_stop;
t = yaz_timing_create();
-
+
yaz_timing_start(t);
/* create block system */
}
bench_insert(isb, number_of_isams, number_of_rounds, number_of_items,
extra_size);
-
+
isamb_close(isb);
/* exit block system */
int log_io; /* log level for bf_read/bf_write calls */
int log_freelist; /* log level for freelist handling */
zint skipped_numbers; /* on a leaf node */
- zint returned_numbers;
+ zint returned_numbers;
zint skipped_nodes[ISAMB_MAX_LEVEL]; /* [0]=skipped leaves, 1 = higher etc */
zint accessed_nodes[ISAMB_MAX_LEVEL]; /* nodes we did not skip */
zint number_of_int_splits;
zint total_size;
zint no_blocks;
zint skipped_numbers; /* on a leaf node */
- zint returned_numbers;
+ zint returned_numbers;
zint skipped_nodes[ISAMB_MAX_LEVEL]; /* [0]=skipped leaves, 1 = higher etc */
zint accessed_nodes[ISAMB_MAX_LEVEL]; /* nodes we did not skip */
struct ISAMB_block **block;
pos++;
if (!bf_read(isamb->file[i].bf, pos, 0, 0, hbuf + pos*sizes[i]))
{
- yaz_log(YLOG_WARN, "truncated isamb header for "
+ yaz_log(YLOG_WARN, "truncated isamb header for "
"file=%s len=%d pos=%d",
fname, len, pos);
isamb_close(isamb);
{
int sizes[CAT_NO];
int i, b_size = ISAMB_MIN_SIZE;
-
+
for (i = 0; i<CAT_NO; i++)
{
sizes[i] = b_size;
static int cache_block(ISAMB b, ISAM_P pos, unsigned char *userbuf, int wr)
{
int cat = (int) (pos&CAT_MASK);
- int off = (int) (((pos/CAT_MAX) &
+ int off = (int) (((pos/CAT_MAX) &
(ISAMB_CACHE_ENTRY_SIZE / b->file[cat].head.block_size - 1))
* b->file[cat].head.block_size);
zint norm = pos / (CAT_MASK*ISAMB_CACHE_ENTRY_SIZE / b->file[cat].head.block_size);
{
ce_this = *ce;
*ce = (*ce)->next; /* remove from list */
-
+
ce_this->next = b->file[cat].cache_entries; /* move to front */
b->file[cat].cache_entries = ce_this;
-
+
if (wr)
{
- memcpy(ce_this->buf + off, userbuf,
+ memcpy(ce_this->buf + off, userbuf,
b->file[cat].head.block_size);
ce_this->dirty = 1;
}
0: leader byte, != 0 leaf, == 0, non-leaf
1-2: used size of block
3-7*: number of items and all children
-
+
* Reserve 5 bytes for large block sizes. 1 for small ones .. Number
- of items. We can thus have at most 2^40 nodes.
+ of items. We can thus have at most 2^40 nodes.
*/
static struct ISAMB_block *open_block(ISAMB b, ISAM_P pos)
{
block_no = b->file[cat].head.last_block++;
p->pos = block_no * CAT_MAX + cat;
if (b->log_freelist)
- yaz_log(b->log_freelist, "got block "
+ yaz_log(b->log_freelist, "got block "
ZINT_FORMAT " from last %d:" ZINT_FORMAT, p->pos,
cat, p->pos/CAT_MAX);
}
}
}
if (b->log_freelist)
- yaz_log(b->log_freelist, "got block "
+ yaz_log(b->log_freelist, "got block "
ZINT_FORMAT " from freelist %d:" ZINT_FORMAT, p->pos,
cat, p->pos/CAT_MAX);
memcpy(&b->file[cat].head.free_list, p->buf, sizeof(zint));
char *endp = p->bytes + p->size;
ISAM_P pos;
void *c1 = (*b->method->codec.start)();
-
+
decode_ptr(&src, &pos);
assert((pos&CAT_MASK) == p->cat);
while (src != endp)
int size = p->size + offset;
char *dst = (char*)p->buf + 3;
assert(p->size >= 0);
-
+
/* memset becuase encode_ptr usually does not write all bytes */
memset(p->buf, 0, b->file[p->cat].head.block_offset);
p->buf[0] = p->leaf;
assert(sub_p1);
diff_terms -= sub_p1->no_items;
more = insert_sub(b, &sub_p1, lookahead_item, mode,
- stream, &sub_p2,
+ stream, &sub_p2,
sub_item, &sub_size, file_item_buf);
diff_terms += sub_p1->no_items;
src = src0;
assert(sub_p1);
diff_terms -= sub_p1->no_items;
more = insert_sub(b, &sub_p1, lookahead_item, mode,
- stream, &sub_p2,
+ stream, &sub_p2,
sub_item, &sub_size, src);
diff_terms += sub_p1->no_items;
src = src0;
sub_p1 = open_block(b, pos);
assert(sub_p1);
diff_terms -= sub_p1->no_items;
- more = insert_sub(b, &sub_p1, lookahead_item, mode, stream, &sub_p2,
+ more = insert_sub(b, &sub_p1, lookahead_item, mode, stream, &sub_p2,
sub_item, &sub_size, last_max_item);
diff_terms += sub_p1->no_items;
}
assert(sub_size < DST_ITEM_MAX && sub_size > 1);
memcpy(dst, startp, src - startp);
-
+
dst += src - startp;
#if INT_ENCODE
const char *half;
src = dst_buf;
endp = dst;
-
+
b->number_of_int_splits++;
p->dirty = 1;
{
char file_item_buf[DST_ITEM_MAX];
char *file_item = file_item_buf;
-
+
src = p->bytes;
endp = p->bytes + p->size;
(*b->method->codec.decode)(c1, &file_item, &src);
char *lookahead_next;
char *dst_0 = dst;
int d = -1;
-
+
if (lookahead_item)
d = (*b->method->compare_item)(file_item_buf, lookahead_item);
-
+
/* d now holds comparison between existing file item and
- lookahead item
+ lookahead item
d = 0: equal
d > 0: lookahead before file
d < 0: lookahead after file
}
else if (d == 0 && *lookahead_mode == 2)
{
- /* For mode == 2, we insert the new key anyway - even
+ /* For mode == 2, we insert the new key anyway - even
though the comparison is 0. */
dst_item = lookahead_item;
p->dirty = 1;
/* encode the resulting item */
(*b->method->codec.encode)(c2, &dst, &dst_item);
-
+
cut_item_size = dst_item - dst_item_0;
assert(cut_item_size > 0);
memcpy(cut_item_buf, dst_item_0, cut_item_size);
-
+
half2 = dst;
no_items_1 = no_items;
no_items++;
}
/* now move "pointers" .. result has been encoded .. */
- if (d > 0)
+ if (d > 0)
{
/* we must move the lookahead pointer */
leaf. Mark it as "gone" */
lookahead_item = 0;
}
-
+
p->dirty = 1;
}
}
char *dst_item;
const char *src = lookahead_item;
char *dst_0 = dst;
-
+
/* if we have a lookahead item, we stop if we exceed the value of it */
if (max_item &&
(*b->method->compare_item)(max_item, lookahead_item) <= 0)
{
const char *src_0 = src;
half1 = dst; /* candidate for splitting */
-
+
(*b->method->codec.encode)(c2, &dst, &src);
-
+
cut_item_size = src - src_0;
assert(cut_item_size > 0);
memcpy(cut_item_buf, src_0, cut_item_size);
-
+
no_items_1 = no_items;
half2 = dst;
}
}
}
new_size = dst - dst_buf;
- if (p && p->cat != b->no_cat-1 &&
+ if (p && p->cat != b->no_cat-1 &&
new_size > b->file[p->cat].head.block_max)
{
/* non-btree block will be removed */
assert(half2);
assert(cut_item_size > 0);
-
+
/* first half */
p->size = half1 - dst_buf;
assert(p->size <= b->file[p->cat].head.block_max);
const void *max_item)
{
if (!*p || (*p)->leaf)
- return insert_leaf(b, p, new_item, mode, stream, sp, sub_item,
+ return insert_leaf(b, p, new_item, mode, stream, sp, sub_item,
sub_size, max_item);
else
return insert_int(b, *p, new_item, mode, stream, sp, sub_item,
#endif
decode_ptr(&src, &sub_p);
isamb_unlink(b, sub_p);
-
+
while (src != p1->bytes + p1->size)
{
#if INT_ENCODE
struct ISAMB_block *p = 0, *sp = 0;
char sub_item[DST_ITEM_MAX];
int sub_size;
-
+
if (*pos)
p = open_block(b, *pos);
more = insert_sub(b, &p, item_buf, &i_mode, stream, &sp,
dst += sub_size;
#endif
encode_ptr(&dst, sp->pos);
-
+
p2->size = dst - p2->bytes;
p2->no_items = p->no_items + sp->no_items;
*pos = p2->pos; /* return new super page */
decode_ptr(&src, &pos);
p->offset = src - p->bytes;
pp->level++;
- pp->accessed_nodes[pp->level]++;
+ pp->accessed_nodes[pp->level]++;
}
pp->block[pp->level+1] = 0;
pp->maxlevel = pp->level;
int i;
if (!pp)
return;
- yaz_log(YLOG_DEBUG, "isamb_pp_close lev=%d returned "ZINT_FORMAT" values, "
+ yaz_log(YLOG_DEBUG, "isamb_pp_close lev=%d returned "ZINT_FORMAT" values, "
"skipped "ZINT_FORMAT,
pp->maxlevel, pp->skipped_numbers, pp->returned_numbers);
for (i = pp->maxlevel; i>=0; i--)
p->offset = src - (char*) p->bytes;
isamb_dump_r(b, sub, pr, level+1);
-
+
while (p->offset < p->size)
{
#if INT_ENCODE
src += item_len;
#endif
decode_ptr(&src, &sub);
-
+
p->offset = src - (char*) p->bytes;
-
+
isamb_dump_r(b, sub, pr, level+1);
- }
+ }
}
close_block(b, p);
}
/* occureences in the isam tree, based on the current leaf */
assert(total);
assert(current);
-
+
/* if end-of-stream PP may not be leaf */
*total = (double) (pp->block[0]->no_items);
pp->block[pp->level] = 0;
(pp->level)--;
p = pp->block[pp->level];
- assert(!p->leaf);
+ assert(!p->leaf);
}
assert(!p->leaf);
src = p->bytes + p->offset;
-
+
#if INT_ENCODE
c1 = (*b->method->codec.start)();
(*b->method->codec.decode)(c1, &file_item, &src);
#else
decode_ptr(&src, &item_len);
src += item_len;
-#endif
+#endif
decode_ptr(&src, &pos);
p->offset = src - (char*) p->bytes;
pp->total_size += p->size;
pp->no_blocks++;
-
- if (p->leaf)
+
+ if (p->leaf)
{
break;
}
-
+
src = p->bytes + p->offset;
while(1)
{
decode_ptr(&src, &pos);
p->offset = src - (char*) p->bytes;
-
+
if (!untilb || p->offset == p->size)
break;
assert(p->offset < p->size);
dst = dst0;
if (p->offset == p->size) goto again;
}
- pp->returned_numbers++;
+ pp->returned_numbers++;
return 1;
}
isamc_i.clientData = &ri;
isamc_i.read_item = code_read;
-
+
isamc_p = 0; /* new list */
isamb_merge (isb, &isamc_p , &isamc_i);
isamc_i.clientData = &ri;
isamc_i.read_item = code_read;
-
+
isamb_merge (isb, &isamc_p , &isamc_i);
/* delete a number of entries (odd ones) */
isamc_i.clientData = &ri;
isamc_i.read_item = code_read;
-
+
isamb_merge (isb, &isamc_p, &isamc_i);
if (isamc_p)
isamc_i.clientData = &ri;
isamc_i.read_item = code_read;
-
+
isamc_p = 0;
isamb_merge (isb, &isamc_p, &isamc_i);
/* read the entries */
pp = isamb_pp_open (isb, isamc_p, 1);
-
+
for (i = 0; i<ri.max; i +=2 )
{
int x = -1;
ri.no++;
}
isamb_pp_close(pp);
-
+
pp = isamb_pp_open (isb, isamc_p, 1);
for (i = 0; i<ri.max; i += 100)
{
ri.val = 0;
ri.step = 1;
ri.insertMode = 1;
-
+
isamc_i.clientData = &ri;
isamc_i.read_item = code_read;
-
+
isamb_merge (isb, &isamb_p , &isamc_i);
}
}
}
if (ri->idx >= ri->max)
return 0;
-
+
if (ri->delta[ri->idx] > 0)
{
ri->level++;
int i, j;
for (i = 0; i<n; i++)
freq[i] = 0;
-
+
for (j = 0; j<rounds; j++)
{
yaz_log(YLOG_DEBUG, "round %d", j);
{
ISAMC_I isamc_i;
struct random_read_info ri;
-
+
ri.delta = delta;
ri.idx = 0;
ri.max = n;
ri.level = 0;
-
+
isamc_i.clientData = &ri;
isamc_i.read_item = tst_random_read;
isamb_merge (isb, &isamb_p , &isamc_i);
}
-
+
yaz_log(YLOG_DEBUG, "dump %d", j);
isamb_dump(isb, isamb_p, log_pr);
isamc_i.clientData = &ri;
/* all have same value = 1 */
- ri.val = 1;
+ ri.val = 1;
ri.step = 0;
isamc_i.read_item = code_read;
isamb_merge (isb, &isamb_p , &isamc_i);
isamb_dump(isb, isamb_p, log_pr);
-
+
ri.no = 0;
ri.max = n - n/2;
BFiles bfs;
ISAMB isb;
ISAMC_M method;
-
+
if (argc == 2)
yaz_log_init_level(YLOG_ALL);
-
+
/* setup method (attributes) */
method.compare_item = compare_item;
method.log_item = log_item;
if (0)
identical_keys_tests(isb);
-
+
isamb_close(isb);
/* exit block system */
ISAMC_head head;
BFile bf;
int head_is_dirty;
-
+
int no_writes;
int no_reads;
int no_skip_writes;
char *merge_buf;
ISAMC_M *method;
ISAMC_file files;
-};
+};
struct ISAMC_PP_s {
char *buf;
zint numKeys;
};
-/*
+/*
first block consists of
next pointer : zint
size : ISAMC_BLOCK_SIZE (int)
size : ISAMC_BLOCK_SIZE (int)
data
*/
-#define ISAMC_BLOCK_OFFSET_1 (sizeof(zint)+sizeof(ISAMC_BLOCK_SIZE)+sizeof(zint))
-#define ISAMC_BLOCK_OFFSET_N (sizeof(zint)+sizeof(ISAMC_BLOCK_SIZE))
+#define ISAMC_BLOCK_OFFSET_1 (sizeof(zint)+sizeof(ISAMC_BLOCK_SIZE)+sizeof(zint))
+#define ISAMC_BLOCK_OFFSET_N (sizeof(zint)+sizeof(ISAMC_BLOCK_SIZE))
zint isamc_alloc_block (ISAMC is, int cat);
void isamc_release_block (ISAMC is, int cat, zint pos);
*/
-/*
+/*
* TODO:
* Reduction to lower categories in isamc_merge
*/
{
if (is->method->debug)
yaz_log (YLOG_LOG, "isc:%6d %6d %6d %6d",
- filecat[i].bsize, filecat[i].ifill,
+ filecat[i].bsize, filecat[i].ifill,
filecat[i].mfill, filecat[i].mblocks);
if (max_buf_size < filecat[i].mblocks * filecat[i].bsize)
max_buf_size = filecat[i].mblocks * filecat[i].bsize;
max_buf_size = (1+is->method->max_blocks_mem) * filecat[i].bsize;
if (is->method->debug)
yaz_log (YLOG_LOG, "isc: max_buf_size %d", max_buf_size);
-
+
assert (is->no_files > 0);
is->files = (ISAMC_file) xmalloc (sizeof(*is->files)*is->no_files);
if (writeflag)
{
memcpy (abuf + sizeof(int), &block, sizeof(zint));
is->files[cat].head.freelist = pos;
- is->files[cat].head_is_dirty = 1;
+ is->files[cat].head_is_dirty = 1;
}
else
{
static void release_block (ISAMC is, int cat, zint pos)
{
char buf[sizeof(zint)];
-
+
(is->files[cat].no_released)++;
- is->files[cat].head_is_dirty = 1;
+ is->files[cat].head_is_dirty = 1;
memcpy (buf, &is->files[cat].head.freelist, sizeof(zint));
is->files[cat].head.freelist = pos;
bf_write (is->files[cat].bf, pos, 0, sizeof(zint), buf);
static void init_fc (ISAMC is, int cat)
{
int j = 100;
-
+
is->files[cat].fc_max = j;
is->files[cat].fc_list = (zint *)
xmalloc (sizeof(*is->files[0].fc_list) * j);
{
ISAMC_PP pp = (ISAMC_PP) xmalloc (sizeof(*pp));
char *src;
-
+
pp->cat = (int) isamc_type(ipos);
- pp->pos = isamc_block(ipos);
+ pp->pos = isamc_block(ipos);
src = pp->buf = (char *) xmalloc (is->method->filecat[pp->cat].bsize);
yaz_log(YLOG_FATAL|YLOG_LOG, "pp->pos = " ZINT_FORMAT, pp->pos);
assert (pp->next != pp->pos);
}
- pp->offset = src - pp->buf;
+ pp->offset = src - pp->buf;
assert (pp->offset == ISAMC_BLOCK_OFFSET_1);
if (is->method->debug > 2)
yaz_log (YLOG_LOG, "isc: read_block size=%d %d " ZINT_FORMAT " next="
if (pp->deleteFlag)
isamc_release_block (is, pp->cat, pp->pos);
(*is->method->codec.decode)(pp->decodeClientData, dst, &src);
- pp->offset = src - pp->buf;
+ pp->offset = src - pp->buf;
if (is->method->debug > 2)
yaz_log (YLOG_LOG, "isc: read_block size=%d %d " ZINT_FORMAT " next="
ZINT_FORMAT, pp->size, pp->cat, pp->pos, pp->next);
return 2;
}
(*is->method->codec.decode)(pp->decodeClientData, dst, &src);
- pp->offset = src - pp->buf;
+ pp->offset = src - pp->buf;
return 1;
}
for (i = 0; i<ptr; i++)
{
/* consider this block number */
- if (!mb[i].block)
+ if (!mb[i].block)
{
mb[i].block = isamc_alloc_block (is, cat);
mb[i].dirty = 1;
/* consider next block pointer */
if (last && i == ptr-1)
mb[i+1].block = 0;
- else if (!mb[i+1].block)
+ else if (!mb[i+1].block)
{
mb[i+1].block = isamc_alloc_block (is, cat);
mb[i+1].dirty = 1;
/* Border set to initial fill or block size depending on
whether we are creating a new one or updating and old one.
*/
-
+
int fill = mb[ptr].block ? is->method->filecat[cat].bsize :
is->method->filecat[cat].ifill;
int off = (ptr||firstpos) ? ISAMC_BLOCK_OFFSET_N : ISAMC_BLOCK_OFFSET_1;
-
+
assert (ptr < 199);
return mb[ptr].offset + fill - off;
char i_item[128], *i_item_ptr;
int i_more, i_mode, i;
- ISAMC_PP pp;
+ ISAMC_PP pp;
char f_item[128], *f_item_ptr;
int f_more;
int last_dirty = 0;
int debug = is->method->debug;
-
+
struct isamc_merge_block mb[200];
zint firstpos = 0;
{
/* block to block boundary in the original file. */
f_more = 1;
- if (cat == pp->cat)
+ if (cat == pp->cat)
{
/* the resulting output is of the same category as the
- the original
+ the original
*/
if (r_offset <= mb[ptr].offset +is->method->filecat[cat].mfill)
{
int new_offset;
(*is->method->codec.encode)(r_clientData, &r_out_ptr, &src);
- new_offset = r_out_ptr - r_buf;
+ new_offset = r_out_ptr - r_buf;
numKeys++;
if (cat < is->max_cat && ptr >= is->method->filecat[cat].mblocks)
{
/* Max number blocks in current category reached ->
- must switch to next category (with larger block size)
+ must switch to next category (with larger block size)
*/
int j = 0;
}
if (mb[ptr].offset < r_offset)
{ /* make the final boundary offset */
- mb[++ptr].dirty = 1;
- mb[ptr].block = 0;
+ mb[++ptr].dirty = 1;
+ mb[ptr].block = 0;
mb[ptr].offset = r_offset;
}
else
int block_size;
int debug;
BFile bf;
-};
+};
struct ISAMS_PP_s {
ISAMS is;
char *tmp_ptr = i_item;
i_more = (*data->read_item)(data->clientData, &tmp_ptr, &i_mode);
assert (i_mode);
-
+
if (!i_more)
break;
else
{
char *r_out_ptr = is->merge_buf + is->head.last_offset;
-
+
const char *i_item_ptr = i_item;
(*is->method->codec.encode)(r_clientData, &r_out_ptr, &i_item_ptr);
is->head.last_offset = r_out_ptr - is->merge_buf;
}
src = pp->buf + pp->block_offset;
(*pp->is->method->codec.decode)(pp->decodeClientData, dst, &src);
- pp->block_offset = src - pp->buf;
+ pp->block_offset = src - pp->buf;
return 1;
}
/* rsbetween is (mostly) used for xml searches. It returns the hits of the
* "middle" rset, that are in between the "left" and "right" rsets. For
- * example "Shakespeare" in between "<author>" and </author>. The thing is
+ * example "Shakespeare" in between "<author>" and </author>. The thing is
* complicated by the inclusion of attributes (from their own rset). If attrs
* specified, they must match the "left" rset (start tag). "Hamlet" between
* "<title lang = eng>" and "</title>". (This assumes that the attributes are
* indexed to the same seqno as the tags).
*
-*/
+*/
#if HAVE_CONFIG_H
#include <config.h>
static RSFD r_open(RSET ct, int flag);
static void r_close(RSFD rfd);
static void r_delete(RSET ct);
-static int r_forward(RSFD rfd, void *buf,
+static int r_forward(RSFD rfd, void *buf,
TERMID *term, const void *untilbuf);
static int r_read(RSFD rfd, void *buf, TERMID *term );
static int r_write(RSFD rfd, const void *buf);
static void r_pos(RSFD rfd, double *current, double *total);
static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm);
-static const struct rset_control control =
+static const struct rset_control control =
{
"between",
r_delete,
r_get_terms,
r_open,
r_close,
- r_forward,
+ r_forward,
r_pos,
r_read,
r_write,
int depth; /* number of start-tags without end-tags */
int attrdepth; /* on what depth the attr matched */
zint hits;
-};
+};
static int log_level = 0;
static int log_level_initialized = 0;
(struct rset_between_info *) nmem_malloc(rnew->nmem,sizeof(*info));
RSET rsetarray[4];
int n = 4;
-
+
if (!log_level_initialized)
{
log_level = yaz_log_module_level("rsbetween");
else
{
info->attrterm = NULL;
- n = 3;
+ n = 3;
}
rnew->no_children = 1;
rnew->children = nmem_malloc(rnew->nmem, sizeof(RSET *));
- rnew->children[0] = rset_create_and(nmem, kcontrol,
+ rnew->children[0] = rset_create_and(nmem, kcontrol,
scope, n, rsetarray);
rnew->priv = info;
yaz_log(log_level, "create rset at %p", rnew);
return NULL;
}
rfd = rfd_create_base(ct);
- if (rfd->priv)
+ if (rfd->priv)
p=(struct rset_between_rfd *)rfd->priv;
else {
p = (struct rset_between_rfd *) nmem_malloc(ct->nmem, (sizeof(*p)));
rfd->priv = p;
- p->recbuf = nmem_malloc(ct->nmem, ct->keycontrol->key_size);
- p->startbuf = nmem_malloc(ct->nmem, ct->keycontrol->key_size);
- p->attrbuf = nmem_malloc(ct->nmem, ct->keycontrol->key_size);
+ p->recbuf = nmem_malloc(ct->nmem, ct->keycontrol->key_size);
+ p->startbuf = nmem_malloc(ct->nmem, ct->keycontrol->key_size);
+ p->attrbuf = nmem_malloc(ct->nmem, ct->keycontrol->key_size);
}
p->andrfd = rset_open(ct->children[0], RSETF_READ);
p->hits = -1;
rset_close(p->andrfd);
}
-static int r_forward(RSFD rfd, void *buf,
+static int r_forward(RSFD rfd, void *buf,
TERMID *term, const void *untilbuf)
{
struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv;
int cmp;
if (p->attrdepth)
return; /* already found one */
- if (!info->attrterm)
+ if (!info->attrterm)
{
p->attrdepth=-1; /* matches always */
return;
{
yaz_log(log_level,"read loop term=%p d=%d ad=%d",
*term, p->depth, p->attrdepth);
- if (p->hits<0)
+ if (p->hits<0)
{/* first time? */
memcpy(p->recbuf, buf, kctrl->key_size);
p->hits = 0;
}
if (cmp>=rfd->rset->scope)
- {
+ {
yaz_log(log_level, "new record");
p->depth = 0;
p->attrdepth = 0;
p->attrbufok = 1;
checkattr(rfd); /* in case the start tag came first */
}
- else
+ else
{ /* mut be a real hit */
if (p->depth && p->attrdepth)
{
p->hits++;
- yaz_log(log_level,"got a hit h="ZINT_FORMAT" d=%d ad=%d",
+ yaz_log(log_level,"got a hit h="ZINT_FORMAT" d=%d ad=%d",
p->hits, p->depth, p->attrdepth);
return 1; /* we have everything in place already! */
} else
rset_getterms(ct->children[0], terms, maxterms, curterm);
}
-
+
/*
* Local variables:
* c-basic-offset: 4
static void r_close(RSFD rfd);
static void r_delete(RSET ct);
static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf);
-static void r_pos(RSFD rfd, double *current, double *total);
+static void r_pos(RSFD rfd, double *current, double *total);
static int r_read_not(RSFD rfd, void *buf, TERMID *term);
static int r_write(RSFD rfd, const void *buf);
static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm);
-static const struct rset_control control_not =
+static const struct rset_control control_not =
{
"not",
r_delete,
r_get_terms,
r_open,
r_close,
- r_forward,
+ r_forward,
r_pos,
r_read_not,
r_write,
TERMID term_l;
TERMID term_r;
int tail;
-};
+};
static RSET rsbool_create_base(const struct rset_control *ctrl,
NMEM nmem,
p->more_l = rset_forward(p->rfd_l, p->buf_l, &p->term_l, untilbuf);
if ( p->more_r && ((kctrl->cmp)(untilbuf,p->buf_r)>=rfd->rset->scope))
p->more_r = rset_forward(p->rfd_r, p->buf_r, &p->term_r, untilbuf);
- p->tail = 0;
- return rset_read(rfd,buf,term);
+ p->tail = 0;
+ return rset_read(rfd,buf,term);
}
}
else if (cmp >= rfd->rset->scope) /* cmp >1 */
{
- p->more_r = rset_forward( p->rfd_r, p->buf_r,
+ p->more_r = rset_forward( p->rfd_r, p->buf_r,
&p->term_r, p->buf_l);
}
else
if (term)
*term = p->term_l;
do
- {
+ {
p->more_l = rset_read(p->rfd_l, p->buf_l, &p->term_l);
if (!p->more_l)
break;
*current = rcur; /* return same as you got */
*total = rtot; /* probably -1 for not available */
}
- if (rtot < 0)
- rtot = rcur = 0; /* if only one useful, use it */
- if (ltot < 0)
+ if (rtot < 0)
+ rtot = rcur = 0; /* if only one useful, use it */
+ if (ltot < 0)
ltot = lcur = 0;
- if (rtot+ltot < 1)
+ if (rtot+ltot < 1)
{ /* empty rset */
*current = *total = 0;
return;
}
r = 1.0*(lcur+rcur)/(ltot+rtot); /* weighed average of l and r */
*current = (double) (p->hits);
- *total = *current/r ;
+ *total = *current/r ;
#if RSET_DEBUG
yaz_log(YLOG_DEBUG,"bool_pos: (%s/%s) %0.1f/%0.1f= %0.4f ",
info->rset_l->control->desc, info->rset_r->control->desc,
/**
\brief Common constuctor for RFDs
\param rs Result set handle.
-
- Creates an rfd. Either allocates a new one, in which case the priv
- pointer is null, and will have to be filled in, or picks up one
+
+ Creates an rfd. Either allocates a new one, in which case the priv
+ pointer is null, and will have to be filled in, or picks up one
from the freelist, in which case the priv is already allocated,
- and presumably everything that hangs from it as well
+ and presumably everything that hangs from it as well
*/
RSFD rfd_create_base(RSET rs)
{
RSFD rnew = rs->free_list;
- if (rnew)
+ if (rnew)
{
rs->free_list = rnew->next;
assert(rnew->rset==rs);
- yaz_log(log_level, "rfd_create_base (fl): rfd=%p rs=%p fl=%p priv=%p",
- rnew, rs, rs->free_list, rnew->priv);
- }
+ yaz_log(log_level, "rfd_create_base (fl): rfd=%p rs=%p fl=%p priv=%p",
+ rnew, rs, rs->free_list, rnew->priv);
+ }
else
{
rnew = nmem_malloc(rs->nmem, sizeof(*rnew));
rnew->counted_buf = nmem_malloc(rs->nmem, rs->keycontrol->key_size);
rnew->priv = 0;
rnew->rset = rs;
- yaz_log(log_level, "rfd_create_base (new): rfd=%p rs=%p fl=%p priv=%p",
- rnew, rs, rs->free_list, rnew->priv);
+ yaz_log(log_level, "rfd_create_base (new): rfd=%p rs=%p fl=%p priv=%p",
+ rnew, rs, rs->free_list, rnew->priv);
}
rnew->next = rs->use_list;
rs->use_list = rnew;
{
RSFD *pfd;
(*rs->control->f_close)(rfd);
-
+
yaz_log(log_level, "rfd_delete_base: rfd=%p rs=%p priv=%p fl=%p",
- rfd, rs, rfd->priv, rs->free_list);
+ rfd, rs, rfd->priv, rs->free_list);
for (pfd = &rs->use_list; *pfd; pfd = &(*pfd)->next)
if (*pfd == rfd)
{
while (rfd->counted_items <= rs->hits_limit
&& rset_default_read(rfd, buf, &termid))
;
-
+
rs->hits_count = rfd->counted_items;
yaz_log(log_level, "rset_close rset=%p hits_count=" ZINT_FORMAT
" hits_limit=" ZINT_FORMAT,
{
double cur, tot;
zint est;
- rset_pos(rfd, &cur, &tot);
+ rset_pos(rfd, &cur, &tot);
if (tot > 0) {
int i;
double ratio = cur/tot;
rs->hits_approx = 1;
}
}
- yaz_log(log_level, "rset_close(%s) p=%p count=" ZINT_FORMAT,
+ yaz_log(log_level, "rset_close(%s) p=%p count=" ZINT_FORMAT,
rs->control->desc, rs,
rs->hits_count);
}
\param term Information about term for it (NULL for none).
\param no_children number of child rsets (0 for none)
\param children child rsets (NULL for none).
-
- Creates an rfd. Either allocates a new one, in which case the priv
- pointer is null, and will have to be filled in, or picks up one
+
+ Creates an rfd. Either allocates a new one, in which case the priv
+ pointer is null, and will have to be filled in, or picks up one
from the freelist, in which case the priv is already allocated,
- and presumably everything that hangs from it as well
+ and presumably everything that hangs from it as well
*/
-RSET rset_create_base(const struct rset_control *sel,
+RSET rset_create_base(const struct rset_control *sel,
NMEM nmem, struct rset_key_control *kcontrol,
int scope, TERMID term,
int no_children, RSET *children)
{
RSET rset;
assert(nmem);
- if (!log_level_initialized)
+ if (!log_level_initialized)
{
log_level = yaz_log_module_level("rset");
log_level_initialized = 1;
}
rset = (RSET) nmem_malloc(nmem, sizeof(*rset));
- yaz_log(log_level, "rs_create(%s) rs=%p (nm=%p)", sel->desc, rset, nmem);
- yaz_log(log_level, " ref_id=%s",
+ yaz_log(log_level, "rs_create(%s) rs=%p (nm=%p)", sel->desc, rset, nmem);
+ yaz_log(log_level, " ref_id=%s",
(term && term->ref_id ? term->ref_id : "null"));
rset->nmem = nmem;
rset->control = sel;
/**
\brief Destructor RSETs
\param rs Handle for result set.
-
+
Destroys a result set and all its children.
The f_delete method of control is called for the result set.
*/
{
(rs->refcount)--;
yaz_log(log_level, "rs_delete(%s), rs=%p, refcount=%d",
- rs->control->desc, rs, rs->refcount);
+ rs->control->desc, rs, rs->refcount);
if (!rs->refcount)
{
int i;
/**
\brief Test for last use of RFD
\param rfd RFD handle.
-
+
Returns 1 if this RFD is the last reference to it; 0 otherwise.
*/
int rfd_is_last(RSFD rfd)
/**
\brief Duplicate an RSET
\param rs Handle for result set.
-
+
Duplicates a result set by incrementing the reference count to it.
*/
RSET rset_dup (RSET rs)
{
(rs->refcount)++;
yaz_log(log_level, "rs_dup(%s), rs=%p, refcount=%d",
- rs->control->desc, rs, rs->refcount);
+ rs->control->desc, rs, rs->refcount);
return rs;
}
-/**
+/**
\brief Estimates hit count for result set.
\param rs Result Set.
got_scope = rset->scope+1;
else
got_scope = rset->keycontrol->cmp(buf, rfd->counted_buf);
-
+
#if 0
key_logdump_txt(YLOG_LOG, buf, "rset_default_read");
yaz_log(YLOG_LOG, "rset_scope=%d got_scope=%d", rset->scope, got_scope);
assert (rset->control->f_forward != rset_default_forward);
return rset->control->f_forward(rfd, buf, term, untilbuf);
}
-
+
while ((more = rset_read(rfd, buf, term)) > 0)
{
if ((rfd->rset->keycontrol->cmp)(untilbuf, buf) < rset->scope)
if (log_level)
yaz_log(log_level, "rset_default_forward exiting rfd=%p scope=%d m=%d c=%d",
rfd, rset->scope, more, rset->scope);
-
+
return more;
}
static int r_read_filter(RSFD rfd, void *buf, TERMID *term);
static int r_write(RSFD rfd, const void *buf);
-static const struct rset_control control =
+static const struct rset_control control =
{
"isamb",
r_delete,
rset_get_one_term,
r_open,
r_close,
- r_forward,
+ r_forward,
r_pos,
r_read,
r_write,
};
-static const struct rset_control control_filter =
+static const struct rset_control control_filter =
{
"isamb",
r_delete,
rset_get_one_term,
r_open,
r_close,
- r_forward,
+ r_forward,
r_pos,
r_read_filter,
r_write,
if (rc && term)
*term = rfd->rset->term;
yaz_log(log_level, "rsisamb_forward");
- return rc;
+ return rc;
}
static void r_pos(RSFD rfd, double *current, double *total)
static int r_write (RSFD rfd, const void *buf);
static void r_pos (RSFD rfd, double *current, double *total);
-static const struct rset_control control =
+static const struct rset_control control =
{
"isamc",
r_delete,
static int r_write (RSFD rfd, const void *buf);
static void r_pos (RSFD rfd, double *current, double *total);
-static const struct rset_control control =
+static const struct rset_control control =
{
"isams",
r_delete,
static void r_pos_or(RSFD rfd, double *current, double *total);
static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm);
-static const struct rset_control control_or =
+static const struct rset_control control_or =
{
"multi-or",
r_delete,
r_write,
};
-static const struct rset_control control_and =
+static const struct rset_control control_and =
{
"multi-and",
r_delete,
r_write,
};
-/* The heap structure:
- * The rset contains a list or rsets we are ORing together
+/* The heap structure:
+ * The rset contains a list or rsets we are ORing together
* The rfd contains a heap of heap-items, which contain
* a rfd opened to those rsets, and a buffer for one key.
- * They also contain a ptr to the rset list in the rset
- * itself, for practical reasons.
+ * They also contain a ptr to the rset list in the rset
+ * itself, for practical reasons.
*/
struct heap_item {
if (i>h->heapnum)
return;
(void)rset_pos(h->heap[i]->rset,h->heap[i]->fd, &cur, &tot);
- yaz_log(log_level," %d %*s i=%p buf=%p %0.1f/%0.1f",i, level, "",
+ yaz_log(log_level," %d %*s i=%p buf=%p %0.1f/%0.1f",i, level, "",
&(h->heap[i]), h->heap[i]->buf, cur,tot );
heap_dump_item(h, 2*i, level+1);
heap_dump_item(h, 2*i+1, level+1);
return ( 0==h->heapnum );
}
-/** \brief deletes the first item in the heap, and balances the rest
+/** \brief deletes the first item in the heap, and balances the rest
*/
static void heap_delete (HEAP h)
{
}
/** \brief puts item into heap.
- The heap root element has changed value (to bigger)
- Swap downwards until the heap is ordered again
+ The heap root element has changed value (to bigger)
+ Swap downwards until the heap is ordered again
*/
static void heap_balance (HEAP h)
{
}
static RSET rsmulti_andor_create(NMEM nmem,
- struct rset_key_control *kcontrol,
+ struct rset_key_control *kcontrol,
int scope, TERMID termid,
- int no_rsets, RSET* rsets,
+ int no_rsets, RSET* rsets,
const struct rset_control *ctrl)
{
RSET rnew = rset_create_base(ctrl, nmem, kcontrol, scope, termid,
assert(p->items);
/* all other pointers shouls already be allocated, in right sizes! */
}
- else
+ else
{
p = (struct rfd_private *) nmem_malloc (ct->nmem,sizeof(*p));
rfd->priv = p;
p->tailbits = 0;
if (is_and)
p->tailbits = nmem_malloc(ct->nmem, ct->no_children*sizeof(char) );
- else
+ else
p->h = heap_create( ct->nmem, ct->no_children, kctrl);
- p->items = (struct heap_item *)
+ p->items = (struct heap_item *)
nmem_malloc(ct->nmem, ct->no_children*sizeof(*p->items));
for (i = 0; i<ct->no_children; i++)
{
p->tailbits[i] = 0;
}
qsort(p->items, ct->no_children, sizeof(p->items[0]), compare_ands);
- }
+ }
else
{ /* fill the heap for ORing */
for (i = 0; i<ct->no_children; i++){
if (p->h)
heap_destroy (p->h);
- for (i = 0; i<rfd->rset->no_children; i++)
+ for (i = 0; i<rfd->rset->no_children; i++)
if (p->items[i].fd)
rset_close(p->items[i].fd);
}
-static int r_forward_or(RSFD rfd, void *buf,
+static int r_forward_or(RSFD rfd, void *buf,
TERMID *term, const void *untilbuf)
{ /* while heap head behind untilbuf, forward it and rebalance heap */
struct rfd_private *p = rfd->priv;
if (rset_forward(p->h->heap[1]->fd,p->h->heap[1]->buf,
&p->h->heap[1]->term, untilbuf))
heap_balance(p->h);
- else
+ else
{
heap_delete(p->h);
if (heap_empty(p->h))
\param term resulting term
\retval 0 EOF
\retval 1 item could be read
-
+
Has to return all hits where each item points to the
same sysno (scope), in order. Keep an extra key (hitkey)
as long as all records do not point to hitkey, forward
int i;
while (1) {
- if (p->tailcount)
+ if (p->tailcount)
{ /* we are tailing, find lowest tail and return it */
int mintail = -1;
int cmp;
-
+
for (i = 0; i<ct->no_children; i++)
{
if (p->tailbits[i])
/* store segment if not stored already */
if (!p->segment && segment)
p->segment = segment;
-
+
/* skip rest entirely if segments don't match */
if (p->segment && segment && p->segment != segment)
p->skip = 1;
}
}
/* return the lowest tail */
- memcpy(buf, p->items[mintail].buf, kctrl->key_size);
+ memcpy(buf, p->items[mintail].buf, kctrl->key_size);
if (term)
*term = p->items[mintail].term;
if (!rset_read(p->items[mintail].fd, p->items[mintail].buf,
&p->items[mintail].term))
{
p->eof = 1; /* game over, once tails have been returned */
- p->tailbits[mintail] = 0;
+ p->tailbits[mintail] = 0;
(p->tailcount)--;
}
else
if (p->tailcount == 0)
(p->hits)++;
return 1;
- }
+ }
/* not tailing, forward until all records match, and set up */
/* as tails. the earlier 'if' will then return the hits */
if (p->eof)
return 0; /* nothing more to see */
i = 1; /* assume items[0] is highest up */
- while (i < ct->no_children)
+ while (i < ct->no_children)
{
int cmp = (*kctrl->cmp)(p->items[0].buf, p->items[i].buf);
if (cmp <= -rfd->rset->scope) { /* [0] was behind, forward it */
- if (!rset_forward(p->items[0].fd, p->items[0].buf,
+ if (!rset_forward(p->items[0].fd, p->items[0].buf,
&p->items[0].term, p->items[i].buf))
{
p->eof = 1; /* game over */
return 0;
}
i = 0; /* start forwarding from scratch */
- }
+ }
else if (cmp>=rfd->rset->scope)
{ /* [0] was ahead, forward i */
- if (!rset_forward(p->items[i].fd, p->items[i].buf,
+ if (!rset_forward(p->items[i].fd, p->items[i].buf,
&p->items[i].term, p->items[0].buf))
{
p->eof = 1; /* game over */
return 0;
}
- }
+ }
else
i++;
} /* while i */
}
-static int r_forward_and(RSFD rfd, void *buf, TERMID *term,
+static int r_forward_and(RSFD rfd, void *buf, TERMID *term,
const void *untilbuf)
-{
+{
struct rfd_private *p = rfd->priv;
RSET ct = rfd->rset;
const struct rset_key_control *kctrl = ct->keycontrol;
if (cmp <= -rfd->rset->scope)
{
killtail = 1; /* we are moving to a different hit */
- if (!rset_forward(p->items[i].fd, p->items[i].buf,
+ if (!rset_forward(p->items[i].fd, p->items[i].buf,
&p->items[i].term, untilbuf))
{
p->eof = 1; /* game over */
}
}
}
- if (killtail)
+ if (killtail)
{
for (i = 0; i<ct->no_children; i++)
p->tailbits[i] = 0;
static void r_pos_x(RSFD rfd, double *current, double *total, int and_op)
{
RSET ct = rfd->rset;
- struct rfd_private *mrfd =
+ struct rfd_private *mrfd =
(struct rfd_private *)(rfd->priv);
double ratio = and_op ? 0.0 : 1.0;
int i;
rset_get_one_term(ct, terms, maxterms, curterm);
else
{
- /* Special case: Some multi-ors have all terms pointing to the same
+ /* Special case: Some multi-ors have all terms pointing to the same
term. We do not want to duplicate those. Other multiors (and ands)
- have different terms under them. Those we want.
+ have different terms under them. Those we want.
*/
int firstterm= *curterm;
int i;
rset_getterms(ct->children[i], terms, maxterms, curterm);
if ( ( *curterm > firstterm+1 ) &&
( *curterm <= maxterms ) &&
- ( terms[(*curterm)-1] == terms[firstterm] )
+ ( terms[(*curterm)-1] == terms[firstterm] )
)
(*curterm)--; /* forget the term, seen that before */
}
static int r_read(RSFD rfd, void *buf, TERMID *term);
static int r_write(RSFD rfd, const void *buf);
-static const struct rset_control control =
+static const struct rset_control control =
{
"null",
r_delete,
static void r_pos(RSFD rfd, double *current, double *total);
static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm);
-static const struct rset_control control =
+static const struct rset_control control =
{
"prox",
r_delete,
char *more; /* more in each lookahead? */
TERMID *terms; /* lookahead terms */
zint hits;
-};
+};
RSET rset_create_prox(NMEM nmem, struct rset_key_control *kcontrol,
p->more = nmem_malloc(ct->nmem,sizeof(*p->more) * ct->no_children);
p->buf = nmem_malloc(ct->nmem,sizeof(*p->buf) * ct->no_children);
p->terms = nmem_malloc(ct->nmem,sizeof(*p->terms) * ct->no_children);
- for (i = 0; i < ct->no_children; i++)
+ for (i = 0; i < ct->no_children; i++)
{
p->buf[i] = nmem_malloc(ct->nmem,ct->keycontrol->key_size);
p->terms[i] = 0;
}
p->rfd = nmem_malloc(ct->nmem,sizeof(*p->rfd) * ct->no_children);
}
- yaz_log(YLOG_DEBUG,"rsprox (%s) open [%p] n=%d",
+ yaz_log(YLOG_DEBUG,"rsprox (%s) open [%p] n=%d",
ct->control->desc, rfd, ct->no_children);
-
+
for (i = 0; i < ct->no_children; i++)
{
p->rfd[i] = rset_open(ct->children[i], RSETF_READ);
{
RSET ct = rfd->rset;
struct rset_prox_rfd *p = (struct rset_prox_rfd *)(rfd->priv);
-
+
int i;
for (i = 0; i < ct->no_children; i++)
rset_close(p->rfd[i]);
{
/* it is enough to forward first one. Other will follow. */
if (p->more[0] && /* was: cmp >=2 */
- ((kctrl->cmp)(untilbuf, p->buf[0]) >= rfd->rset->scope) )
- p->more[0] = rset_forward(p->rfd[0], p->buf[0],
+ ((kctrl->cmp)(untilbuf, p->buf[0]) >= rfd->rset->scope) )
+ p->more[0] = rset_forward(p->rfd[0], p->buf[0],
&p->terms[0], untilbuf);
}
if (info->ordered && info->relation <= 3 && info->exclusion == 0)
{
- while (p->more[0])
+ while (p->more[0])
{
for (i = 1; i < ct->no_children; i++)
{
- if (!p->more[i])
+ if (!p->more[i])
{
p->more[0] = 0; /* saves us a goto out of while loop. */
break;
continue;
else if (info->relation == 1 && diff < info->distance)
continue;
-
+
p->more[i-1] = rset_read(p->rfd[i-1], p->buf[i-1],
&p->terms[i-1]);
break;
}
else if (ct->no_children == 2)
{
- while (p->more[0] && p->more[1])
+ while (p->more[0] && p->more[1])
{
int cmp = (*kctrl->cmp)(p->buf[0], p->buf[1]);
if ( cmp <= - rfd->rset->scope) /* cmp<-1*/
- p->more[0] = rset_forward(p->rfd[0], p->buf[0],
+ p->more[0] = rset_forward(p->rfd[0], p->buf[0],
&p->terms[0],p->buf[1]);
else if ( cmp >= rfd->rset->scope ) /* cmp>1 */
- p->more[1] = rset_forward(p->rfd[1], p->buf[1],
+ p->more[1] = rset_forward(p->rfd[1], p->buf[1],
&p->terms[1],p->buf[0]);
else
{
zint seqno[500]; /* FIXME - why 500 ?? */
int n = 0;
-
+
seqno[n++] = (*kctrl->getseq)(p->buf[0]);
while ((p->more[0] = rset_read(p->rfd[0],
p->buf[0], &p->terms[0])))
struct rset_prox_rfd *p = (struct rset_prox_rfd *)(rfd->priv);
int i;
double ratio = 0.0;
-
+
for (i = 0; i < ct->no_children; i++)
{
double cur, tot;
*total = *current/ratio;
else
*total = 0.0;
-
+
yaz_log(YLOG_DEBUG, "prox_pos: [%d] %0.1f/%0.1f= %0.4f ",
i, *current, *total, ratio);
}
static void r_flush(RSFD rfd, int mk);
static void r_reread(RSFD rfd);
-static const struct rset_control control =
+static const struct rset_control control =
{
"temp",
r_delete,
r_open,
r_close,
0, /* no forward */
- r_pos,
+ r_pos,
r_read,
r_write,
};
info->temp_path = NULL;
else
info->temp_path = nmem_strdup(rnew->nmem, temp_path);
- rnew->priv = info;
+ rnew->priv = info;
return rnew;
} /* rstemp_create */
prfd = (struct rfd_private *) nmem_malloc(ct->nmem, sizeof(*prfd));
rfd->priv = (void *)prfd;
prfd->buf = nmem_malloc(ct->nmem,ct->keycontrol->key_size);
- }
+ }
else
prfd= rfd->priv;
r_flush(rfd, 0);
{
size_t count;
int r;
-
+
if (lseek(info->fd, info->pos_buf, SEEK_SET) == -1)
{
yaz_log(YLOG_FATAL|YLOG_ERRNO, "rstemp: lseek (1) %s", info->fname);
*/
static void r_reread(RSFD rfd)
{
- struct rfd_private *mrfd = (struct rfd_private*) rfd->priv;
+ struct rfd_private *mrfd = (struct rfd_private*) rfd->priv;
struct rset_private *info = (struct rset_private *)rfd->rset->priv;
if (info->fname)
static int r_read(RSFD rfd, void *buf, TERMID *term)
{
- struct rfd_private *mrfd = (struct rfd_private*) rfd->priv;
+ struct rfd_private *mrfd = (struct rfd_private*) rfd->priv;
struct rset_private *info = (struct rset_private *)rfd->rset->priv;
size_t nc = mrfd->pos_cur + rfd->rset->keycontrol->key_size;
memcpy(buf, info->buf_mem + (mrfd->pos_cur - info->pos_buf),
rfd->rset->keycontrol->key_size);
if (term)
- *term = rfd->rset->term;
+ *term = rfd->rset->term;
/* FIXME - should we store and return terms ?? */
mrfd->pos_cur = nc;
mrfd->cur++;
static int r_write(RSFD rfd, const void *buf)
{
- struct rfd_private *mrfd = (struct rfd_private*) rfd->priv;
+ struct rfd_private *mrfd = (struct rfd_private*) rfd->priv;
struct rset_private *info = (struct rset_private *)rfd->rset->priv;
size_t nc = mrfd->pos_cur + rfd->rset->keycontrol->key_size;
static void r_pos(RSFD rfd, double *current, double *total)
{
- struct rfd_private *mrfd = (struct rfd_private*) rfd->priv;
+ struct rfd_private *mrfd = (struct rfd_private*) rfd->priv;
struct rset_private *info = (struct rset_private *)rfd->rset->priv;
-
+
*current = (double) mrfd->cur;
*total = (double) info->hits;
}
zh = zebra_open(zs, 0);
YAZ_CHECK(zh);
-
+
YAZ_CHECK(zebra_begin_trans (zh, 1) == ZEBRA_OK);
for (i = 0; i<no_db; i++)
sprintf(dbstr, "%d", i);
YAZ_CHECK(zebra_select_database(zh, dbstr) == ZEBRA_OK);
-
+
sprintf(rec_buf, "<gils><title>title %d</title></gils>\n", i);
zebra_add_record (zh, rec_buf, strlen(rec_buf));
"<gils>\n<title>B" char_aring "d</title>\n"
"<abstract>זיהוי סדר הארועים בסיפור המרד הגדול מאת צביה בן-שלום 提示:直接点击数据库名称,将进入单库检索 Ngày xửa ngày xưa D.W. all wet</abstract>\n</gils>\n" ,
0} ;
-
+
static void tst(int argc, char **argv)
{
#if YAZ_HAVE_ICU
/* simple term */
YAZ_CHECK(tl_query(zh, "@attr 1=title notfound", 0));
-
+
YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 3));
YAZ_CHECK(tl_query(zh, "@attr 5=1 @attr 1=title computer", 3));
YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 5=1 ב", 1));
YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 5=102 בן", 1));
-
+
/* phrase search */
YAZ_CHECK(tl_query(zh, "@attr 1=title {my computer}", 2));
YAZ_CHECK(tl_query(zh, "@attr 1=title @attr 6=1 {my computer}", 2));
YAZ_CHECK(tl_query(zh, "@attr 1=title @attr 2=103 {}", 5));
YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 2=103 {}", 1));
YAZ_CHECK(tl_query(zh, "@attr 1=abstract @attr 2=103 {does not match}", 1));
-
+
/* scan */
{ /* word search */
- const char *ent[] = { char_ae "rme", "B" char_aring "d", "computer",
+ const char *ent[] = { char_ae "rme", "B" char_aring "d", "computer",
"My", "x", 0 };
YAZ_CHECK(tl_scan(zh, "@attr 1=title 0", 1, 10, 1, 5, 1, ent));
}
const char *ent[] = { char_ae "rme", "B" char_aring "d", "My computer" };
YAZ_CHECK(tl_scan(zh, "@attr 1=title @attr 6=2 0", 1, 3, 1, 3, 0, ent));
}
-
+
YAZ_CHECK(tl_close_down(zh, zs));
#endif
}
" <title>My title</title>\n"
"</gils>\n",
0};
-
+
#define NUMBER_TO_FETCH_MAX 1000
static void tst(int argc, char **argv)
ZebraRetrievalRecord retrievalRecord[NUMBER_TO_FETCH_MAX];
char setname[20];
int j;
- ODR odr_input = odr_createmem(ODR_DECODE);
- ODR odr_output = odr_createmem(ODR_DECODE);
+ ODR odr_input = odr_createmem(ODR_DECODE);
+ ODR odr_output = odr_createmem(ODR_DECODE);
YAZ_PQF_Parser parser = yaz_pqf_create();
Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, "@attr 1=4 my");
zint hits;
-
+
sprintf(setname, "s%d", i+1);
ret = zebra_search_RPN(zh, odr_input, query, setname, &hits);
if (ret != ZEBRA_OK)
}
if (hits != number_to_be_inserted)
{
- yaz_log(YLOG_WARN, "Unexpected hit count " ZINT_FORMAT
+ yaz_log(YLOG_WARN, "Unexpected hit count " ZINT_FORMAT
"(should be %d)", hits, number_to_be_inserted);
exit(1);
}
code);
exit(1);
}
-
+
for (j = 0; j < number_to_fetch; j++)
{
if (!retrievalRecord[j].buf)
YAZ_CHECK(tl_query(zh, "@attr 1=extra_title my", 1));
// numeric attributes with Bib-1 should produce an error
- YAZ_CHECK(tl_query_x(zh,
+ YAZ_CHECK(tl_query_x(zh,
"@attr 1=4 my", 0, 121));
- YAZ_CHECK(tl_query_x(zh,
+ YAZ_CHECK(tl_query_x(zh,
"@attr 1=7 my", 0, 121));
// private OID with incorrect use attribute
- YAZ_CHECK(tl_query_x(zh,
+ YAZ_CHECK(tl_query_x(zh,
"@attr 1.2.840.10003.3.1000.1000.1 1=4 my", 0, 114));
// private OID with OK use attribute
- YAZ_CHECK(tl_query(zh,
+ YAZ_CHECK(tl_query(zh,
"@attr 1.2.840.10003.3.1000.1000.1 1=7 my", 1));
- YAZ_CHECK(tl_query(zh,
+ YAZ_CHECK(tl_query(zh,
"@attr 1.2.840.10003.3.1000.1000.1 1=8 my", 1));
YAZ_CHECK(tl_close_down(zh, zs));
" but all have the foo bar \n"
" </abstract>\n"
"</gils>\n",
-
+
0 };
static void tst(int argc, char **argv)
ZebraHandle zh = zebra_open(zs, 0);
YAZ_CHECK(tl_init_data(zh, recs));
-
+
YAZ_CHECK(tl_ranking_query(zh, "@attr 1=4 @attr 2=102 the",
3, "first title", 936 ));
-
+
YAZ_CHECK(tl_ranking_query(zh, "@attr 1=62 @attr 2=102 foo",
3, "second title", 850 ));
-
+
YAZ_CHECK(tl_close_down(zh, zs));
}
temp_res = res_open(0, 0); /* completely empty */
YAZ_CHECK(temp_res);
-
+
zs = zebra_start_res(0, default_res, temp_res);
YAZ_CHECK(zs);
-
+
zh = zebra_open(zs, 0);
YAZ_CHECK(zh);
/* we should find the name1 from temp_res */
val = zebra_get_resource(zh, "name1", 0);
YAZ_CHECK(val && !strcmp(val, "value2"));
-
+
val = zebra_get_resource(zh, "name4", 0);
YAZ_CHECK(val && !strcmp(val, "value4"));
-
+
res_clear(temp_res);
}
zebra_close(zh);
YAZ_CHECK_EQ(zebra_select_database(zh, "Default"), ZEBRA_OK);
YAZ_CHECK_EQ(zebra_init(zh), ZEBRA_OK);
-
+
zebra_set_resource(zh, "profilePath", "${srcdir:-.}/../../tab");
-
+
YAZ_CHECK_EQ(zebra_update_record(zh /* handle */,
action_insert,
"grs.sgml" /* record type */,
char setname[20];
char *setnamep = setname;
int status;
- ODR odr_input = odr_createmem (ODR_DECODE);
- ODR odr_output = odr_createmem (ODR_ENCODE);
+ ODR odr_input = odr_createmem (ODR_DECODE);
+ ODR odr_output = odr_createmem (ODR_ENCODE);
YAZ_PQF_Parser parser = yaz_pqf_create();
- Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input,
+ Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input,
"@attr 1=4 my");
zint hits;
if (zebra_begin_trans (zh, 1) != ZEBRA_OK)
fprintf(stderr, "zebra_begin_trans failed\n");
exit(1);
}
-
+
sprintf(setname, "s%d", i+1);
zebra_search_RPN (zh, odr_input, query, setname, &hits);
#endif
#include "testlib.h"
-const char *myrec[] =
+const char *myrec[] =
{
"1234\n" /* ID first record */
/* chunk owner seq idx term */
zint ids[3];
zint limits[3];
ZebraService zs = tl_start_up("test_safari.cfg", argc, argv);
-
+
ZebraHandle zh = zebra_open(zs, 0);
YAZ_CHECK(tl_init_data(zh, myrec));
myrec[2]), ZEBRA_OK);
YAZ_CHECK_EQ(tl_fetch_compare(zh, 3, "R", yaz_oid_recsyn_sutrs,
myrec[4]), ZEBRA_OK);
- YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0",
+ YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0",
yaz_oid_recsyn_xml,
"<record xmlns=\"http://www.indexdata.com/zebra/\">\n"
" <facet type=\"0\" index=\"any\">\n"
" <term coccur=\"1\" occur=\"1\">old</term>\n"
" </facet>\n"
"</record>\n"), ZEBRA_OK);
- YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0:2",
+ YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0:2",
yaz_oid_recsyn_xml,
"<record xmlns=\"http://www.indexdata.com/zebra/\">\n"
" <facet type=\"0\" index=\"any\">\n"
"</record>\n"), ZEBRA_OK);
- YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::ti:s",
+ YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::ti:s",
yaz_oid_recsyn_xml,
"<record xmlns=\"http://www.indexdata.com/zebra/\">\n"
" <facet type=\"s\" index=\"ti\">\n"
YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and a b", 1));
YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and a c", 1));
-
+
YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and c d", 1));
YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and b f", 1));
YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and f g", 0));
"<gils>\n<title>c d</title>\n</gils>\n",
"<gils>\n<title>e f</title>\n</gils>\n" ,
0} ;
-
+
static void tst(int argc, char **argv)
{
ZebraService zs = tl_start_up(0, argc, argv);
"</gils>"
,
0} ;
-
+
static void tst(int argc, char **argv)
{
ZebraService zs = tl_start_up(0, argc, argv);
"term 3 3: my\n"
"term 3 3: title\n"
"term 2 2: x\n"), ZEBRA_OK);
-
+
YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::title:s",
yaz_oid_recsyn_sutrs,
"facet s title\n"
"term 2 2: my\n"
"term 2 2: title\n"
"term 2 2: x\n"), ZEBRA_OK);
-
+
/* trunc left */
YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=2 titl", 0));
YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=2 x", 2));
/* = */
YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=3 my", 3));
YAZ_CHECK(
- tl_query(zh,
+ tl_query(zh,
"@attr 1=4 @attr 2=3 "
"1234567890" "1234567890""1234567890""1234567890""1234567890"
"1234567890" "1234567890""1234567890""1234567890""1234567890"
"1234567890" "1234567890""1234567890""1234567890""1234567890"
"1234567890" "1"
, 1));
-
+
YAZ_CHECK(
- tl_query_x(zh,
+ tl_query_x(zh,
"@attr 1=4 @attr 2=3 "
"1234567890" "1234567890""1234567890""1234567890""1234567890"
"1234567890" "1234567890""1234567890""1234567890""1234567890"
"1234567890" "1234567890""1234567890""1234567890""1234567890"
"1234567890" "1234567890""1234567890""1234567890""1234567890"
"1234567890" "1234567890""1234567890""1234567890""1234567890"
-
+
"1234567890" "1234567890""1234567890""1234567890""1234567890"
"1234567890" "1234567890""1234567890""1234567890""1234567890"
"1234567890" "1234567890""1234567890""1234567890""1234567890"
"1234567890" "1234567890""1234567890""1234567890""1234567890"
"1234567890" "12"
, 0, 11));
-
+
/* string relations, >= */
YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=4 x", 2));
YAZ_CHECK(tl_query_x(zh, "@attr 1=1 @attr 2=103 {x my}", 0, 114));
/* and searches */
- YAZ_CHECK(tl_query(zh, "@and @attr 1=4 notfound @attr 1=4 x", 0));
- YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 notfound", 0));
- YAZ_CHECK(tl_query(zh, "@and @attr 1=4 notfound @attr 1=4 notfound", 0));
- YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 x", 2));
- YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 my", 2));
- YAZ_CHECK(tl_query(zh, "@and @attr 1=4 my @attr 1=4 x", 2));
- YAZ_CHECK(tl_query(zh, "@and @attr 1=4 my @attr 1=4 my", 3));
+ YAZ_CHECK(tl_query(zh, "@and @attr 1=4 notfound @attr 1=4 x", 0));
+ YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 notfound", 0));
+ YAZ_CHECK(tl_query(zh, "@and @attr 1=4 notfound @attr 1=4 notfound", 0));
+ YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 x", 2));
+ YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 my", 2));
+ YAZ_CHECK(tl_query(zh, "@and @attr 1=4 my @attr 1=4 x", 2));
+ YAZ_CHECK(tl_query(zh, "@and @attr 1=4 my @attr 1=4 my", 3));
/* or searches */
- YAZ_CHECK(tl_query(zh, "@or @attr 1=4 notfound @attr 1=4 x", 2));
- YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 notfound", 2));
- YAZ_CHECK(tl_query(zh, "@or @attr 1=4 notfound @attr 1=4 notfound", 0));
- YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 x", 2));
- YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 my", 3));
- YAZ_CHECK(tl_query(zh, "@or @attr 1=4 my @attr 1=4 x", 3));
- YAZ_CHECK(tl_query(zh, "@or @attr 1=4 my @attr 1=4 my", 3));
+ YAZ_CHECK(tl_query(zh, "@or @attr 1=4 notfound @attr 1=4 x", 2));
+ YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 notfound", 2));
+ YAZ_CHECK(tl_query(zh, "@or @attr 1=4 notfound @attr 1=4 notfound", 0));
+ YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 x", 2));
+ YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 my", 3));
+ YAZ_CHECK(tl_query(zh, "@or @attr 1=4 my @attr 1=4 x", 3));
+ YAZ_CHECK(tl_query(zh, "@or @attr 1=4 my @attr 1=4 my", 3));
/* not searches */
/* bug 619 */
- YAZ_CHECK(tl_query(zh, "@not @attr 1=4 notfound @attr 1=4 x", 0));
+ YAZ_CHECK(tl_query(zh, "@not @attr 1=4 notfound @attr 1=4 x", 0));
YAZ_CHECK(tl_query(zh, "@not @attr 1=4 x @attr 1=4 x", 0));
YAZ_CHECK(tl_query(zh, "@not @attr 1=4 my @attr 1=4 x", 1));
YAZ_CHECK(tl_query(zh, "@not @attr 1=4 my @attr 1=4 notfound", 3));
YAZ_CHECK(tl_query(zh, "@not @attr 1=4 notfound @attr 1=4 notfound", 0));
-
+
/* phrase searches */
YAZ_CHECK(tl_query(zh, "@attr 1=4 my", 3));
YAZ_CHECK(tl_query(zh, "@attr 1=4 {my x}", 1));
/* exl=1 distance=2 order=0 relation=3 (=), known, unit=word */
YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 1 2 1 3 k 2 my x", 1));
-
+
/* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */
YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 2 1 2 k 2 a y", 1));
/* position , or-list */
YAZ_CHECK(tl_query(zh, "@attr 4=105 @attr 3=1 {title my}", 3));
YAZ_CHECK(tl_query(zh, "@attr 4=105 @attr 3=1 {title x}", 0));
-
+
/* position, and-list */
YAZ_CHECK(tl_query(zh, "@attr 4=6 @attr 3=1 {title my}", 0));
YAZ_CHECK(tl_query(zh, "@attr 4=6 @attr 3=1 {title x}", 0));
YAZ_CHECK(tl_query(zh, "@attr 1=30 @attr 4=5 @attr 2=4 {2107-09-19 00:00:00}", 1));
/* > */
YAZ_CHECK(tl_query(zh, "@attr 1=30 @attr 4=5 @attr 2=5 {2107-09-19 00:00:00}", 0));
-
+
YAZ_CHECK(tl_close_down(zh, zs));
}
*/
-/** \file
+/** \file
\brief sort using various sortindex types
*/
"</gils>\n",
/* 3 */
- "<gils>\n"
+ "<gils>\n"
" <title>My x title</title>\n"
" <title>B</title>\n"
"</gils>\n",
" <title>A</title>\n"
"</gils>\n" ,
0} ;
-
+
static void tst_sortindex(int argc, char **argv, const char *type)
{
zint ids[5];
res_set(res, "sortindex", type);
zh = zebra_open(zs, res);
-
+
YAZ_CHECK(tl_init_data(zh, myrec));
if (strcmp(type, "m"))
int status;
ZebraService zs = tl_start_up(0, argc, argv);
ZebraHandle zh = zebra_open (zs, 0);
- ODR odr_input = odr_createmem (ODR_DECODE);
- ODR odr_output = odr_createmem (ODR_ENCODE);
+ ODR odr_input = odr_createmem (ODR_DECODE);
+ ODR odr_output = odr_createmem (ODR_ENCODE);
YAZ_PQF_Parser parser = yaz_pqf_create();
Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, "@attr 1=4 my");
Z_SortKeySpecList *spec = yaz_sort_spec (odr_output, "1=4 <!");
YAZ_CHECK(tl_init_data(zh, recs));
YAZ_CHECK(zebra_begin_trans(zh, 0) == ZEBRA_OK);
-
+
YAZ_CHECK(zebra_search_RPN(zh, odr_input, query, setname1, &hits) ==
ZEBRA_OK);
YAZ_CHECK(zebra_sort(zh, odr_output, 1, &setname1, setname2, spec,
&status)
== ZEBRA_OK);
- YAZ_CHECK(zebra_sort(zh, odr_output, 1, &setname2, setname3, spec,
+ YAZ_CHECK(zebra_sort(zh, odr_output, 1, &setname2, setname3, spec,
&status) == ZEBRA_OK);
spec = yaz_sort_spec(odr_output, "1=5 <!"); /* invalid sort spec */
/*
zebra_deleteResultSet(zh, Z_DeleteRequest_list,
1, &setnamep, &status);
- */
+ */
odr_destroy(odr_input);
odr_destroy(odr_output);
WRBUF w2 = wrbuf_alloc();
zebra_sort_sysno(si, sysno);
YAZ_CHECK_EQ(zebra_sort_read(si, 0, w2), 0);
-
+
for (i = 0; i < 600; i++) /* 600 * 6 < max size =4K */
wrbuf_write(w1, "12345", 6);
-
+
zebra_sort_add(si, input_section_id, w1);
-
+
zebra_sort_sysno(si, sysno);
-
+
YAZ_CHECK_EQ(zebra_sort_read(si, &output_section_id, w2), 1);
-
+
YAZ_CHECK_EQ(wrbuf_len(w1), wrbuf_len(w2));
YAZ_CHECK(!memcmp(wrbuf_buf(w1), wrbuf_buf(w2), wrbuf_len(w2)));
YAZ_CHECK_EQ(input_section_id, output_section_id);
" <title>My title</title>\n"
"</gils>\n",
0};
-
+
static void tst(int argc, char **argv)
{
zint hits;
ZEBRA_RES res;
- const char * zebra_xml_sysno
+ const char * zebra_xml_sysno
= "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\"/>\n";
- const char * zebra_xml_meta
+ const char * zebra_xml_meta
= "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\" base=\"Default\" type=\"grs.sgml\" rank=\"0\" size=\"41\" set=\"zebra::meta\"/>\n";
const char * zebra_xml_index_title_p
res = zebra_search_PQF(zh, "@attr 1=4 my", "rsetname", &hits);
YAZ_CHECK_EQ(res, ZEBRA_OK);
YAZ_CHECK_EQ(hits, 1);
-
+
YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml,
"mismatch"), ZEBRA_FAIL);
-
+
YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_sutrs,
myrec[0]), ZEBRA_OK);
-
+
YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml,
myrec[0]), ZEBRA_OK);
-
- YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno",
+
+ YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno",
yaz_oid_recsyn_sutrs,
"2"), ZEBRA_OK);
-
- YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno",
+
+ YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno",
yaz_oid_recsyn_xml,
zebra_xml_sysno), ZEBRA_OK);
-
+
YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta", yaz_oid_recsyn_xml,
zebra_xml_meta), ZEBRA_OK);
-
- YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::title:p",
+
+ YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::title:p",
yaz_oid_recsyn_xml,
zebra_xml_index_title_p), ZEBRA_OK);
-
- YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::title:s",
+
+ YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::title:s",
yaz_oid_recsyn_xml,
zebra_xml_index_title_s), ZEBRA_OK);
-
- YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::nonexistent",
+
+ YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::nonexistent",
yaz_oid_recsyn_xml, ""), ZEBRA_OK);
-
- YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::nonexistent",
+
+ YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::nonexistent",
yaz_oid_recsyn_xml, ""), ZEBRA_OK);
-
+
YAZ_CHECK(tl_close_down(zh, zs));
}
{
ZebraService zs = tl_start_up(0, argc, argv);
- ZebraHandle zh = 0;
+ ZebraHandle zh = 0;
YAZ_CHECK(zs);
if (zs)
zh = zebra_open(zs, 0);
YAZ_CHECK(zh);
}
-
+
YAZ_CHECK(tl_close_down(zh, zs));
}
}
ZebraHandle zh = zebra_open(zs, 0);
srand(17);
-
+
YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
zebra_init(zh);
zebra_close(zh);
YAZ_CHECK(zh);
YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
-
+
YAZ_CHECK(zebra_begin_trans (zh, 1) == ZEBRA_OK);
for (l = 0; l<100; l++)
0 /* fname */,
rec, strlen(rec))
== ZEBRA_OK); /* insert really */
-
+
YAZ_CHECK(zebra_update_record(
zh, action_update,
0 /* record type */,
0 /* fname */,
rec, strlen(rec))
== ZEBRA_OK); /* replace really */
-
+
YAZ_CHECK(tl_query(zh, "@attr 1=4 some", 1));
zebra_drop_database(zh, "Default");
for (i = 0; i<iter; i++)
{
ZebraHandle zh = zebra_open(zs, 0);
- zint hits;
+ zint hits;
ZEBRA_RES res = zebra_search_PQF(zh, "@attr 1=4 some", "default",
&hits);
YAZ_CHECK(res == ZEBRA_OK);
-
+
YAZ_CHECK(hits >= hits_max);
if (hits < hits_max)
printf("i=%d hits=%lld hits_max=%lld\n", i, hits, hits_max);
YAZ_CHECK(pid != -1);
if (pid)
return pid;
-
+
(*f)(zs, iter);
YAZ_CHECK_TERM;
}
{
ZebraService zs;
ZebraHandle zh;
-
+
mkdir("register", 0775);
mkdir("shadow", 0775);
exit (3);
}
z = ZOOM_connection_new (target, 0);
-
+
if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
{
printf ("Error: %s (%d) %s\n", errmsg, error, addinfo);
ZOOM_record_get(
ZOOM_resultset_record(r, pos + retrieve_offset),
"render", &len);
-
+
if (rec)
fwrite (rec, 1, len, stdout);
}
int log_level = YLOG_LOG;
-/*
+/*
* tl_start_up : do common start things, and a zebra_start
* - build the name of logfile from argv[0], and open it
* if no argv passed, do not open a log
- * - read zebra.cfg from env var srcdir if it exists; otherwise current dir
+ * - read zebra.cfg from env var srcdir if it exists; otherwise current dir
* default to zebra.cfg, if no name is given
*/
ZebraService tl_start_up(char *cfgname, int argc, char **argv)
yaz_log(log_level, "going to call init");
res = zebra_init(zh);
- if (res == ZEBRA_FAIL)
+ if (res == ZEBRA_FAIL)
{
yaz_log(log_level, "init_data: zebra_init failed with %d", res);
printf("init_data failed with %d\n", res);
if (rc == ZEBRA_FAIL) {
int code = zebra_errCode(zh);
yaz_log(log_level, "search returned %d. Code %d", rc, code);
-
- printf("Error: search returned %d. Code %d\n%s\n", rc,
+
+ printf("Error: search returned %d. Code %d\n%s\n", rc,
code, query);
return 0;
}
if (exphits != -1 && hits != exphits)
{
- yaz_log(log_level, "search returned " ZINT_FORMAT
+ yaz_log(log_level, "search returned " ZINT_FORMAT
" hits instead of " ZINT_FORMAT, hits, exphits);
- printf("Error: search returned " ZINT_FORMAT
+ printf("Error: search returned " ZINT_FORMAT
" hits instead of " ZINT_FORMAT "\n%s\n",
hits, exphits, query);
return 0;
yaz_log(log_level, "======================================");
yaz_log(log_level, "scan: pos=%d num=%d %s", pos, num, query);
- res = zebra_scan_PQF(zh, odr, query, &pos, &num, &entries, &partial,
+ res = zebra_scan_PQF(zh, odr, query, &pos, &num, &entries, &partial,
0 /* setname */);
if (partial == -123)
return ret;
}
-/**
- * makes a query, checks number of hits, and for the first hit, that
+/**
+ * makes a query, checks number of hits, and for the first hit, that
* it contains the given string, and that it gets the right score
*/
-int tl_ranking_query(ZebraHandle zh, char *query,
+int tl_ranking_query(ZebraHandle zh, char *query,
int exphits, char *firstrec, int firstscore)
{
ZebraRetrievalRecord retrievalRecord[10];
int rc;
int i;
int ret = 1;
-
+
if (!tl_query(zh, query, exphits))
return 0;
for (i = 0; i<10; i++)
retrievalRecord[i].position = i+1;
- odr_output = odr_createmem(ODR_ENCODE);
+ odr_output = odr_createmem(ODR_ENCODE);
rc = zebra_records_retrieve(zh, odr_output, setname, 0,
yaz_oid_recsyn_xml, exphits, retrievalRecord);
if (rc != ZEBRA_OK)
const char *setname= "rsetname";
zint *positions = 0;
int i, ret = 1;
-
+
if (!tl_query(zh, query, exphits))
return 0;
-
+
positions = (zint *) xmalloc(1 + (exphits * sizeof(zint)));
for (i = 0; i<exphits; i++)
positions[i] = i+1;
meta = zebra_meta_records_create(zh, setname, exphits, positions);
-
+
if (!meta)
{
printf("Error: retrieve returned error\n%s\n", query);
if (min_val_exp == 0 || exp[i] < min_val_exp)
min_val_exp = exp[i];
}
-
+
/* compare sequences using base offset */
for (i = 0; i<hits; i++)
if ((recs[i].sysno-min_val_recs) != (exp[i]-min_val_exp))
ZEBRA_RES res;
retrievalRecord[0].position = position;
-
+
yaz_set_esn(&comp, element_set, odr->mem);
- res = zebra_records_retrieve(zh, odr, "rsetname", comp, format, 1,
+ res = zebra_records_retrieve(zh, odr, "rsetname", comp, format, 1,
retrievalRecord);
if (res != ZEBRA_OK)
{
#include <yaz/test.h>
#include <yaz/oid_db.h>
-/**
+/**
* tl_start_up : Does all the usual start functions
* - nmem_init
* - build the name of logfile from argv[0], and open it
* if no argv passed, do not open a log
- * - read zebra.cfg from env var srcdir if it exists; otherwise current dir
+ * - read zebra.cfg from env var srcdir if it exists; otherwise current dir
* default to zebra.cfg, if no name is given
*/
ZebraService tl_start_up(char *cfgname, int argc, char **argv);
/**
* get_srcdir : returns the source dir. Most often ".", but when
- * making distcheck, some other dir
+ * making distcheck, some other dir
*/
const char *tl_get_srcdir(void);
-/**
- * start_log: open a log file
+/**
+ * start_log: open a log file
*/
/* FIXME - parse command line arguments to set log levels etc */
void tl_start_log(int argc, char **argv);
-/**
- * tl_zebra_start - do a zebra_start with a decent config name
+/**
+ * tl_zebra_start - do a zebra_start with a decent config name
* Takes care of checking the environment for srcdir (as needed by distcheck)
- * and uses that if need be.
+ * and uses that if need be.
* The name defaults to zebra.cfg, if null or emtpy
*/
ZebraService tl_zebra_start(const char *cfgname);
-/**
+/**
* close_down closes it all down
* Does a zebra_close on zh, if not null.
- * Does a zebra_stop on zs, if not null
+ * Does a zebra_stop on zs, if not null
* Writes a log message, OK if retcode is zero, error if not
* closes down nmem and xmalloc
* returns the retcode, for use in return or exit in main()
*/
int tl_close_down(ZebraHandle zh, ZebraService zs
- ) ZEBRA_GCC_ATTR((warn_unused_result));
+ ) ZEBRA_GCC_ATTR((warn_unused_result));
/** inits the database and inserts test data */
int tl_init_data(ZebraHandle zh, const char **recs
- ) ZEBRA_GCC_ATTR((warn_unused_result));
+ ) ZEBRA_GCC_ATTR((warn_unused_result));
/**
* tl_query does a simple query, and checks that the number of hits matches
int tl_query_x(ZebraHandle zh, const char *query, zint exphits,
int experror
) ZEBRA_GCC_ATTR((warn_unused_result));
-
+
/**
- * tl_scan is a utility for scan testing
+ * tl_scan is a utility for scan testing
*/
int tl_scan(ZebraHandle zh, const char *query,
int pos, int num, /* input params */
int tl_sort(ZebraHandle zh, const char *query, zint hits, zint *exp
) ZEBRA_GCC_ATTR((warn_unused_result));
-/**
- * ranking_query makes a query, checks number of hits, and for
- * the first hit, that it contains the given string, and that it
+/**
+ * ranking_query makes a query, checks number of hits, and for
+ * the first hit, that it contains the given string, and that it
* gets the right score
*/
-int tl_ranking_query(ZebraHandle zh, char *query,
+int tl_ranking_query(ZebraHandle zh, char *query,
int exphits, char *firstrec, int firstscore
) ZEBRA_GCC_ATTR((warn_unused_result));
-/**
- * meta_query makes a query, checks number of hits, and for
+/**
+ * meta_query makes a query, checks number of hits, and for
* checks that the all records in result set has the proper identifiers (ids)
*/
int tl_meta_query(ZebraHandle zh, char *query, int exphits,
) ZEBRA_GCC_ATTR((warn_unused_result));
/**
- * if filter given by name does not exist, exit nicely but warn in log
+ * if filter given by name does not exist, exit nicely but warn in log
*/
void tl_check_filter(ZebraService zs, const char *name);
/* search for aaa */
YAZ_CHECK(tl_query(zh, "@attr 1=4 @term string laaas", 0));
-
+
/* search ABC in title:0 . */
YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=3 @attr 1=4 ABC", 1));
-
+
/* search DEF in title:0 . */
YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=3 @attr 1=4 DEF", 0));
-
+
/* search [ in title:0 . */
YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=3 @attr 1=4 [", 1));
-
+
/* search \ in title:0 . */
YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=3 @attr 1=4 \\\\\\\\", 1));
/* search { in title:0 . */
YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=3 @attr 1=4 \\{", 1));
-
+
YAZ_CHECK(tl_close_down(zh, zs));
}
char *dst = (char *) &key;
const char *src0 = src;
iscz1_decode(codec_handle, &dst, &src);
-
+
if (key.len != 2)
{
printf ("%s: i=%d key.len=%d expected 2\n", prog,
dst = (char*) &key2;
src = buf;
-
+
iscz1_decode(codec_handle, &dst, &src);
iscz1_stop(codec_handle);
const char *src = (const char *) &ar1;
char *dst = dstbuf;
iscz1_encode(encode_handle, &dst, &src);
-
+
src = dstbuf;
dst = (char *) &ar2;
iscz1_decode(decode_handle, &dst, &src);
ret = tst_encode(num);
exit(ret);
}
-
+
/*
* Local variables:
* c-basic-offset: 4
TL_MAIN
/*
- * Local variables:
+ * Local variables:
* c-basic-offset: 4
* c-file-style: "Stroustrup"
* indent-tabs-mode: nil
zebra_repository_update(zh, path);
YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK);
zebra_commit(zh);
-
+
YAZ_CHECK(tl_query(zh, "@and "
"@attr 1=54 eng "
"@and @attr 1=1003 jack @attr 1=4 computer", 2));
zebra_init(zh);
zebra_set_resource(zh, "recordType", "grs.marcxml.record");
-
+
YAZ_CHECK(zebra_begin_trans(zh, 1) == ZEBRA_OK);
sprintf(path, "%.200s/sample-marc", tl_get_srcdir());
#include <config.h>
#endif
#include "testlib.h"
-
+
static void tst(int argc, char **argv)
{
char path[256];
YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK);
zebra_commit(zh);
-
+
YAZ_CHECK(tl_close_down(zh, zs));
}
static void tst(int argc, char **argv)
{
-
+
ZebraService zs = tl_start_up(0, argc, argv);
ZebraHandle zh = zebra_open(zs, 0);
char path[256];
YAZ_CHECK(tl_query(zh, "@attr 1=/root/first content",1));
YAZ_CHECK(tl_query(zh, "@attr {1=/root/first[@attr='danish']} content",1));
YAZ_CHECK(tl_query(zh, "@attr {1=/root/second[@attr='danish lake']} content",1));
- YAZ_CHECK(tl_query(zh, "@attr {1=/root/third[@attr='dansk s\xc3\xb8']} content",1));
+ YAZ_CHECK(tl_query(zh, "@attr {1=/root/third[@attr='dansk s\xc3\xb8']} content",1));
/* FIXME - This triggers bug200 */
YAZ_CHECK(tl_close_down(zh, zs));
" <title>bar</title> \n"
" <author>gryf</author> \n"
"</record> \n",
-
+
"<record> \n"
" <title>foo bar</title> \n"
" <author>gryf</author> \n"
"</record> \n",
-
+
"<record> \n"
" <title lang=en>foo gryf</title> \n"
" <author>grunt</author> \n"
"</record> \n",
-
+
"<record> \n"
" <title lang=da>foo grunt</title> \n"
" <value>bar</value> \n"
"</record> \n",
-
+
"<record> \n"
" <title lang=en>double english</title> \n"
" <title lang=da>double danish</title> \n"
YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='da'] foo",1));
YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='en'] foo",1));
- YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='en'] english",1));
- YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='da'] english",0));
- YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='da'] danish",1));
- YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='en'] danish",0));
+ YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='en'] english",1));
+ YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='da'] english",0));
+ YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='da'] danish",1));
+ YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='en'] danish",0));
YAZ_CHECK(tl_query(zh, "@attr 1=/record/title @and foo bar",2));
/* The previous one returns two hits, as the and applies to the whole
" but all have the foo bar \n"
" </abstract>\n"
"</record>\n",
-
+
0 };
YAZ_CHECK(tl_query(zh, "@attr 5=1 @attr 6=3 @attr 4=1 @attr 1=18 \"367-93-1\"", 2));
YAZ_CHECK(tl_query(zh, "@attr 1=/assembled/orgs/org 0", 1));
-
- YAZ_CHECK(tl_query(zh,
+
+ YAZ_CHECK(tl_query(zh,
"@and @attr 1=/assembled/orgs/org 0 @attr 5=1 @attr 6=3 @attr 4=1 "
"@attr 1=/assembled/basic/names/CASno \"367-93-1\"", 1));
char path[256];
char profile_path[256];
- sprintf(profile_path, "%.80s:%.80s/../../tab",
+ sprintf(profile_path, "%.80s:%.80s/../../tab",
tl_get_srcdir(), tl_get_srcdir());
zebra_set_resource(zh, "profilePath", profile_path);
void tst(int argc, char **argv)
{
ZebraHandle zh;
-
+
ZebraService zs = tl_start_up(0, argc, argv);
zh = index_some(zs, "dom.bad.xml", "marc-col.xml");
zebra_close(zh);
-
- /* testing XMLREADER input with PI stylesheet */
+
+ /* testing XMLREADER input with PI stylesheet */
zh = index_some(zs, "dom.dom-config-col.xml", "marc-col.xml");
YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 3));
ZEBRA_OK);
YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
-
+
YAZ_CHECK(tl_query_x(zh, "@attr 1=titl computer", 0, 114));
YAZ_CHECK(tl_query_x(zh, "@attr 1=4 computer", 0, 121));
zebra_close(zh);
- /* testing XMLREADER input with ELEMENT stylesheet */
+ /* testing XMLREADER input with ELEMENT stylesheet */
zh = index_some(zs, "dom.dom-config-one.xml", "marc-one.xml");
YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 1));
YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
YAZ_CHECK(tl_query_x(zh, "@attr 1=4 computer", 0, 121));
zebra_close(zh);
- /* testing MARC input with ELEMENT stylesheet */
+ /* testing MARC input with ELEMENT stylesheet */
zh = index_some(zs, "dom.dom-config-marc.xml", "marc-col.mrc");
YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 3));
YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
YAZ_CHECK(tl_query_x(zh, "@attr 1=4 computer", 0, 121));
zebra_close(zh);
- /* testing XMLREADER input with ELEMENT stylesheet and skipped records */
+ /* testing XMLREADER input with ELEMENT stylesheet and skipped records */
zh = index_some(zs, "dom.dom-config-skipped.xml", "marc-col.xml");
YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 1));
YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 0));
YAZ_CHECK(tl_query(zh, "@attr 1=control 11224467", 1));
YAZ_CHECK(tl_query(zh, "@attr 1=control 73090924", 0));
- /* testing XMLREADER input with type attributes (insert,delete,..) */
+ /* testing XMLREADER input with type attributes (insert,delete,..) */
zh = index_some(zs, "dom.dom-config-del.xml", "del-col.xml");
YAZ_CHECK(tl_query(zh, "@attr 1=title a", 1));
YAZ_CHECK(tl_query(zh, "@attr 1=title 1", 0));
zebra_init(zh);
- sprintf(profile_path, "%s:%s/../../tab",
+ sprintf(profile_path, "%s:%s/../../tab",
tl_get_srcdir(), tl_get_srcdir());
zebra_set_resource(zh, "profilePath", profile_path);
YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
YAZ_CHECK(tl_query_x(zh, "@attr 1=titl computer", 0, 114));
YAZ_CHECK(tl_query_x(zh, "@attr 1=4 computer", 0, 121));
-
+
YAZ_CHECK(tl_close_down(zh, zs));
}
tl_check_filter(zs, "alvis");
YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
-
+
zebra_init(zh);
- sprintf(profile_path, "%s:%s/../../tab",
+ sprintf(profile_path, "%s:%s/../../tab",
tl_get_srcdir(), tl_get_srcdir());
zebra_set_resource(zh, "profilePath", profile_path);
YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 3));
YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
YAZ_CHECK(tl_query_x(zh, "@attr 1=titl computer", 0, 114));
-
+
YAZ_CHECK(tl_close_down(zh, zs));
}
tl_check_filter(zs, "alvis");
YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
-
+
zebra_init(zh);
- sprintf(profile_path, "%s:%s/../../tab",
+ sprintf(profile_path, "%s:%s/../../tab",
tl_get_srcdir(), tl_get_srcdir());
zebra_set_resource(zh, "profilePath", profile_path);
YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
YAZ_CHECK(tl_query_x(zh, "@attr 1=titl computer", 0, 114));
-
+
/* index one more time to see that we don't get dups, since
index.xsl has a record ID associated with them */
zebra_add_record(zh, record_buf, strlen(record_buf));
YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 1));
YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
YAZ_CHECK(tl_query_x(zh, "@attr 1=titl computer", 0, 114));
-
+
YAZ_CHECK(tl_close_down(zh, zs));
}
#endif
#include <yaz/test.h>
#include "testlib.h"
-
+
static void tst(int argc, char **argv)
{
char path[256];
zebra_init(zh);
- sprintf(profile_path, "%s:%s/../../tab",
+ sprintf(profile_path, "%s:%s/../../tab",
tl_get_srcdir(), tl_get_srcdir());
zebra_set_resource(zh, "profilePath", profile_path);
tl_check_filter(zs, "alvis");
YAZ_CHECK_EQ(zebra_select_database(zh, "Default"), ZEBRA_OK);
-
+
zebra_init(zh);
- sprintf(profile_path, "%s:%s/../../tab",
+ sprintf(profile_path, "%s:%s/../../tab",
tl_get_srcdir(), tl_get_srcdir());
zebra_set_resource(zh, "profilePath", profile_path);
record_buf[r] = '\0';
#if 0
-/* disable this test for now: bug #730 */
+/* disable this test for now: bug #730 */
/* http://xmlsoft.org/html/libxml-parser.html#xmlReadIO */
#if YAZ_HAVE_XML2
/* On Mac OSX using Libxml 2.6.16, we xmlTextReaderExpand does
element = src->attributeList[src->major];
if (src->type == *element->attributeType)
{
- switch (element->which)
+ switch (element->which)
{
case Z_AttributeValue_numeric:
++(src->major);
break;
if (element->attributeSet && attribute_set_oid)
*attribute_set_oid = element->attributeSet;
- if (element->value.complex->list[src->minor]->which ==
+ if (element->value.complex->list[src->minor]->which ==
Z_StringOrNumeric_numeric)
{
++(src->minor);
return
*element->value.complex->list[src->minor-1]->u.numeric;
}
- else if (element->value.complex->list[src->minor]->which ==
+ else if (element->value.complex->list[src->minor]->which ==
Z_StringOrNumeric_string)
{
if (!string_value)
break;
++(src->minor);
- *string_value =
+ *string_value =
element->value.complex->list[src->minor-1]->u.string;
return -2;
}
/**
* \file charmap.c
* \brief character conversions (.chr)
- *
+ *
* Support module to handle character-conversions into and out of the
* Zebra dictionary.
*/
/*
* General argument structure for callback functions (internal use only)
*/
-typedef struct chrwork
+typedef struct chrwork
{
chrmaptab map;
char string[CHR_MAXSTR+1];
}
if (!len)
{
- if (!root->target || !root->target[0] ||
+ if (!root->target || !root->target[0] ||
strcmp((const char *) root->target[0], to))
{
- if (from_0 &&
+ if (from_0 &&
root->target && root->target[0] && root->target[0][0] &&
strcmp((const char *) root->target[0], CHR_UNKNOWN))
{
else
res = 0;
/* otherwhise there was no match on beginning of field, move on */
- }
-
+ }
+
if (!res && t->children[(unsigned char) **from])
{
(*len)--;
chr_t_entry *t = maptab->q_input;
chr_t_entry *res;
int len_tmp[2];
-
+
len_tmp[0] = len;
len_tmp[1] = -1;
if (!(res = find_entry_x(t, from, len_tmp, first)))
case 'n': c = '\n'; (*s)++; break;
case 't': c = '\t'; (*s)++; break;
case 's': c = ' '; (*s)++; break;
- case 'x':
+ case 'x':
if (zebra_ucs4_strlen(*s) >= 3)
{
fmtstr[0] = (*s)[1];
{
chrmaptab tab = (chrmaptab) data;
char tmp[2];
-
+
tmp[0] = num; tmp[1] = '\0';
tab->input = set_map_string(tab->input, tab->nmem, s, strlen(s), tmp, 0);
tab->output[num + tab->base_uppercase] =
(unsigned char *) nmem_strdup(tab->nmem, s);
}
-/*
+/*
* Callback function.
* Add a space-entry to the value space.
*/
(char*) CHR_SPACE, 0);
}
-/*
+/*
* Callback function.
* Add a space-entry to the value space.
*/
static void fun_add_equivalent_string(const char *s, void *data, int num)
{
chr_equiv_work *arg = (chr_equiv_work *) data;
-
+
if (arg->no_eq == CHR_MAXEQUIV)
return;
arg->eq[arg->no_eq++] = nmem_strdup(arg->nmem, s);
size_t inbytesleft = inlen * sizeof(ucs4_t);
char *inbuf = (char*) from;
size_t ret;
-
+
if (t == 0)
*outbuf++ = *from; /* ISO-8859-1 is OK here */
else
ret = yaz_iconv(t, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
if (ret != (size_t) (-1))
ret = yaz_iconv(t, 0, 0, &outbuf, &outbytesleft);
-
-
+
+
if (ret == (size_t) (-1))
{
yaz_log(YLOG_LOG, "from: %2X %2X %2X %2X",
char *inbuf = s_native;
size_t outbytesleft = sizeof(arg)-4;
size_t inbytesleft = strlen(s_native);
- size_t ret;
+ size_t ret;
ret = yaz_iconv(t_unicode, &inbuf, &inbytesleft,
&outbuf, &outbytesleft);
if (ret != (size_t)(-1))
ret = yaz_iconv(t_unicode, 0, 0, &outbuf, &outbytesleft);
-
+
if (ret == (size_t)(-1))
return -1;
i = (outbuf - (char*) arg)/sizeof(ucs4_t);
}
else
- {
+ {
for (i = 0; s_native[i]; i++)
arg[i] = s_native[i] & 255; /* ISO-8859-1 conversion */
}
}
w.nmem = res->nmem;
w.no_eq = 0;
- if (scan_string(argv[1], t_unicode, t_utf8,
+ if (scan_string(argv[1], t_unicode, t_utf8,
fun_add_equivalent_string, &w, 0) < 0)
{
yaz_log(YLOG_FATAL, "equivalent: invalid string");
yaz_log(YLOG_WARN, "Syntax error at '%s' in %s", line, name);
errors++;
}
- }
+ }
yaz_fclose(f);
if (no_directives == 0)
{
dd->handle = FindFirstFile(fullName, &dd->find_data);
return dd;
}
-
+
struct dirent *readdir (DIR *dd)
{
if (dd->handle == INVALID_HANDLE_VALUE)
{
int dlen = dir ? strlen(dir) : 0;
char *fname = xmalloc(dlen + strlen(name) + 3);
-
+
#ifdef WIN32
if (dlen)
{
int last_one = dir[dlen-1];
-
+
if (!strchr("/\\:", last_one))
sprintf(fname, "%s\\%s", dir, name);
else
if (!p)
{ /* didn't match (or we didn't want it to match! */
p = (struct zebra_lock_info *) xmalloc(sizeof(*p));
-
+
p->ref_count = 0;
#ifdef WIN32
p->fd = open(name, O_BINARY|O_RDONLY);
if (p->fd == -1)
{
xfree(p);
- yaz_log(YLOG_WARN | YLOG_ERRNO,
+ yaz_log(YLOG_WARN | YLOG_ERRNO,
"zebra_lock_create fail fname=%s", fname);
p = 0;
}
yaz_log(YLOG_WARN|YLOG_ERRNO, "fcntl FAIL type=%d fd=%d", type, fd);
else
yaz_log(log_level, "fcntl type=%d OK fd=%d", type, fd);
-
+
return r;
}
#endif
{
int r = 0;
int do_lock = 0;
- yaz_log(log_level, "zebra_lock_w fd=%d p=%p fname=%s begin",
+ yaz_log(log_level, "zebra_lock_w fd=%d p=%p fname=%s begin",
h->p->fd, h, h->p->fname);
#ifdef WIN32
h->write_flag = 1;
#endif
- yaz_log(log_level, "zebra_lock_w fd=%d p=%p fname=%s end",
+ yaz_log(log_level, "zebra_lock_w fd=%d p=%p fname=%s end",
h->p->fd, h, h->p->fname);
return r;
int r = 0;
int do_lock = 0;
- yaz_log(log_level, "zebra_lock_r fd=%d p=%p fname=%s begin",
+ yaz_log(log_level, "zebra_lock_r fd=%d p=%p fname=%s begin",
h->p->fd, h, h->p->fname);
#ifdef WIN32
while ((r = _locking(h->p->fd, _LK_LOCK, 1)))
assert(posix_locks);
}
zebra_mutex_unlock(&h->p->file_mutex);
-
+
h->write_flag = 0;
#endif
- yaz_log(log_level, "zebra_lock_r fd=%d p=%p fname=%s end",
+ yaz_log(log_level, "zebra_lock_r fd=%d p=%p fname=%s end",
h->p->fd, h, h->p->fname);
return r;
}
return r;
}
-/** \brief see if the fcntl locking is not POSIX
+/** \brief see if the fcntl locking is not POSIX
*
* The default posix_locks=1 is assumed.. This function sets posix_locks
* to zero if linuxthreads is in use.
size_t l;
char *cp1 = *(char **) p1;
char *cp2 = *(char **) p2;
-
+
if ((r = strcmp (cp1, cp2)))
return r;
l = strlen(cp1)+1;
3, 2, 9, 12
3, 2, 10, 2
4, 1
-
+
if diff is 0, then there is more ...
if diff is non-zero, then _may_ be more
*/
}
static int get_entry (const char **p, char *dst, int max)
-{
+{
int i = 0;
while ((*p)[i] != ':' && (*p)[i])
i++;
while (pe)
{
struct passwd_entry *pe_next = pe->next;
-
+
xfree (pe->name);
xfree (pe->des);
xfree (pe);
if (strcmp (pe->des, pass))
return -2;
}
- return 0;
+ return 0;
}
int passwd_db_file_crypt(Passwd_db db, const char *fname)
strcpy(dst+j, env_val);
j += strlen(env_val);
}
- else if (src[i] == ':' && src[i+1] == '-')
+ else if (src[i] == ':' && src[i+1] == '-')
{
i = i + 2;
while (src[i] && !strchr("}\n\r\f", src[i]))
int lineno = 1;
WRBUF wrbuf_val = wrbuf_alloc();
yaz_tok_cfg_t yt = yaz_tok_cfg_create();
-
+
while ((line = fgets(fr_buf, sizeof(fr_buf)-1, fr)))
{
yaz_tok_parse_t tp = yaz_tok_parse_buf(yt, line);
int t = yaz_tok_move(tp);
-
+
if (t == YAZ_TOK_STRING)
{
size_t sz;
{
/* name: value */
t = yaz_tok_move(tp);
-
+
if (t != YAZ_TOK_STRING)
{
resp->value = xstrdup("");
}
lineno++;
yaz_tok_parse_destroy(tp);
- }
+ }
fclose(fr);
yaz_tok_cfg_destroy(yt);
wrbuf_destroy(wrbuf_val);
if (prefix)
{
char rname[128];
-
+
if (strlen(name) + strlen(prefix) >= (sizeof(rname)-2))
return 0;
strcpy(rname, prefix);
if (!r)
return 0;
-
+
v = res_get(r->over_res, name);
if (v)
return v;
struct res_entry *re;
int l = 0;
int no = 0;
-
+
if (!r)
return 0;
no = res_trav(r->over_res, prefix, p, f);
re->value = xstrdup_env(value);
}
-void res_dump(Res r, int level)
+void res_dump(Res r, int level)
{
struct res_entry *re;
-
+
if (!r)
return;
-
+
for (re = r->first; re; re=re->next) {
printf("%*s - %s:='%s'\n",level * 4,"",re->name,re->value);
}
-
+
if (r->def_res) {
printf("%*s DEF ",level * 4,"");
res_dump(r->def_res, level + 1);
}
-
+
if (r->over_res) {
printf("%*s OVER ",level * 4,"");
res_dump(r->over_res, level + 1);
{
struct res_entry *e_i;
int errors = 0;
-
+
for (e_i = r_i->first; e_i; e_i = e_i->next)
{
struct res_entry *e_v;
prefix_allowed = 1;
if (strchr(e_v->value, 's'))
suffix_allowed = 1;
-
+
first_dot = strchr(name, '.');
if (prefix_allowed && first_dot)
{
if (all || w->mark)
yaz_log(log_level, "term='%s'%s mark=%d seqno=" ZINT_FORMAT " ord=%d",
- wrbuf_cstr(wr_term),
+ wrbuf_cstr(wr_term),
(w->match && !w->ws ? "*" : ""), w->mark,
w->seqno, w->ord);
wrbuf_destroy(wr_term);
hit_w = hit_w->next)
{
if (hit_w->ord == ord && hit_w->seqno == doc_w->seqno)
-
+
{
match = 1;
break;
}
zebra_snippets_append_match(result, doc_w->seqno,
doc_w->ws,
- ord, doc_w->term,
+ ord, doc_w->term,
strlen(doc_w->term), match);
}
}
doc_w->mark = 1;
break;
}
-
+
}
/* mark following terms */
if (doc_w)
zebra_snippet_word *w = doc_w->next;
while (w)
if (w->ord == ord
- && hit_w->seqno - before < w->seqno
+ && hit_w->seqno - before < w->seqno
&& hit_w->seqno + after > w->seqno)
{
w->mark = 1;
zebra_snippet_word *w = doc_w->prev;
while (w)
if (w->ord == ord
- && hit_w->seqno - before < w->seqno
+ && hit_w->seqno - before < w->seqno
&& hit_w->seqno + after > w->seqno)
{
w->mark = 1;
}
}
-
+
/*
* Local variables:
* c-basic-offset: 4
void *data_buf;
struct strmap_entry *next;
};
-
+
struct zebra_strmap {
NMEM nmem_str;
NMEM nmem_ent;
int hno;
struct strmap_entry *ent;
zebra_strmap_t st;
-
+
};
zebra_strmap_it zebra_strmap_it_create(zebra_strmap_t st)
}
return 0;
}
-
+
/*
* Local variables:
* c-basic-offset: 4
size_t data_len;
zebra_strmap_t sm = zebra_strmap_create();
YAZ_CHECK(!zebra_strmap_lookup(sm, "a", 0, 0));
-
+
zebra_strmap_add(sm, "a", &v, sizeof v);
data_buf = zebra_strmap_lookup(sm, "a", 0, &data_len);
- YAZ_CHECK(data_buf && data_len == sizeof v
+ YAZ_CHECK(data_buf && data_len == sizeof v
&& v == *((int*) data_buf));
zebra_strmap_remove(sm, "a");
if (use_write_lock == 2) /* random lock */
write_lock = (rand() & 3) == 3 ? 1 : 0;
-
+
if (write_lock)
{
zebra_lock_w(lh);
write(test_fd, "L", 1);
*seqp++ = 'L';
small_sleep();
- *seqp++ = 'U';
+ *seqp++ = 'U';
write(test_fd, "U", 1);
-
+
zebra_unlock(lh);
}
else
{
zebra_lock_r(lh);
-
+
write(test_fd, "l", 1);
*seqp++ = 'l';
small_sleep();
*seqp++ = 'u';
write(test_fd, "u", 1);
-
+
zebra_unlock(lh);
}
}
for (i = 0; i < num; i++)
YAZ_CHECK(id[i] == 123);
*seqp++ = '\0';
- yaz_log(YLOG_LOG, "tst_thread(%d,%d) returns seq=%s",
+ yaz_log(YLOG_LOG, "tst_thread(%d,%d) returns seq=%s",
num, write_flag, seq);
}
area.l_type = type;
area.l_whence = SEEK_SET;
area.l_len = area.l_start = 0L;
-
+
return fcntl(fd, cmd, &area);
}
{
char path[1024];
Passwd_db db;
-
+
db = passwd_db_open();
YAZ_CHECK(db);
if (!db)
const char *v;
char path[1024];
int r;
-
+
yaz_snprintf(path, sizeof(path), "%s/tstres.cfg", get_srcdir());
r = res_read_file(res, path);
YAZ_CHECK_EQ(r, ZEBRA_OK);
char **look, int *literal)
{
struct xpath_predicate *left = 0;
-
+
left = get_xpath_relation(pr, mem, look, literal);
if (!left)
return 0;
-
+
while (*look && !*literal &&
- (!strcmp(*look, "and") || !strcmp(*look, "or") ||
+ (!strcmp(*look, "and") || !strcmp(*look, "or") ||
!strcmp(*look, "not")))
{
struct xpath_predicate *res, *right;
{
const char *cp;
char *a;
-
+
int no = 0;
-
+
if (!xpath_string || *xpath_string != '/')
return -1;
cp = xpath_string;
-
+
while (*cp && no < max)
{
int i = 0;
if (p) {
if (p->which == XPATH_PREDICATE_RELATION &&
p->u.relation.name[0]) {
- fprintf (stderr, "%s,%s,%s",
+ fprintf (stderr, "%s,%s,%s",
p->u.relation.name,
p->u.relation.op,
p->u.relation.value);
if (p->state != 0)
{
fprintf (stderr, "zebra_mutex_destroy. state = %d\n", p->state);
- }
+ }
#if YAZ_POSIX_THREADS
pthread_mutex_destroy (&p->mutex);
#endif
{
pthread_mutex_unlock (&p->mutex);
return -1;
- }
+ }
else
{
p->readers_reading--;
}
else if (!zm)
{
- yaz_log(YLOG_WARN, "%s:%d: Missing sort/index before '%s'",
+ yaz_log(YLOG_WARN, "%s:%d: Missing sort/index before '%s'",
fname, lineno, argv[0]);
return -1;
}
zm->u.sort.entry_size = atoi(argv[1]);
else
{
- yaz_log(YLOG_WARN,
- "%s:%d: entrysize only valid in sort section",
+ yaz_log(YLOG_WARN,
+ "%s:%d: entrysize only valid in sort section",
fname, lineno);
return -1;
}
#if YAZ_HAVE_ICU
UErrorCode status;
xmlNode *xml_node = xmlDocGetRootElement(zm->doc);
- zm->icu_chain =
+ zm->icu_chain =
icu_chain_xml_config(xml_node,
/* not sure about sort for this function yet.. */
#if 1
1,
#else
zm->type == ZEBRA_MAP_TYPE_SORT,
-#endif
+#endif
&status);
if (!zm->icu_chain)
{
}
else
{
- yaz_log(YLOG_WARN, "%s:%d: Unrecognized directive '%s'",
+ yaz_log(YLOG_WARN, "%s:%d: Unrecognized directive '%s'",
fname, lineno, argv[0]);
return -1;
}
if (!zm)
{
zm = zebra_add_map(zms, id, ZEBRA_MAP_TYPE_INDEX);
-
+
/* no reason to warn if no maps are read from file */
if (zms->no_files_read)
yaz_log(YLOG_WARN, "Unknown register type: %s", id);
chrmaptab maptab = zebra_charmap_get(zm);
if (maptab)
return chr_map_input(maptab, from, len, first);
-
+
zm->zebra_maps->temp_map_str[0] = **from;
(*from)++;
const char **from, int len, int *q_map_match)
{
chrmaptab maptab;
-
+
*q_map_match = 0;
maptab = zebra_charmap_get(zm);
if (maptab)
/* ------------------------------------ */
int zebra_maps_is_complete(zebra_map_t zm)
-{
+{
if (zm)
return zm->completeness;
return 0;
return zm->type == ZEBRA_MAP_TYPE_STATICRANK;
return 0;
}
-
+
int zebra_maps_is_sort(zebra_map_t zm)
{
if (zm)
break;
case 106: /* document-text */
*search_type = "or-list";
- break;
+ break;
case -1:
case 1: /* phrase */
case 2: /* word */
- case 108: /* string */
+ case 108: /* string */
*search_type = "phrase";
break;
case 107: /* local-number */
wrbuf_rewind(zm->print_str);
wrbuf_write_escaped(zm->print_str, wrbuf_buf(zm->input_str),
wrbuf_len(zm->input_str));
-
- yaz_log(YLOG_LOG, "input %s",
- wrbuf_cstr(zm->print_str));
+
+ yaz_log(YLOG_LOG, "input %s",
+ wrbuf_cstr(zm->print_str));
}
ret = icu_chain_assign_cstr(zm->icu_chain,
wrbuf_cstr(zm->input_str), &status);