2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.62 1996-10-11 10:57:01 adam
8 * New module recctrl. Used to manage records (extract/retrieval).
9 * Several files have been moved to the recctrl sub directory.
11 * Revision 1.61 1996/06/06 12:08:37 quinn
12 * Added showRecord function
14 * Revision 1.60 1996/06/04 10:18:12 adam
15 * Search/scan uses character mapping module.
17 * Revision 1.59 1996/05/14 15:47:07 adam
18 * Cleanup of various buffer size entities.
20 * Revision 1.58 1996/05/14 06:16:38 adam
21 * Compact use/set bytes used in search service.
23 * Revision 1.57 1996/05/13 14:23:04 adam
24 * Work on compaction of set/use bytes in dictionary.
26 * Revision 1.56 1996/05/09 09:54:42 adam
27 * Server supports maps from one logical attributes to a list of physical
29 * The extraction process doesn't make space consuming 'any' keys.
31 * Revision 1.55 1996/05/09 07:28:55 quinn
32 * Work towards phrases and multiple registers
34 * Revision 1.54 1996/05/01 13:46:35 adam
35 * First work on multiple records in one file.
36 * New option, -offset, to the "unread" command in the filter module.
38 * Revision 1.53 1996/04/26 12:09:43 adam
39 * Added a few comments.
41 * Revision 1.52 1996/04/25 13:27:57 adam
42 * Function recordExtract modified so that files with no keys (possibly empty)
45 * Revision 1.51 1996/03/19 11:08:42 adam
46 * Bug fix: Log preamble wasn't always turned off after recordExtract.
48 * Revision 1.50 1996/02/12 18:45:36 adam
49 * New fileVerboseFlag in record group control.
51 * Revision 1.49 1996/02/05 12:29:57 adam
52 * Logging reduced a bit.
53 * The remaining running time is estimated during register merge.
55 * Revision 1.48 1996/02/01 20:53:26 adam
56 * The temporary per-record keys are compacted a little, and duplication
57 * of the per-records keys are avoided when they are saved in the record
60 * Revision 1.47 1996/01/17 14:57:48 adam
61 * Prototype changed for reader functions in extract/retrieve. File
62 * is identified by 'void *' instead of 'int.
64 * Revision 1.46 1995/12/15 14:57:16 adam
67 * Revision 1.45 1995/12/15 12:37:41 adam
68 * In addRecordKeyAny: Writes key only when attrSet != -1.
70 * Revision 1.44 1995/12/12 16:00:54 adam
71 * System call sync(2) used after update/commit.
72 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
75 * Revision 1.43 1995/12/11 09:12:46 adam
76 * The rec_get function returns NULL if record doesn't exist - will
77 * happen in the server if the result set records have been deleted since
78 * the creation of the set (i.e. the search).
79 * The server saves a result temporarily if it is 'volatile', i.e. the
80 * set is register dependent.
82 * Revision 1.42 1995/12/07 17:38:46 adam
83 * Work locking mechanisms for concurrent updates/commit.
85 * Revision 1.41 1995/12/06 16:06:42 adam
86 * Better diagnostics. Work on 'real' dictionary deletion.
88 * Revision 1.40 1995/12/05 16:57:40 adam
89 * More work on regular patterns.
91 * Revision 1.39 1995/12/05 13:20:18 adam
92 * Bug fix: file_read sometimes returned early EOF.
94 * Revision 1.38 1995/12/04 17:59:21 adam
95 * More work on regular expression conversion.
97 * Revision 1.37 1995/12/04 14:22:27 adam
98 * Extra arg to recType_byName.
99 * Started work on new regular expression parsed input to
100 * structured records.
102 * Revision 1.36 1995/11/30 08:34:29 adam
103 * Started work on commit facility.
104 * Changed a few malloc/free to xmalloc/xfree.
106 * Revision 1.35 1995/11/28 14:26:21 adam
107 * Bug fix: recordId with constant wasn't right.
108 * Bug fix: recordId dictionary entry wasn't deleted when needed.
110 * Revision 1.34 1995/11/28 09:09:38 adam
111 * Zebra config renamed.
112 * Use setting 'recordId' to identify record now.
113 * Bug fix in recindex.c: rec_release_blocks was invokeded even
114 * though the blocks were already released.
115 * File traversal properly deletes records when needed.
117 * Revision 1.33 1995/11/27 09:56:20 adam
118 * Record info elements better enumerated. Internal store of records.
120 * Revision 1.32 1995/11/25 10:24:05 adam
121 * More record fields - they are enumerated now.
122 * New options: flagStoreData flagStoreKey.
124 * Revision 1.31 1995/11/24 11:31:35 adam
125 * Commands add & del read filenames from stdin if source directory is
127 * Match criteria supports 'constant' strings.
129 * Revision 1.30 1995/11/22 17:19:16 adam
130 * Record management uses the bfile system.
132 * Revision 1.29 1995/11/21 15:01:14 adam
133 * New general match criteria implemented.
134 * New feature: document groups.
136 * Revision 1.28 1995/11/21 09:20:30 adam
137 * Yet more work on record match.
139 * Revision 1.27 1995/11/20 16:59:45 adam
140 * New update method: the 'old' keys are saved for each records.
142 * Revision 1.26 1995/11/20 11:56:24 adam
143 * Work on new traversal.
145 * Revision 1.25 1995/11/16 15:34:54 adam
146 * Uses new record management system in both indexer and server.
148 * Revision 1.24 1995/11/15 19:13:08 adam
149 * Work on record management.
151 * Revision 1.23 1995/10/27 14:00:10 adam
152 * Implemented detection of database availability.
154 * Revision 1.22 1995/10/17 18:02:07 adam
155 * New feature: databases. Implemented as prefix to words in dictionary.
157 * Revision 1.21 1995/10/10 12:24:38 adam
158 * Temporary sort files are compressed.
160 * Revision 1.20 1995/10/06 13:52:05 adam
161 * Bug fixes. Handler may abort further scanning.
163 * Revision 1.19 1995/10/04 12:55:16 adam
164 * Bug fix in ranked search. Use=Any keys inserted.
166 * Revision 1.18 1995/10/04 09:37:08 quinn
169 * Revision 1.17 1995/10/03 14:28:57 adam
170 * Buffered read in extract works.
172 * Revision 1.16 1995/10/03 14:28:45 adam
173 * Work on more effecient read handler in extract.
175 * Revision 1.15 1995/10/02 15:42:53 adam
176 * Extract uses file descriptors instead of FILE pointers.
178 * Revision 1.14 1995/10/02 15:29:13 adam
179 * More logging in file_extract.
181 * Revision 1.13 1995/09/29 14:01:39 adam
184 * Revision 1.12 1995/09/28 14:22:56 adam
185 * Sort uses smaller temporary files.
187 * Revision 1.11 1995/09/28 12:10:31 adam
188 * Bug fixes. Field prefix used in queries.
190 * Revision 1.10 1995/09/28 09:19:41 adam
191 * xfree/xmalloc used everywhere.
192 * Extract/retrieve method seems to work for text records.
194 * Revision 1.9 1995/09/27 12:22:28 adam
195 * More work on extract in record control.
196 * Field name is not in isam keys but in prefix in dictionary words.
198 * Revision 1.8 1995/09/14 07:48:22 adam
199 * Record control management.
201 * Revision 1.7 1995/09/11 13:09:32 adam
202 * More work on relevance feedback.
204 * Revision 1.6 1995/09/08 14:52:27 adam
205 * Minor changes. Dictionary is lower case now.
207 * Revision 1.5 1995/09/06 16:11:16 adam
208 * Option: only one word key per file.
210 * Revision 1.4 1995/09/05 15:28:39 adam
211 * More work on search engine.
213 * Revision 1.3 1995/09/04 12:33:41 adam
214 * Various cleanup. YAZ util used instead.
216 * Revision 1.2 1995/09/04 09:10:34 adam
217 * More work on index add/del/update.
218 * Merge sort implemented.
219 * Initial work on z39 server.
221 * Revision 1.1 1995/09/01 14:06:35 adam
222 * Split of work into more files.
230 #include <alexutil.h>
236 static Dict matchDict;
238 static Records records = NULL;
240 static char **key_buf;
241 static size_t ptr_top;
243 static size_t key_buf_used;
244 static int key_file_no;
246 static int records_inserted = 0;
247 static int records_updated = 0;
248 static int records_deleted = 0;
249 static int records_processed = 0;
251 static ZebTargetInfo *zti = NULL;
253 static void logRecord (int showFlag)
257 if (showFlag || !(records_processed % 1000))
259 logf (LOG_LOG, "Records: %7d i/u/d %d/%d/%d",
260 records_processed, records_inserted, records_updated,
265 void key_open (int mem)
269 key_buf = xmalloc (mem);
270 ptr_top = mem/sizeof(char*);
276 if (!(matchDict = dict_open (GMATCH_DICT, 50, 1)))
278 logf (LOG_FATAL, "dict_open fail of %s", GMATCH_DICT);
282 records = rec_open (1);
284 zti = zebTargetInfo_open (records, 1);
294 void encode_key_init (struct encode_info *i)
300 char *encode_key_int (int d, char *bp)
309 else if (d <= 4194303)
311 *bp++ = 128 + (d>>16);
312 *bp++ = (d>>8) & 255;
317 *bp++ = 192 + (d>>24);
318 *bp++ = (d>>16) & 255;
319 *bp++ = (d>>8) & 255;
325 void encode_key_write (char *k, struct encode_info *i, FILE *outf)
330 while ((*bp++ = *k++))
332 memcpy (&key, k+1, sizeof(struct it_key));
333 bp = encode_key_int ( (key.sysno - i->sysno) * 2 + *k, bp);
334 if (i->sysno != key.sysno)
336 i->sysno = key.sysno;
339 bp = encode_key_int (key.seqno - i->seqno, bp);
340 i->seqno = key.seqno;
341 if (fwrite (i->buf, bp - i->buf, 1, outf) != 1)
343 logf (LOG_FATAL|LOG_ERRNO, "fwrite");
348 void key_flush (void)
353 struct encode_info encode_info;
359 logf (LOG_LOG, "sorting section %d", key_file_no);
360 qsort (key_buf + ptr_top-ptr_i, ptr_i, sizeof(char*), key_qsort_compare);
361 sprintf (out_fname, TEMP_FNAME, key_file_no);
363 if (!(outf = fopen (out_fname, "w")))
365 logf (LOG_FATAL|LOG_ERRNO, "fopen (4) %s", out_fname);
368 logf (LOG_LOG, "writing section %d", key_file_no);
369 prevcp = cp = key_buf[ptr_top-ptr_i];
371 encode_key_init (&encode_info);
372 encode_key_write (cp, &encode_info, outf);
375 cp = key_buf[ptr_top-ptr_i];
376 if (strcmp (cp, prevcp))
378 encode_key_init (&encode_info);
379 encode_key_write (cp, &encode_info, outf);
383 encode_key_write (cp + strlen(cp), &encode_info, outf);
387 logf (LOG_FATAL|LOG_ERRNO, "fclose %s", out_fname);
390 logf (LOG_LOG, "finished section %d", key_file_no);
400 zebTargetInfo_close (zti, 1);
402 rec_close (&records);
403 dict_close (matchDict);
409 static void wordInit (RecWord *p)
413 p->which = Word_String;
424 static void addRecordKey (const RecWord *p)
432 if (reckeys.buf_used+1024 > reckeys.buf_max)
436 b = xmalloc (reckeys.buf_max += 128000);
437 if (reckeys.buf_used > 0)
438 memcpy (b, reckeys.buf, reckeys.buf_used);
442 dst = reckeys.buf + reckeys.buf_used;
444 attrSet = p->attrSet;
445 if (reckeys.buf_used > 0 && reckeys.prevAttrSet == attrSet)
448 reckeys.prevAttrSet = attrSet;
449 attrUse = p->attrUse;
450 if (reckeys.buf_used > 0 && reckeys.prevAttrUse == attrUse)
453 reckeys.prevAttrUse = attrUse;
459 memcpy (dst, &attrSet, sizeof(attrSet));
460 dst += sizeof(attrSet);
464 memcpy (dst, &attrUse, sizeof(attrUse));
465 dst += sizeof(attrUse);
478 for (i = 0; p->u.string[i]; i++)
479 *dst++ = p->u.string[i];
482 memcpy (dst, &p->seqno, sizeof(p->seqno));
483 dst += sizeof(p->seqno);
484 reckeys.buf_used = dst - reckeys.buf;
487 static void flushRecordKeys (SYSNO sysno, int cmd, struct recKeys *reckeys,
488 const char *databaseName)
494 if (zebTargetInfo_curDatabase (zti, databaseName))
496 if (zebTargetInfo_newDatabase (zti, databaseName))
499 while (off < reckeys->buf_used)
501 const char *src = reckeys->buf + off;
509 memcpy (&attrSet, src, sizeof(attrSet));
510 src += sizeof(attrSet);
514 memcpy (&attrUse, src, sizeof(attrUse));
515 src += sizeof(attrUse);
517 if (key_buf_used + 1024 > (ptr_top-ptr_i)*sizeof(char*))
520 key_buf[ptr_top-ptr_i] = (char*)key_buf + key_buf_used;
522 lead = zebTargetInfo_lookupSU (zti, attrSet, attrUse);
524 lead = zebTargetInfo_addSU (zti, attrSet, attrUse);
526 ((char*) key_buf) [key_buf_used++] = lead;
528 ((char*)key_buf) [key_buf_used++] = *src++;
530 ((char*)key_buf) [key_buf_used++] = '\0';
532 ((char*) key_buf)[key_buf_used++] = cmd;
534 memcpy (&key.seqno, src, sizeof(key.seqno));
535 src += sizeof(key.seqno);
537 memcpy ((char*)key_buf + key_buf_used, &key, sizeof(key));
538 key_buf_used += sizeof(key);
539 off = src - reckeys->buf;
541 assert (off == reckeys->buf_used);
544 static const char **searchRecordKey (struct recKeys *reckeys,
545 int attrSetS, int attrUseS)
547 static const char *ws[32];
552 for (i = 0; i<32; i++)
555 while (off < reckeys->buf_used)
557 const char *src = reckeys->buf + off;
563 memcpy (&attrSet, src, sizeof(attrSet));
564 src += sizeof(attrSet);
566 memcpy (&attrUse, src, sizeof(attrUse));
567 src += sizeof(attrUse);
573 memcpy (&seqno, src, sizeof(seqno));
574 src += sizeof(seqno);
577 logf (LOG_LOG, "(%d,%d) %d %s", attrSet, attrUse, seqno, wstart);
579 if (attrUseS == attrUse && attrSetS == attrSet)
586 woff = seqno - startSeq;
587 if (woff >= 0 && woff < 31)
591 off = src - reckeys->buf;
593 assert (off == reckeys->buf_used);
597 struct file_read_info {
605 static struct file_read_info *file_read_start (int fd)
607 struct file_read_info *fi = xmalloc (sizeof(*fi));
611 fi->file_moffset = 0;
615 static void file_read_stop (struct file_read_info *fi)
621 static off_t file_seek (void *handle, off_t offset)
623 struct file_read_info *p = handle;
624 p->file_offset = offset;
625 return lseek (p->fd, offset, SEEK_SET);
628 static int file_read (void *handle, char *buf, size_t count)
630 struct file_read_info *p = handle;
633 r = read (fd, buf, count);
637 if (p->file_offset > p->file_max)
638 p->file_max = p->file_offset;
643 static void file_begin (void *handle)
645 struct file_read_info *p = handle;
647 p->file_offset = p->file_moffset;
649 lseek (p->fd, p->file_moffset, SEEK_SET);
653 static void file_end (void *handle, off_t offset)
655 struct file_read_info *p = handle;
657 assert (p->file_more == 0);
659 p->file_moffset = offset;
662 static int atois (const char **s)
665 while ( (c=**s) >= '0' && c <= '9')
667 val = val*10 + c - '0';
673 static char *fileMatchStr (struct recKeys *reckeys, struct recordGroup *rGroup,
677 static char dstBuf[2048];
679 const char *s = spec;
680 static const char **w;
685 while (*s == ' ' || *s == '\t')
692 int attrSet, attrUse;
696 attrSet = atois (&s);
699 logf (LOG_WARN, "Missing , in match criteria %s in group %s",
700 spec, rGroup->groupName ? rGroup->groupName : "none");
704 attrUse = atois (&s);
705 w = searchRecordKey (reckeys, attrSet, attrUse);
710 for (i = 0; i<32; i++)
715 logf (LOG_WARN, "Missing ) in match criteria %s in group %s",
716 spec, rGroup->groupName ? rGroup->groupName : "none");
721 for (i = 0; i<32; i++)
722 if (matchFlag[i] && w[i])
734 logf (LOG_WARN, "Record didn't contain match"
735 " fields in (%d,%d)", attrSet, attrUse);
743 const char *spec_src = NULL;
744 const char *s1 = ++s;
745 while (*s1 && *s1 != ' ' && *s1 != '\t')
751 memcpy (special, s, spec_len);
752 special[spec_len] = '\0';
755 if (!strcmp (special, "group"))
756 spec_src = rGroup->groupName;
757 else if (!strcmp (special, "database"))
758 spec_src = rGroup->databaseName;
759 else if (!strcmp (special, "filename"))
761 else if (!strcmp (special, "type"))
762 spec_src = rGroup->recordType;
767 strcpy (dst, spec_src);
768 dst += strlen (spec_src);
771 else if (*s == '\"' || *s == '\'')
773 int stopMarker = *s++;
777 while (*s && *s != stopMarker)
780 tmpString[i++] = *s++;
785 strcpy (dst, tmpString);
786 dst += strlen (tmpString);
790 logf (LOG_WARN, "Syntax error in match criteria %s in group %s",
791 spec, rGroup->groupName ? rGroup->groupName : "none");
798 logf (LOG_WARN, "No match criteria for record %s in group %s",
799 fname, rGroup->groupName ? rGroup->groupName : "none");
805 struct recordLogInfo {
808 struct recordGroup *rGroup;
811 static void recordLogPreamble (int level, const char *msg, void *info)
813 struct recordLogInfo *p = info;
814 FILE *outf = log_file ();
819 fprintf (outf, "%s of ", p->op);
820 fprintf (outf, "%s type %s\n", p->rGroup->recordType, p->fname);
821 log_event_start (NULL, NULL);
824 static int recordExtract (SYSNO *sysno, const char *fname,
825 struct recordGroup *rGroup, int deleteFlag,
826 struct file_read_info *fi, RecType recType,
829 struct recExtractCtrl extractCtrl;
833 off_t recordOffset = 0;
835 struct recordLogInfo logInfo;
837 logInfo.fname = fname;
839 logInfo.rGroup = rGroup;
840 log_event_start (recordLogPreamble, &logInfo);
844 /* we are going to read from a file, so prepare the extraction */
846 extractCtrl.subType = subType;
847 extractCtrl.init = wordInit;
848 extractCtrl.add = addRecordKey;
850 reckeys.buf_used = 0;
851 reckeys.prevAttrUse = -1;
852 reckeys.prevAttrSet = -1;
854 recordOffset = fi->file_moffset;
855 extractCtrl.offset = recordOffset;
856 extractCtrl.readf = file_read;
857 extractCtrl.seekf = file_seek;
858 extractCtrl.endf = file_end;
859 extractCtrl.map_chrs_input = map_chrs_input;
860 extractCtrl.flagShowRecords = rGroup->flagShowRecords;
861 r = (*recType->extract)(&extractCtrl);
865 /* error occured during extraction ... */
866 logf (LOG_WARN, "Couldn't extract file %s, code %d", fname, r);
869 if (reckeys.buf_used == 0)
871 /* the extraction process returned no information - the record
873 logf (LOG_WARN, "Empty file %s", fname);
878 /* perform match if sysno not known and if match criteria is specified */
885 if (rGroup->recordId && *rGroup->recordId)
889 matchStr = fileMatchStr (&reckeys, rGroup, fname,
893 rinfo = dict_lookup (matchDict, matchStr);
895 memcpy (sysno, rinfo+1, sizeof(*sysno));
899 logf (LOG_WARN, "Bad match criteria");
910 logf (LOG_LOG, "Cannot delete new record");
914 if (rGroup->fileVerboseFlag)
915 logf (LOG_LOG, "add %s %s+%ld", rGroup->recordType,
916 fname, (long) recordOffset);
917 rec = rec_new (records);
922 dict_insert (matchDict, matchStr, sizeof(*sysno), sysno);
924 flushRecordKeys (*sysno, 1, &reckeys, rGroup->databaseName);
930 /* record already exists */
931 struct recKeys delkeys;
933 rec = rec_get (records, *sysno);
935 delkeys.buf_used = rec->size[recInfo_delKeys];
936 delkeys.buf = rec->info[recInfo_delKeys];
937 flushRecordKeys (*sysno, 0, &delkeys, rec->info[recInfo_databaseName]);
940 /* record going to be deleted */
941 logInfo.op = "delete";
942 if (!delkeys.buf_used)
944 logf (LOG_WARN, "cannot delete; storeKeys false");
948 if (rGroup->fileVerboseFlag)
949 logf (LOG_LOG, "delete %s %s %ld", rGroup->recordType,
950 fname, (long) recordOffset);
953 dict_delete (matchDict, matchStr);
954 rec_del (records, &rec);
961 /* record going to be updated */
962 logInfo.op = "update";
963 if (!delkeys.buf_used)
965 logf (LOG_WARN, "cannot update; storeKeys false");
969 if (rGroup->fileVerboseFlag)
970 logf (LOG_LOG, "update %s %s %ld", rGroup->recordType,
971 fname, (long) recordOffset);
972 flushRecordKeys (*sysno, 1, &reckeys, rGroup->databaseName);
977 /* update file type */
978 xfree (rec->info[recInfo_fileType]);
979 rec->info[recInfo_fileType] =
980 rec_strdup (rGroup->recordType, &rec->size[recInfo_fileType]);
982 /* update filename */
983 xfree (rec->info[recInfo_filename]);
984 rec->info[recInfo_filename] =
985 rec_strdup (fname, &rec->size[recInfo_filename]);
987 /* update delete keys */
988 xfree (rec->info[recInfo_delKeys]);
989 if (reckeys.buf_used > 0 && rGroup->flagStoreKeys == 1)
992 rec->size[recInfo_delKeys] = reckeys.buf_used;
993 rec->info[recInfo_delKeys] = reckeys.buf;
997 rec->info[recInfo_delKeys] = xmalloc (reckeys.buf_used);
998 rec->size[recInfo_delKeys] = reckeys.buf_used;
999 memcpy (rec->info[recInfo_delKeys], reckeys.buf,
1000 rec->size[recInfo_delKeys]);
1005 rec->info[recInfo_delKeys] = NULL;
1006 rec->size[recInfo_delKeys] = 0;
1009 /* update store data */
1010 xfree (rec->info[recInfo_storeData]);
1011 if (rGroup->flagStoreData == 1)
1013 rec->size[recInfo_storeData] = fi->file_max;
1014 rec->info[recInfo_storeData] = xmalloc (fi->file_max);
1015 if (lseek (fi->fd, recordOffset, SEEK_SET) < 0)
1017 logf (LOG_ERRNO|LOG_FATAL, "seek to %ld in %s", fname,
1018 (long) recordOffset);
1021 if (read (fi->fd, rec->info[recInfo_storeData], fi->file_max)
1024 logf (LOG_ERRNO|LOG_FATAL, "read %d bytes of %s",
1025 fi->file_max, fname);
1031 rec->info[recInfo_storeData] = NULL;
1032 rec->size[recInfo_storeData] = 0;
1034 /* update database name */
1035 xfree (rec->info[recInfo_databaseName]);
1036 rec->info[recInfo_databaseName] =
1037 rec_strdup (rGroup->databaseName, &rec->size[recInfo_databaseName]);
1040 xfree (rec->info[recInfo_offset]);
1042 rec->size[recInfo_offset] = sizeof(recordOffset);
1043 rec->info[recInfo_offset] = xmalloc (sizeof(recordOffset));
1044 memcpy (rec->info[recInfo_offset], &recordOffset, sizeof(recordOffset));
1046 /* commit this record */
1047 rec_put (records, &rec);
1052 int fileExtract (SYSNO *sysno, const char *fname,
1053 const struct recordGroup *rGroupP, int deleteFlag)
1061 struct recordGroup rGroupM;
1062 struct recordGroup *rGroup = &rGroupM;
1063 struct file_read_info *fi;
1065 memcpy (rGroup, rGroupP, sizeof(*rGroupP));
1067 if (!rGroup->groupName || !*rGroup->groupName)
1070 sprintf (gprefix, "%s.", rGroup->groupName);
1072 logf (LOG_DEBUG, "fileExtract %s", fname);
1074 /* determine file extension */
1075 for (i = strlen(fname); --i >= 0; )
1076 if (fname[i] == '/')
1081 else if (fname[i] == '.')
1083 strcpy (ext, fname+i+1);
1086 /* determine file type - depending on extension */
1087 if (!rGroup->recordType)
1089 sprintf (ext_res, "%srecordType.%s", gprefix, ext);
1090 if (!(rGroup->recordType = res_get (common_resource, ext_res)))
1092 sprintf (ext_res, "%srecordType", gprefix);
1093 if (!(rGroup->recordType = res_get (common_resource, ext_res)))
1095 if (rGroup->fileVerboseFlag)
1096 logf (LOG_LOG, "? %s", fname);
1101 if (!rGroup->recordType)
1103 if (rGroup->fileVerboseFlag)
1104 logf (LOG_LOG, "? record %s", fname);
1107 if (!(recType = recType_byName (rGroup->recordType, subType)))
1109 logf (LOG_WARN, "No such record type: %s", rGroup->recordType);
1113 /* determine match criteria */
1114 if (!rGroup->recordId)
1116 sprintf (ext_res, "%srecordId.%s", gprefix, ext);
1117 rGroup->recordId = res_get (common_resource, ext_res);
1120 /* determine database name */
1121 if (!rGroup->databaseName)
1123 sprintf (ext_res, "%sdatabase.%s", gprefix, ext);
1124 if (!(rGroup->databaseName = res_get (common_resource, ext_res)))
1126 sprintf (ext_res, "%sdatabase", gprefix);
1127 rGroup->databaseName = res_get (common_resource, ext_res);
1130 if (!rGroup->databaseName)
1131 rGroup->databaseName = "Default";
1133 if (rGroup->flagStoreData == -1)
1136 sprintf (ext_res, "%sstoreData.%s", gprefix, ext);
1137 if (!(sval = res_get (common_resource, ext_res)))
1139 sprintf (ext_res, "%sstoreData", gprefix);
1140 sval = res_get (common_resource, ext_res);
1143 rGroup->flagStoreData = atoi (sval);
1145 if (rGroup->flagStoreData == -1)
1146 rGroup->flagStoreData = 0;
1148 if (rGroup->flagStoreKeys == -1)
1152 sprintf (ext_res, "%sstoreKeys.%s", gprefix, ext);
1153 if (!(sval = res_get (common_resource, ext_res)))
1155 sprintf (ext_res, "%sstoreKeys", gprefix);
1156 sval = res_get (common_resource, ext_res);
1159 rGroup->flagStoreKeys = atoi (sval);
1161 if (rGroup->flagStoreKeys == -1)
1162 rGroup->flagStoreKeys = 0;
1164 if (sysno && deleteFlag)
1168 if ((fd = open (fname, O_RDONLY)) == -1)
1170 logf (LOG_WARN|LOG_ERRNO, "open %s", fname);
1174 fi = file_read_start (fd);
1178 r = recordExtract (sysno, fname, rGroup, deleteFlag, fi,
1180 } while (r && !sysno && fi->file_more);
1181 log_event_start (NULL, NULL);
1182 file_read_stop (fi);