From bd58c091d65d69624f6851974ae989376823ca9f Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 5 Apr 2006 02:11:44 +0000 Subject: [PATCH] Renamed fileExtract to zebra_extract_file.. The new function returns ZEBRA_RES. --- index/extract.c | 61 +++++++++++++++++++++++++++++++------------------------ index/index.h | 6 +++--- index/kinput.c | 6 +++--- index/trav.c | 18 ++++++++-------- 4 files changed, 49 insertions(+), 42 deletions(-) diff --git a/index/extract.c b/index/extract.c index f1506c5..a48dc38 100644 --- a/index/extract.c +++ b/index/extract.c @@ -1,4 +1,4 @@ -/* $Id: extract.c,v 1.206 2006-03-30 09:52:15 adam Exp $ +/* $Id: extract.c,v 1.207 2006-04-05 02:11:44 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -379,13 +379,13 @@ static void init_extractCtrl(ZebraHandle zh, struct recExtractCtrl *ctrl) ctrl->flagShowRecords = !zh->m_flag_rw; } -static int file_extract_record(ZebraHandle zh, - SYSNO *sysno, const char *fname, - int deleteFlag, - struct file_read_info *fi, - int force_update, - RecType recType, - void *recTypeClientData) +static ZEBRA_RES file_extract_record(ZebraHandle zh, + SYSNO *sysno, const char *fname, + int deleteFlag, + struct file_read_info *fi, + int force_update, + RecType recType, + void *recTypeClientData) { RecordAttr *recordAttr; int r; @@ -400,7 +400,7 @@ static int file_extract_record(ZebraHandle zh, { if (zebraExplain_newDatabase (zh->reg->zei, zh->basenames[0], zh->m_explain_database)) - return 0; + return ZEBRA_FAIL; } if (fi->fd != -1) @@ -447,7 +447,7 @@ static int file_extract_record(ZebraHandle zh, yaz_log_init_prefix2 (0); if (r == RECCTRL_EXTRACT_EOF) - return 0; + return ZEBRA_FAIL; else if (r == RECCTRL_EXTRACT_ERROR_GENERIC) { /* error occured during extraction ... */ @@ -457,7 +457,7 @@ static int file_extract_record(ZebraHandle zh, yaz_log (YLOG_WARN, "fail %s %s " PRINTF_OFF_T, zh->m_record_type, fname, recordOffset); } - return 0; + return ZEBRA_FAIL; } else if (r == RECCTRL_EXTRACT_ERROR_NO_SUCH_FILTER) { @@ -469,7 +469,7 @@ static int file_extract_record(ZebraHandle zh, PRINTF_OFF_T, zh->m_record_type, fname, recordOffset); } - return 0; + return ZEBRA_FAIL; } if (extractCtrl.match_criteria[0]) matchStr = extractCtrl.match_criteria; @@ -488,7 +488,7 @@ static int file_extract_record(ZebraHandle zh, if (!matchStr) { yaz_log(YLOG_WARN, "Bad match criteria"); - return 0; + return ZEBRA_FAIL; } } if (matchStr) @@ -508,12 +508,12 @@ static int file_extract_record(ZebraHandle zh, /* the extraction process returned no information - the record is probably empty - unless flagShowRecords is in use */ if (!zh->m_flag_rw) - return 1; + return ZEBRA_OK; if (zh->records_processed < zh->m_file_verbose_limit) yaz_log (YLOG_WARN, "empty %s %s " PRINTF_OFF_T, zh->m_record_type, fname, recordOffset); - return 1; + return ZEBRA_OK; } if (! *sysno) @@ -524,7 +524,7 @@ static int file_extract_record(ZebraHandle zh, yaz_log (YLOG_LOG, "delete %s %s " PRINTF_OFF_T, zh->m_record_type, fname, recordOffset); yaz_log (YLOG_WARN, "cannot delete record above (seems new)"); - return 1; + return ZEBRA_OK; } if (zh->records_processed < zh->m_file_verbose_limit) yaz_log (YLOG_LOG, "add %s %s " PRINTF_OFF_T, zh->m_record_type, @@ -610,7 +610,7 @@ static int file_extract_record(ZebraHandle zh, } rec_rm (&rec); logRecord (zh); - return 1; + return ZEBRA_OK; } else { @@ -727,13 +727,14 @@ static int file_extract_record(ZebraHandle zh, /* commit this record */ rec_put (zh->reg->records, &rec); logRecord (zh); - return 1; + return ZEBRA_OK; } -int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, - int deleteFlag) +ZEBRA_RES zebra_extract_file(ZebraHandle zh, SYSNO *sysno, const char *fname, + int deleteFlag) { - int r, i, fd; + ZEBRA_RES r = ZEBRA_OK; + int i, fd; char gprefix[128]; char ext[128]; char ext_res[128]; @@ -784,7 +785,7 @@ int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, &recTypeClientData))) { yaz_log(YLOG_WARN, "No such record type: %s", zh->m_record_type); - return 0; + return ZEBRA_FAIL; } switch(recType->version) @@ -809,16 +810,15 @@ int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *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; + return ZEBRA_FAIL; } } fi = file_read_start (fd); - do + while(1) { fi->file_moffset = fi->file_offset; fi->file_more = 0; /* file_end not called (yet) */ @@ -829,8 +829,15 @@ int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, fi->file_offset = fi->file_moffset; lseek(fi->fd, fi->file_moffset, SEEK_SET); } + if (r != ZEBRA_OK) + { + break; + } + if (sysno) + { + break; + } } - while (r && !sysno); file_read_stop (fi); if (fd != -1) close (fd); @@ -1554,7 +1561,7 @@ ZEBRA_RES zebra_snippets_rec_keys(ZebraHandle zh, zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type, 0/* db */, 0/* set */, 0/* use */, - 0 /* string index */); + 0 /* string_index */); assert(index_type); zebra_term_untrans_iconv(zh, nmem, index_type, &dst_term, str); diff --git a/index/index.h b/index/index.h index a716601..25fb160 100644 --- a/index/index.h +++ b/index/index.h @@ -1,4 +1,4 @@ -/* $Id: index.h,v 1.157 2006-03-26 14:17:01 adam Exp $ +/* $Id: index.h,v 1.158 2006-04-05 02:11:44 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -482,8 +482,8 @@ void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid); void extract_token_add (RecWord *p); int explain_extract (void *handle, Record rec, data1_node *n); -int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, - int deleteFlag); +ZEBRA_RES zebra_extract_file(ZebraHandle zh, SYSNO *sysno, const char *fname, + int deleteFlag); ZEBRA_RES zebra_begin_read (ZebraHandle zh); ZEBRA_RES zebra_end_read (ZebraHandle zh); diff --git a/index/kinput.c b/index/kinput.c index 9d4beaa..bedc874 100644 --- a/index/kinput.c +++ b/index/kinput.c @@ -1,4 +1,4 @@ -/* $Id: kinput.c,v 1.71 2006-03-30 09:52:15 adam Exp $ +/* $Id: kinput.c,v 1.72 2006-04-05 02:11:44 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -55,7 +55,7 @@ struct key_file { Res res; }; -#if 1 +#if 0 static void pkey(const char *b, int mode) { key_logdump_txt(YLOG_LOG, b, mode ? "i" : "d"); @@ -420,7 +420,7 @@ static int heap_read_one (struct heap_info *hi, char *name, char *key) #define PR_KEY_LOW 0 #define PR_KEY_TOP 0 -#if 1 +#if 0 /* for debugging only */ static void print_dict_item(ZebraHandle zh, const char *s) { diff --git a/index/trav.c b/index/trav.c index 3dff5f5..a2786fc 100644 --- a/index/trav.c +++ b/index/trav.c @@ -1,4 +1,4 @@ -/* $Id: trav.c,v 1.49 2005-06-14 20:28:54 adam Exp $ +/* $Id: trav.c,v 1.50 2006-04-05 02:11:44 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -70,7 +70,7 @@ static void repositoryExtractR (ZebraHandle zh, int deleteFlag, char *rep, switch (e[i].kind) { case dirs_file: - fileExtract (zh, NULL, rep, deleteFlag); + zebra_extract_file (zh, NULL, rep, deleteFlag); break; case dirs_dir: repositoryExtractR (zh, deleteFlag, rep, level+1); @@ -94,7 +94,7 @@ static void fileDeleteR (ZebraHandle zh, { case dirs_file: sprintf (tmppath, "%s%s", base, dst->path); - fileExtract (zh, &dst->sysno, tmppath, 1); + zebra_extract_file (zh, &dst->sysno, tmppath, 1); strcpy (tmppath, dst->path); dst = dirs_read (di); @@ -191,7 +191,7 @@ static void fileUpdateR (ZebraHandle zh, case dirs_file: if (e_src[i_src].mtime > dst->mtime) { - if (fileExtract (zh, &dst->sysno, tmppath, 0)) + if (zebra_extract_file (zh, &dst->sysno, tmppath, 0) == ZEBRA_OK) { dirs_add (di, src, dst->sysno, e_src[i_src].mtime); } @@ -219,7 +219,7 @@ static void fileUpdateR (ZebraHandle zh, switch (e_src[i_src].kind) { case dirs_file: - if (fileExtract (zh, &sysno, tmppath, 0)) + if (zebra_extract_file (zh, &sysno, tmppath, 0) == ZEBRA_OK) dirs_add (di, src, sysno, e_src[i_src].mtime); break; case dirs_dir: @@ -238,7 +238,7 @@ static void fileUpdateR (ZebraHandle zh, switch (dst->kind) { case dirs_file: - fileExtract (zh, &dst->sysno, tmppath, 1); + zebra_extract_file (zh, &dst->sysno, tmppath, 1); dirs_del (di, dst->path); dst = dirs_read (di); break; @@ -319,13 +319,13 @@ static void fileUpdate (ZebraHandle zh, Dict dict, const char *path) if (e_dst) { if (sbuf.st_mtime > e_dst->mtime) - if (fileExtract (zh, &e_dst->sysno, src, 0)) + if (zebra_extract_file (zh, &e_dst->sysno, src, 0) == ZEBRA_OK) dirs_add (di, src, e_dst->sysno, sbuf.st_mtime); } else { SYSNO sysno = 0; - if (fileExtract (zh, &sysno, src, 0)) + if (zebra_extract_file (zh, &sysno, src, 0) == ZEBRA_OK) dirs_add (di, src, sysno, sbuf.st_mtime); } dirs_free (&di); @@ -372,7 +372,7 @@ static void repositoryExtract (ZebraHandle zh, if (ret == -1) yaz_log (YLOG_WARN|YLOG_ERRNO, "Cannot access path %s", src); else if (S_ISREG(sbuf.st_mode)) - fileExtract (zh, NULL, src, deleteFlag); + zebra_extract_file (zh, NULL, src, deleteFlag); else if (S_ISDIR(sbuf.st_mode)) repositoryExtractR (zh, deleteFlag, src, 0); else -- 1.7.10.4