Added a few comments.
[idzebra-moved-to-github.git] / index / extract.c
index 798354a..45e6363 100644 (file)
@@ -4,7 +4,20 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: extract.c,v $
- * Revision 1.49  1996-02-05 12:29:57  adam
+ * Revision 1.53  1996-04-26 12:09:43  adam
+ * Added a few comments.
+ *
+ * Revision 1.52  1996/04/25  13:27:57  adam
+ * Function recordExtract modified so that files with no keys (possibly empty)
+ * are ignored.
+ *
+ * Revision 1.51  1996/03/19  11:08:42  adam
+ * Bug fix: Log preamble wasn't always turned off after recordExtract.
+ *
+ * Revision 1.50  1996/02/12  18:45:36  adam
+ * New fileVerboseFlag in record group control.
+ *
+ * Revision 1.49  1996/02/05  12:29:57  adam
  * Logging reduced a bit.
  * The remaining running time is estimated during register merge.
  *
@@ -809,8 +822,8 @@ static int recordExtract (SYSNO *sysno, const char *fname,
     
     if (fi->fd != -1)
     {
+        /* we are going to read from a file, so prepare the extraction */
         extractCtrl.fh = fi;
-        /* extract keys */
         extractCtrl.subType = subType;
         extractCtrl.init = wordInit;
         extractCtrl.add = addRecordKeyAny;
@@ -820,12 +833,20 @@ static int recordExtract (SYSNO *sysno, const char *fname,
         reckeys.prevAttrSet = -1;
         extractCtrl.readf = file_read;
         r = (*recType->extract)(&extractCtrl);
-  
+
         if (r)      
         {
+            /* error occured during extraction ... */
             logf (LOG_WARN, "Couldn't extract file %s, code %d", fname, r);
             return 0;
         }
+        if (reckeys.buf_used == 0)
+        {
+            /* the extraction process returned no information - the record
+               is probably empty */
+            logf (LOG_WARN, "Empty file %s", fname);
+            return 0;
+        }
     }
 
     /* perform match if sysno not known and if match criteria is specified */
@@ -855,19 +876,17 @@ static int recordExtract (SYSNO *sysno, const char *fname,
         }
     }
 
-    /* new record ? */
     if (! *sysno)
     {
+        /* new record */
         if (deleteFlag)
         {
             logf (LOG_LOG, "Cannot delete new record");
             return 1;
         }
         logInfo.op = "add";
-#if 0
-        logf (LOG_LOG, "update %s %s", rGroup->recordType,
-              fname);
-#endif
+        if (rGroup->fileVerboseFlag)
+            logf (LOG_LOG, "add %s %s", rGroup->recordType, fname);
         rec = rec_new (records);
         *sysno = rec->sysno;
 
@@ -881,6 +900,7 @@ static int recordExtract (SYSNO *sysno, const char *fname,
     }
     else
     {
+        /* record already exists */
         struct recKeys delkeys;
 
         rec = rec_get (records, *sysno);
@@ -890,6 +910,7 @@ static int recordExtract (SYSNO *sysno, const char *fname,
         flushRecordKeys (*sysno, 0, &delkeys, rec->info[recInfo_databaseName]);
         if (deleteFlag)
         {
+            /* record going to be deleted */
             logInfo.op = "delete";
             if (!delkeys.buf_used)
             {
@@ -897,9 +918,8 @@ static int recordExtract (SYSNO *sysno, const char *fname,
             }
             else
             {
-#if 0
-                logf (LOG_LOG, "delete %s %s", rGroup->recordType, fname);
-#endif
+                if (rGroup->fileVerboseFlag)
+                    logf (LOG_LOG, "delete %s %s", rGroup->recordType, fname);
                 records_deleted++;
                 if (matchStr)
                     dict_delete (matchDict, matchStr);
@@ -909,6 +929,7 @@ static int recordExtract (SYSNO *sysno, const char *fname,
         }
         else
         {
+            /* record going to be updated */
             logInfo.op = "update";
             if (!delkeys.buf_used)
             {
@@ -916,23 +937,24 @@ static int recordExtract (SYSNO *sysno, const char *fname,
             }
             else
             {
-#if 0
-                logf (LOG_LOG, "update %s %s", rGroup->recordType,
-                      fname);
-#endif
+                if (rGroup->fileVerboseFlag)
+                    logf (LOG_LOG, "update %s %s", rGroup->recordType, fname);
                 flushRecordKeys (*sysno, 1, &reckeys, rGroup->databaseName); 
                 records_updated++;
             }
         }
     }
+    /* update file type */
     xfree (rec->info[recInfo_fileType]);
     rec->info[recInfo_fileType] =
         rec_strdup (rGroup->recordType, &rec->size[recInfo_fileType]);
 
+    /* update filename */
     xfree (rec->info[recInfo_filename]);
     rec->info[recInfo_filename] =
         rec_strdup (fname, &rec->size[recInfo_filename]);
 
+    /* update delete keys */
     xfree (rec->info[recInfo_delKeys]);
     if (reckeys.buf_used > 0 && rGroup->flagStoreKeys == 1)
     {
@@ -954,6 +976,7 @@ static int recordExtract (SYSNO *sysno, const char *fname,
         rec->size[recInfo_delKeys] = 0;
     }
 
+    /* update store data */
     xfree (rec->info[recInfo_storeData]);
     if (rGroup->flagStoreData == 1)
     {
@@ -985,19 +1008,20 @@ static int recordExtract (SYSNO *sysno, const char *fname,
         rec->info[recInfo_storeData] = NULL;
         rec->size[recInfo_storeData] = 0;
     }
+    /* update database name */
     xfree (rec->info[recInfo_databaseName]);
     rec->info[recInfo_databaseName] =
         rec_strdup (rGroup->databaseName, &rec->size[recInfo_databaseName]); 
 
+    /* commit this record */
     rec_put (records, &rec);
-    log_event_start (NULL, NULL);
     return 1;
 }
 
 int fileExtract (SYSNO *sysno, const char *fname, 
                  const struct recordGroup *rGroupP, int deleteFlag)
 {
-    int i, fd;
+    int r, i, fd;
     char gprefix[128];
     char ext[128];
     char ext_res[128];
@@ -1037,18 +1061,16 @@ int fileExtract (SYSNO *sysno, const char *fname,
             sprintf (ext_res, "%srecordType", gprefix);
             if (!(rGroup->recordType = res_get (common_resource, ext_res)))
             {
-#if 0
-                logf (LOG_LOG, "? %s", fname);
-#endif
+                if (rGroup->fileVerboseFlag)
+                    logf (LOG_LOG, "? %s", fname);
                 return 0;
             }
         }
     }
     if (!rGroup->recordType)
     {
-#if 0
-        logf (LOG_LOG, "? record %s", fname);
-#endif
+        if (rGroup->fileVerboseFlag)
+            logf (LOG_LOG, "? record %s", fname);
         return 0;
     }
     if (!(recType = recType_byName (rGroup->recordType, subType)))
@@ -1119,10 +1141,11 @@ int fileExtract (SYSNO *sysno, const char *fname,
         }
     }
     fi = file_read_start (fd);
-    recordExtract (sysno, fname, rGroup, deleteFlag, fi, recType, subType);
+    r = recordExtract (sysno, fname, rGroup, deleteFlag, fi, recType, subType);
+    log_event_start (NULL, NULL);
     file_read_stop (fi);
     if (fd != -1)
         close (fd);
-    return 1;
+    return r;
 }