X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=index%2Fzinfo.c;h=223508931990c30ea878e39793442c8eb25a2829;hb=cdcde0c689ec4b66f1884dbd455284b7a35fb425;hp=b474306016b76c0a322c0fef9a3f6dd105047d69;hpb=4d7345f0e28b1e56658c26a31ffaee95dcf502c0;p=idzebra-moved-to-github.git diff --git a/index/zinfo.c b/index/zinfo.c index b474306..2235089 100644 --- a/index/zinfo.c +++ b/index/zinfo.c @@ -1,4 +1,4 @@ -/* $Id: zinfo.c,v 1.55 2006-02-20 12:41:42 adam Exp $ +/* $Id: zinfo.c,v 1.59 2006-05-10 09:08:55 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -150,11 +150,15 @@ static Record createRecord(Records records, SYSNO *sysno) if (*sysno) { rec = rec_get(records, *sysno); + if (!rec) + return 0; xfree(rec->info[recInfo_storeData]); } else { rec = rec_new(records); + if (!rec) + return 0; *sysno = rec->sysno; rec->info[recInfo_fileType] = @@ -520,6 +524,12 @@ ZebraExplainInfo zebraExplain_open( /* write now because we want to be sure about the sysno */ trec = rec_new(records); + if (!trec) + { + yaz_log(YLOG_FATAL, "Cannot create root Explain record"); + nmem_destroy(zei->nmem); + return 0; + } trec->info[recInfo_fileType] = rec_strdup("grs.sgml", &trec->size[recInfo_fileType]); trec->info[recInfo_databaseName] = @@ -529,11 +539,11 @@ ZebraExplainInfo zebraExplain_open( trec->info[recInfo_storeData] = (char *) xmalloc(sgml_len); memcpy(trec->info[recInfo_storeData], sgml_buf, sgml_len); trec->size[recInfo_storeData] = sgml_len; - + rec_put(records, &trec); rec_rm(&trec); - } + zebraExplain_newDatabase(zei, "IR-Explain-1", 0); if (!zei->categoryList->dirty) @@ -986,6 +996,8 @@ static void zebraExplain_writeCategoryList (ZebraExplainInfo zei, #endif drec = createRecord (zei->records, &sysno); + if (!drec) + return; node_ci = data1_search_tag (zei->dh, node_categoryList, "/categoryList"); @@ -1040,6 +1052,8 @@ static void zebraExplain_writeAttributeDetails (ZebraExplainInfo zei, #endif drec = createRecord (zei->records, &zad->sysno); + if (!drec) + return; assert (zad->data1_tree); node_adinfo = data1_search_tag (zei->dh, zad->data1_tree, @@ -1182,6 +1196,8 @@ static void zebraExplain_writeDatabase (ZebraExplainInfo zei, yaz_log(YLOG_LOG, "zebraExplain_writeDatabase %s", zdi->databaseName); #endif drec = createRecord (zei->records, &zdi->sysno); + if (!drec) + return; assert (zdi->data1_database); node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database, @@ -1272,6 +1288,8 @@ static void zebraExplain_writeAttributeSet (ZebraExplainInfo zei, #endif drec = createRecord (zei->records, &o->sysno); + if (!drec) + return; node_root = data1_read_sgml (zei->dh, zei->nmem, "AttributeSetInfo\n" @@ -1403,29 +1421,52 @@ int zebraExplain_lookup_attr_su_any_index(ZebraExplainInfo zei, int zebraExplain_lookup_attr_su(ZebraExplainInfo zei, int index_type, int set, int use) { - struct zebSUInfoB *zsui; + struct zebSUInfoB **zsui; +#if 0 + yaz_log(YLOG_LOG, "lookup_attr_su index_type=%d set=%d use=%d", + index_type, set, use); +#endif assert (zei->curDatabaseInfo); - for (zsui = zei->curDatabaseInfo->attributeDetails->SUInfo; - zsui; zsui=zsui->next) - if (zsui->info.index_type == index_type && - zsui->info.which == ZEB_SU_SET_USE && - zsui->info.u.su.use == use && zsui->info.u.su.set == set) - return zsui->info.ordinal; + for (zsui = &zei->curDatabaseInfo->attributeDetails->SUInfo; + *zsui; zsui = &(*zsui)->next) + if ((*zsui)->info.index_type == index_type && + (*zsui)->info.which == ZEB_SU_SET_USE && + (*zsui)->info.u.su.use == use && (*zsui)->info.u.su.set == set) + { + struct zebSUInfoB *zsui_this = *zsui; + + /* take it out of the list and move to front */ + *zsui = (*zsui)->next; + zsui_this->next = zei->curDatabaseInfo->attributeDetails->SUInfo; + zei->curDatabaseInfo->attributeDetails->SUInfo = zsui_this; + + return zsui_this->info.ordinal; + } return -1; } int zebraExplain_lookup_attr_str(ZebraExplainInfo zei, int index_type, const char *str) { - struct zebSUInfoB *zsui; + struct zebSUInfoB **zsui; assert (zei->curDatabaseInfo); - for (zsui = zei->curDatabaseInfo->attributeDetails->SUInfo; - zsui; zsui=zsui->next) - if (zsui->info.index_type == index_type && - zsui->info.which == ZEB_SU_STR && !strcmp(zsui->info.u.str, str)) - return zsui->info.ordinal; + for (zsui = &zei->curDatabaseInfo->attributeDetails->SUInfo; + *zsui; zsui = &(*zsui)->next) + if ((*zsui)->info.index_type == index_type + && (*zsui)->info.which == ZEB_SU_STR + && !strcmp((*zsui)->info.u.str, str)) + { + struct zebSUInfoB *zsui_this = *zsui; + + /* take it out of the list and move to front */ + *zsui = (*zsui)->next; + zsui_this->next = zei->curDatabaseInfo->attributeDetails->SUInfo; + zei->curDatabaseInfo->attributeDetails->SUInfo = zsui_this; + + return zsui_this->info.ordinal; + } return -1; } @@ -1445,9 +1486,20 @@ int zebraExplain_trav_ord(ZebraExplainInfo zei, void *handle, int zebraExplain_lookup_ord (ZebraExplainInfo zei, int ord, int *index_type, const char **db, - int *set, int *use) + int *set, int *use, + const char **string_index) { struct zebDatabaseInfoB *zdb; + + if (set) + *set = -1; + if (use) + *use = -1; + if (index_type) + *index_type = 0; + if (string_index) + *string_index = 0; + for (zdb = zei->databaseInfo; zdb; zdb = zdb->next) { struct zebSUInfoB *zsui; @@ -1467,6 +1519,11 @@ int zebraExplain_lookup_ord (ZebraExplainInfo zei, int ord, if (use) *use = zsui->info.u.su.use; } + + if (zsui->info.which == ZEB_SU_STR) + if (string_index) + *string_index = zsui->info.u.str; + if (index_type) *index_type = zsui->info.index_type; return 0; @@ -1633,3 +1690,11 @@ void zebraExplain_loadAttsets (data1_handle dh, Res res) If the database doesn't exist globally (in TargetInfo) an AttributeSetInfo must be added (globally). */ +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +