-/*
- * Copyright (C) 1994-1995, Index Data I/S
- * All rights reserved.
- * Sebastian Hammer, Adam Dickmeiss
- *
- * $Log: recindex.c,v $
- * Revision 1.11 1995-12-06 13:58:26 adam
- * Improved flushing of records - all flushes except the last one
- * don't write the last accessed. Also flush takes place if record
- * info occupy more than about 256k.
- *
- * Revision 1.10 1995/12/06 12:41:24 adam
- * New command 'stat' for the index program.
- * Filenames can be read from stdin by specifying '-'.
- * Bug fix/enhancement of the transformation from terms to regular
- * expressons in the search engine.
- *
- * Revision 1.9 1995/11/30 08:34:33 adam
- * Started work on commit facility.
- * Changed a few malloc/free to xmalloc/xfree.
- *
- * Revision 1.8 1995/11/28 14:26:21 adam
- * Bug fix: recordId with constant wasn't right.
- * Bug fix: recordId dictionary entry wasn't deleted when needed.
- *
- * Revision 1.7 1995/11/28 09:09:43 adam
- * Zebra config renamed.
- * Use setting 'recordId' to identify record now.
- * Bug fix in recindex.c: rec_release_blocks was invokeded even
- * though the blocks were already released.
- * File traversal properly deletes records when needed.
- *
- * Revision 1.6 1995/11/25 10:24:06 adam
- * More record fields - they are enumerated now.
- * New options: flagStoreData flagStoreKey.
- *
- * Revision 1.5 1995/11/22 17:19:18 adam
- * Record management uses the bfile system.
- *
- * Revision 1.4 1995/11/20 16:59:46 adam
- * New update method: the 'old' keys are saved for each records.
- *
- * Revision 1.3 1995/11/16 15:34:55 adam
- * Uses new record management system in both indexer and server.
- *
- * Revision 1.2 1995/11/15 19:13:08 adam
- * Work on record management.
- *
- * Revision 1.1 1995/11/15 14:46:20 adam
- * Started work on better record management system.
- *
- */
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "recindxp.h"
-
-static void rec_write_head (Records p)
-{
- int r;
-
- assert (p);
- assert (p->index_BFile);
-
- r = bf_write (p->index_BFile, 0, 0, sizeof(p->head), &p->head);
- if (r)
- {
- logf (LOG_FATAL|LOG_ERRNO, "write head of %s", p->index_fname);
- exit (1);
- }
-}
-
-static void rec_tmp_expand (Records p, int size, int dst_type)
-{
- if (p->tmp_size < size + 256 ||
- p->tmp_size < p->head.block_size[dst_type]*2)
- {
- xfree (p->tmp_buf);
- p->tmp_size = size + p->head.block_size[dst_type]*2 + 256;
- p->tmp_buf = xmalloc (p->tmp_size);
- }
-}
-
-static int read_indx (Records p, int sysno, void *buf, int itemsize,
- int ignoreError)
-{
- int r;
- int pos = (sysno-1)*itemsize;
-
- r = bf_read (p->index_BFile, 1+pos/128, pos%128, itemsize, buf);
- if (r != 1 && !ignoreError)
- {
- logf (LOG_FATAL|LOG_ERRNO, "read in %s at pos %ld",
- p->index_fname, (long) pos);
- abort ();
- exit (1);
- }
- return r;
-}
-
-static void write_indx (Records p, int sysno, void *buf, int itemsize)
-{
- int pos = (sysno-1)*itemsize;