-int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname,
- int deleteFlag)
-{
- int r, i, fd;
- char gprefix[128];
- char ext[128];
- char ext_res[128];
- struct file_read_info *fi;
- const char *original_record_type = 0;
- RecType recType;
- void *recTypeClientData;
-
- if (!zh->m_group || !*zh->m_group)
- *gprefix = '\0';
- else
- sprintf (gprefix, "%s.", zh->m_group);
-
- yaz_log (YLOG_DEBUG, "fileExtract %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 0;
- }
-
- switch(recType->version)
- {
- case 0:
- break;
- default:
- yaz_log(YLOG_WARN, "Bad filter version: %s", zh->m_record_type);
- }
- if (sysno && deleteFlag)
- fd = -1;
- 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 0;
- }
- }
- fi = file_read_start (fd);
- do
- {
- fi->file_moffset = fi->file_offset;
- fi->file_more = 0; /* file_end not called (yet) */
- r = file_extract_record (zh, sysno, fname, deleteFlag, fi, 1,
- recType, recTypeClientData);
- if (fi->file_more)
- { /* file_end has been called so reset offset .. */
- fi->file_offset = fi->file_moffset;
- lseek(fi->fd, fi->file_moffset, SEEK_SET);
- }
- }
- while (r && !sysno);
- file_read_stop (fi);
- if (fd != -1)
- close (fd);
- zh->m_record_type = original_record_type;
- return r;
-}