+
+int fileExtract (SYSNO *sysno, const char *fname,
+ const struct recordGroup *rGroupP, int deleteFlag)
+{
+ int r, i, fd;
+ char gprefix[128];
+ char ext[128];
+ char ext_res[128];
+ char subType[128];
+ RecType recType;
+ struct recordGroup rGroupM;
+ struct recordGroup *rGroup = &rGroupM;
+ struct file_read_info *fi;
+
+ memcpy (rGroup, rGroupP, sizeof(*rGroupP));
+
+ 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 */
+ if (!rGroup->recordType)
+ {
+ sprintf (ext_res, "%srecordType.%s", gprefix, ext);
+ if (!(rGroup->recordType = res_get (common_resource, ext_res)))
+ {
+ sprintf (ext_res, "%srecordType", gprefix);
+ if (!(rGroup->recordType = res_get (common_resource, ext_res)))
+ {
+ if (rGroup->fileVerboseFlag)
+ logf (LOG_LOG, "? %s", fname);
+ return 0;
+ }
+ }
+ }
+ if (!rGroup->recordType)
+ {
+ if (rGroup->fileVerboseFlag)
+ logf (LOG_LOG, "? record %s", fname);
+ return 0;
+ }
+ if (!(recType = recType_byName (rGroup->recordType, subType)))
+ {
+ logf (LOG_WARN, "No such record type: %s", rGroup->recordType);
+ return 0;
+ }
+
+ /* determine match criteria */
+ if (!rGroup->recordId)
+ {
+ sprintf (ext_res, "%srecordId.%s", gprefix, ext);
+ rGroup->recordId = 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;
+
+ if (sysno && deleteFlag)
+ fd = -1;
+ else
+ {
+ if ((fd = open (fname, O_RDONLY)) == -1)
+ {
+ logf (LOG_WARN|LOG_ERRNO, "open %s", fname);
+ return 0;
+ }
+ }
+ fi = file_read_start (fd);
+ r = recordExtract (sysno, fname, rGroup, deleteFlag, fi, recType, subType);
+ log_event_start (NULL, NULL);
+ file_read_stop (fi);
+ if (fd != -1)
+ close (fd);
+ return r;
+}
+