2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.64 1996-11-08 11:10:16 adam
8 * Buffers used during file match got bigger.
9 * Compressed ISAM support everywhere.
10 * Bug fixes regarding masking characters in queries.
11 * Redesigned Regexp-2 queries.
13 * Revision 1.63 1996/10/29 14:09:39 adam
14 * Use of cisam system - enabled if setting isamc is 1.
16 * Revision 1.62 1996/10/11 10:57:01 adam
17 * New module recctrl. Used to manage records (extract/retrieval).
18 * Several files have been moved to the recctrl sub directory.
20 * Revision 1.61 1996/06/06 12:08:37 quinn
21 * Added showRecord function
23 * Revision 1.60 1996/06/04 10:18:12 adam
24 * Search/scan uses character mapping module.
26 * Revision 1.59 1996/05/14 15:47:07 adam
27 * Cleanup of various buffer size entities.
29 * Revision 1.58 1996/05/14 06:16:38 adam
30 * Compact use/set bytes used in search service.
32 * Revision 1.57 1996/05/13 14:23:04 adam
33 * Work on compaction of set/use bytes in dictionary.
35 * Revision 1.56 1996/05/09 09:54:42 adam
36 * Server supports maps from one logical attributes to a list of physical
38 * The extraction process doesn't make space consuming 'any' keys.
40 * Revision 1.55 1996/05/09 07:28:55 quinn
41 * Work towards phrases and multiple registers
43 * Revision 1.54 1996/05/01 13:46:35 adam
44 * First work on multiple records in one file.
45 * New option, -offset, to the "unread" command in the filter module.
47 * Revision 1.53 1996/04/26 12:09:43 adam
48 * Added a few comments.
50 * Revision 1.52 1996/04/25 13:27:57 adam
51 * Function recordExtract modified so that files with no keys (possibly empty)
54 * Revision 1.51 1996/03/19 11:08:42 adam
55 * Bug fix: Log preamble wasn't always turned off after recordExtract.
57 * Revision 1.50 1996/02/12 18:45:36 adam
58 * New fileVerboseFlag in record group control.
60 * Revision 1.49 1996/02/05 12:29:57 adam
61 * Logging reduced a bit.
62 * The remaining running time is estimated during register merge.
64 * Revision 1.48 1996/02/01 20:53:26 adam
65 * The temporary per-record keys are compacted a little, and duplication
66 * of the per-records keys are avoided when they are saved in the record
69 * Revision 1.47 1996/01/17 14:57:48 adam
70 * Prototype changed for reader functions in extract/retrieve. File
71 * is identified by 'void *' instead of 'int.
73 * Revision 1.46 1995/12/15 14:57:16 adam
76 * Revision 1.45 1995/12/15 12:37:41 adam
77 * In addRecordKeyAny: Writes key only when attrSet != -1.
79 * Revision 1.44 1995/12/12 16:00:54 adam
80 * System call sync(2) used after update/commit.
81 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
84 * Revision 1.43 1995/12/11 09:12:46 adam
85 * The rec_get function returns NULL if record doesn't exist - will
86 * happen in the server if the result set records have been deleted since
87 * the creation of the set (i.e. the search).
88 * The server saves a result temporarily if it is 'volatile', i.e. the
89 * set is register dependent.
91 * Revision 1.42 1995/12/07 17:38:46 adam
92 * Work locking mechanisms for concurrent updates/commit.
94 * Revision 1.41 1995/12/06 16:06:42 adam
95 * Better diagnostics. Work on 'real' dictionary deletion.
97 * Revision 1.40 1995/12/05 16:57:40 adam
98 * More work on regular patterns.
100 * Revision 1.39 1995/12/05 13:20:18 adam
101 * Bug fix: file_read sometimes returned early EOF.
103 * Revision 1.38 1995/12/04 17:59:21 adam
104 * More work on regular expression conversion.
106 * Revision 1.37 1995/12/04 14:22:27 adam
107 * Extra arg to recType_byName.
108 * Started work on new regular expression parsed input to
109 * structured records.
111 * Revision 1.36 1995/11/30 08:34:29 adam
112 * Started work on commit facility.
113 * Changed a few malloc/free to xmalloc/xfree.
115 * Revision 1.35 1995/11/28 14:26:21 adam
116 * Bug fix: recordId with constant wasn't right.
117 * Bug fix: recordId dictionary entry wasn't deleted when needed.
119 * Revision 1.34 1995/11/28 09:09:38 adam
120 * Zebra config renamed.
121 * Use setting 'recordId' to identify record now.
122 * Bug fix in recindex.c: rec_release_blocks was invokeded even
123 * though the blocks were already released.
124 * File traversal properly deletes records when needed.
126 * Revision 1.33 1995/11/27 09:56:20 adam
127 * Record info elements better enumerated. Internal store of records.
129 * Revision 1.32 1995/11/25 10:24:05 adam
130 * More record fields - they are enumerated now.
131 * New options: flagStoreData flagStoreKey.
133 * Revision 1.31 1995/11/24 11:31:35 adam
134 * Commands add & del read filenames from stdin if source directory is
136 * Match criteria supports 'constant' strings.
138 * Revision 1.30 1995/11/22 17:19:16 adam
139 * Record management uses the bfile system.
141 * Revision 1.29 1995/11/21 15:01:14 adam
142 * New general match criteria implemented.
143 * New feature: document groups.
145 * Revision 1.28 1995/11/21 09:20:30 adam
146 * Yet more work on record match.
148 * Revision 1.27 1995/11/20 16:59:45 adam
149 * New update method: the 'old' keys are saved for each records.
151 * Revision 1.26 1995/11/20 11:56:24 adam
152 * Work on new traversal.
154 * Revision 1.25 1995/11/16 15:34:54 adam
155 * Uses new record management system in both indexer and server.
157 * Revision 1.24 1995/11/15 19:13:08 adam
158 * Work on record management.
160 * Revision 1.23 1995/10/27 14:00:10 adam
161 * Implemented detection of database availability.
163 * Revision 1.22 1995/10/17 18:02:07 adam
164 * New feature: databases. Implemented as prefix to words in dictionary.
166 * Revision 1.21 1995/10/10 12:24:38 adam
167 * Temporary sort files are compressed.
169 * Revision 1.20 1995/10/06 13:52:05 adam
170 * Bug fixes. Handler may abort further scanning.
172 * Revision 1.19 1995/10/04 12:55:16 adam
173 * Bug fix in ranked search. Use=Any keys inserted.
175 * Revision 1.18 1995/10/04 09:37:08 quinn
178 * Revision 1.17 1995/10/03 14:28:57 adam
179 * Buffered read in extract works.
181 * Revision 1.16 1995/10/03 14:28:45 adam
182 * Work on more effecient read handler in extract.
184 * Revision 1.15 1995/10/02 15:42:53 adam
185 * Extract uses file descriptors instead of FILE pointers.
187 * Revision 1.14 1995/10/02 15:29:13 adam
188 * More logging in file_extract.
190 * Revision 1.13 1995/09/29 14:01:39 adam
193 * Revision 1.12 1995/09/28 14:22:56 adam
194 * Sort uses smaller temporary files.
196 * Revision 1.11 1995/09/28 12:10:31 adam
197 * Bug fixes. Field prefix used in queries.
199 * Revision 1.10 1995/09/28 09:19:41 adam
200 * xfree/xmalloc used everywhere.
201 * Extract/retrieve method seems to work for text records.
203 * Revision 1.9 1995/09/27 12:22:28 adam
204 * More work on extract in record control.
205 * Field name is not in isam keys but in prefix in dictionary words.
207 * Revision 1.8 1995/09/14 07:48:22 adam
208 * Record control management.
210 * Revision 1.7 1995/09/11 13:09:32 adam
211 * More work on relevance feedback.
213 * Revision 1.6 1995/09/08 14:52:27 adam
214 * Minor changes. Dictionary is lower case now.
216 * Revision 1.5 1995/09/06 16:11:16 adam
217 * Option: only one word key per file.
219 * Revision 1.4 1995/09/05 15:28:39 adam
220 * More work on search engine.
222 * Revision 1.3 1995/09/04 12:33:41 adam
223 * Various cleanup. YAZ util used instead.
225 * Revision 1.2 1995/09/04 09:10:34 adam
226 * More work on index add/del/update.
227 * Merge sort implemented.
228 * Initial work on z39 server.
230 * Revision 1.1 1995/09/01 14:06:35 adam
231 * Split of work into more files.
244 static Dict matchDict;
246 static Records records = NULL;
248 static char **key_buf;
249 static size_t ptr_top;
251 static size_t key_buf_used;
252 static int key_file_no;
254 static int records_inserted = 0;
255 static int records_updated = 0;
256 static int records_deleted = 0;
257 static int records_processed = 0;
259 static ZebTargetInfo *zti = NULL;
261 static void logRecord (int showFlag)
265 if (showFlag || !(records_processed % 1000))
267 logf (LOG_LOG, "Records: %7d i/u/d %d/%d/%d",
268 records_processed, records_inserted, records_updated,
273 void key_open (int mem)
276 mem = atoi(res_get_def (common_resource, "memMax", "4"))*1024*1024;
279 key_buf = xmalloc (mem);
280 ptr_top = mem/sizeof(char*);
286 if (!(matchDict = dict_open (GMATCH_DICT, 50, 1)))
288 logf (LOG_FATAL, "dict_open fail of %s", GMATCH_DICT);
292 records = rec_open (1);
294 zti = zebTargetInfo_open (records, 1);
304 void encode_key_init (struct encode_info *i)
310 char *encode_key_int (int d, char *bp)
319 else if (d <= 4194303)
321 *bp++ = 128 + (d>>16);
322 *bp++ = (d>>8) & 255;
327 *bp++ = 192 + (d>>24);
328 *bp++ = (d>>16) & 255;
329 *bp++ = (d>>8) & 255;
335 void encode_key_write (char *k, struct encode_info *i, FILE *outf)
340 while ((*bp++ = *k++))
342 memcpy (&key, k+1, sizeof(struct it_key));
343 bp = encode_key_int ( (key.sysno - i->sysno) * 2 + *k, bp);
344 if (i->sysno != key.sysno)
346 i->sysno = key.sysno;
349 bp = encode_key_int (key.seqno - i->seqno, bp);
350 i->seqno = key.seqno;
351 if (fwrite (i->buf, bp - i->buf, 1, outf) != 1)
353 logf (LOG_FATAL|LOG_ERRNO, "fwrite");
358 static int key_y_len;
360 static int key_y_compare (const void *p1, const void *p2)
364 if ((r = key_compare (*(char**) p1 + key_y_len + 1,
365 *(char**) p2 + key_y_len + 1)))
367 return *(*(char**) p1 + key_y_len) - *(*(char**) p2 + key_y_len);
370 static int key_x_compare (const void *p1, const void *p2)
372 return strcmp (*(char**) p1, *(char**) p2);
375 void key_flush (void)
380 struct encode_info encode_info;
387 logf (LOG_LOG, "sorting section %d", key_file_no);
389 qsort (key_buf + ptr_top-ptr_i, ptr_i, sizeof(char*), key_qsort_compare);
390 getFnameTmp (out_fname, key_file_no);
392 if (!(outf = fopen (out_fname, "w")))
394 logf (LOG_FATAL|LOG_ERRNO, "fopen (4) %s", out_fname);
397 logf (LOG_LOG, "writing section %d", key_file_no);
398 prevcp = cp = key_buf[ptr_top-ptr_i];
400 encode_key_init (&encode_info);
401 encode_key_write (cp, &encode_info, outf);
404 cp = key_buf[ptr_top-ptr_i];
405 if (strcmp (cp, prevcp))
407 encode_key_init (&encode_info);
408 encode_key_write (cp, &encode_info, outf);
412 encode_key_write (cp + strlen(cp), &encode_info, outf);
415 qsort (key_buf + ptr_top-ptr_i, ptr_i, sizeof(char*), key_x_compare);
416 getFnameTmp (out_fname, key_file_no);
418 if (!(outf = fopen (out_fname, "w")))
420 logf (LOG_FATAL|LOG_ERRNO, "fopen (4) %s", out_fname);
423 logf (LOG_LOG, "writing section %d", key_file_no);
425 prevcp = key_buf[ptr_top-i];
427 if (!--i || strcmp (prevcp, key_buf[ptr_top-i]))
429 key_y_len = strlen(prevcp)+1;
431 logf (LOG_LOG, "key_y_len: %2d %02x %02x %s",
432 key_y_len, prevcp[0], prevcp[1], 2+prevcp);
434 qsort (key_buf + ptr_top-ptr_i, ptr_i - i,
435 sizeof(char*), key_y_compare);
436 cp = key_buf[ptr_top-ptr_i];
438 encode_key_init (&encode_info);
439 encode_key_write (cp, &encode_info, outf);
442 cp = key_buf[ptr_top-ptr_i];
443 encode_key_write (cp+key_y_len, &encode_info, outf);
447 prevcp = key_buf[ptr_top-ptr_i];
452 logf (LOG_FATAL|LOG_ERRNO, "fclose %s", out_fname);
455 logf (LOG_LOG, "finished section %d", key_file_no);
465 zebTargetInfo_close (zti, 1);
467 rec_close (&records);
468 dict_close (matchDict);
474 static void wordInit (RecWord *p)
478 p->which = Word_String;
489 static void addRecordKey (const RecWord *p)
497 if (reckeys.buf_used+1024 > reckeys.buf_max)
501 b = xmalloc (reckeys.buf_max += 128000);
502 if (reckeys.buf_used > 0)
503 memcpy (b, reckeys.buf, reckeys.buf_used);
507 dst = reckeys.buf + reckeys.buf_used;
509 attrSet = p->attrSet;
510 if (reckeys.buf_used > 0 && reckeys.prevAttrSet == attrSet)
513 reckeys.prevAttrSet = attrSet;
514 attrUse = p->attrUse;
515 if (reckeys.buf_used > 0 && reckeys.prevAttrUse == attrUse)
518 reckeys.prevAttrUse = attrUse;
524 memcpy (dst, &attrSet, sizeof(attrSet));
525 dst += sizeof(attrSet);
529 memcpy (dst, &attrUse, sizeof(attrUse));
530 dst += sizeof(attrUse);
543 for (i = 0; p->u.string[i]; i++)
544 *dst++ = p->u.string[i];
547 memcpy (dst, &p->seqno, sizeof(p->seqno));
548 dst += sizeof(p->seqno);
549 reckeys.buf_used = dst - reckeys.buf;
552 static void flushRecordKeys (SYSNO sysno, int cmd, struct recKeys *reckeys,
553 const char *databaseName)
559 if (zebTargetInfo_curDatabase (zti, databaseName))
561 if (zebTargetInfo_newDatabase (zti, databaseName))
564 while (off < reckeys->buf_used)
566 const char *src = reckeys->buf + off;
574 memcpy (&attrSet, src, sizeof(attrSet));
575 src += sizeof(attrSet);
579 memcpy (&attrUse, src, sizeof(attrUse));
580 src += sizeof(attrUse);
582 if (key_buf_used + 1024 > (ptr_top-ptr_i)*sizeof(char*))
585 key_buf[ptr_top-ptr_i] = (char*)key_buf + key_buf_used;
587 lead = zebTargetInfo_lookupSU (zti, attrSet, attrUse);
589 lead = zebTargetInfo_addSU (zti, attrSet, attrUse);
591 ((char*) key_buf) [key_buf_used++] = lead;
593 ((char*)key_buf) [key_buf_used++] = *src++;
595 ((char*)key_buf) [key_buf_used++] = '\0';
597 ((char*) key_buf)[key_buf_used++] = cmd;
599 memcpy (&key.seqno, src, sizeof(key.seqno));
600 src += sizeof(key.seqno);
602 memcpy ((char*)key_buf + key_buf_used, &key, sizeof(key));
603 key_buf_used += sizeof(key);
604 off = src - reckeys->buf;
606 assert (off == reckeys->buf_used);
609 static const char **searchRecordKey (struct recKeys *reckeys,
610 int attrSetS, int attrUseS)
612 static const char *ws[32];
617 for (i = 0; i<32; i++)
620 while (off < reckeys->buf_used)
622 const char *src = reckeys->buf + off;
628 memcpy (&attrSet, src, sizeof(attrSet));
629 src += sizeof(attrSet);
631 memcpy (&attrUse, src, sizeof(attrUse));
632 src += sizeof(attrUse);
638 memcpy (&seqno, src, sizeof(seqno));
639 src += sizeof(seqno);
642 logf (LOG_LOG, "(%d,%d) %d %s", attrSet, attrUse, seqno, wstart);
644 if (attrUseS == attrUse && attrSetS == attrSet)
651 woff = seqno - startSeq;
652 if (woff >= 0 && woff < 31)
656 off = src - reckeys->buf;
658 assert (off == reckeys->buf_used);
662 struct file_read_info {
670 static struct file_read_info *file_read_start (int fd)
672 struct file_read_info *fi = xmalloc (sizeof(*fi));
676 fi->file_moffset = 0;
680 static void file_read_stop (struct file_read_info *fi)
686 static off_t file_seek (void *handle, off_t offset)
688 struct file_read_info *p = handle;
689 p->file_offset = offset;
690 return lseek (p->fd, offset, SEEK_SET);
693 static int file_read (void *handle, char *buf, size_t count)
695 struct file_read_info *p = handle;
698 r = read (fd, buf, count);
702 if (p->file_offset > p->file_max)
703 p->file_max = p->file_offset;
708 static void file_begin (void *handle)
710 struct file_read_info *p = handle;
712 p->file_offset = p->file_moffset;
714 lseek (p->fd, p->file_moffset, SEEK_SET);
718 static void file_end (void *handle, off_t offset)
720 struct file_read_info *p = handle;
722 assert (p->file_more == 0);
724 p->file_moffset = offset;
727 static int atois (const char **s)
730 while ( (c=**s) >= '0' && c <= '9')
732 val = val*10 + c - '0';
738 static char *fileMatchStr (struct recKeys *reckeys, struct recordGroup *rGroup,
742 static char dstBuf[2048];
744 const char *s = spec;
745 static const char **w;
750 while (*s == ' ' || *s == '\t')
757 int attrSet, attrUse;
761 attrSet = atois (&s);
764 logf (LOG_WARN, "Missing , in match criteria %s in group %s",
765 spec, rGroup->groupName ? rGroup->groupName : "none");
769 attrUse = atois (&s);
770 w = searchRecordKey (reckeys, attrSet, attrUse);
775 for (i = 0; i<32; i++)
780 logf (LOG_WARN, "Missing ) in match criteria %s in group %s",
781 spec, rGroup->groupName ? rGroup->groupName : "none");
786 for (i = 0; i<32; i++)
787 if (matchFlag[i] && w[i])
799 logf (LOG_WARN, "Record didn't contain match"
800 " fields in (%d,%d)", attrSet, attrUse);
808 const char *spec_src = NULL;
809 const char *s1 = ++s;
810 while (*s1 && *s1 != ' ' && *s1 != '\t')
816 memcpy (special, s, spec_len);
817 special[spec_len] = '\0';
820 if (!strcmp (special, "group"))
821 spec_src = rGroup->groupName;
822 else if (!strcmp (special, "database"))
823 spec_src = rGroup->databaseName;
824 else if (!strcmp (special, "filename"))
826 else if (!strcmp (special, "type"))
827 spec_src = rGroup->recordType;
832 strcpy (dst, spec_src);
833 dst += strlen (spec_src);
836 else if (*s == '\"' || *s == '\'')
838 int stopMarker = *s++;
842 while (*s && *s != stopMarker)
845 tmpString[i++] = *s++;
850 strcpy (dst, tmpString);
851 dst += strlen (tmpString);
855 logf (LOG_WARN, "Syntax error in match criteria %s in group %s",
856 spec, rGroup->groupName ? rGroup->groupName : "none");
863 logf (LOG_WARN, "No match criteria for record %s in group %s",
864 fname, rGroup->groupName ? rGroup->groupName : "none");
870 struct recordLogInfo {
873 struct recordGroup *rGroup;
876 static void recordLogPreamble (int level, const char *msg, void *info)
878 struct recordLogInfo *p = info;
879 FILE *outf = log_file ();
884 fprintf (outf, "%s of ", p->op);
885 fprintf (outf, "%s type %s\n", p->rGroup->recordType, p->fname);
886 log_event_start (NULL, NULL);
889 static int recordExtract (SYSNO *sysno, const char *fname,
890 struct recordGroup *rGroup, int deleteFlag,
891 struct file_read_info *fi, RecType recType,
894 struct recExtractCtrl extractCtrl;
898 off_t recordOffset = 0;
900 struct recordLogInfo logInfo;
902 logInfo.fname = fname;
904 logInfo.rGroup = rGroup;
905 log_event_start (recordLogPreamble, &logInfo);
909 /* we are going to read from a file, so prepare the extraction */
911 extractCtrl.subType = subType;
912 extractCtrl.init = wordInit;
913 extractCtrl.add = addRecordKey;
915 reckeys.buf_used = 0;
916 reckeys.prevAttrUse = -1;
917 reckeys.prevAttrSet = -1;
919 recordOffset = fi->file_moffset;
920 extractCtrl.offset = recordOffset;
921 extractCtrl.readf = file_read;
922 extractCtrl.seekf = file_seek;
923 extractCtrl.endf = file_end;
924 extractCtrl.map_chrs_input = map_chrs_input;
925 extractCtrl.flagShowRecords = rGroup->flagShowRecords;
926 r = (*recType->extract)(&extractCtrl);
930 /* error occured during extraction ... */
931 logf (LOG_WARN, "Couldn't extract file %s, code %d", fname, r);
934 if (reckeys.buf_used == 0)
936 /* the extraction process returned no information - the record
938 logf (LOG_WARN, "Empty file %s", fname);
943 /* perform match if sysno not known and if match criteria is specified */
950 if (rGroup->recordId && *rGroup->recordId)
954 matchStr = fileMatchStr (&reckeys, rGroup, fname,
958 rinfo = dict_lookup (matchDict, matchStr);
960 memcpy (sysno, rinfo+1, sizeof(*sysno));
964 logf (LOG_WARN, "Bad match criteria");
975 logf (LOG_LOG, "Cannot delete new record");
979 if (rGroup->fileVerboseFlag)
980 logf (LOG_LOG, "add %s %s+%ld", rGroup->recordType,
981 fname, (long) recordOffset);
982 rec = rec_new (records);
987 dict_insert (matchDict, matchStr, sizeof(*sysno), sysno);
989 flushRecordKeys (*sysno, 1, &reckeys, rGroup->databaseName);
995 /* record already exists */
996 struct recKeys delkeys;
998 rec = rec_get (records, *sysno);
1000 delkeys.buf_used = rec->size[recInfo_delKeys];
1001 delkeys.buf = rec->info[recInfo_delKeys];
1002 flushRecordKeys (*sysno, 0, &delkeys, rec->info[recInfo_databaseName]);
1005 /* record going to be deleted */
1006 logInfo.op = "delete";
1007 if (!delkeys.buf_used)
1009 logf (LOG_WARN, "cannot delete; storeKeys false");
1013 if (rGroup->fileVerboseFlag)
1014 logf (LOG_LOG, "delete %s %s %ld", rGroup->recordType,
1015 fname, (long) recordOffset);
1018 dict_delete (matchDict, matchStr);
1019 rec_del (records, &rec);
1026 /* record going to be updated */
1027 logInfo.op = "update";
1028 if (!delkeys.buf_used)
1030 logf (LOG_WARN, "cannot update; storeKeys false");
1034 if (rGroup->fileVerboseFlag)
1035 logf (LOG_LOG, "update %s %s %ld", rGroup->recordType,
1036 fname, (long) recordOffset);
1037 flushRecordKeys (*sysno, 1, &reckeys, rGroup->databaseName);
1042 /* update file type */
1043 xfree (rec->info[recInfo_fileType]);
1044 rec->info[recInfo_fileType] =
1045 rec_strdup (rGroup->recordType, &rec->size[recInfo_fileType]);
1047 /* update filename */
1048 xfree (rec->info[recInfo_filename]);
1049 rec->info[recInfo_filename] =
1050 rec_strdup (fname, &rec->size[recInfo_filename]);
1052 /* update delete keys */
1053 xfree (rec->info[recInfo_delKeys]);
1054 if (reckeys.buf_used > 0 && rGroup->flagStoreKeys == 1)
1057 rec->size[recInfo_delKeys] = reckeys.buf_used;
1058 rec->info[recInfo_delKeys] = reckeys.buf;
1060 reckeys.buf_max = 0;
1062 rec->info[recInfo_delKeys] = xmalloc (reckeys.buf_used);
1063 rec->size[recInfo_delKeys] = reckeys.buf_used;
1064 memcpy (rec->info[recInfo_delKeys], reckeys.buf,
1065 rec->size[recInfo_delKeys]);
1070 rec->info[recInfo_delKeys] = NULL;
1071 rec->size[recInfo_delKeys] = 0;
1074 /* update store data */
1075 xfree (rec->info[recInfo_storeData]);
1076 if (rGroup->flagStoreData == 1)
1078 rec->size[recInfo_storeData] = fi->file_max;
1079 rec->info[recInfo_storeData] = xmalloc (fi->file_max);
1080 if (lseek (fi->fd, recordOffset, SEEK_SET) < 0)
1082 logf (LOG_ERRNO|LOG_FATAL, "seek to %ld in %s", fname,
1083 (long) recordOffset);
1086 if (read (fi->fd, rec->info[recInfo_storeData], fi->file_max)
1089 logf (LOG_ERRNO|LOG_FATAL, "read %d bytes of %s",
1090 fi->file_max, fname);
1096 rec->info[recInfo_storeData] = NULL;
1097 rec->size[recInfo_storeData] = 0;
1099 /* update database name */
1100 xfree (rec->info[recInfo_databaseName]);
1101 rec->info[recInfo_databaseName] =
1102 rec_strdup (rGroup->databaseName, &rec->size[recInfo_databaseName]);
1105 xfree (rec->info[recInfo_offset]);
1107 rec->size[recInfo_offset] = sizeof(recordOffset);
1108 rec->info[recInfo_offset] = xmalloc (sizeof(recordOffset));
1109 memcpy (rec->info[recInfo_offset], &recordOffset, sizeof(recordOffset));
1111 /* commit this record */
1112 rec_put (records, &rec);
1117 int fileExtract (SYSNO *sysno, const char *fname,
1118 const struct recordGroup *rGroupP, int deleteFlag)
1126 struct recordGroup rGroupM;
1127 struct recordGroup *rGroup = &rGroupM;
1128 struct file_read_info *fi;
1130 memcpy (rGroup, rGroupP, sizeof(*rGroupP));
1132 if (!rGroup->groupName || !*rGroup->groupName)
1135 sprintf (gprefix, "%s.", rGroup->groupName);
1137 logf (LOG_DEBUG, "fileExtract %s", fname);
1139 /* determine file extension */
1140 for (i = strlen(fname); --i >= 0; )
1141 if (fname[i] == '/')
1146 else if (fname[i] == '.')
1148 strcpy (ext, fname+i+1);
1151 /* determine file type - depending on extension */
1152 if (!rGroup->recordType)
1154 sprintf (ext_res, "%srecordType.%s", gprefix, ext);
1155 if (!(rGroup->recordType = res_get (common_resource, ext_res)))
1157 sprintf (ext_res, "%srecordType", gprefix);
1158 if (!(rGroup->recordType = res_get (common_resource, ext_res)))
1160 if (rGroup->fileVerboseFlag)
1161 logf (LOG_LOG, "? %s", fname);
1166 if (!rGroup->recordType)
1168 if (rGroup->fileVerboseFlag)
1169 logf (LOG_LOG, "? record %s", fname);
1172 if (!(recType = recType_byName (rGroup->recordType, subType)))
1174 logf (LOG_WARN, "No such record type: %s", rGroup->recordType);
1178 /* determine match criteria */
1179 if (!rGroup->recordId)
1181 sprintf (ext_res, "%srecordId.%s", gprefix, ext);
1182 rGroup->recordId = res_get (common_resource, ext_res);
1185 /* determine database name */
1186 if (!rGroup->databaseName)
1188 sprintf (ext_res, "%sdatabase.%s", gprefix, ext);
1189 if (!(rGroup->databaseName = res_get (common_resource, ext_res)))
1191 sprintf (ext_res, "%sdatabase", gprefix);
1192 rGroup->databaseName = res_get (common_resource, ext_res);
1195 if (!rGroup->databaseName)
1196 rGroup->databaseName = "Default";
1198 if (rGroup->flagStoreData == -1)
1201 sprintf (ext_res, "%sstoreData.%s", gprefix, ext);
1202 if (!(sval = res_get (common_resource, ext_res)))
1204 sprintf (ext_res, "%sstoreData", gprefix);
1205 sval = res_get (common_resource, ext_res);
1208 rGroup->flagStoreData = atoi (sval);
1210 if (rGroup->flagStoreData == -1)
1211 rGroup->flagStoreData = 0;
1213 if (rGroup->flagStoreKeys == -1)
1217 sprintf (ext_res, "%sstoreKeys.%s", gprefix, ext);
1218 if (!(sval = res_get (common_resource, ext_res)))
1220 sprintf (ext_res, "%sstoreKeys", gprefix);
1221 sval = res_get (common_resource, ext_res);
1224 rGroup->flagStoreKeys = atoi (sval);
1226 if (rGroup->flagStoreKeys == -1)
1227 rGroup->flagStoreKeys = 0;
1229 if (sysno && deleteFlag)
1233 if ((fd = open (fname, O_RDONLY)) == -1)
1235 logf (LOG_WARN|LOG_ERRNO, "open %s", fname);
1239 fi = file_read_start (fd);
1243 r = recordExtract (sysno, fname, rGroup, deleteFlag, fi,
1245 } while (r && !sysno && fi->file_more);
1246 log_event_start (NULL, NULL);
1247 file_read_stop (fi);