+struct recordLogInfo {
+ const char *fname;
+ int recordOffset;
+ struct recordGroup *rGroup;
+};
+
+static void init_extractCtrl(ZebraHandle zh, struct recExtractCtrl *ctrl)
+{
+ int i;
+ for (i = 0; i<256; i++)
+ {
+ if (zebra_maps_is_positioned(zh->reg->zebra_maps, i))
+ ctrl->seqno[i] = 1;
+ else
+ ctrl->seqno[i] = 0;
+ }
+ ctrl->flagShowRecords = !zh->m_flag_rw;
+}
+
+static void all_matches_add(struct recExtractCtrl *ctrl)
+{
+ RecWord word;
+ extract_init(ctrl, &word);
+ word.index_name = "_ALLRECORDS";
+ word.index_type = 'w';
+ word.seqno = 1;
+ extract_add_index_string (&word, zinfo_index_category_alwaysmatches,
+ "", 0);
+}
+
+ZEBRA_RES zebra_extract_file(ZebraHandle zh, SYSNO *sysno, const char *fname,
+ int deleteFlag)
+{
+ ZEBRA_RES r = ZEBRA_OK;
+ int i, fd;
+ char gprefix[128];
+ char ext[128];
+ char ext_res[128];
+ struct file_read_info *fi = 0;
+ const char *original_record_type = 0;
+ RecType recType;
+ void *recTypeClientData;
+ struct ZebraRecStream stream, *streamp;
+
+ zebra_init_log_level();
+
+ if (!zh->m_group || !*zh->m_group)
+ *gprefix = '\0';
+ else
+ sprintf (gprefix, "%s.", zh->m_group);
+
+ yaz_log(log_level, "zebra_extract_file %s", fname);
+
+ /* determine file extension */
+ *ext = '\0';
+ for (i = strlen(fname); --i >= 0; )
+ if (fname[i] == '/')
+ break;
+ else if (fname[i] == '.')
+ {
+ strcpy (ext, fname+i+1);
+ break;
+ }
+ /* determine file type - depending on extension */
+ original_record_type = zh->m_record_type;
+ if (!zh->m_record_type)
+ {
+ sprintf (ext_res, "%srecordType.%s", gprefix, ext);
+ zh->m_record_type = res_get (zh->res, ext_res);
+ }
+ if (!zh->m_record_type)
+ {
+ if (zh->records_processed < zh->m_file_verbose_limit)
+ yaz_log (YLOG_LOG, "? %s", fname);
+ return 0;
+ }
+ /* determine match criteria */
+ if (!zh->m_record_id)
+ {
+ sprintf (ext_res, "%srecordId.%s", gprefix, ext);
+ zh->m_record_id = res_get (zh->res, ext_res);
+ }
+
+ if (!(recType =
+ recType_byName (zh->reg->recTypes, zh->res, zh->m_record_type,
+ &recTypeClientData)))
+ {
+ yaz_log(YLOG_WARN, "No such record type: %s", zh->m_record_type);
+ return ZEBRA_FAIL;
+ }
+
+ switch(recType->version)
+ {
+ case 0:
+ break;
+ default:
+ yaz_log(YLOG_WARN, "Bad filter version: %s", zh->m_record_type);
+ }
+ if (sysno && deleteFlag)
+ {
+ streamp = 0;
+ fi = 0;
+ }
+ else
+ {
+ char full_rep[1024];
+
+ if (zh->path_reg && !yaz_is_abspath (fname))
+ {
+ strcpy (full_rep, zh->path_reg);
+ strcat (full_rep, "/");
+ strcat (full_rep, fname);
+ }
+ else
+ strcpy (full_rep, fname);
+
+ if ((fd = open (full_rep, O_BINARY|O_RDONLY)) == -1)
+ {
+ yaz_log (YLOG_WARN|YLOG_ERRNO, "open %s", full_rep);
+ zh->m_record_type = original_record_type;
+ return ZEBRA_FAIL;
+ }
+ streamp = &stream;
+ zebra_create_stream_fd(streamp, fd, 0);
+ }
+ while(1)
+ {
+ r = zebra_extract_record_stream(zh, streamp,
+ deleteFlag,
+ 0, /* tst_mode */
+ zh->m_record_type,
+ sysno,
+ 0, /*match_criteria */
+ fname,
+ 1, /* force_update */
+ 1, /* allow_update */
+ recType, recTypeClientData);
+ if (r != ZEBRA_OK)
+ {
+ break;
+ }
+ if (sysno)
+ {
+ break;
+ }
+ }
+ if (streamp)
+ stream.destroy(streamp);
+ zh->m_record_type = original_record_type;
+ return r;
+}
+
+/*
+ If sysno is provided, then it's used to identify the reocord.
+ If not, and match_criteria is provided, then sysno is guessed
+ If not, and a record is provided, then sysno is got from there
+
+ */
+
+ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh,
+ const char *buf, size_t buf_size,
+ int delete_flag,
+ int test_mode,
+ const char *recordType,
+ SYSNO *sysno,
+ const char *match_criteria,
+ const char *fname,
+ int force_update,
+ int allow_update)
+{
+ struct ZebraRecStream stream;
+ ZEBRA_RES res;
+ void *clientData;
+ RecType recType = 0;
+
+ if (recordType && *recordType)
+ {
+ yaz_log(log_level, "Record type explicitly specified: %s", recordType);
+ recType = recType_byName (zh->reg->recTypes, zh->res, recordType,
+ &clientData);
+ }
+ else
+ {
+ if (!(zh->m_record_type))
+ {
+ yaz_log (YLOG_WARN, "No such record type defined");
+ return ZEBRA_FAIL;
+ }
+ yaz_log(log_level, "Get record type from rgroup: %s",
+ zh->m_record_type);
+ recType = recType_byName (zh->reg->recTypes, zh->res,
+ zh->m_record_type, &clientData);
+ recordType = zh->m_record_type;
+ }
+
+ if (!recType)
+ {
+ yaz_log (YLOG_WARN, "No such record type: %s", recordType);
+ return ZEBRA_FAIL;
+ }
+
+
+
+ zebra_create_stream_mem(&stream, buf, buf_size);
+
+ res = zebra_extract_record_stream(zh, &stream,
+ delete_flag,
+ test_mode,
+ recordType,
+ sysno,
+ match_criteria,
+ fname,
+ force_update,
+ allow_update,
+ recType, clientData);
+ stream.destroy(&stream);
+ return res;
+}
+
+
+ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh,
+ struct ZebraRecStream *stream,
+ int delete_flag,
+ int test_mode,
+ const char *recordType,
+ SYSNO *sysno,
+ const char *match_criteria,
+ const char *fname,
+ int force_update,
+ int allow_update,
+ RecType recType,
+ void *recTypeClientData)
+