More record fields - they are enumerated now.
authorAdam Dickmeiss <adam@indexdata.dk>
Sat, 25 Nov 1995 10:24:05 +0000 (10:24 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Sat, 25 Nov 1995 10:24:05 +0000 (10:24 +0000)
New options: flagStoreData flagStoreKey.

index/extract.c
index/index.h
index/main.c
index/recindex.c
index/recindex.h
index/zserver.c

index 413b6eb..09c2d74 100644 (file)
@@ -4,7 +4,11 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: extract.c,v $
- * Revision 1.31  1995-11-24 11:31:35  adam
+ * Revision 1.32  1995-11-25 10:24:05  adam
+ * More record fields - they are enumerated now.
+ * New options: flagStoreData flagStoreKey.
+ *
+ * Revision 1.31  1995/11/24  11:31:35  adam
  * Commands add & del read filenames from stdin if source directory is
  * empty.
  * Match criteria supports 'constant' strings.
@@ -641,76 +645,20 @@ static char *fileMatchStr (struct recKeys *reckeys, struct recordGroup *rGroup,
     return dstBuf;
 }
 
-int fileExtract (SYSNO *sysno, const char *fname, struct recordGroup *rGroup,
-                 int deleteFlag)
+static int recordExtract (SYSNO *sysno, const char *fname,
+                          struct recordGroup *rGroup, int deleteFlag,
+                          int fd,
+                          const char *file_type,
+                          RecType recType)
 {
-    SYSNO sysnotmp;
-    int i, r;
-    char gprefix[128];
-    char ext[128];
-    char ext_res[128];
-    const char *file_type;
-    const char *file_match;
     struct recExtractCtrl extractCtrl;
-    RecType recType;
-    Record rec;
+    int r;
     char *matchStr;
+    SYSNO sysnotmp;
+    Record rec;
 
-    if (!rGroup->groupName || !*rGroup->groupName)
-        *gprefix = '\0';
-    else
-        sprintf (gprefix, "%s.", rGroup->groupName);
-
-    logf (LOG_DEBUG, "fileExtract %s", fname);
-
-    /* determine file extension */
-    for (i = strlen(fname); --i >= 0; )
-        if (fname[i] == '/')
-        {
-            strcpy (ext, "");
-            break;
-        }
-        else if (fname[i] == '.')
-        {
-            strcpy (ext, fname+i+1);
-            break;
-        }
-    /* determine file type - depending on extension */
-    sprintf (ext_res, "%sfileExtension.%s", gprefix, ext);
-    if (!(file_type = res_get (common_resource, ext_res)))
-        return 0;
-    if (!(recType = recType_byName (file_type)))
-        return 0;
-
-    /* determine match criteria */
-    sprintf (ext_res, "%sfileMatch.%s", gprefix, ext);
-    file_match = res_get (common_resource, ext_res);
-    if (!file_match)
-    {
-        sprintf (ext_res, "%sfileMatch", gprefix);
-        file_match = res_get (common_resource, ext_res);
-    }
-
-    /* determine database name */
-    if (!rGroup->databaseName)
-    {
-        sprintf (ext_res, "%sdatabase.%s", gprefix, ext);
-        if (!(rGroup->databaseName = res_get (common_resource, ext_res)))
-        {
-            sprintf (ext_res, "%sdatabase", gprefix);
-            rGroup->databaseName = res_get (common_resource, ext_res);
-        }
-    }
-    if (!rGroup->databaseName)
-        rGroup->databaseName = "Default";
-
-    /* open input file */
-    if ((extractCtrl.fd = open (fname, O_RDONLY)) == -1)
-    {
-        logf (LOG_WARN|LOG_ERRNO, "open %s", fname);
-        return 0;
-    }
-
+    extractCtrl.fd = fd;
+    
     /* extract keys */
     extractCtrl.subType = "";
     extractCtrl.init = wordInit;
@@ -736,12 +684,12 @@ int fileExtract (SYSNO *sysno, const char *fname, struct recordGroup *rGroup,
     {
         sysnotmp = 0;
         sysno = &sysnotmp;
-        if (file_match)
+        if (rGroup->fileMatch)
         {
             char *rinfo;
         
             matchStr = fileMatchStr(&reckeys, rGroup, fname, file_type,
-                                    file_match);
+                                    rGroup->fileMatch);
             if (matchStr)
             {
                 rinfo = dict_lookup (matchDict, matchStr);
@@ -780,44 +728,170 @@ int fileExtract (SYSNO *sysno, const char *fname, struct recordGroup *rGroup,
 
         rec = rec_get (records, *sysno);
 
-        delkeys.buf_used = rec->size[2];
-       delkeys.buf = rec->info[2];
-        flushRecordKeys (*sysno, 0, &delkeys, rec->info[3]);
+        delkeys.buf_used = rec->size[recInfo_delKeys];
+       delkeys.buf = rec->info[recInfo_delKeys];
+        flushRecordKeys (*sysno, 0, &delkeys, rec->info[recInfo_databaseName]);
         if (deleteFlag)
         {
-            logf (LOG_LOG, "delete record %s", fname);
+            if (!delkeys.buf_used)
+            {
+                logf (LOG_WARN, "cannot delete %s - no delete keys",
+                      fname);
+            }
+            else
+                logf (LOG_LOG, "delete record %s", fname);
             records_deleted++;
             rec_del (records, &rec);
             return 1;
         }
         else
         {
-            logf (LOG_LOG, "update record %s", fname);
-            flushRecordKeys (*sysno, 1, &reckeys, rGroup->databaseName); 
-            records_updated++;
+            if (!delkeys.buf_used)
+            {
+                logf (LOG_WARN, "cannot update %s - no delete keys",
+                      fname);
+            }
+            else
+            {
+                logf (LOG_LOG, "update record %s", fname);
+                flushRecordKeys (*sysno, 1, &reckeys, rGroup->databaseName); 
+                records_updated++;
+            }
         }
     }
-    free (rec->info[0]);
-    rec->info[0] = rec_strdup (file_type, &rec->size[0]);
+    free (rec->info[recInfo_fileType]);
+    rec->info[recInfo_fileType] =
+        rec_strdup (file_type, &rec->size[recInfo_fileType]);
 
-    free (rec->info[1]);
-    rec->info[1] = rec_strdup (fname, &rec->size[1]);
+    free (rec->info[recInfo_filename]);
+    rec->info[recInfo_filename] =
+        rec_strdup (fname, &rec->size[recInfo_filename]);
 
-    free (rec->info[2]);
-    if (reckeys.buf_used > 0)
+    free (rec->info[recInfo_delKeys]);
+    if (reckeys.buf_used > 0 && rGroup->flagStoreKeys == 1)
     {
-        rec->info[2] = malloc (reckeys.buf_used);
-        rec->size[2] = reckeys.buf_used;
-        memcpy (rec->info[2], reckeys.buf, rec->size[2]);
+        logf (LOG_LOG, "Storing keys...");
+        rec->info[recInfo_delKeys] = malloc (reckeys.buf_used);
+        rec->size[recInfo_delKeys] = reckeys.buf_used;
+        memcpy (rec->info[recInfo_delKeys], reckeys.buf,
+                rec->size[recInfo_delKeys]);
     }
     else
     {
-        rec->info[2] = NULL;
-        rec->size[2] = 0;
+        rec->info[recInfo_delKeys] = NULL;
+        rec->size[recInfo_delKeys] = 0;
     }
-    free (rec->info[3]);
-    rec->info[3] = rec_strdup (rGroup->databaseName, &rec->size[3]); 
+    free (rec->info[recInfo_databaseName]);
+    rec->info[recInfo_databaseName] =
+        rec_strdup (rGroup->databaseName, &rec->size[recInfo_databaseName]); 
 
     rec_put (records, &rec);
     return 1;
 }
+
+int fileExtract (SYSNO *sysno, const char *fname, struct recordGroup *rGroup,
+                 int deleteFlag)
+{
+    int i, fd;
+    char gprefix[128];
+    char ext[128];
+    char ext_res[128];
+    const char *file_type;
+    RecType recType;
+
+    if (!rGroup->groupName || !*rGroup->groupName)
+        *gprefix = '\0';
+    else
+        sprintf (gprefix, "%s.", rGroup->groupName);
+
+    logf (LOG_DEBUG, "fileExtract %s", fname);
+
+    /* determine file extension */
+    for (i = strlen(fname); --i >= 0; )
+        if (fname[i] == '/')
+        {
+            strcpy (ext, "");
+            break;
+        }
+        else if (fname[i] == '.')
+        {
+            strcpy (ext, fname+i+1);
+            break;
+        }
+    /* determine file type - depending on extension */
+    sprintf (ext_res, "%sfileExtension.%s", gprefix, ext);
+    if (!(file_type = res_get (common_resource, ext_res)))
+        return 0;
+    if (!(recType = recType_byName (file_type)))
+        return 0;
+
+    /* determine match criteria */
+    if (rGroup->fileMatch)
+    {
+        sprintf (ext_res, "%sfileMatch.%s", gprefix, ext);
+        rGroup->fileMatch = res_get (common_resource, ext_res);
+        if (!rGroup->fileMatch)
+        {
+            sprintf (ext_res, "%sfileMatch", gprefix);
+            rGroup->fileMatch = res_get (common_resource, ext_res);
+        }
+    }
+
+    /* determine database name */
+    if (!rGroup->databaseName)
+    {
+        sprintf (ext_res, "%sdatabase.%s", gprefix, ext);
+        if (!(rGroup->databaseName = res_get (common_resource, ext_res)))
+        {
+            sprintf (ext_res, "%sdatabase", gprefix);
+            rGroup->databaseName = res_get (common_resource, ext_res);
+        }
+    }
+    if (!rGroup->databaseName)
+        rGroup->databaseName = "Default";
+
+    if (rGroup->flagStoreData == -1)
+    {
+        const char *sval;
+        sprintf (ext_res, "%sstoreData.%s", gprefix, ext);
+        if (!(sval = res_get (common_resource, ext_res)))
+        {
+            sprintf (ext_res, "%sstoreData", gprefix);
+            sval = res_get (common_resource, ext_res);
+        }
+        if (sval)
+            rGroup->flagStoreData = atoi (sval);
+    }
+    if (rGroup->flagStoreData == -1)
+        rGroup->flagStoreData = 0;
+
+
+    if (rGroup->flagStoreKeys == -1)
+    {
+        const char *sval;
+
+        sprintf (ext_res, "%sstoreKeys.%s", gprefix, ext);
+        if (!(sval = res_get (common_resource, ext_res)))
+        {
+            sprintf (ext_res, "%sstoreKeys", gprefix);
+            sval = res_get (common_resource, ext_res);
+        }
+        if (sval)
+            rGroup->flagStoreKeys = atoi (sval);
+    }
+    if (rGroup->flagStoreKeys == -1)
+        rGroup->flagStoreKeys = 0;
+
+
+    /* open input file */
+    if ((fd = open (fname, O_RDONLY)) == -1)
+    {
+        logf (LOG_WARN|LOG_ERRNO, "open %s", fname);
+        return 0;
+    }
+    recordExtract (sysno, fname, rGroup, deleteFlag, fd,
+                   file_type, recType);
+    close (fd);
+    return 1;
+}
+
index 6fdee19..ae05ece 100644 (file)
@@ -4,7 +4,11 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: index.h,v $
- * Revision 1.26  1995-11-22 17:19:17  adam
+ * Revision 1.27  1995-11-25 10:24:06  adam
+ * More record fields - they are enumerated now.
+ * New options: flagStoreData flagStoreKey.
+ *
+ * Revision 1.26  1995/11/22  17:19:17  adam
  * Record management uses the bfile system.
  *
  * Revision 1.25  1995/11/21  15:29:12  adam
@@ -120,6 +124,9 @@ struct recordGroup {
     char *groupName;
     char *databaseName;
     char *path;
+    char *fileMatch;
+    int  flagStoreData;
+    int  flagStoreKeys;
 };
 
 struct dirs_info *dirs_open (Dict dict, const char *rep);
index 8e68139..ae3095e 100644 (file)
@@ -4,7 +4,11 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: main.c,v $
- * Revision 1.18  1995-11-22 17:19:17  adam
+ * Revision 1.19  1995-11-25 10:24:06  adam
+ * More record fields - they are enumerated now.
+ * New options: flagStoreData flagStoreKey.
+ *
+ * Revision 1.18  1995/11/22  17:19:17  adam
  * Record management uses the bfile system.
  *
  * Revision 1.17  1995/11/21  15:01:16  adam
@@ -88,6 +92,9 @@ int main (int argc, char **argv)
     rGroup.groupName = NULL;
     rGroup.databaseName = NULL;
     rGroup.path = NULL;
+    rGroup.fileMatch = NULL;
+    rGroup.flagStoreData = -1;
+    rGroup.flagStoreKeys = -1;
 
     prog = *argv;
     if (argc < 2)
index 1955b98..3233a3c 100644 (file)
@@ -4,7 +4,11 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: recindex.c,v $
- * Revision 1.5  1995-11-22 17:19:18  adam
+ * 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
@@ -249,6 +253,7 @@ static void rec_write_single (Records p, Record rec)
         else
         {
             memcpy (cptr, &block_free, sizeof(int));
+            logf (LOG_LOG, "writing block %d (1)", block_prev);
             bf_write (p->data_BFile[dst_type], block_prev, 0, 0, cptr);
             cptr = p->tmp_buf + no_written;
         }
@@ -259,6 +264,7 @@ static void rec_write_single (Records p, Record rec)
     assert (block_prev != -1);
     block_free = 0;
     memcpy (cptr, &block_free, sizeof(int));
+    logf (LOG_LOG, "writing block %d (2) dst=%d", block_prev, dst_type);
     bf_write (p->data_BFile[dst_type], block_prev, 0,
               sizeof(int) + (p->tmp_buf+size) - cptr, cptr);
 }
index ad3d41e..53d9dca 100644 (file)
@@ -4,7 +4,11 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: recindex.h,v $
- * Revision 1.4  1995-11-22 17:19:19  adam
+ * Revision 1.5  1995-11-25 10:24:07  adam
+ * More record fields - they are enumerated now.
+ * New options: flagStoreData flagStoreKey.
+ *
+ * Revision 1.4  1995/11/22  17:19:19  adam
  * Record management uses the bfile system.
  *
  * Revision 1.3  1995/11/20  16:59:46  adam
@@ -39,3 +43,11 @@ Record rec_get (Records p, int sysno);
 void rec_close (Records *p);
 Records rec_open (int rw);
 char *rec_strdup (const char *s, size_t *len);
+
+enum { recInfo_fileType,
+           recInfo_filename,
+           recInfo_delKeys,
+           recInfo_databaseName,
+           recInfo_recordData
+   };
+           
index a208a37..74a017c 100644 (file)
@@ -4,7 +4,11 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: zserver.c,v $
- * Revision 1.25  1995-11-21 15:29:13  adam
+ * Revision 1.26  1995-11-25 10:24:07  adam
+ * More record fields - they are enumerated now.
+ * New options: flagStoreData flagStoreKey.
+ *
+ * Revision 1.25  1995/11/21  15:29:13  adam
  * Config file 'base' read by default by both indexer and server.
  *
  * Revision 1.24  1995/11/20  16:59:47  adam
@@ -189,8 +193,8 @@ static int record_fetch (ZServerInfo *zi, int sysno, int score, ODR stream,
     struct recRetrieveCtrl retrieveCtrl;
 
     rec = rec_get (zi->records, sysno);
-    file_type = rec->info[0];
-    fname = rec->info[1];
+    file_type = rec->info[recInfo_fileType];
+    fname = rec->info[recInfo_filename];
 
     if (!(rt = recType_byName (file_type)))
     {