Commands add & del read filenames from stdin if source directory is
[idzebra-moved-to-github.git] / index / extract.c
index 76e4938..413b6eb 100644 (file)
@@ -4,7 +4,15 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: extract.c,v $
- * Revision 1.29  1995-11-21 15:01:14  adam
+ * 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.
+ *
+ * Revision 1.30  1995/11/22  17:19:16  adam
+ * Record management uses the bfile system.
+ *
+ * Revision 1.29  1995/11/21  15:01:14  adam
  * New general match criteria implemented.
  * New feature: document groups.
  *
@@ -570,15 +578,15 @@ static char *fileMatchStr (struct recKeys *reckeys, struct recordGroup *rGroup,
         else if (*s == '$')
         {
             int spec_len;
-            char special[32];
+            char special[64];
             const char *spec_src = NULL;
             const char *s1 = ++s;
             while (*s1 && *s1 != ' ' && *s1 != '\t')
                 s1++;
 
             spec_len = s1 - s;
-            if (spec_len > 31)
-                spec_len = 31;
+            if (spec_len > 63)
+                spec_len = 63;
             memcpy (special, s, spec_len);
             special[spec_len] = '\0';
             s = s1;
@@ -596,8 +604,25 @@ static char *fileMatchStr (struct recKeys *reckeys, struct recordGroup *rGroup,
             if (spec_src)
             {
                 strcpy (dst, spec_src);
-                dst += strlen(spec_src);
+                dst += strlen (spec_src);
+            }
+        }
+        else if (*s == '\"' || *s == '\'')
+        {
+            int stopMarker = *s++;
+            char tmpString[64];
+            int i = 0;
+
+            while (*s && *s != stopMarker)
+            {
+                if (i < 63)
+                    tmpString[i++] = *s;
             }
+            if (*s)
+                s++;
+            tmpString[i] = '\0';
+            strcpy (dst, tmpString);
+            dst += strlen (tmpString);
         }
         else
         {
@@ -636,7 +661,7 @@ int fileExtract (SYSNO *sysno, const char *fname, struct recordGroup *rGroup,
     else
         sprintf (gprefix, "%s.", rGroup->groupName);
 
-    logf (LOG_DEBUG, "fileExtractAdd %s", fname);
+    logf (LOG_DEBUG, "fileExtract %s", fname);
 
     /* determine file extension */
     for (i = strlen(fname); --i >= 0; )
@@ -707,31 +732,38 @@ int fileExtract (SYSNO *sysno, const char *fname, struct recordGroup *rGroup,
     /* perform match if sysno not known and if match criteria is specified */
        
     matchStr = NULL;
-    if (!sysno && file_match)
+    if (!sysno) 
     {
-        char *rinfo;
-        
+        sysnotmp = 0;
         sysno = &sysnotmp;
-        matchStr = fileMatchStr(&reckeys, rGroup, fname, file_type,
-                                file_match);
-        if (matchStr)
+        if (file_match)
         {
-            rinfo = dict_lookup (matchDict, matchStr);
-            if (rinfo)
-                memcpy (sysno, rinfo+1, sizeof(*sysno));
+            char *rinfo;
+        
+            matchStr = fileMatchStr(&reckeys, rGroup, fname, file_type,
+                                    file_match);
+            if (matchStr)
+            {
+                rinfo = dict_lookup (matchDict, matchStr);
+                if (rinfo)
+                    memcpy (sysno, rinfo+1, sizeof(*sysno));
+            }
             else
-                *sysno = 0;
-        }
-        else
-        {
-            logf (LOG_WARN, "Record not inserted");
-            return 0;
+            {
+                logf (LOG_WARN, "Record not inserted");
+                return 0;
+            }
         }
     }
 
     /* new record ? */
     if (! *sysno)
     {
+        if (deleteFlag)
+        {
+            logf (LOG_LOG, "? record %s", fname);
+            return 1;
+        }
         logf (LOG_LOG, "add record %s", fname);
         rec = rec_new (records);
         *sysno = rec->sysno;
@@ -745,15 +777,25 @@ int fileExtract (SYSNO *sysno, const char *fname, struct recordGroup *rGroup,
     else
     {
         struct recKeys delkeys;
-        
+
         rec = rec_get (records, *sysno);
 
         delkeys.buf_used = rec->size[2];
        delkeys.buf = rec->info[2];
         flushRecordKeys (*sysno, 0, &delkeys, rec->info[3]);
-        flushRecordKeys (*sysno, 1, &reckeys, rGroup->databaseName); 
-
-        records_updated++;
+        if (deleteFlag)
+        {
+            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++;
+        }
     }
     free (rec->info[0]);
     rec->info[0] = rec_strdup (file_type, &rec->size[0]);