xfree/xmalloc used everywhere.
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 28 Sep 1995 09:19:40 +0000 (09:19 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 28 Sep 1995 09:19:40 +0000 (09:19 +0000)
Extract/retrieve method seems to work for text records.

index/dir.c
index/extract.c
index/kcompare.c
index/symtab.c
index/trav.c
index/zserver.c
index/zserver.h
index/zsets.c

index 74c93aa..a13c74c 100644 (file)
@@ -4,7 +4,11 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: dir.c,v $
- * Revision 1.6  1995-09-08 14:52:26  adam
+ * Revision 1.7  1995-09-28 09:19:40  adam
+ * xfree/xmalloc used everywhere.
+ * Extract/retrieve method seems to work for text records.
+ *
+ * Revision 1.6  1995/09/08  14:52:26  adam
  * Minor changes. Dictionary is lower case now.
  *
  * Revision 1.5  1995/09/06  16:11:16  adam
@@ -51,11 +55,7 @@ struct dir_entry *dir_open (const char *rep)
             exit (1);
         return NULL;
     }
-    if (!(entry = malloc (sizeof(*entry) * entry_max)))
-    {
-        logf (LOG_FATAL|LOG_ERRNO, "malloc");
-        exit (1);
-    }    
+    entry = xmalloc (sizeof(*entry) * entry_max);
     while ((dent = readdir (dir)))
     {
         if (strcmp (dent->d_name, ".") == 0 ||
@@ -65,21 +65,13 @@ struct dir_entry *dir_open (const char *rep)
         {
             struct dir_entry *entry_n;
 
-            if (!(entry_n = malloc (sizeof(*entry) * (entry_max + 400))))
-            {
-                logf (LOG_FATAL|LOG_ERRNO, "malloc");
-                exit (1);
-            }
+            entry_n = xmalloc (sizeof(*entry) * (entry_max + 400));
             memcpy (entry_n, entry, idx * sizeof(*entry));
-            free (entry);
+            xfree (entry);
             entry = entry_n;
             entry_max += 100;
         }
-        if (!(entry[idx].name = malloc (strlen(dent->d_name)+1)))
-        {
-            logf (LOG_FATAL|LOG_ERRNO, "malloc");
-            exit (1);
-        }
+        entry[idx].name = xmalloc (strlen(dent->d_name)+1);
         strcpy (entry[idx].name, dent->d_name);
         idx++;
     }
@@ -109,7 +101,7 @@ void dir_free (struct dir_entry **e_p)
 
     assert (e);
     while (e[i].name)
-        free (e[i++].name);
-    free (e);
+        xfree (e[i++].name);
+    xfree (e);
     *e_p = NULL;
 }
index dac9820..9b7f76b 100644 (file)
@@ -4,7 +4,11 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: extract.c,v $
- * Revision 1.9  1995-09-27 12:22:28  adam
+ * Revision 1.10  1995-09-28 09:19:41  adam
+ * xfree/xmalloc used everywhere.
+ * Extract/retrieve method seems to work for text records.
+ *
+ * Revision 1.9  1995/09/27  12:22:28  adam
  * More work on extract in record control.
  * Field name is not in isam keys but in prefix in dictionary words.
  *
@@ -195,13 +199,15 @@ void file_extract (int cmd, const char *fname, const char *kname)
     sprintf (ext_res, "fileExtension.%s", ext);
     if (!(file_type = res_get (common_resource, ext_res)))
         return;
-    
+    if (!(rt = recType_byName (file_type)))
+        return;
     file_info = dict_lookup (file_idx, kname);
     if (!file_info)
     {
         sysno = sysno_next++;
         dict_insert (file_idx, kname, sizeof(sysno), &sysno);
         lseek (sys_idx_fd, sysno * SYS_IDX_ENTRY_LEN, SEEK_SET);
+        write (sys_idx_fd, file_type, strlen (file_type)+1);
         write (sys_idx_fd, kname, strlen(kname)+1);
     }
     else
@@ -212,8 +218,6 @@ void file_extract (int cmd, const char *fname, const char *kname)
         logf (LOG_WARN|LOG_ERRNO, "open %s", fname);
         return;
     }
-    if (!(rt = recType_byName (file_type)))
-        return;
     extractCtrl.inf = inf;
     extractCtrl.subType = "";
     extractCtrl.init = wordInit;
index b39535d..d326493 100644 (file)
@@ -4,7 +4,11 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: kcompare.c,v $
- * Revision 1.7  1995-09-27 12:22:28  adam
+ * Revision 1.8  1995-09-28 09:19:42  adam
+ * xfree/xmalloc used everywhere.
+ * Extract/retrieve method seems to work for text records.
+ *
+ * Revision 1.7  1995/09/27  12:22:28  adam
  * More work on extract in record control.
  * Field name is not in isam keys but in prefix in dictionary words.
  *
@@ -51,28 +55,26 @@ void key_logdump (int logmask, const void *p)
 
 int key_compare (const void *p1, const void *p2)
 {
-    struct it_key i1, i2;
-    memcpy (&i1, p1, sizeof(i1));
-    memcpy (&i2, p2, sizeof(i2));
-    if (i1.sysno != i2.sysno)
+    const struct it_key *i1 = p1, *i2 = p2;
+    if (i1->sysno != i2->sysno)
     {
-        if (i1.sysno > i2.sysno)
+        if (i1->sysno > i2->sysno)
             return 2;
         else
             return -2;
     }
 #if IT_KEY_HAVE_SEQNO
-    if (i1.seqno != i2.seqno)
+    if (i1->seqno != i2->seqno)
     {
-        if (i1.seqno > i2.seqno)
+        if (i1->seqno > i2->seqno)
             return 1;
         else
             return -1;
     }
 #else
-    if (i1.freq != i2.freq)
+    if (i1->freq != i2->freq)
     {
-        if (i1.freq > i2.freq)
+        if (i1->freq > i2->freq)
             return 1;
         else
             return -1;
index d656621..6f1000e 100644 (file)
@@ -4,7 +4,11 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: symtab.c,v $
- * Revision 1.1  1995-09-06 16:11:18  adam
+ * Revision 1.2  1995-09-28 09:19:44  adam
+ * xfree/xmalloc used everywhere.
+ * Extract/retrieve method seems to work for text records.
+ *
+ * Revision 1.1  1995/09/06  16:11:18  adam
  * Option: only one word key per file.
  *
  */
@@ -72,8 +76,8 @@ void strtab_del (struct strtab *t,
         {
             e1 = e->next;
             (*func)(e->name, e->info, data);
-            free (e->name);
-            free (e);
+            xfree (e->name);
+            xfree (e);
         }
-    free (t);
+    xfree (t);
 }
index b87dbab..c3e8c49 100644 (file)
@@ -4,7 +4,11 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: trav.c,v $
- * Revision 1.3  1995-09-06 16:11:18  adam
+ * Revision 1.4  1995-09-28 09:19:46  adam
+ * xfree/xmalloc used everywhere.
+ * Extract/retrieve method seems to work for text records.
+ *
+ * Revision 1.3  1995/09/06  16:11:18  adam
  * Option: only one word key per file.
  *
  * Revision 1.2  1995/09/04  12:33:43  adam
@@ -74,11 +78,7 @@ void copy_file (const char *dst, const char *src)
         logf (LOG_FATAL|LOG_ERRNO, "Cannot open %s", src);
         exit (1);
     }
-    if (!(buf = malloc (4096)))
-    {
-        logf (LOG_FATAL|LOG_ERRNO, "malloc");
-        exit (1);
-    }
+    buf = xmalloc (4096);
     while ((r=read (s_fd, buf, 4096))>0)
         for (w = 0; w < r; w += i)
         {
@@ -94,7 +94,7 @@ void copy_file (const char *dst, const char *src)
         logf (LOG_FATAL|LOG_ERRNO, "read");
         exit (1);
     }
-    free (buf);
+    xfree (buf);
     close (d_fd);
     close (s_fd);
 }
index e1413f2..17d3016 100644 (file)
@@ -4,7 +4,11 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: zserver.c,v $
- * Revision 1.7  1995-09-27 16:17:32  adam
+ * Revision 1.8  1995-09-28 09:19:47  adam
+ * xfree/xmalloc used everywhere.
+ * Extract/retrieve method seems to work for text records.
+ *
+ * Revision 1.7  1995/09/27  16:17:32  adam
  * More work on retrieve.
  *
  * Revision 1.6  1995/09/08  08:53:22  adam
 #include <unistd.h>
 #include <fcntl.h>
 
-#include "zserver.h"
-
+#include <recctrl.h>
 #include <backend.h>
 #include <dmalloc.h>
+#include "zserver.h"
 
 ZServerInfo server_info;
 
@@ -103,6 +107,55 @@ bend_searchresult *bend_search (void *handle, bend_searchrequest *q, int *fd)
     return &r;
 }
 
+static int record_read (int fd, char *buf, size_t count)
+{
+    return read (fd, buf, count);
+}
+
+static int record_fetch (ZServerInfo *zi, int sysno, ODR stream,
+                          oid_value input_format, oid_value *output_format,
+                          char **rec_bufp, int *rec_lenp)
+{
+    char record_info[SYS_IDX_ENTRY_LEN];
+    char *fname, *file_type;
+    RecType rt;
+    struct recRetrieveCtrl retrieveCtrl;
+
+    if (lseek (zi->sys_idx_fd, sysno * SYS_IDX_ENTRY_LEN,
+               SEEK_SET) == -1)
+    {
+        logf (LOG_FATAL|LOG_ERRNO, "Retrieve: lseek of sys_idx");
+        exit (1);
+    }
+    if (read (zi->sys_idx_fd, record_info, SYS_IDX_ENTRY_LEN) == -1)
+    {
+        logf (LOG_FATAL|LOG_ERRNO, "Retrieve: read of sys_idx");
+        exit (1);
+    }
+    file_type = record_info;
+    fname = record_info + strlen(record_info) + 1;
+    if (!(rt = recType_byName (file_type)))
+    {
+        logf (LOG_FATAL|LOG_ERRNO, "Retrieve: Cannot handle type %s", 
+              file_type);
+        exit (1);
+    }
+    if ((retrieveCtrl.fd = open (fname, O_RDONLY)) == -1)
+    {
+        logf (LOG_FATAL|LOG_ERRNO, "Retrieve: Open record file %s", fname);
+        exit (1);
+    }
+    retrieveCtrl.odr = stream;
+    retrieveCtrl.readf = record_read;
+    retrieveCtrl.input_format = input_format;
+    (*rt->retrieve)(&retrieveCtrl);
+    *output_format = retrieveCtrl.output_format;
+    *rec_bufp = retrieveCtrl.rec_buf;
+    *rec_lenp = retrieveCtrl.rec_len;
+    close (retrieveCtrl.fd);
+    return 0;
+}
+
 bend_fetchresult *bend_fetch (void *handle, bend_fetchrequest *q, int *num)
 {
     static bend_fetchresult r;
@@ -129,14 +182,8 @@ bend_fetchresult *bend_fetch (void *handle, bend_fetchrequest *q, int *num)
         logf (LOG_DEBUG, "Out of range. pos=%d", q->number);
         return &r;
     }
-#if 0
-    r.len = records[0].size;
-    server_info.recordBuf = r.record = xmalloc (r.len+1);
-    strcpy (r.record, records[0].buf);
-    resultSetRecordDel (&server_info, records, 1);
-    r.format = VAL_SUTRS;
-    r.errcode = 0;
-#endif
+    r.errcode = record_fetch (&server_info, records[0].sysno, q->stream,
+                              q->format, &r.format, &r.record, &r.len);
     return &r;
 }
 
index afce157..b5899c1 100644 (file)
@@ -4,7 +4,11 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: zserver.h,v $
- * Revision 1.5  1995-09-27 16:17:32  adam
+ * Revision 1.6  1995-09-28 09:19:48  adam
+ * xfree/xmalloc used everywhere.
+ * Extract/retrieve method seems to work for text records.
+ *
+ * Revision 1.5  1995/09/27  16:17:32  adam
  * More work on retrieve.
  *
  * Revision 1.4  1995/09/14  11:53:28  adam
@@ -59,6 +63,6 @@ int rpn_search (ZServerInfo *zi,
 ZServerSet *resultSetAdd (ZServerInfo *zi, const char *name,
                           int ov, RSET rset);
 ZServerSet *resultSetGet (ZServerInfo *zi, const char *name);
-ZServerRecord *resultSetRecordGet (ZServerInfo *zi, const char *name,
-                                   int num, int *positions);
+ZServerSetSysno *resultSetSysnoGet (ZServerInfo *zi, const char *name,
+                                    int num, int *positions);
 void resultSetRecordDel (ZServerInfo *zi, ZServerRecord *records, int num);
index 00258a0..75d5c6c 100644 (file)
@@ -4,7 +4,11 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: zsets.c,v $
- * Revision 1.5  1995-09-27 16:17:32  adam
+ * Revision 1.6  1995-09-28 09:19:49  adam
+ * xfree/xmalloc used everywhere.
+ * Extract/retrieve method seems to work for text records.
+ *
+ * Revision 1.5  1995/09/27  16:17:32  adam
  * More work on retrieve.
  *
  * Revision 1.4  1995/09/07  13:58:36  adam
@@ -110,8 +114,8 @@ void resultSetRecordDel (ZServerInfo *zi, ZServerRecord *records, int num)
     int i;
 
     for (i = 0; i<num; i++)
-        free (records[i].buf);
-    free (records);
+        xfree (records[i].buf);
+    xfree (records);
 }