From: Adam Dickmeiss Date: Thu, 2 Jul 2009 09:23:43 +0000 (+0200) Subject: Reindent X-Git-Tag: v2.0.40~8 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=a89d8384ad975fdddb2aa56e8c27b689a5e23f96;p=idzebra-moved-to-github.git Reindent --- diff --git a/dict/close.c b/dict/close.c index ebc7594..714963b 100644 --- a/dict/close.c +++ b/dict/close.c @@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "dict-p.h" -int dict_close (Dict dict) +int dict_close(Dict dict) { if (!dict) return 0; @@ -34,12 +34,12 @@ int dict_close (Dict dict) 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; } diff --git a/dict/dclose.c b/dict/dclose.c index f1970df..d9c9bf8 100644 --- a/dict/dclose.c +++ b/dict/dclose.c @@ -26,15 +26,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #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; } /* diff --git a/dict/dcompact.c b/dict/dcompact.c index 46d067b..4c7e832 100644 --- a/dict/dcompact.c +++ b/dict/dcompact.c @@ -35,7 +35,7 @@ static void dict_copy_page(Dict dict, char *to_p, char *from_p, int *map) 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! */ { @@ -46,7 +46,7 @@ static void dict_copy_page(Dict dict, char *to_p, char *from_p, int *map) 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; } @@ -62,20 +62,20 @@ static void dict_copy_page(Dict dict, char *to_p, char *from_p, int *map) *--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; } @@ -84,18 +84,18 @@ static void dict_copy_page(Dict dict, char *to_p, char *from_p, int *map) 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; @@ -106,28 +106,28 @@ int dict_copy_compact (BFiles bfs, const char *from_name, const char *to_name) 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]; @@ -135,8 +135,8 @@ int dict_copy_compact (BFiles bfs, const char *from_name, const char *to_name) 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; } /* diff --git a/dict/delete.c b/dict/delete.c index e871d7e..38e4cd3 100644 --- a/dict/delete.c +++ b/dict/delete.c @@ -24,9 +24,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #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; @@ -35,7 +35,7 @@ static void dict_del_subtree (Dict dict, Dict_ptr ptr, 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++) @@ -59,7 +59,7 @@ static void dict_del_subtree (Dict dict, Dict_ptr ptr, /* 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)]) { @@ -68,22 +68,22 @@ static void dict_del_subtree (Dict dict, Dict_ptr ptr, } 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; @@ -93,7 +93,7 @@ static int dict_del_string (Dict dict, const Dict_char *str, Dict_ptr ptr, 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)); @@ -111,7 +111,7 @@ static int dict_del_string (Dict dict, const Dict_char *str, Dict_ptr ptr, 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) @@ -125,7 +125,7 @@ static int dict_del_string (Dict dict, const Dict_char *str, Dict_ptr ptr, } 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)*/ @@ -145,7 +145,7 @@ static int dict_del_string (Dict dict, const Dict_char *str, Dict_ptr ptr, } DICT_type(p) = 1; (DICT_nodir(p))--; - dict_bf_touch (dict->dbf, ptr); + dict_bf_touch(dict->dbf, ptr); return 1; } } @@ -160,36 +160,36 @@ static int dict_del_string (Dict dict, const Dict_char *str, Dict_ptr ptr, /* 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; } @@ -198,7 +198,7 @@ static int dict_del_string (Dict dict, const Dict_char *str, Dict_ptr ptr, 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)); @@ -214,17 +214,17 @@ static int dict_del_string (Dict dict, const Dict_char *str, Dict_ptr ptr, 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: diff --git a/dict/dictext.c b/dict/dictext.c index 332c9dc..3190e3d 100644 --- a/dict/dictext.c +++ b/dict/dictext.c @@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA char *prog; -int main (int argc, char **argv) +int main(int argc, char **argv) { char *arg; int ret; @@ -48,38 +48,38 @@ int main (int argc, char **argv) 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++) @@ -95,7 +95,7 @@ int main (int argc, char **argv) i++; if (ipf_ptr[i]) ipf_ptr[i++] = '\0'; - printf ("%s\n", ipf_ptr); + printf("%s\n", ipf_ptr); ipf_ptr += (i-1); } } diff --git a/dict/dopen.c b/dict/dopen.c index 5d72410..6e0765e 100644 --- a/dict/dopen.c +++ b/dict/dopen.c @@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #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; @@ -41,7 +41,7 @@ static void common_init (Dict_BFile bf, int block_size, int cache) 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 **) @@ -51,7 +51,7 @@ static void common_init (Dict_BFile bf, int block_size, int cache) /* 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; @@ -69,23 +69,23 @@ static void common_init (Dict_BFile bf, int block_size, int cache) } -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; } diff --git a/dict/drdwr.c b/dict/drdwr.c index 3360383..6809d7b 100644 --- a/dict/drdwr.c +++ b/dict/drdwr.c @@ -1,19 +1,19 @@ /* 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 */ @@ -31,18 +31,18 @@ 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; @@ -52,9 +52,9 @@ static struct Dict_file_block *find_block (Dict_BFile bf, int no) 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) @@ -76,7 +76,7 @@ static void release_block (Dict_BFile bf, struct Dict_file_block *p) 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; @@ -86,7 +86,7 @@ void dict_bf_flush_blocks (Dict_BFile bf, int no_to_flush) 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; @@ -96,44 +96,44 @@ void dict_bf_flush_blocks (Dict_BFile bf, int no_to_flush) 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; @@ -159,7 +159,7 @@ static struct Dict_file_block *alloc_block (Dict_BFile bf, int no) 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) @@ -182,32 +182,32 @@ static void move_to_front (Dict_BFile bf, struct Dict_file_block *p) 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) @@ -215,33 +215,33 @@ int dict_bf_readp (Dict_BFile bf, int no, void **bufp) *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; diff --git a/dict/insert.c b/dict/insert.c index 52f381c..0652f00 100644 --- a/dict/insert.c +++ b/dict/insert.c @@ -28,28 +28,28 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #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; @@ -60,7 +60,7 @@ static Dict_ptr new_page (Dict dict, Dict_ptr back_ptr, void **pp) 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; @@ -74,13 +74,13 @@ static int split_page (Dict dict, Dict_ptr ptr, void *p) 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; @@ -106,7 +106,7 @@ static int split_page (Dict dict, Dict_ptr ptr, void *p) 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; @@ -118,33 +118,33 @@ static int split_page (Dict dict, Dict_ptr ptr, void *p) 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; @@ -153,7 +153,7 @@ static void clean_page (Dict dict, Dict_ptr ptr, void *p, Dict_char *out, 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! */ { @@ -162,18 +162,18 @@ static void clean_page (Dict dict, Dict_ptr ptr, void *p, Dict_char *out, /* 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 @@ -184,7 +184,7 @@ static void clean_page (Dict dict, Dict_ptr ptr, void *p, Dict_char *out, } *--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; } @@ -195,34 +195,34 @@ static void clean_page (Dict dict, Dict_ptr ptr, void *p, Dict_char *out, /* 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); } @@ -231,18 +231,18 @@ static void clean_page (Dict dict, Dict_ptr ptr, void *p, Dict_char *out, /* 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; @@ -264,10 +264,10 @@ static int dict_ins (Dict dict, const Dict_char *str, 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 */ @@ -278,8 +278,8 @@ static int dict_ins (Dict dict, const Dict_char *str, /* 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; @@ -295,11 +295,11 @@ static int dict_ins (Dict dict, const Dict_char *str, /* 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... */ @@ -307,12 +307,12 @@ static int dict_ins (Dict dict, const Dict_char *str, 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; @@ -321,9 +321,9 @@ static int dict_ins (Dict dict, const Dict_char *str, { 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 ... */ @@ -334,30 +334,30 @@ static int dict_ins (Dict dict, const Dict_char *str, /* 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; @@ -367,11 +367,11 @@ static int dict_ins (Dict dict, const Dict_char *str, { 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); } } } @@ -389,11 +389,11 @@ static int dict_ins (Dict dict, const Dict_char *str, { 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) { @@ -418,21 +418,21 @@ static int dict_ins (Dict dict, const Dict_char *str, 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; @@ -440,12 +440,12 @@ int dict_insert (Dict dict, const char *str, int userlen, void *userinfo) 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); } /* diff --git a/dict/lookgrep.c b/dict/lookgrep.c index b56df31..eb91782 100644 --- a/dict/lookgrep.c +++ b/dict/lookgrep.c @@ -1,19 +1,19 @@ /* 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 */ @@ -42,15 +42,15 @@ typedef unsigned MatchWord; */ 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; @@ -58,8 +58,8 @@ static INLINE void set_bit (MatchContext *mc, MatchWord *m, int ch, int state) m[mc->n * ch + wno] |= 1<n * ch + wno] & (1<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; sno_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; @@ -112,7 +112,7 @@ static void mask_shift (MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc, 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) { @@ -121,7 +121,7 @@ static void mask_shift (MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc, 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) { @@ -130,7 +130,7 @@ static void mask_shift (MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc, 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) { @@ -139,7 +139,7 @@ static void mask_shift (MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc, 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; @@ -150,8 +150,8 @@ static void mask_shift (MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc, } } -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; @@ -169,28 +169,28 @@ static void shift (MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc, 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; @@ -201,35 +201,35 @@ static void shift (MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc, } } -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; in; 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; } @@ -249,7 +249,7 @@ static int grep(Dict dict, Dict_ptr ptr, MatchContext *mc, 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)); @@ -281,7 +281,7 @@ static int grep(Dict dict, Dict_ptr ptr, MatchContext *mc, 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; } @@ -291,7 +291,7 @@ static int grep(Dict dict, Dict_ptr ptr, MatchContext *mc, 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; @@ -318,7 +318,7 @@ static int grep(Dict dict, Dict_ptr ptr, MatchContext *mc, /* 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) @@ -327,7 +327,7 @@ static int grep(Dict dict, Dict_ptr ptr, MatchContext *mc, 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; @@ -349,7 +349,7 @@ static int grep(Dict dict, Dict_ptr ptr, MatchContext *mc, break; } } - memcpy (&subptr, info, sizeof(Dict_ptr)); + memcpy(&subptr, info, sizeof(Dict_ptr)); if (subptr) { int ret = grep(dict, subptr, mc, Rj1, pos+1, @@ -358,7 +358,7 @@ static int grep(Dict dict, Dict_ptr ptr, MatchContext *mc, 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)); } } @@ -393,21 +393,21 @@ int dict_lookup_grep(Dict dict, const char *pattern, int range, void *client, 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)); @@ -415,15 +415,15 @@ int dict_lookup_grep(Dict dict, const char *pattern, int range, void *client, 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); } } } @@ -435,12 +435,12 @@ int dict_lookup_grep(Dict dict, const char *pattern, int range, void *client, 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; diff --git a/dict/lookup.c b/dict/lookup.c index b0459dd..f7d5a48 100644 --- a/dict/lookup.c +++ b/dict/lookup.c @@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #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; @@ -34,7 +34,7 @@ static char *dict_look (Dict dict, const Dict_char *str, Dict_ptr ptr) 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)); @@ -62,11 +62,11 @@ static char *dict_look (Dict dict, const Dict_char *str, Dict_ptr ptr) /* 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)]) @@ -78,7 +78,7 @@ static char *dict_look (Dict dict, const Dict_char *str, Dict_ptr ptr) 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)); @@ -94,12 +94,12 @@ static char *dict_look (Dict dict, const Dict_char *str, Dict_ptr ptr) 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: diff --git a/dict/lookupec.c b/dict/lookupec.c index 0d80584..86f0fe0 100644 --- a/dict/lookupec.c +++ b/dict/lookupec.c @@ -44,7 +44,7 @@ static int lookup_ec(Dict dict, Dict_ptr ptr, 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)); @@ -93,7 +93,7 @@ static int lookup_ec(Dict dict, Dict_ptr ptr, /* 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]; @@ -134,7 +134,7 @@ static MatchInfo *prepare_match(Dict_char *pattern) 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; diff --git a/dict/open.c b/dict/open.c index 27b197f..250a1d4 100644 --- a/dict/open.c +++ b/dict/open.c @@ -1,19 +1,19 @@ /* 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 */ @@ -31,8 +31,8 @@ void dict_clean(Dict dict) 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; @@ -41,16 +41,16 @@ void dict_clean(Dict dict) /* 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; @@ -59,11 +59,11 @@ Dict dict_open (BFiles bfs, const char *name, int cache, int rw, 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; @@ -71,11 +71,11 @@ Dict dict_open (BFiles bfs, const char *name, int cache, int rw, 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; @@ -83,18 +83,18 @@ Dict dict_open (BFiles bfs, const char *name, int cache, int rw, } 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) @@ -102,17 +102,17 @@ Dict dict_open (BFiles bfs, const char *name, int cache, int rw, 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); } diff --git a/dict/scan.c b/dict/scan.c index ce123cd..0485d94 100644 --- a/dict/scan.c +++ b/dict/scan.c @@ -1,19 +1,19 @@ /* 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 */ @@ -35,7 +35,7 @@ static void scan_direction(Dict dict, Dict_ptr ptr, int pos, Dict_char *str, 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; @@ -79,39 +79,39 @@ static void scan_direction(Dict dict, Dict_ptr ptr, int pos, Dict_char *str, /* 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; @@ -127,7 +127,7 @@ void dict_scan_r(Dict dict, Dict_ptr ptr, int pos, Dict_char *str, short *indxp; char *info; - dict_bf_readp (dict->dbf, ptr, &p); + dict_bf_readp(dict->dbf, ptr, &p); if (!p) return; mid = lo = 0; @@ -142,7 +142,7 @@ void dict_scan_r(Dict dict, Dict_ptr ptr, int pos, Dict_char *str, /* 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) @@ -170,11 +170,11 @@ void dict_scan_r(Dict dict, Dict_ptr ptr, int pos, Dict_char *str, /* 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)])