New command 'stat' for the index program.
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 6 Dec 1995 12:41:20 +0000 (12:41 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 6 Dec 1995 12:41:20 +0000 (12:41 +0000)
Filenames can be read from stdin by specifying '-'.
Bug fix/enhancement of the transformation from terms to regular
expressons in the search engine.

index/Makefile
index/index.h
index/kinput.c
index/main.c
index/recindex.c
index/recindex.h
index/recindxp.h [new file with mode: 0644]
index/recstat.c [new file with mode: 0644]
index/trav.c
index/zrpn.c

index cbddcf8..078d52c 100644 (file)
@@ -1,7 +1,7 @@
 # Copyright (C) 1995, Index Data I/S 
 # All rights reserved.
 # Sebastian Hammer, Adam Dickmeiss
-# $Id: Makefile,v 1.27 1995-12-04 17:59:15 adam Exp $
+# $Id: Makefile,v 1.28 1995-12-06 12:41:20 adam Exp $
 
 SHELL=/bin/sh
 RANLIB=ranlib
@@ -19,7 +19,7 @@ TPROG2=kdump
 TPROG3=zebrasrv
 DEFS=$(INCLUDE)
 O1 = main.o dir.o dirs.o trav.o extract.o kinput.o kcompare.o \
- symtab.o text.o recctrl.o structrec.o recindex.o regxread.o
+ symtab.o text.o recctrl.o structrec.o recindex.o regxread.o recstat.o
 O2 = kdump.o
 O3 = zserver.o kcompare.o zrpn.o zsets.o text.o recctrl.o structrec.o  \
        attribute.o recindex.o zlogs.o regxread.o
index 47f2a3b..d40a588 100644 (file)
@@ -4,7 +4,13 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: index.h,v $
- * Revision 1.30  1995-12-05 11:25:02  adam
+ * Revision 1.31  1995-12-06 12:41:22  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.30  1995/12/05  11:25:02  adam
  * Include of zebraver.h.
  *
  * Revision 1.29  1995/11/28  09:09:40  adam
@@ -144,6 +150,7 @@ struct recordGroup {
     int  flagStoreKeys;
 };
 
+        
 struct dirs_info *dirs_open (Dict dict, const char *rep);
 struct dirs_entry *dirs_read (struct dirs_info *p);
 struct dirs_entry *dirs_last (struct dirs_info *p);
@@ -187,3 +194,5 @@ int index_word_prefix (char *string, int attset_ordinal,
 
 int fileExtract (SYSNO *sysno, const char *fname,
                  const struct recordGroup *rGroup, int deleteFlag);
+
+void rec_prstat (void);
index e9d467a..dd7583e 100644 (file)
@@ -4,7 +4,13 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: kinput.c,v $
- * Revision 1.9  1995-10-10 12:24:39  adam
+ * Revision 1.10  1995-12-06 12:41:22  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/10/10  12:24:39  adam
  * Temporary sort files are compressed.
  *
  * Revision 1.8  1995/10/04  16:57:19  adam
@@ -364,7 +370,8 @@ int heap_inp (Dict dict, ISAM isam, struct heap_info *hi)
 }
 
 void key_input (const char *dict_fname, const char *isam_fname,
-                 int nkeys, int cache)
+                int nkeys, int cache)
+                
 {
     Dict dict;
     ISAM isam;
index 17fdbb4..574c212 100644 (file)
@@ -4,7 +4,13 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: main.c,v $
- * Revision 1.25  1995-12-01 16:24:39  adam
+ * Revision 1.26  1995-12-06 12:41:23  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.25  1995/12/01  16:24:39  adam
  * Commit files use separate meta file area.
  *
  * Revision 1.24  1995/11/30  17:01:38  adam
@@ -104,13 +110,11 @@ extern char *data1_tabpath;
 
 int main (int argc, char **argv)
 {
-    int commit_at_end = 0;
     int ret;
     int cmd = 0;
     char *arg;
     char *configName = NULL;
     int nsections;
-    int key_open_flag = 0;
 
     struct recordGroup rGroupDef;
     
@@ -166,7 +170,14 @@ int main (int argc, char **argv)
                 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
                     cmd = 'd';
                 else if (!strcmp (arg, "commit"))
-                    commit_at_end = 1;
+                {
+                    logf (LOG_LOG, "Commit");
+                    bf_commit ();
+                }
+                else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
+                {
+                    rec_prstat ();
+                }
                 else
                 {
                     logf (LOG_FATAL, "Unknown command: %s", arg);
@@ -178,17 +189,26 @@ int main (int argc, char **argv)
                 struct recordGroup rGroup;
 
                 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
-                if (!key_open_flag)
-                {
-                    key_open (mem_max);
-                    key_open_flag = 1;
-                }
+                key_open (mem_max);
                 rGroup.path = arg;
                 if (cmd == 'u')
+                {
+                    logf (LOG_LOG, "Updating %s", rGroup.path);
                     repositoryUpdate (&rGroup);
+                }
                 else if (cmd == 'd')
+                {
+                    logf (LOG_LOG, "Deleting %s", rGroup.path);
                     repositoryDelete (&rGroup);
+                }
                 cmd = 0;
+                nsections = key_close ();
+                if (nsections)
+                {
+                    logf (LOG_LOG, "Merging with index");
+                    key_input (FNAME_WORD_DICT, FNAME_WORD_ISAM, nsections,
+                               60);
+                }
             }
         }
         else if (ret == 'v')
@@ -217,20 +237,6 @@ int main (int argc, char **argv)
             exit (1);
         }
     }
-    if (key_open_flag)
-    {
-        nsections = key_close ();
-        if (nsections)
-        {
-            logf (LOG_LOG, "Merging with index");
-            key_input (FNAME_WORD_DICT, FNAME_WORD_ISAM, nsections, 60);
-        }
-    }
-    if (commit_at_end)
-    {
-        logf (LOG_LOG, "commiting");
-        bf_commit ();
-    }
     exit (0);
 }
 
index 90efa63..6f06cd5 100644 (file)
@@ -4,7 +4,13 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: recindex.c,v $
- * Revision 1.9  1995-11-30 08:34:33  adam
+ * 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.
  *
 #include <assert.h>
 #include <string.h>
 #include <ctype.h>
-#include <assert.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "recindex.h"
-
-#define USE_BF 1
-
-#if USE_BF
-#include <bfile.h>
-
-#define REC_BLOCK_TYPES 2
-#define REC_HEAD_MAGIC "recindx"
-
-struct records_info {
-    int rw;
-
-    char *index_fname;
-    BFile index_BFile;
-
-
-    char *data_fname[REC_BLOCK_TYPES];
-    BFile data_BFile[REC_BLOCK_TYPES];
-
-    char *tmp_buf;
-    int tmp_size;
-
-    struct record_cache_entry *record_cache;
-    int cache_size;
-    int cache_cur;
-    int cache_max;
-
-    struct records_head {
-        char magic[8];
-        int block_size[REC_BLOCK_TYPES];
-        int block_free[REC_BLOCK_TYPES];
-        int block_last[REC_BLOCK_TYPES];
-        int block_used[REC_BLOCK_TYPES];
-        int block_move[REC_BLOCK_TYPES];
-
-        int index_last;
-        int index_free;
-        int no_records;
-
-    } head;
-};
-
-enum recordCacheFlag { recordFlagNop, recordFlagWrite, recordFlagNew,
-                       recordFlagDelete };
-
-struct record_cache_entry {
-    Record rec;
-    enum recordCacheFlag flag;
-};
-
-struct record_index_entry {
-    union {
-        struct {
-            int next;
-            int size;
-        } used;
-        struct {
-            int next;
-        } free;
-    } u;
-};
 
+#include "recindxp.h"
 
 static void rec_write_head (Records p)
 {
@@ -169,6 +110,7 @@ static void rec_release_blocks (Records p, int sysno)
 
     if (read_indx (p, sysno, &entry, sizeof(entry), 1) != 1)
         return ;
+    p->head.total_bytes -= entry.u.used.size;
     freeblock = entry.u.used.next;
     assert (freeblock > 0);
     dst_type = freeblock & 7;
@@ -258,7 +200,7 @@ static void rec_write_single (Records p, Record rec)
         {
             entry.u.used.next = block_free*8 + dst_type;
             entry.u.used.size = size;
-
+            p->head.total_bytes += size;
             write_indx (p, rec->sysno, &entry, sizeof(entry));
         }
         else
@@ -308,6 +250,7 @@ Records rec_open (int rw)
         p->head.index_free = 0;
         p->head.index_last = 1;
         p->head.no_records = 0;
+        p->head.total_bytes = 0;
         for (i = 0; i<REC_BLOCK_TYPES; i++)
         {
             p->head.block_free[i] = 0;
@@ -593,435 +536,6 @@ Record rec_cp (Record rec)
     return n;
 }
 
-/* no BF --------------------------------------------------- */
-#else
-
-struct records_info {
-    int rw;
-    int index_fd;
-    char *index_fname;
-    int data_fd;
-    char *data_fname;
-    struct records_head {
-        char magic[8];
-       int no_records;
-        int index_free;
-        int index_last;
-        int data_size;
-        int data_slack;
-        int data_used;
-    } head;
-    char *tmp_buf;
-    int tmp_size;
-    int cache_size;
-    int cache_cur;
-    int cache_max;
-    struct record_cache_entry *record_cache;
-};
-
-struct record_cache_entry {
-    Record rec;
-    int dirty;
-};
-
-struct record_index_entry {
-    union {
-        struct {
-            int offset;
-            int size;
-        } used;
-        struct {
-            int next;
-        } free;
-    } u;
-};
-
-#define REC_HEAD_MAGIC "rechead"
-
-static void rec_write_head (Records p)
-{
-    int r;
-
-    assert (p);
-    assert (p->index_fd != -1);
-    if (lseek (p->index_fd, (off_t) 0, SEEK_SET) == -1)
-    {
-        logf (LOG_FATAL|LOG_ERRNO, "lseek to 0 in %s", p->index_fname);
-        exit (1);
-    }
-    r = write (p->index_fd, &p->head, sizeof(p->head));    
-    switch (r)
-    {
-    case -1:
-        logf (LOG_FATAL|LOG_ERRNO, "write head of %s", p->index_fname);
-        exit (1);
-    case sizeof(p->head):
-        break;
-    default:
-        logf (LOG_FATAL, "write head of %s. wrote %d", p->index_fname, r);
-        exit (1);
-    }
-}
-
-Records rec_open (int rw)
-{
-    Records p;
-    int r;
-
-    p = xmalloc (sizeof(*p));
-    p->rw = rw;
-    p->tmp_buf = NULL;
-    p->tmp_size = 0;
-    p->data_fname = "recdata";
-    p->data_fd = -1;
-    p->index_fname = "recindex";
-    p->index_fd = open (p->index_fname,
-                        rw ? (O_RDWR|O_CREAT) : O_RDONLY, 0666);
-    if (p->index_fd == -1)
-    {
-        logf (LOG_FATAL|LOG_ERRNO, "open %s", p->index_fname);
-        exit (1);
-    }
-    r = read (p->index_fd, &p->head, sizeof(p->head));
-    switch (r)
-    {
-    case -1:
-        logf (LOG_FATAL|LOG_ERRNO, "read %s", p->index_fname);
-        exit (1);
-    case 0:
-        memcpy (p->head.magic, REC_HEAD_MAGIC, sizeof(p->head.magic));
-        p->head.index_free = 0;
-        p->head.index_last = 1;
-        p->head.no_records = 0;
-        p->head.data_size = 0;
-        p->head.data_slack = 0;
-        p->head.data_used = 0;
-        if (rw)
-            rec_write_head (p);
-        break;
-    case sizeof(p->head):
-        if (memcmp (p->head.magic, REC_HEAD_MAGIC, sizeof(p->head.magic)))
-        {
-            logf (LOG_FATAL, "read %s. bad header", p->index_fname);
-            exit (1);
-        }
-        break;
-    default:
-        logf (LOG_FATAL, "read head of %s. expected %d. got %d",
-             p->index_fname, sizeof(p->head), r);
-        exit (1);
-    }
-    p->data_fd = open (p->data_fname,
-                       rw ? (O_RDWR|O_CREAT) : O_RDONLY, 0666);
-    if (p->data_fd == -1)
-    {
-        logf (LOG_FATAL|LOG_ERRNO, "open %s", p->data_fname);
-        exit (1);
-    }
-    p->cache_max = 10;
-    p->cache_cur = 0;
-    p->record_cache = xmalloc (sizeof(*p->record_cache)*p->cache_max));
-    return p;
-}
-
-static void read_indx (Records p, int sysno, void *buf, int itemsize)
-{
-    int r;
-    off_t pos = (sysno-1)*itemsize + sizeof(p->head);
-
-    if (lseek (p->index_fd, pos, SEEK_SET) == (pos) -1)
-    {
-        logf (LOG_FATAL|LOG_ERRNO, "seek in %s to pos %ld",
-              p->index_fname, (long) pos);
-        exit (1);
-    }
-    r = read (p->index_fd, buf, itemsize);
-    if (r != itemsize)
-    {
-        if (r == -1)
-            logf (LOG_FATAL|LOG_ERRNO, "read in %s at pos %ld",
-                  p->index_fname, (long) pos);
-        else
-            logf (LOG_FATAL, "read in %s at pos %ld",
-                  p->index_fname, (long) pos);
-        exit (1);
-    }
-}
-
-static void rec_write_single (Records p, Record rec)
-{
-    struct record_index_entry entry;
-    int r, i, size = 0, got;
-    char *cptr;
-    off_t pos = (rec->sysno-1)*sizeof(entry) + sizeof(p->head);
-
-    for (i = 0; i < REC_NO_INFO; i++)
-        if (!rec->info[i])
-            size += sizeof(*rec->size);
-        else
-            size += sizeof(*rec->size) + rec->size[i];
-    
-    entry.u.used.offset = p->head.data_size;
-    entry.u.used.size = size;
-    p->head.data_size += size;
-    p->head.data_used += size;
-
-    if (lseek (p->index_fd, pos, SEEK_SET) == (pos) -1)
-    {
-        logf (LOG_FATAL|LOG_ERRNO, "seek in %s to pos %ld",
-              p->index_fname, (long) pos);
-        exit (1);
-    }
-    r = write (p->index_fd, &entry, sizeof(entry));
-    if (r != sizeof(entry))
-    {
-        if (r == -1)
-            logf (LOG_FATAL|LOG_ERRNO, "write of %s at pos %ld",
-                  p->index_fname, (long) pos);
-        else
-            logf (LOG_FATAL, "write of %s at pos %ld",
-                  p->index_fname, (long) pos);
-        exit (1);
-    }
-    if (lseek (p->data_fd, entry.u.used.offset, SEEK_SET) == -1) 
-    {
-        logf (LOG_FATAL|LOG_ERRNO, "lseek in %s to pos %ld",
-              p->data_fname, entry.u.used.offset);
-        exit (1);
-    }
-    if (p->tmp_size < entry.u.used.size) 
-    {
-        xfree (p->tmp_buf);
-        p->tmp_size = entry.u.used.size + 16384;
-        p->tmp_buf = xmalloc (p->tmp_size));
-    }
-    cptr = p->tmp_buf;
-    for (i = 0; i < REC_NO_INFO; i++)
-    {
-        memcpy (cptr, &rec->size[i], sizeof(*rec->size));
-        cptr += sizeof(*rec->size);
-        if (rec->info[i])
-        {
-            memcpy (cptr, rec->info[i], rec->size[i]);
-            cptr += rec->size[i];
-        }
-    }
-    for (got = 0; got < entry.u.used.size; got += r)
-    {
-        r = write (p->data_fd, p->tmp_buf + got, entry.u.used.size - got);
-        if (r <= 0)
-        {
-            logf (LOG_FATAL|LOG_ERRNO, "write of %s", p->data_fname);
-            exit (1);
-        }
-    }
-}
-
-static void rec_cache_flush (Records p)
-{
-    int i;
-    for (i = 0; i<p->cache_cur; i++)
-    {
-        struct record_cache_entry *e = p->record_cache + i;
-        if (e->dirty)
-            rec_write_single (p, e->rec);
-        rec_rm (&e->rec);
-    }
-    p->cache_cur = 0;
-}
-
-static Record *rec_cache_lookup (Records p, int sysno, int dirty)
-{
-    int i;
-    for (i = 0; i<p->cache_cur; i++)
-    {
-        struct record_cache_entry *e = p->record_cache + i;
-        if (e->rec->sysno == sysno)
-        {
-            if (dirty)
-                e->dirty = 1;
-            return &e->rec;
-        }
-    }
-    return NULL;
-}
-
-static void rec_cache_insert (Records p, Record rec, int dirty)
-{
-    struct record_cache_entry *e;
-
-    if (p->cache_cur == p->cache_max)
-        rec_cache_flush (p);
-    assert (p->cache_cur < p->cache_max);
-
-    e = p->record_cache + (p->cache_cur)++;
-    e->dirty = dirty;
-    e->rec = rec_cp (rec);
-}
-
-void rec_close (Records *p)
-{
-    assert (*p);
-
-    rec_cache_flush (*p);
-    xfree ((*p)->record_cache);
-
-    if ((*p)->rw)
-        rec_write_head (*p);
-
-    if ((*p)->index_fd != -1)
-        close ((*p)->index_fd);
-
-    if ((*p)->data_fd != -1)
-        close ((*p)->data_fd);
-
-    xfree ((*p)->tmp_buf);
-
-    xfree (*p);
-    *p = NULL;
-}
-
-Record rec_get (Records p, int sysno)
-{
-    int i;
-    Record rec, *recp;
-    struct record_index_entry entry;
-    int r, got;
-    char *nptr;
-
-    assert (sysno > 0);
-    assert (p);
-
-    if ((recp = rec_cache_lookup (p, sysno, 0)))
-        return rec_cp (*recp);
-
-    read_indx (p, sysno, &entry, sizeof(entry));
-    
-    rec = xmalloc (sizeof(*rec));
-    if (lseek (p->data_fd, entry.u.used.offset, SEEK_SET) == -1) 
-    {
-        logf (LOG_FATAL|LOG_ERRNO, "lseek in %s to pos %ld",
-              p->data_fname, entry.u.used.offset);
-        exit (1);
-    }
-    if (p->tmp_size < entry.u.used.size) 
-    {
-        xfree (p->tmp_buf);
-        p->tmp_size = entry.u.used.size + 16384;
-        p->tmp_buf = xmalloc (p->tmp_size));
-    }
-    for (got = 0; got < entry.u.used.size; got += r)
-    {
-        r = read (p->data_fd, p->tmp_buf + got, entry.u.used.size - got);
-        if (r <= 0)
-        {
-            logf (LOG_FATAL|LOG_ERRNO, "read of %s", p->data_fname);
-            exit (1);
-        }
-    }
-    rec->sysno = sysno;
-
-    nptr = p->tmp_buf;
-    for (i = 0; i < REC_NO_INFO; i++)
-    {
-        memcpy (&rec->size[i], nptr, sizeof(*rec->size));
-        nptr += sizeof(*rec->size);
-        if (rec->size[i])
-        {
-            rec->info[i] = xmalloc (rec->size[i]);
-            memcpy (rec->info[i], nptr, rec->size[i]);
-            nptr += rec->size[i];
-        }
-        else
-            rec->info[i] = NULL;
-    }
-    rec_cache_insert (p, rec, 0);
-    return rec;
-}
-
-Record rec_new (Records p)
-{
-    int sysno, i;
-    Record rec;
-
-    assert (p);
-    rec = xmalloc (sizeof(*rec));
-    if (p->head.index_free == 0)
-        sysno = (p->head.index_last)++;
-    else
-    {
-        struct record_index_entry entry;
-
-        read_indx (p, p->head.index_free, &entry, sizeof(entry));
-        sysno = p->head.index_free;
-        p->head.index_free = entry.u.free.next;
-    }
-    (p->head.no_records)++;
-    rec->sysno = sysno;
-    for (i = 0; i < REC_NO_INFO; i++)
-    {
-        rec->info[i] = NULL;
-        rec->size[i] = 0;
-    }
-    rec_cache_insert (p, rec, 1);
-    return rec;
-}
-
-void rec_put (Records p, Record *recpp)
-{
-    Record *recp;
-
-    if ((recp = rec_cache_lookup (p, (*recpp)->sysno, 1)))
-    {
-        rec_rm (recp);
-        *recp = *recpp;
-    }
-    else
-    {
-        rec_cache_insert (p, *recpp, 1);
-        rec_rm (recpp);
-    }
-    *recpp = NULL;
-}
-
-void rec_rm (Record *recpp)
-{
-    int i;
-    for (i = 0; i < REC_NO_INFO; i++)
-        xfree ((*recpp)->info[i]);
-    xfree (*recpp);
-    *recpp = NULL;
-}
-
-Record rec_cp (Record rec)
-{
-    Record n;
-    int i;
-
-    n = xmalloc (sizeof(*n));
-    n->sysno = rec->sysno;
-    for (i = 0; i < REC_NO_INFO; i++)
-        if (!rec->info[i])
-        {
-            n->info[i] = NULL;
-            n->size[i] = 0;
-        }
-        else
-        {
-            n->size[i] = rec->size[i];
-            n->info[i] = xmalloc (rec->size[i]);
-            memcpy (n->info[i], rec->info[i], rec->size[i]);
-        }
-    return n;
-}
-
-void rec_del (Records p, Record *recpp)
-{
-    assert (0);
-}
-
-
-#endif
 
 char *rec_strdup (const char *s, size_t *len)
 {
index 1ec146a..d95c9ef 100644 (file)
@@ -4,7 +4,13 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: recindex.h,v $
- * Revision 1.7  1995-11-28 09:09:45  adam
+ * Revision 1.8  1995-12-06 12:41:25  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.7  1995/11/28  09:09:45  adam
  * Zebra config renamed.
  * Use setting 'recordId' to identify record now.
  * Bug fix in recindex.c: rec_release_blocks was invokeded even
@@ -62,3 +68,4 @@ enum {
     recInfo_databaseName,
     recInfo_storeData
 };
+
diff --git a/index/recindxp.h b/index/recindxp.h
new file mode 100644 (file)
index 0000000..a0d9d4c
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 1994-1995, Index Data I/S 
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: recindxp.h,v $
+ * Revision 1.1  1995-12-06 12:41:25  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.
+ *
+ */
+
+#include "recindex.h"
+
+#include <bfile.h>
+
+#define REC_BLOCK_TYPES 2
+#define REC_HEAD_MAGIC "recindx"
+
+struct records_info {
+    int rw;
+
+    char *index_fname;
+    BFile index_BFile;
+
+
+    char *data_fname[REC_BLOCK_TYPES];
+    BFile data_BFile[REC_BLOCK_TYPES];
+
+    char *tmp_buf;
+    int tmp_size;
+
+    struct record_cache_entry *record_cache;
+    int cache_size;
+    int cache_cur;
+    int cache_max;
+
+    struct records_head {
+        char magic[8];
+        int block_size[REC_BLOCK_TYPES];
+        int block_free[REC_BLOCK_TYPES];
+        int block_last[REC_BLOCK_TYPES];
+        int block_used[REC_BLOCK_TYPES];
+        int block_move[REC_BLOCK_TYPES];
+
+        int total_bytes;
+        int index_last;
+        int index_free;
+        int no_records;
+
+    } head;
+};
+
+enum recordCacheFlag { recordFlagNop, recordFlagWrite, recordFlagNew,
+                       recordFlagDelete };
+
+struct record_cache_entry {
+    Record rec;
+    enum recordCacheFlag flag;
+};
+
+struct record_index_entry {
+    union {
+        struct {
+            int next;
+            int size;
+        } used;
+        struct {
+            int next;
+        } free;
+    } u;
+};
+
diff --git a/index/recstat.c b/index/recstat.c
new file mode 100644 (file)
index 0000000..aa1ff65
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 1994-1995, Index Data I/S 
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: recstat.c,v $
+ * Revision 1.1  1995-12-06 12:41:26  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.
+ *
+ */
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+#include <ctype.h>
+#include <assert.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "recindxp.h"
+
+void rec_prstat (void)
+{
+    Records records = rec_open (0);
+    int i;
+    int total_bytes = 0;
+    
+    logf (LOG_LOG,
+          "Total records                        %8d",
+          records->head.no_records);
+
+    for (i = 0; i< REC_BLOCK_TYPES; i++)
+    {
+        logf (LOG_LOG, "Record blocks of size %d",
+              records->head.block_size[i]);
+        logf (LOG_LOG,
+          " Used/Total/Bytes used            %d/%d/%d",
+              records->head.block_used[i], records->head.block_last[i]-1,
+              records->head.block_used[i] * records->head.block_size[i]);
+        total_bytes +=
+            records->head.block_used[i] * records->head.block_size[i];
+    }
+    logf (LOG_LOG,
+          "Total size of record index in bytes  %8d",
+          records->head.total_bytes);
+    logf (LOG_LOG,
+          "Total size with overhead             %8d", total_bytes);
+    rec_close (&records);
+}
index d055ad5..c3f6aca 100644 (file)
@@ -4,7 +4,13 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: trav.c,v $
- * Revision 1.13  1995-11-28 09:09:46  adam
+ * Revision 1.14  1995-12-06 12:41:26  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.13  1995/11/28  09:09:46  adam
  * Zebra config renamed.
  * Use setting 'recordId' to identify record now.
  * Bug fix in recindex.c: rec_release_blocks was invokeded even
@@ -311,7 +317,7 @@ void repositoryUpdate (struct recordGroup *rGroup)
     else 
     {
         strcpy (src, rGroup->path);
-        if (*src == '\0')
+        if (*src == '\0' || !strcmp (src, "-"))
             stdinExtractR (0, rGroup);
         else
             repositoryExtractR (0, src, rGroup);
@@ -325,7 +331,7 @@ void repositoryDelete (struct recordGroup *rGroup)
     assert (rGroup->path);
     groupRes (rGroup);
     strcpy (src, rGroup->path);
-    if (*src == '\0')
+    if (*src == '\0' || !strcmp(src, "-"))
        stdinExtractR (1, rGroup);
     else
        repositoryExtractR (1, src, rGroup);
index 24a7ae7..115f691 100644 (file)
@@ -4,7 +4,13 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: zrpn.c,v $
- * Revision 1.35  1995-11-27 09:29:00  adam
+ * Revision 1.36  1995-12-06 12:41:27  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.35  1995/11/27  09:29:00  adam
  * Bug fixes regarding conversion to regular expressions.
  *
  * Revision 1.34  1995/11/16  17:00:56  adam
 #include <stdio.h>
 #include <assert.h>
 #include <unistd.h>
+#include <ctype.h>
 
 #include "zserver.h"
 #include "attribute.h"
@@ -617,6 +624,13 @@ static int relational_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
     return 1;
 }
 
+static void verbatim_char (int ch, int *indx, char *dst)
+{
+    if (!isalnum (ch))
+        dst[(*indx)++] = '\\';
+    dst[(*indx)++] = ch;
+}
+
 static int trunc_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
                        const char *term_sub,
                        oid_value attributeSet, struct grep_info *grep_info,
@@ -658,17 +672,22 @@ static int trunc_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
             {
             case -1:         /* not specified */
             case 100:        /* do not truncate */
-               sprintf (term_dict + strlen(term_dict), 
-                         "([]%d %s)", strlen(term_sub), term_sub);
-                logf (LOG_DEBUG, "dict_lookup_grep: %s", term_dict);
+                j = strlen(term_dict);
+                term_dict[j++] = '(';
+                for (i = 0; term_sub[i]; i++)
+                    verbatim_char (term_sub[i], &j, term_dict);
+                strcpy (term_dict+j, ")");
                 r = dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info,
                                       &max_pos, grep_handle);
                 if (r)
                     logf (LOG_WARN, "dict_lookup_grep err, trunc=none:%d", r);
                 break;
             case 1:          /* right truncation */
-               sprintf (term_dict + strlen(term_dict),
-                        "([]%d %s.*)", strlen(term_sub), term_sub);
+                j = strlen(term_dict);
+                term_dict[j++] = '(';
+                for (i = 0; term_sub[i]; i++)
+                    verbatim_char (term_sub[i], &j, term_dict);
+                strcpy (term_dict+j, ".*)");
                 dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info,
                                   &max_pos, grep_handle);
                 break;
@@ -677,19 +696,16 @@ static int trunc_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
                 zi->errCode = 120;
                 return -1;
             case 101:        /* process # in term */
-                strcat (term_dict, "(");
                 j = strlen(term_dict);
+                term_dict[j++] = '(';
                 for (i=0; term_sub[i]; i++)
-                    if (i > 2 && term_sub[i] == '#')
+                    if (term_sub[i] == '#' && i > 2)
                     {
                         term_dict[j++] = '.';
                         term_dict[j++] = '*';
                     }
                     else
-                    {
-                        term_dict[j++] = '\\';
-                        term_dict[j++] = term_sub[i];
-                    }
+                        verbatim_char (term_sub[i], &j, term_dict);
                 strcpy (term_dict+j, ")");
                 r = dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info,
                                       &max_pos, grep_handle);
@@ -699,7 +715,6 @@ static int trunc_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
                 break;
             case 102:        /* regular expression */
                sprintf (term_dict + strlen(term_dict), "(%s)", term_sub);
-                logf (LOG_DEBUG, "dict_lookup_grep: %s", term_dict);
                 r = dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info,
                                       &max_pos, grep_handle);
                 if (r)