#include "dict-p.h"
-int dict_close (Dict dict)
+int dict_close(Dict dict)
{
if (!dict)
return 0;
if (dict->rw)
{
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_readp(dict->dbf, 0, &head_buf);
+ memcpy(head_buf, &dict->head, sizeof(dict->head));
+ dict_bf_touch(dict->dbf, 0);
}
- dict_bf_close (dict->dbf);
- xfree (dict);
+ dict_bf_close(dict->dbf);
+ xfree(dict);
return 0;
}
#include "dict-p.h"
-int dict_bf_close (Dict_BFile dbf)
+int dict_bf_close(Dict_BFile dbf)
{
- dict_bf_flush_blocks (dbf, -1);
+ dict_bf_flush_blocks(dbf, -1);
- xfree (dbf->all_blocks);
- xfree (dbf->all_data);
- xfree (dbf->hash_array);
+ xfree(dbf->all_blocks);
+ xfree(dbf->all_data);
+ xfree(dbf->hash_array);
bf_close(dbf->bf);
- xfree (dbf);
+ xfree(dbf);
return 0;
}
/*
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;
- for (i = DICT_nodir (from_p); --i >= 0; )
+ for (i = DICT_nodir(from_p); --i >= 0; )
{
if (*--from_indxp > 0) /* tail string here! */
{
from_info = (char*) from_p + *from_indxp;
*--to_indxp = to_info - to_p;
slen = (dict_strlen((Dict_char*) from_info)+1)*sizeof(Dict_char);
- memcpy (to_info, from_info, slen);
+ memcpy(to_info, from_info, slen);
from_info += slen;
to_info += slen;
}
*--to_indxp = -(to_info - to_p);
from_info = (char*) from_p - *from_indxp;
- memcpy (&subptr, from_info, sizeof(subptr));
+ memcpy(&subptr, from_info, sizeof(subptr));
subptr = map[subptr];
from_info += sizeof(Dict_ptr);
- memcpy (&subchar, from_info, sizeof(subchar));
+ memcpy(&subchar, from_info, sizeof(subchar));
from_info += sizeof(Dict_char);
- memcpy (to_info, &subptr, sizeof(Dict_ptr));
+ memcpy(to_info, &subptr, sizeof(Dict_ptr));
to_info += sizeof(Dict_ptr);
- memcpy (to_info, &subchar, sizeof(Dict_char));
+ memcpy(to_info, &subchar, sizeof(Dict_char));
to_info += sizeof(Dict_char);
}
- assert (to_info < (char*) to_indxp);
+ assert(to_info < (char*) to_indxp);
slen = *from_info+1;
- memcpy (to_info, from_info, slen);
+ memcpy(to_info, from_info, slen);
to_info += slen;
++no;
}
DICT_nodir(to_p) = no;
}
-int dict_copy_compact (BFiles bfs, const char *from_name, const char *to_name)
+int dict_copy_compact(BFiles bfs, const char *from_name, const char *to_name)
{
int no_dir = 0;
Dict dict_from, dict_to;
int *map, i;
- dict_from = dict_open (bfs, from_name, 0, 0, 0, 4096);
+ dict_from = dict_open(bfs, from_name, 0, 0, 0, 4096);
if (!dict_from)
return -1;
- map = (int *) xmalloc ((dict_from->head.last+1) * sizeof(*map));
- for (i = 0; i <= (int) (dict_from->head.last); i++)
+ map = (int *) xmalloc((dict_from->head.last+1) * sizeof(*map));
+ for (i = 0; i <= (int)(dict_from->head.last); i++)
map[i] = -1;
- dict_to = dict_open (bfs, to_name, 0, 1, 1, 4096);
+ dict_to = dict_open(bfs, to_name, 0, 1, 1, 4096);
if (!dict_to)
return -1;
map[0] = 0;
void *buf;
int size;
#if 0
- yaz_log (YLOG_LOG, "map[%d] = %d", i, map[i]);
+ yaz_log(YLOG_LOG, "map[%d] = %d", i, map[i]);
#endif
- dict_bf_readp (dict_from->dbf, i, &buf);
+ dict_bf_readp(dict_from->dbf, i, &buf);
size = ((DICT_size(buf)+sizeof(short)-1)/sizeof(short) +
DICT_nodir(buf))*sizeof(short);
map[i+1] = map[i] + size;
no_dir += DICT_nodir(buf);
}
#if 0
- yaz_log (YLOG_LOG, "map[%d] = %d", i, map[i]);
- yaz_log (YLOG_LOG, "nodir = %d", no_dir);
+ yaz_log(YLOG_LOG, "map[%d] = %d", i, map[i]);
+ yaz_log(YLOG_LOG, "nodir = %d", no_dir);
#endif
dict_to->head.root = map[1];
dict_to->head.last = map[i];
for (i = 1; i< (int) (dict_from->head.last); i++)
{
void *old_p, *new_p;
- dict_bf_readp (dict_from->dbf, i, &old_p);
+ dict_bf_readp(dict_from->dbf, i, &old_p);
- yaz_log (YLOG_LOG, "dict_bf_newp no=%d size=%d", map[i],
+ yaz_log(YLOG_LOG, "dict_bf_newp no=%d size=%d", map[i],
map[i+1] - map[i]);
- dict_bf_newp (dict_to->dbf, map[i], &new_p, map[i+1] - map[i]);
+ dict_bf_newp(dict_to->dbf, map[i], &new_p, map[i+1] - map[i]);
DICT_type(new_p) = 0;
DICT_backptr(new_p) = map[i-1];
dict_copy_page(dict_from, (char*) new_p, (char*) old_p, map);
}
- dict_close (dict_from);
- dict_close (dict_to);
+ dict_close(dict_from);
+ dict_close(dict_to);
return 0;
}
/*
#include "dict-p.h"
-static void dict_del_subtree (Dict dict, Dict_ptr ptr,
- void *client,
- int (*f)(const char *, void *))
+static void dict_del_subtree(Dict dict, Dict_ptr ptr,
+ void *client,
+ int (*f)(const char *, void *))
{
void *p = 0;
short *indxp;
if (!ptr)
return;
- dict_bf_readp (dict->dbf, ptr, &p);
+ dict_bf_readp(dict->dbf, ptr, &p);
indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
hi = DICT_nodir(p)-1;
for (i = 0; i <= hi; i++)
/* unsigned char length of information */
/* char * information */
char *info = (char*)p - indxp[-i];
- memcpy (&subptr, info, sizeof(Dict_ptr));
+ memcpy(&subptr, info, sizeof(Dict_ptr));
if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
{
}
if (subptr)
{
- dict_del_subtree (dict, subptr, client, f);
+ dict_del_subtree(dict, subptr, client, f);
/* page may be gone. reread it .. */
- dict_bf_readp (dict->dbf, ptr, &p);
+ dict_bf_readp(dict->dbf, ptr, &p);
indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
}
}
}
DICT_backptr(p) = dict->head.freelist;
dict->head.freelist = ptr;
- dict_bf_touch (dict->dbf, ptr);
+ dict_bf_touch(dict->dbf, ptr);
}
-static int dict_del_string (Dict dict, const Dict_char *str, Dict_ptr ptr,
- int sub_flag, void *client,
- int (*f)(const char *, void *))
+static int dict_del_string(Dict dict, const Dict_char *str, Dict_ptr ptr,
+ int sub_flag, void *client,
+ int (*f)(const char *, void *))
{
int mid, lo, hi;
int cmp;
if (!ptr)
return 0;
- dict_bf_readp (dict->dbf, ptr, &p);
+ dict_bf_readp(dict->dbf, ptr, &p);
mid = lo = 0;
hi = DICT_nodir(p)-1;
indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
if (sub_flag)
{
/* determine if prefix match */
- if (!dict_strncmp (str, (Dict_char*) info, dict_strlen(str)))
+ if (!dict_strncmp(str, (Dict_char*) info, dict_strlen(str)))
{
if (f)
(*f)(info + (dict_strlen((Dict_char*) info)+1)
}
DICT_type(p) = 1;
(DICT_nodir(p))--;
- dict_bf_touch (dict->dbf, ptr);
+ dict_bf_touch(dict->dbf, ptr);
--hi;
mid = lo = 0;
/* start again (may not be the most efficient way to go)*/
}
DICT_type(p) = 1;
(DICT_nodir(p))--;
- dict_bf_touch (dict->dbf, ptr);
+ dict_bf_touch(dict->dbf, ptr);
return 1;
}
}
/* unsigned char length of information */
/* char * information */
info = (char*)p - indxp[-mid];
- memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
+ memcpy(&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
cmp = dc- *str;
if (!cmp)
{
- memcpy (&subptr, info, sizeof(Dict_ptr));
+ memcpy(&subptr, info, sizeof(Dict_ptr));
if (*++str == DICT_EOS)
{
if (sub_flag && subptr)
{
Dict null_ptr = 0;
- memcpy (info, &null_ptr, sizeof(Dict_ptr));
+ memcpy(info, &null_ptr, sizeof(Dict_ptr));
}
if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
{
info[sizeof(Dict_ptr)+sizeof(Dict_char)] = 0;
DICT_type(p) = 1;
- dict_bf_touch (dict->dbf, ptr);
+ dict_bf_touch(dict->dbf, ptr);
if (f)
(*f)(info+sizeof(Dict_ptr)+sizeof(Dict_char),
client);
if (sub_flag && subptr)
- dict_del_subtree (dict, subptr, client, f);
+ dict_del_subtree(dict, subptr, client, f);
return 1;
}
if (sub_flag && subptr)
{
DICT_type(p) = 1;
- dict_bf_touch (dict->dbf, ptr);
- dict_del_subtree (dict, subptr, client, f);
+ dict_bf_touch(dict->dbf, ptr);
+ dict_del_subtree(dict, subptr, client, f);
}
return 0;
}
if (subptr == 0)
return 0;
ptr = subptr;
- dict_bf_readp (dict->dbf, ptr, &p);
+ dict_bf_readp(dict->dbf, ptr, &p);
mid = lo = 0;
hi = DICT_nodir(p)-1;
indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
return 0;
}
-int dict_delete (Dict dict, const char *p)
+int dict_delete(Dict dict, const char *p)
{
- return dict_del_string (dict, (const Dict_char*) p, dict->head.root, 0,
- 0, 0);
+ return dict_del_string(dict, (const Dict_char*) p, dict->head.root, 0,
+ 0, 0);
}
-int dict_delete_subtree (Dict dict, const char *p, void *client,
- int (*f)(const char *info, void *client))
+int dict_delete_subtree(Dict dict, const char *p, void *client,
+ int (*f)(const char *info, void *client))
{
- return dict_del_string (dict, (const Dict_char*) p, dict->head.root, 1,
- client, f);
+ return dict_del_string(dict, (const Dict_char*) p, dict->head.root, 1,
+ client, f);
}
/*
* Local variables:
char *prog;
-int main (int argc, char **argv)
+int main(int argc, char **argv)
{
char *arg;
int ret;
inputfile = arg;
else
{
- yaz_log (YLOG_FATAL, "too many files specified\n");
- exit (1);
+ yaz_log(YLOG_FATAL, "too many files specified\n");
+ exit(1);
}
}
else if (ret == 'v')
{
- yaz_log_init (yaz_log_mask_str(arg), prog, NULL);
+ yaz_log_init(yaz_log_mask_str(arg), prog, NULL);
}
else if (ret == 'h')
{
- fprintf (stderr, "usage:\n"
- " %s [-8] [-h] [-v n] [file]\n", prog);
- exit (1);
+ fprintf(stderr, "usage:\n"
+ " %s [-8] [-h] [-v n] [file]\n", prog);
+ exit(1);
}
else if (ret == '8')
use8 = 1;
else
{
- yaz_log (YLOG_FATAL, "Unknown option '-%s'", arg);
- exit (1);
+ yaz_log(YLOG_FATAL, "Unknown option '-%s'", arg);
+ exit(1);
}
}
if (inputfile)
{
- ipf = fopen (inputfile, "r");
+ ipf = fopen(inputfile, "r");
if (!ipf)
{
- yaz_log (YLOG_FATAL|YLOG_ERRNO, "cannot open '%s'", inputfile);
- exit (1);
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "cannot open '%s'", inputfile);
+ exit(1);
}
}
- while (fgets (ipf_buf, 1023, ipf))
+ while (fgets(ipf_buf, 1023, ipf))
{
char *ipf_ptr = ipf_buf;
for (;*ipf_ptr && *ipf_ptr != '\n';ipf_ptr++)
i++;
if (ipf_ptr[i])
ipf_ptr[i++] = '\0';
- printf ("%s\n", ipf_ptr);
+ printf("%s\n", ipf_ptr);
ipf_ptr += (i-1);
}
}
#include "dict-p.h"
-static void common_init (Dict_BFile bf, int block_size, int cache)
+static void common_init(Dict_BFile bf, int block_size, int cache)
{
int i;
bf->hits = bf->misses = 0;
/* Allocate all blocks in one chunk. */
- bf->all_data = xmalloc (block_size * cache);
+ bf->all_data = xmalloc(block_size * cache);
/* Allocate and initialize hash array (as empty) */
bf->hash_array = (struct Dict_file_block **)
/* Allocate all block descriptors in one chunk */
bf->all_blocks = (struct Dict_file_block *)
- xmalloc (sizeof(*bf->all_blocks) * cache);
+ xmalloc(sizeof(*bf->all_blocks) * cache);
/* Initialize the free list */
bf->free_list = bf->all_blocks;
}
-Dict_BFile dict_bf_open (BFiles bfs, const char *name, int block_size,
- int cache, int rw)
+Dict_BFile dict_bf_open(BFiles bfs, const char *name, int block_size,
+ int cache, int rw)
{
Dict_BFile dbf;
-
- dbf = (Dict_BFile) xmalloc (sizeof(*dbf));
- dbf->bf = bf_open (bfs, name, block_size, rw);
+
+ dbf = (Dict_BFile) xmalloc(sizeof(*dbf));
+ dbf->bf = bf_open(bfs, name, block_size, rw);
if (!dbf->bf)
{
xfree(dbf);
return 0;
}
- common_init (dbf, block_size, cache);
+ common_init(dbf, block_size, cache);
return dbf;
}
-void dict_bf_compact (Dict_BFile dbf)
+void dict_bf_compact(Dict_BFile dbf)
{
dbf->compact_flag = 1;
}
/* This file is part of the Zebra server.
Copyright (C) 1994-2009 Index Data
-Zebra is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
-version.
+ Zebra is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
-Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
+ Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "dict-p.h"
-void dict_pr_lru (Dict_BFile bf)
+void dict_pr_lru(Dict_BFile bf)
{
struct Dict_file_block *p;
for (p=bf->lru_back; p; p = p->lru_next)
{
- printf (" %d", p->no);
+ printf(" %d", p->no);
}
- printf ("\n");
- fflush (stdout);
+ printf("\n");
+ fflush(stdout);
}
-static struct Dict_file_block *find_block (Dict_BFile bf, int no)
+static struct Dict_file_block *find_block(Dict_BFile bf, int no)
{
struct Dict_file_block *p;
return p;
}
-static void release_block (Dict_BFile bf, struct Dict_file_block *p)
+static void release_block(Dict_BFile bf, struct Dict_file_block *p)
{
- assert (p);
+ assert(p);
/* remove from lru queue */
if (p->lru_prev)
bf->free_list = p;
}
-void dict_bf_flush_blocks (Dict_BFile bf, int no_to_flush)
+void dict_bf_flush_blocks(Dict_BFile bf, int no_to_flush)
{
struct Dict_file_block *p;
int i;
if (p->dirty)
{
if (!bf->compact_flag)
- bf_write (bf->bf, p->no, 0, 0, p->data);
+ bf_write(bf->bf, p->no, 0, 0, p->data);
else
{
int effective_block = p->no / bf->block_size;
if (remain >= p->nbytes)
{
- bf_write (bf->bf, effective_block, effective_offset,
- p->nbytes, p->data);
+ bf_write(bf->bf, effective_block, effective_offset,
+ p->nbytes, p->data);
#if 0
- yaz_log (YLOG_LOG, "bf_write no=%d offset=%d size=%d",
- effective_block, effective_offset,
- p->nbytes);
+ yaz_log(YLOG_LOG, "bf_write no=%d offset=%d size=%d",
+ effective_block, effective_offset,
+ p->nbytes);
#endif
}
else
{
#if 0
- yaz_log (YLOG_LOG, "bf_write1 no=%d offset=%d size=%d",
- effective_block, effective_offset,
- remain);
+ yaz_log(YLOG_LOG, "bf_write1 no=%d offset=%d size=%d",
+ effective_block, effective_offset,
+ remain);
#endif
- bf_write (bf->bf, effective_block, effective_offset,
- remain, p->data);
+ bf_write(bf->bf, effective_block, effective_offset,
+ remain, p->data);
#if 0
- yaz_log (YLOG_LOG, "bf_write2 no=%d offset=%d size=%d",
- effective_block+1, 0, p->nbytes - remain);
+ yaz_log(YLOG_LOG, "bf_write2 no=%d offset=%d size=%d",
+ effective_block+1, 0, p->nbytes - remain);
#endif
- bf_write (bf->bf, effective_block+1, 0,
- p->nbytes - remain, (char*)p->data + remain);
+ bf_write(bf->bf, effective_block+1, 0,
+ p->nbytes - remain, (char*)p->data + remain);
}
}
}
- release_block (bf, p);
+ release_block(bf, p);
}
}
-static struct Dict_file_block *alloc_block (Dict_BFile bf, int no)
+static struct Dict_file_block *alloc_block(Dict_BFile bf, int no)
{
struct Dict_file_block *p, **pp;
if (!bf->free_list)
- dict_bf_flush_blocks (bf, 1);
- assert (bf->free_list);
+ dict_bf_flush_blocks(bf, 1);
+ assert(bf->free_list);
p = bf->free_list;
bf->free_list = p->h_next;
p->dirty = 0;
return p;
}
-static void move_to_front (Dict_BFile bf, struct Dict_file_block *p)
+static void move_to_front(Dict_BFile bf, struct Dict_file_block *p)
{
/* Already at front? */
if (!p->lru_next)
bf->lru_front = p;
}
-int dict_bf_readp (Dict_BFile bf, int no, void **bufp)
+int dict_bf_readp(Dict_BFile bf, int no, void **bufp)
{
struct Dict_file_block *p;
int i;
- if ((p = find_block (bf, no)))
+ if ((p = find_block(bf, no)))
{
*bufp = p->data;
- move_to_front (bf, p);
+ move_to_front(bf, p);
bf->hits++;
return 1;
}
bf->misses++;
- p = alloc_block (bf, no);
+ p = alloc_block(bf, no);
if (!bf->compact_flag)
- i = bf_read (bf->bf, no, 0, 0, p->data);
+ i = bf_read(bf->bf, no, 0, 0, p->data);
else
{
int effective_block = no / bf->block_size;
int effective_offset = no - effective_block * bf->block_size;
- i = bf_read (bf->bf, effective_block, effective_offset,
- bf->block_size - effective_offset, p->data);
+ i = bf_read(bf->bf, effective_block, effective_offset,
+ bf->block_size - effective_offset, p->data);
if (i > 0 && effective_offset > 0)
- i = bf_read (bf->bf, effective_block+1, 0, effective_offset,
- (char*) p->data + bf->block_size - effective_offset);
+ i = bf_read(bf->bf, effective_block+1, 0, effective_offset,
+ (char*) p->data + bf->block_size - effective_offset);
i = 1;
}
if (i > 0)
*bufp = p->data;
return i;
}
- release_block (bf, p);
+ release_block(bf, p);
*bufp = NULL;
return i;
}
-int dict_bf_newp (Dict_BFile dbf, int no, void **bufp, int nbytes)
+int dict_bf_newp(Dict_BFile dbf, int no, void **bufp, int nbytes)
{
struct Dict_file_block *p;
- if (!(p = find_block (dbf, no)))
- p = alloc_block (dbf, no);
+ if (!(p = find_block(dbf, no)))
+ p = alloc_block(dbf, no);
else
- move_to_front (dbf, p);
+ move_to_front(dbf, p);
*bufp = p->data;
- memset (p->data, 0, dbf->block_size);
+ memset(p->data, 0, dbf->block_size);
p->dirty = 1;
p->nbytes = nbytes;
#if 0
- printf ("bf_newp of %d:", no);
- dict_pr_lru (dbf);
+ printf("bf_newp of %d:", no);
+ dict_pr_lru(dbf);
#endif
return 1;
}
-int dict_bf_touch (Dict_BFile dbf, int no)
+int dict_bf_touch(Dict_BFile dbf, int no)
{
struct Dict_file_block *p;
- if ((p = find_block (dbf, no)))
+ if ((p = find_block(dbf, no)))
{
p->dirty = 1;
return 0;
#define CHECK 0
-static int dict_ins (Dict dict, const Dict_char *str,
- Dict_ptr back_ptr, int userlen, void *userinfo);
-static void clean_page (Dict dict, Dict_ptr ptr, void *p, Dict_char *out,
- Dict_ptr subptr, char *userinfo);
+static int dict_ins(Dict dict, const Dict_char *str,
+ Dict_ptr back_ptr, int userlen, void *userinfo);
+static void clean_page(Dict dict, Dict_ptr ptr, void *p, Dict_char *out,
+ Dict_ptr subptr, char *userinfo);
-static Dict_ptr new_page (Dict dict, Dict_ptr back_ptr, void **pp)
+static Dict_ptr new_page(Dict dict, Dict_ptr back_ptr, void **pp)
{
void *p;
Dict_ptr ptr = dict->head.last;
if (!dict->head.freelist)
{
- dict_bf_newp (dict->dbf, dict->head.last, &p, dict->head.page_size);
+ dict_bf_newp(dict->dbf, dict->head.last, &p, dict->head.page_size);
(dict->head.last)++;
}
else
{
ptr = dict->head.freelist;
- dict_bf_readp (dict->dbf, ptr, &p);
+ dict_bf_readp(dict->dbf, ptr, &p);
dict->head.freelist = DICT_backptr(p);
}
- assert (p);
+ assert(p);
DICT_type(p) = 0;
DICT_backptr(p) = back_ptr;
DICT_nodir(p) = 0;
return ptr;
}
-static int split_page (Dict dict, Dict_ptr ptr, void *p)
+static int split_page(Dict dict, Dict_ptr ptr, void *p)
{
void *subp;
char *info_here;
dict->no_split++;
/* determine splitting char... */
indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
- for (i = DICT_nodir (p); --i >= 0; --indxp)
+ for (i = DICT_nodir(p); --i >= 0; --indxp)
{
if (*indxp > 0) /* tail string here! */
{
Dict_char dc;
- memcpy (&dc, (char*) p + *indxp, sizeof(dc));
+ memcpy(&dc, (char*) p + *indxp, sizeof(dc));
if (best_no < 0)
{ /* first entry met */
best_char = prev_char = dc;
assert(best_no >= 0); /* we didn't find any tail string entry at all! */
j = best_indxp - (short*) p;
- subptr = new_page (dict, ptr, &subp);
+ subptr = new_page(dict, ptr, &subp);
/* scan entries to see if there is a string with */
/* length 1. info_here indicates if such entry exist */
info_here = NULL;
info = (char*) p + ((short*) p)[j];
/* entry start */
- memcpy (&dc, info, sizeof(dc));
- assert (dc == best_char);
+ memcpy(&dc, info, sizeof(dc));
+ assert(dc == best_char);
slen = 1+dict_strlen((Dict_char*) info);
- assert (slen > 1);
+ assert(slen > 1);
if (slen == 2)
{
- assert (!info_here);
+ assert(!info_here);
info_here = info+slen*sizeof(Dict_char);
}
else
{
info1 = info+slen*sizeof(Dict_char); /* info start */
- dict_ins (dict, (Dict_char*) (info+sizeof(Dict_char)),
- subptr, *info1, info1+1);
- dict_bf_readp (dict->dbf, ptr, &p);
+ dict_ins(dict, (Dict_char*) (info+sizeof(Dict_char)),
+ subptr, *info1, info1+1);
+ dict_bf_readp(dict->dbf, ptr, &p);
}
}
/* now clean the page ... */
- clean_page (dict, ptr, p, &best_char, subptr, info_here);
+ clean_page(dict, ptr, p, &best_char, subptr, info_here);
return 0;
}
-static void clean_page (Dict dict, Dict_ptr ptr, void *p, Dict_char *out,
- Dict_ptr subptr, char *userinfo)
+static void clean_page(Dict dict, Dict_ptr ptr, void *p, Dict_char *out,
+ Dict_ptr subptr, char *userinfo)
{
- char *np = (char *) xmalloc (dict->head.page_size);
+ char *np = (char *) xmalloc(dict->head.page_size);
int i, slen, no = 0;
short *indxp1, *indxp2;
char *info1, *info2;
indxp1 = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
indxp2 = (short*) ((char*) np+DICT_bsize(np));
info2 = (char*) np + DICT_infoffset;
- for (i = DICT_nodir (p); --i >= 0; --indxp1)
+ for (i = DICT_nodir(p); --i >= 0; --indxp1)
{
if (*indxp1 > 0) /* tail string here! */
{
/* char * information */
info1 = (char*) p + *indxp1;
- if (out && memcmp (out, info1, sizeof(Dict_char)) == 0)
+ if (out && memcmp(out, info1, sizeof(Dict_char)) == 0)
{
if (subptr == 0)
continue;
*--indxp2 = -(info2 - np);
- memcpy (info2, &subptr, sizeof(Dict_ptr));
+ memcpy(info2, &subptr, sizeof(Dict_ptr));
info2 += sizeof(Dict_ptr);
- memcpy (info2, out, sizeof(Dict_char));
+ memcpy(info2, out, sizeof(Dict_char));
info2 += sizeof(Dict_char);
if (userinfo)
{
- memcpy (info2, userinfo, *userinfo+1);
+ memcpy(info2, userinfo, *userinfo+1);
info2 += *userinfo + 1;
}
else
}
*--indxp2 = info2 - np;
slen = (dict_strlen((Dict_char*) info1)+1)*sizeof(Dict_char);
- memcpy (info2, info1, slen);
+ memcpy(info2, info1, slen);
info1 += slen;
info2 += slen;
}
/* unsigned char length of information */
/* char * information */
- assert (*indxp1 < 0);
+ assert(*indxp1 < 0);
*--indxp2 = -(info2 - np);
info1 = (char*) p - *indxp1;
- memcpy (info2, info1, sizeof(Dict_ptr)+sizeof(Dict_char));
+ memcpy(info2, info1, sizeof(Dict_ptr)+sizeof(Dict_char));
info1 += sizeof(Dict_ptr)+sizeof(Dict_char);
info2 += sizeof(Dict_ptr)+sizeof(Dict_char);
}
slen = *info1+1;
- memcpy (info2, info1, slen);
+ memcpy(info2, info1, slen);
info2 += slen;
++no;
}
#if 1
- memcpy ((char*)p+DICT_infoffset,
- (char*)np+DICT_infoffset,
- info2 - ((char*)np+DICT_infoffset));
- memcpy ((char*)p + ((char*)indxp2 - (char*)np),
- indxp2,
- ((char*) np+DICT_bsize(p)) - (char*)indxp2);
+ memcpy((char*)p+DICT_infoffset,
+ (char*)np+DICT_infoffset,
+ info2 - ((char*)np+DICT_infoffset));
+ memcpy((char*)p + ((char*)indxp2 - (char*)np),
+ indxp2,
+ ((char*) np+DICT_bsize(p)) - (char*)indxp2);
#else
- memcpy ((char*)p+DICT_infoffset, (char*)np+DICT_infoffset,
- DICT_pagesize(dict)-DICT_infoffset);
+ memcpy((char*)p+DICT_infoffset, (char*)np+DICT_infoffset,
+ DICT_pagesize(dict)-DICT_infoffset);
#endif
DICT_size(p) = info2 - np;
DICT_type(p) = 0;
DICT_nodir(p) = no;
- xfree (np);
- dict_bf_touch (dict->dbf, ptr);
+ xfree(np);
+ dict_bf_touch(dict->dbf, ptr);
}
/* return 1 if before but change of info */
/* return 2 if same as before */
-static int dict_ins (Dict dict, const Dict_char *str,
- Dict_ptr ptr, int userlen, void *userinfo)
+static int dict_ins(Dict dict, const Dict_char *str,
+ Dict_ptr ptr, int userlen, void *userinfo)
{
int hi, lo, mid, slen, cmp = 1;
short *indxp;
char *info;
void *p;
- dict_bf_readp (dict->dbf, ptr, &p);
+ dict_bf_readp(dict->dbf, ptr, &p);
- assert (p);
- assert (ptr);
+ assert(p);
+ assert(ptr);
mid = lo = 0;
hi = DICT_nodir(p)-1;
if (*info == userlen)
{
/* change of userinfo ? */
- if (memcmp (info+1, userinfo, userlen))
+ if (memcmp(info+1, userinfo, userlen))
{
- dict_bf_touch (dict->dbf, ptr);
- memcpy (info+1, userinfo, userlen);
+ dict_bf_touch(dict->dbf, ptr);
+ memcpy(info+1, userinfo, userlen);
return 1;
}
/* same userinfo */
/* room for new userinfo */
DICT_type(p) = 1;
*info = userlen;
- dict_bf_touch (dict->dbf, ptr);
- memcpy (info+1, userinfo, userlen);
+ dict_bf_touch(dict->dbf, ptr);
+ memcpy(info+1, userinfo, userlen);
return 1;
}
break;
/* unsigned char length of information */
/* char * information */
info = (char*)p - indxp[-mid];
- memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
+ memcpy(&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
cmp = dc- *str;
if (!cmp)
{
- memcpy (&subptr, info, sizeof(Dict_ptr));
+ memcpy(&subptr, info, sizeof(Dict_ptr));
if (*++str == DICT_EOS)
{
/* finish of string. Store userinfo here... */
int xlen = info[sizeof(Dict_ptr)+sizeof(Dict_char)];
if (xlen == userlen)
{
- if (memcmp (info+sizeof(Dict_ptr)+sizeof(Dict_char)+1,
- userinfo, userlen))
+ if (memcmp(info+sizeof(Dict_ptr)+sizeof(Dict_char)+1,
+ userinfo, userlen))
{
- dict_bf_touch (dict->dbf, ptr);
- memcpy (info+sizeof(Dict_ptr)+sizeof(Dict_char)+1,
- userinfo, userlen);
+ dict_bf_touch(dict->dbf, ptr);
+ memcpy(info+sizeof(Dict_ptr)+sizeof(Dict_char)+1,
+ userinfo, userlen);
return 1;
}
return 2;
{
DICT_type(p) = 1;
info[sizeof(Dict_ptr)+sizeof(Dict_char)] = userlen;
- memcpy (info+sizeof(Dict_ptr)+sizeof(Dict_char)+1,
- userinfo, userlen);
- dict_bf_touch (dict->dbf, ptr);
+ memcpy(info+sizeof(Dict_ptr)+sizeof(Dict_char)+1,
+ userinfo, userlen);
+ dict_bf_touch(dict->dbf, ptr);
return 1;
}
/* xlen < userlen, expanding needed ... */
/* not enough room - split needed ... */
if (DICT_type(p) == 1)
{
- clean_page (dict, ptr, p, NULL, 0, NULL);
- return dict_ins (dict, str-1, ptr,
- userlen, userinfo);
+ clean_page(dict, ptr, p, NULL, 0, NULL);
+ 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);
+ yaz_log(YLOG_FATAL, "Unable to split page %d\n", ptr);
assert(0);
}
- return dict_ins (dict, str-1, ptr, userlen, userinfo);
+ return dict_ins(dict, str-1, ptr, userlen, userinfo);
}
else
{ /* enough room - no split needed ... */
info = (char*)p + DICT_size(p);
- memcpy (info, &subptr, sizeof(subptr));
- memcpy (info+sizeof(Dict_ptr), &dc, sizeof(Dict_char));
+ memcpy(info, &subptr, sizeof(subptr));
+ memcpy(info+sizeof(Dict_ptr), &dc, sizeof(Dict_char));
info[sizeof(Dict_char)+sizeof(Dict_ptr)] = userlen;
- memcpy (info+sizeof(Dict_char)+sizeof(Dict_ptr)+1,
- userinfo, userlen);
+ memcpy(info+sizeof(Dict_char)+sizeof(Dict_ptr)+1,
+ userinfo, userlen);
indxp[-mid] = -DICT_size(p);
DICT_size(p) += sizeof(Dict_char)+sizeof(Dict_ptr)
+1+userlen;
DICT_type(p) = 1;
- dict_bf_touch (dict->dbf, ptr);
+ dict_bf_touch(dict->dbf, ptr);
}
if (xlen)
return 1;
{
if (subptr == 0)
{
- subptr = new_page (dict, ptr, NULL);
- memcpy (info, &subptr, sizeof(subptr));
- dict_bf_touch (dict->dbf, ptr);
+ subptr = new_page(dict, ptr, NULL);
+ memcpy(info, &subptr, sizeof(subptr));
+ dict_bf_touch(dict->dbf, ptr);
}
- return dict_ins (dict, str, subptr, userlen, userinfo);
+ return dict_ins(dict, str, subptr, userlen, userinfo);
}
}
}
{
if (DICT_type(p))
{
- clean_page (dict, ptr, p, NULL, 0, NULL);
- return dict_ins (dict, str, ptr, userlen, userinfo);
+ clean_page(dict, ptr, p, NULL, 0, NULL);
+ return dict_ins(dict, str, ptr, userlen, userinfo);
}
- split_page (dict, ptr, p);
- return dict_ins (dict, str, ptr, userlen, userinfo);
+ split_page(dict, ptr, p);
+ return dict_ins(dict, str, ptr, userlen, userinfo);
}
if (cmp)
{
else
DICT_type(p) = 1;
info = (char*)p + DICT_size(p);
- memcpy (info, str, slen);
+ memcpy(info, str, slen);
info += slen;
*info++ = userlen;
- memcpy (info, userinfo, userlen);
+ memcpy(info, userinfo, userlen);
info += userlen;
*indxp = DICT_size(p);
DICT_size(p) = info- (char*) p;
- dict_bf_touch (dict->dbf, ptr);
+ dict_bf_touch(dict->dbf, ptr);
if (cmp)
return 0;
return 1;
}
-int dict_insert (Dict dict, const char *str, int userlen, void *userinfo)
+int dict_insert(Dict dict, const char *str, int userlen, void *userinfo)
{
if (!dict->rw)
return -1;
if (!dict->head.root)
{
void *p;
- dict->head.root = new_page (dict, 0, &p);
+ dict->head.root = new_page(dict, 0, &p);
if (!dict->head.root)
return -1;
}
- return dict_ins (dict, (const Dict_char *) str, dict->head.root,
- userlen, userinfo);
+ return dict_ins(dict, (const Dict_char *) str, dict->head.root,
+ userlen, userinfo);
}
/*
/* This file is part of the Zebra server.
Copyright (C) 1994-2009 Index Data
-Zebra is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
-version.
+ Zebra is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
-Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
+ Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
typedef struct {
- int n; /* no of MatchWord needed */
- int range; /* max no. of errors */
- int fact; /* (range+1)*n */
- MatchWord *match_mask; /* match_mask */
+ int n; /* no of MatchWord needed */
+ int range; /* max no. of errors */
+ int fact; /* (range+1)*n */
+ MatchWord *match_mask; /* match_mask */
} MatchContext;
#define INLINE
-static INLINE void set_bit (MatchContext *mc, MatchWord *m, int ch, int state)
+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;
}
-static INLINE MatchWord get_bit (MatchContext *mc, MatchWord *m, int ch,
- int state)
+static INLINE MatchWord get_bit(MatchContext *mc, MatchWord *m, int ch,
+ int state)
{
int off = state & (WORD_BITS-1);
int wno = state / WORD_BITS;
return m[mc->n * ch + wno] & (1<<off);
}
-static MatchContext *mk_MatchContext (struct DFA *dfa, int range)
+static MatchContext *mk_MatchContext(struct DFA *dfa, int range)
{
- MatchContext *mc = (MatchContext *) xmalloc (sizeof(*mc));
+ MatchContext *mc = (MatchContext *) xmalloc(sizeof(*mc));
int s;
mc->n = (dfa->no_states+WORD_BITS) / WORD_BITS;
mc->range = range;
mc->fact = (range+1)*mc->n;
- mc->match_mask = (MatchWord *) xcalloc (mc->n, sizeof(*mc->match_mask));
+ mc->match_mask = (MatchWord *) xcalloc(mc->n, sizeof(*mc->match_mask));
for (s = 0; s<dfa->no_states; s++)
if (dfa->states[s]->rule_no)
- set_bit (mc, mc->match_mask, 0, s);
+ set_bit(mc, mc->match_mask, 0, s);
return mc;
}
-static void rm_MatchContext (MatchContext **mc)
+static void rm_MatchContext(MatchContext **mc)
{
- xfree ((*mc)->match_mask);
- xfree (*mc);
+ xfree((*mc)->match_mask);
+ xfree(*mc);
*mc = NULL;
}
-static void mask_shift (MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc,
- struct DFA *dfa, int ch)
+static void mask_shift(MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc,
+ struct DFA *dfa, int ch)
{
int j, s = 0;
MatchWord *Rsrc_p = Rsrc, mask;
while (--i >= 0)
if (ch >= state->trans[i].ch[0] &&
ch <= state->trans[i].ch[1])
- set_bit (mc, Rdst, 0, state->trans[i].to);
+ set_bit(mc, Rdst, 0, state->trans[i].to);
}
if (mask & 2)
{
while (--i >= 0)
if (ch >= state->trans[i].ch[0] &&
ch <= state->trans[i].ch[1])
- set_bit (mc, Rdst, 0, state->trans[i].to);
+ set_bit(mc, Rdst, 0, state->trans[i].to);
}
if (mask & 4)
{
while (--i >= 0)
if (ch >= state->trans[i].ch[0] &&
ch <= state->trans[i].ch[1])
- set_bit (mc, Rdst, 0, state->trans[i].to);
+ set_bit(mc, Rdst, 0, state->trans[i].to);
}
if (mask & 8)
{
while (--i >= 0)
if (ch >= state->trans[i].ch[0] &&
ch <= state->trans[i].ch[1])
- set_bit (mc, Rdst, 0, state->trans[i].to);
+ set_bit(mc, Rdst, 0, state->trans[i].to);
}
}
s += 4;
}
}
-static void shift (MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc,
- struct DFA *dfa)
+static void shift(MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc,
+ struct DFA *dfa)
{
int j, s = 0;
MatchWord *Rsrc_p = Rsrc, mask;
struct DFA_state *state = dfa->states[s];
int i = state->tran_no;
while (--i >= 0)
- set_bit (mc, Rdst, 0, state->trans[i].to);
+ set_bit(mc, Rdst, 0, state->trans[i].to);
}
if (mask & 2)
{
struct DFA_state *state = dfa->states[s+1];
int i = state->tran_no;
while (--i >= 0)
- set_bit (mc, Rdst, 0, state->trans[i].to);
+ set_bit(mc, Rdst, 0, state->trans[i].to);
}
if (mask & 4)
{
struct DFA_state *state = dfa->states[s+2];
int i = state->tran_no;
while (--i >= 0)
- set_bit (mc, Rdst, 0, state->trans[i].to);
+ set_bit(mc, Rdst, 0, state->trans[i].to);
}
if (mask & 8)
{
struct DFA_state *state = dfa->states[s+3];
int i = state->tran_no;
while (--i >= 0)
- set_bit (mc, Rdst, 0, state->trans[i].to);
+ set_bit(mc, Rdst, 0, state->trans[i].to);
}
}
s += 4;
}
}
-static void or (MatchContext *mc, MatchWord *Rdst,
- MatchWord *Rsrc1, MatchWord *Rsrc2)
+static void or(MatchContext *mc, MatchWord *Rdst,
+ MatchWord *Rsrc1, MatchWord *Rsrc2)
{
int i;
for (i = 0; i<mc->n; i++)
Rdst[i] = Rsrc1[i] | Rsrc2[i];
}
-static INLINE int move (MatchContext *mc, MatchWord *Rj1, MatchWord *Rj,
- Dict_char ch, struct DFA *dfa, MatchWord *Rtmp,
- int range)
+static INLINE int move(MatchContext *mc, MatchWord *Rj1, MatchWord *Rj,
+ Dict_char ch, struct DFA *dfa, MatchWord *Rtmp,
+ int range)
{
int d;
MatchWord *Rtmp_2 = Rtmp + mc->n;
- mask_shift (mc, Rj1, Rj, dfa, ch);
+ mask_shift(mc, Rj1, Rj, dfa, ch);
for (d = 1; d <= mc->range; d++)
{
- or (mc, Rtmp, Rj, Rj1); /* 2,3 */
+ or(mc, Rtmp, Rj, Rj1); /* 2,3 */
- shift (mc, Rtmp_2, Rtmp, dfa);
+ shift(mc, Rtmp_2, Rtmp, dfa);
- mask_shift (mc, Rtmp, Rj+mc->n, dfa, ch); /* 1 */
+ mask_shift(mc, Rtmp, Rj+mc->n, dfa, ch); /* 1 */
- or (mc, Rtmp, Rtmp_2, Rtmp); /* 1,2,3*/
+ or(mc, Rtmp, Rtmp_2, Rtmp); /* 1,2,3*/
Rj1 += mc->n;
- or (mc, Rj1, Rtmp, Rj); /* 1,2,3,4 */
+ or(mc, Rj1, Rtmp, Rj); /* 1,2,3,4 */
Rj += mc->n;
}
short *indxp;
char *info;
- dict_bf_readp (dict->dbf, ptr, &p);
+ dict_bf_readp(dict->dbf, ptr, &p);
lo = 0;
hi = DICT_nodir(p)-1;
indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
if (was_match)
{
int ret = userfunc((char*) prefix,
- info+(j+1)*sizeof(Dict_char), client);
+ info+(j+1)*sizeof(Dict_char), client);
if (ret)
return ret;
}
range = mc->range;
else
range = 0;
- move (mc, Rj1, Rj0, ch, dfa, Rj_tmp, range);
+ move(mc, Rj1, Rj0, ch, dfa, Rj_tmp, range);
for (d = mc->n; --d >= 0; )
if (Rj1[range*mc->n + d])
break;
/* unsigned char length of information */
/* char * information */
info = (char*)p - indxp[-lo];
- memcpy (&ch, info+sizeof(Dict_ptr), sizeof(Dict_char));
+ memcpy(&ch, info+sizeof(Dict_ptr), sizeof(Dict_char));
prefix[pos] = ch;
if (pos > *max_pos)
range = mc->range;
else
range = 0;
- move (mc, Rj1, Rj, ch, dfa, Rj_tmp, range);
+ move(mc, Rj1, Rj, ch, dfa, Rj_tmp, range);
for (d = mc->n; --d >= 0; )
if (Rj1[range*mc->n + d])
break;
break;
}
}
- memcpy (&subptr, info, sizeof(Dict_ptr));
+ memcpy(&subptr, info, sizeof(Dict_ptr));
if (subptr)
{
int ret = grep(dict, subptr, mc, Rj1, pos+1,
if (ret)
return ret;
- dict_bf_readp (dict->dbf, ptr, &p);
+ dict_bf_readp(dict->dbf, ptr, &p);
indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
}
}
for (i = 0; pattern[i]; i++)
{
yaz_log(YLOG_DEBUG, " %2d %3d %c", i, pattern[i],
- (pattern[i] > ' ' && pattern[i] < 127) ? pattern[i] : '?');
+ (pattern[i] > ' ' && pattern[i] < 127) ? pattern[i] : '?');
}
- dfa_set_cmap (dfa, dict->grep_cmap_data, dict->grep_cmap);
+ dfa_set_cmap(dfa, dict->grep_cmap_data, dict->grep_cmap);
- i = dfa_parse (dfa, &this_pattern);
+ i = dfa_parse(dfa, &this_pattern);
if (i || *this_pattern)
{
yaz_log(YLOG_WARN, "dfa_parse fail=%d", i);
- dfa_delete (&dfa);
+ dfa_delete(&dfa);
return -1;
}
- dfa_mkstate (dfa);
+ dfa_mkstate(dfa);
- mc = mk_MatchContext (dfa, range);
+ mc = mk_MatchContext(dfa, range);
Rj = (MatchWord *) xcalloc((MAX_LENGTH+1) * mc->n, sizeof(*Rj));
for (d = 1; d<=mc->range; d++)
{
int s;
- memcpy (Rj + mc->n * d, Rj + mc->n * (d-1), mc->n * sizeof(*Rj));
+ memcpy(Rj + mc->n * d, Rj + mc->n * (d-1), mc->n * sizeof(*Rj));
for (s = 0; s < dfa->no_states; s++)
{
- if (get_bit (mc, Rj, d-1, s))
+ if (get_bit(mc, Rj, d-1, s))
{
struct DFA_state *state = dfa->states[s];
int i = state->tran_no;
while (--i >= 0)
- set_bit (mc, Rj, d, state->trans[i].to);
+ set_bit(mc, Rj, d, state->trans[i].to);
}
}
}
yaz_log(YLOG_DEBUG, "max_pos = %d", *max_pos);
dfa_delete(&dfa);
xfree(Rj);
- rm_MatchContext (&mc);
+ rm_MatchContext(&mc);
return ret;
}
-void dict_grep_cmap (Dict dict, void *vp,
- const char **(*cmap)(void *vp, const char **from, int len))
+void dict_grep_cmap(Dict dict, void *vp,
+ const char **(*cmap)(void *vp, const char **from, int len))
{
dict->grep_cmap = cmap;
dict->grep_cmap_data = vp;
#include "dict-p.h"
-static char *dict_look (Dict dict, const Dict_char *str, Dict_ptr ptr)
+static char *dict_look(Dict dict, const Dict_char *str, Dict_ptr ptr)
{
int mid, lo, hi;
int cmp;
short *indxp;
char *info;
- dict_bf_readp (dict->dbf, ptr, &p);
+ dict_bf_readp(dict->dbf, ptr, &p);
mid = lo = 0;
hi = DICT_nodir(p)-1;
indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
/* unsigned char length of information */
/* char * information */
info = (char*)p - indxp[-mid];
- memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
+ memcpy(&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
cmp = dc- *str;
if (!cmp)
{
- memcpy (&subptr, info, sizeof(Dict_ptr));
+ memcpy(&subptr, info, sizeof(Dict_ptr));
if (*++str == DICT_EOS)
{
if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
if (subptr == 0)
return NULL;
ptr = subptr;
- dict_bf_readp (dict->dbf, ptr, &p);
+ dict_bf_readp(dict->dbf, ptr, &p);
mid = lo = 0;
hi = DICT_nodir(p)-1;
indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
return NULL;
}
-char *dict_lookup (Dict dict, const char *p)
+char *dict_lookup(Dict dict, const char *p)
{
dict->no_lookup++;
if (!dict->head.root)
return NULL;
- return dict_look (dict, (const Dict_char *) p, dict->head.root);
+ return dict_look(dict, (const Dict_char *) p, dict->head.root);
}
/*
* Local variables:
char *info;
MatchWord match_mask = 1<<(mi->m-1);
- dict_bf_readp (dict->dbf, ptr, &p);
+ dict_bf_readp(dict->dbf, ptr, &p);
lo = 0;
hi = DICT_nodir(p)-1;
indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
/* unsigned char length of information */
/* char * information */
info = (char*)p - indxp[-lo];
- memcpy (&ch, info+sizeof(Dict_ptr), sizeof(Dict_char));
+ memcpy(&ch, info+sizeof(Dict_ptr), sizeof(Dict_char));
prefix[pos] = ch;
sc = mi->s[ch & 255];
MatchInfo *mi;
mi = (MatchInfo *) xmalloc(sizeof(*mi));
- mi->m = dict_strlen (pattern);
+ mi->m = dict_strlen(pattern);
mi->s = s = (MatchWord *) xmalloc(sizeof(*s)*256); /* 256 !!! */
for (i = 0; i < 256; i++)
s[i] = 0;
/* This file is part of the Zebra server.
Copyright (C) 1994-2009 Index Data
-Zebra is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
-version.
+ Zebra is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
-Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
+ Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
void *head_buf;
int compact_flag = dict->head.compact_flag;
- memset (dict->head.magic_str, 0, sizeof(dict->head.magic_str));
- strcpy (dict->head.magic_str, DICT_MAGIC);
+ memset(dict->head.magic_str, 0, sizeof(dict->head.magic_str));
+ strcpy(dict->head.magic_str, DICT_MAGIC);
dict->head.last = 1;
dict->head.root = 0;
dict->head.freelist = 0;
/* create header with information (page 0) */
if (dict->rw)
- dict_bf_newp (dict->dbf, 0, &head_buf, page_size);
+ dict_bf_newp(dict->dbf, 0, &head_buf, page_size);
}
-Dict dict_open (BFiles bfs, const char *name, int cache, int rw,
- int compact_flag, int page_size)
+Dict dict_open(BFiles bfs, const char *name, int cache, int rw,
+ int compact_flag, int page_size)
{
Dict dict;
void *head_buf;
- dict = (Dict) xmalloc (sizeof(*dict));
+ dict = (Dict) xmalloc(sizeof(*dict));
if (cache < 5)
cache = 5;
page_size = DICT_DEFAULT_PAGESIZE;
if (page_size < 2048)
{
- yaz_log (YLOG_WARN, "Page size for dict %s %d<2048. Set to 2048",
- name, page_size);
+ yaz_log(YLOG_WARN, "Page size for dict %s %d<2048. Set to 2048",
+ name, page_size);
page_size = 2048;
}
- dict->dbf = dict_bf_open (bfs, name, page_size, cache, rw);
+ dict->dbf = dict_bf_open(bfs, name, page_size, cache, rw);
dict->rw = rw;
dict->no_split = 0;
dict->no_insert = 0;
if(!dict->dbf)
{
- yaz_log (YLOG_WARN, "Cannot open `%s'", name);
- xfree (dict);
+ yaz_log(YLOG_WARN, "Cannot open `%s'", name);
+ xfree(dict);
return NULL;
}
- if (dict_bf_readp (dict->dbf, 0, &head_buf) <= 0)
+ if (dict_bf_readp(dict->dbf, 0, &head_buf) <= 0)
{
dict->head.page_size = page_size;
dict->head.compact_flag = compact_flag;
}
else /* header was there, check magic and page size */
{
- memcpy (&dict->head, head_buf, sizeof(dict->head));
- if (strcmp (dict->head.magic_str, DICT_MAGIC))
+ memcpy(&dict->head, head_buf, sizeof(dict->head));
+ if (strcmp(dict->head.magic_str, DICT_MAGIC))
{
- yaz_log (YLOG_WARN, "Bad magic of `%s'", name);
+ yaz_log(YLOG_WARN, "Bad magic of `%s'", name);
dict_bf_close(dict->dbf);
xfree(dict);
return 0;
}
if (dict->head.page_size != page_size)
{
- yaz_log (YLOG_WARN, "Page size for existing dict %s is %d. Current is %d",
- name, dict->head.page_size, page_size);
+ yaz_log(YLOG_WARN, "Page size for existing dict %s is %d. Current is %d",
+ name, dict->head.page_size, page_size);
}
}
if (dict->head.compact_flag)
return dict;
}
-int dict_strcmp (const Dict_char *s1, const Dict_char *s2)
+int dict_strcmp(const Dict_char *s1, const Dict_char *s2)
{
- return strcmp ((const char *) s1, (const char *) s2);
+ return strcmp((const char *) s1, (const char *) s2);
}
-int dict_strncmp (const Dict_char *s1, const Dict_char *s2, size_t n)
+int dict_strncmp(const Dict_char *s1, const Dict_char *s2, size_t n)
{
- return strncmp ((const char *) s1, (const char *) s2, n);
+ return strncmp((const char *) s1, (const char *) s2, n);
}
-int dict_strlen (const Dict_char *s)
+int dict_strlen(const Dict_char *s)
{
return strlen((const char *) s);
}
/* This file is part of the Zebra server.
Copyright (C) 1994-2009 Index Data
-Zebra is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
-version.
+ Zebra is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
-Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
+ Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
short *indxp;
char *info;
- dict_bf_readp (dict->dbf, ptr, &p);
+ dict_bf_readp(dict->dbf, ptr, &p);
hi = DICT_nodir(p)-1;
if (start != -1)
lo = start;
/* char * information */
info = (char*)p - indxp[-lo];
- memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
+ memcpy(&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
str[pos] = dc;
- memcpy (&subptr, info, sizeof(Dict_ptr));
+ memcpy(&subptr, info, sizeof(Dict_ptr));
if (dir>0 && info[sizeof(Dict_ptr)+sizeof(Dict_char)])
{
- str[pos+1] = DICT_EOS;
- if ((*userfunc)((char*) str,
- info+sizeof(Dict_ptr)+sizeof(Dict_char),
- *count * dir, client))
- {
- *count = 0;
- }
- else
- --(*count);
+ str[pos+1] = DICT_EOS;
+ if ((*userfunc)((char*) str,
+ info+sizeof(Dict_ptr)+sizeof(Dict_char),
+ *count * dir, client))
+ {
+ *count = 0;
+ }
+ else
+ --(*count);
}
if (*count>0 && subptr)
{
- scan_direction (dict, subptr, pos+1, str, -1, count,
- client, userfunc, dir);
- dict_bf_readp (dict->dbf, ptr, &p);
+ 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));
}
if (*count>0 && dir<0 && info[sizeof(Dict_ptr)+sizeof(Dict_char)])
{
- str[pos+1] = DICT_EOS;
- if ((*userfunc)((char*) str,
- info+sizeof(Dict_ptr)+sizeof(Dict_char),
- *count * dir, client))
- {
- *count = 0;
- }
- else
- --(*count);
+ str[pos+1] = DICT_EOS;
+ if ((*userfunc)((char*) str,
+ info+sizeof(Dict_ptr)+sizeof(Dict_char),
+ *count * dir, client))
+ {
+ *count = 0;
+ }
+ else
+ --(*count);
}
}
lo += dir;
short *indxp;
char *info;
- dict_bf_readp (dict->dbf, ptr, &p);
+ dict_bf_readp(dict->dbf, ptr, &p);
if (!p)
return;
mid = lo = 0;
/* unsigned char length of information */
/* char * information */
info = (char*)p + indxp[-mid];
- cmp = dict_strcmp ((Dict_char*) info, str + pos);
+ cmp = dict_strcmp((Dict_char*) info, str + pos);
if (!cmp)
{
if (*after)
/* unsigned char length of information */
/* char * information */
info = (char*)p - indxp[-mid];
- memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
+ memcpy(&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
cmp = dc - str[pos];
if (!cmp)
{
- memcpy (&subptr, info, sizeof(Dict_ptr));
+ memcpy(&subptr, info, sizeof(Dict_ptr));
if (str[pos+1] == DICT_EOS)
{
if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])