コード例 #1
0
ファイル: zimpatch.cpp プロジェクト: kelson42/zimpatch
    virtual const zim::writer::Article* getNextArticle()
    {
        //Add all articles in File_1 that have not ben deleted.
        if(index<start_file.getFileheader().getArticleCount()) //Meaning still on file_1
        {
            zim::Article tmpAr=start_file.getArticle(index);
            while(is_deleted(tmpAr.getLongUrl()))
            {
                index++;
                tmpAr=start_file.getArticle(index);
            }
            tempArticle=Article(tmpAr,index);
            //If the article is also present in file_2
            if(diff_file.getArticleByUrl(tmpAr.getLongUrl()).getIndex()!=4294967295)
            {
                zim::Article tmp=diff_file.getArticleByUrl(tmpAr.getLongUrl());
                tmpAr=tmp;
                tempArticle=Article(tmpAr,start_file.getFileheader().getArticleCount()+diff_file.getArticleByUrl(tmpAr.getLongUrl()).getIndex());
            }
            index++;
            return &tempArticle;
        }

        //Now adding new articles in file_2
        if(index<(start_file.getFileheader().getArticleCount()+diff_file.getFileheader().getArticleCount()))
        {
            zim::Article tmpAr=diff_file.getArticle(index-start_file.getFileheader().getArticleCount());
            //If the article is already in file_1, it has been added.
            while(start_file.getArticleByUrl(tmpAr.getLongUrl()).getIndex()!=4294967295||isAdditionalMetadata(tmpAr.getLongUrl()))
            {
                index++;
                if(index>=(start_file.getFileheader().getArticleCount()+diff_file.getFileheader().getArticleCount()))
                    break;
                tmpAr=diff_file.getArticle(index-start_file.getFileheader().getArticleCount());
            }
            if(index<(start_file.getFileheader().getArticleCount()+diff_file.getFileheader().getArticleCount()))
            {
                tempArticle=Article(tmpAr,index);
                index++;
                return &tempArticle;
            }
        }
        return 0;
    }
コード例 #2
0
ファイル: zimpatch.cpp プロジェクト: kiranmathewkoshy/openzim
        const zim::writer::Article* zimPatch::ArticleSource::getNextArticle()
        {

            //Add all articles in File_1 that have not ben deleted.
            std::string url="";

            if(index<start_file.getFileheader().getArticleCount()) //Meaning still on file_1
            {
                bool eof=false;     //To show wether EOF was reached or not.
                int id=0;
                zim::Article tmpAr=start_file.getArticle(index);
                id=index;
                while(dlist[index]==1)
                {
                    index++;
                    if(index>=start_file.getFileheader().getArticleCount())
                    {
                        eof=true;
                        break;
                    }
                    tmpAr=start_file.getArticle(index);
                    id=index;
                }
                if(!eof)
                {
                    tempArticle=Article(tmpAr,index);
                    id=index;
                    //If the article is also present in file_2
                    if(diff_file.getArticleByUrl(tmpAr.getLongUrl()).getIndex()!=std::numeric_limits<unsigned int>::max())
                    {
                        tmpAr=diff_file.getArticleByUrl(tmpAr.getLongUrl());
                        tempArticle=Article(tmpAr,start_file.getFileheader().getArticleCount()+diff_file.getArticleByUrl(tmpAr.getLongUrl()).getIndex());
                        id=tmpAr.getIndex()+start_file.getFileheader().getArticleCount();
                    }
                    index++;
                    if(redirect[id]!=0)
                        tempArticle.setRedirectAid(toString((long long)redirect[id]));
                    //std::cout<<"\nArticle: "<<tempArticle.getNamespace()<<"/"<<tempArticle.getUrl();
                    //std::cout<<"\nIndex: "<<tempArticle.getAid();
                    //getchar();
                    return &tempArticle;
                }
            }
            //Now adding new articles in file_2
            if(index<(start_file.getFileheader().getArticleCount()+diff_file.getFileheader().getArticleCount()))
            {
                int id=0;
                zim::Article tmpAr=diff_file.getArticle(index-start_file.getFileheader().getArticleCount());
                //If the article is already in file_1, it has been added.
                while(start_file.getArticleByUrl(tmpAr.getLongUrl()).getIndex()!=std::numeric_limits<unsigned int>::max()||isAdditionalMetadata(tmpAr.getLongUrl()))
                {
                    index++;
                    if(index>=(start_file.getFileheader().getArticleCount()+diff_file.getFileheader().getArticleCount()))
                        break;
                    tmpAr=diff_file.getArticle(index-start_file.getFileheader().getArticleCount());
                }
                if(index<(start_file.getFileheader().getArticleCount()+diff_file.getFileheader().getArticleCount()))
                {
                    tempArticle=Article(tmpAr,index);
                    id=index;
                    index++;
                    //std::cout<<"\nRedirectID: "<<redirect[id];
                    //std::cout<<"\nID: "<<id;
                    if(redirect[id]!=0)
                        tempArticle.setRedirectAid(toString((long long)redirect[id]));
                    //std::cout<<"\nArticle: "<<tempArticle.getNamespace()<<"/"<<tempArticle.getUrl();
                    //std::cout<<"\nIndex: "<<tempArticle.getAid();
                    //std::cout<<"\nIsredirect: "<<tempArticle.isRedirect();
                    //getchar();
                    return &tempArticle;
                }
            }
            return 0;
        }