The patch adds support for documents with duplicate page titles. I need this change to update pdf2djvu to the latest version.
I've not tested any djvu viewer, just the conversion. So any test is welcome. OK? Index: Makefile =================================================================== RCS file: /cvs/ports/graphics/djvulibre/Makefile,v retrieving revision 1.34 diff -u -p -r1.34 Makefile --- Makefile 12 May 2015 16:10:27 -0000 1.34 +++ Makefile 3 Feb 2016 01:53:18 -0000 @@ -3,6 +3,7 @@ COMMENT= view, decode and encode DjVu files DISTNAME= djvulibre-3.5.27 +REVISION= 0 SHARED_LIBS= djvulibre 26.0 # 27.0 CATEGORIES= graphics print Index: patches/patch-libdjvu_DjVmDir_cpp =================================================================== RCS file: patches/patch-libdjvu_DjVmDir_cpp diff -N patches/patch-libdjvu_DjVmDir_cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-libdjvu_DjVmDir_cpp 3 Feb 2016 01:53:18 -0000 @@ -0,0 +1,94 @@ +$OpenBSD$ + +"accept documents with duplicate page titles" + +http://sourceforge.net/p/djvu/djvulibre-git/ci/77a4dca8dd3acd0acc1680fa14a352c11084e25d/ +https://bitbucket.org/jwilk/pdf2djvu/issues/113/duplicate-page-title-1 + +--- libdjvu/DjVmDir.cpp.orig Tue Jul 8 23:15:07 2014 ++++ libdjvu/DjVmDir.cpp Wed Feb 3 01:51:28 2016 +@@ -223,7 +223,6 @@ DjVmDir::decode(const GP<ByteStream> &gstr) + page2file.resize(-1); + name2file.empty(); + id2file.empty(); +- title2file.empty(); + + int ver=str.read8(); + bool bundled=(ver & 0x80)!=0; +@@ -375,18 +374,6 @@ DjVmDir::decode(const GP<ByteStream> &gstr) + G_THROW( ERR_MSG("DjVmDir.dupl_id") "\t" + file->id); + id2file[file->id]=file; + } +- +- // Generate title2file map +- for(pos=files_list;pos;++pos) +- { +- GP<File> file=files_list[pos]; +- if (file->title.length()) +- { +- if (title2file.contains(file->title)) +- G_THROW( ERR_MSG("DjVmDir.dupl_title") "\t" + file->title); +- title2file[file->title]=file; +- } +- } + } + } + +@@ -556,11 +543,19 @@ DjVmDir::id_to_file(const GUTF8String &id) const + } + + GP<DjVmDir::File> +-DjVmDir::title_to_file(const GUTF8String &title) const ++DjVmDir::title_to_file(const GUTF8String &title, GPosition spos) const + { +- GCriticalSectionLock lock((GCriticalSection *) &class_lock); +- GPosition pos; +- return (title2file.contains(title, pos))?title2file[pos]:(GP<DjVmDir::File>(0)); ++ if (! title) ++ return 0; ++ GCriticalSectionLock lock((GCriticalSection *) &class_lock); ++ if (! spos) ++ for (GPosition pos = spos; pos; ++pos) ++ if (files_list[pos]->is_page() && files_list[pos]->title == title) ++ return files_list[pos]; ++ for (GPosition pos = files_list; pos; ++pos) ++ if (files_list[pos]->is_page() && files_list[pos]->title == title) ++ return files_list[pos]; ++ return 0; + } + + GP<DjVmDir::File> +@@ -661,14 +656,7 @@ DjVmDir::insert_file(const GP<File> & file, int pos_nu + G_THROW( ERR_MSG("DjVmDir.dupl_name2") "\t" + file->name); + name2file[file->name]=file; + id2file[file->id]=file; +- if (file->title.length()) +- { +- if (title2file.contains(file->title)) +- // duplicate titles may become ok some day +- G_THROW( ERR_MSG("DjVmDir.dupl_title2") "\t" + file->title); +- title2file[file->title]=file; +- } +- ++ + // Make sure that there is no more than one file with shared annotations + if (file->is_shared_anno()) + { +@@ -727,7 +715,6 @@ DjVmDir::delete_file(const GUTF8String &id) + { + name2file.del(f->name); + id2file.del(f->id); +- title2file.del(f->title); + if (f->is_page()) + { + for(int page=0;page<page2file.size();page++) +@@ -788,9 +775,7 @@ DjVmDir::set_file_title(const GUTF8String &id, const G + if (!id2file.contains(id, pos)) + G_THROW( ERR_MSG("DjVmDir.no_info") "\t" + GUTF8String(id)); + GP<File> file=id2file[pos]; +- title2file.del(file->title); + file->title=title; +- title2file[title]=file; + } + + GPList<DjVmDir::File> Index: patches/patch-libdjvu_DjVmDir_h =================================================================== RCS file: patches/patch-libdjvu_DjVmDir_h diff -N patches/patch-libdjvu_DjVmDir_h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-libdjvu_DjVmDir_h 3 Feb 2016 01:53:18 -0000 @@ -0,0 +1,41 @@ +$OpenBSD$ + +"accept documents with duplicate page titles" + +http://sourceforge.net/p/djvu/djvulibre-git/ci/77a4dca8dd3acd0acc1680fa14a352c11084e25d/ +https://bitbucket.org/jwilk/pdf2djvu/issues/113/duplicate-page-title-1 + +--- libdjvu/DjVmDir.h.orig Tue Jul 8 23:15:07 2014 ++++ libdjvu/DjVmDir.h Wed Feb 3 01:51:28 2016 +@@ -181,7 +181,8 @@ class DJVUAPI DjVmDir : public GPEnabled (public) + /** Translates file IDs to file records. */ + GP<File> id_to_file(const GUTF8String &id) const; + /** Translates file shortcuts to file records. */ +- GP<File> title_to_file(const GUTF8String &title) const; ++ GP<File> title_to_file(const GUTF8String &title, GPosition spos) const; ++ GP<File> title_to_file(const GUTF8String &title) const; + /** Access file record by position. */ + GP<File> pos_to_file(int fileno, int *ppageno=0) const; + /** Returns position of the file in the directory. */ +@@ -216,7 +217,6 @@ class DJVUAPI DjVmDir : public GPEnabled (public) + GPArray<File> page2file; + GPMap<GUTF8String, File> name2file; + GPMap<GUTF8String, File> id2file; +- GPMap<GUTF8String, File> title2file; + private: //dummy stuff + static void decode(ByteStream *); + static void encode(ByteStream *); +@@ -438,6 +438,13 @@ DjVmDir::is_indirect(void) const + GCriticalSectionLock lock((GCriticalSection *) &class_lock); + return ( files_list.size() && files_list[files_list] != 0 && + files_list[files_list]->offset==0 ); ++} ++ ++inline GP<DjVmDir::File> ++DjVmDir::title_to_file(const GUTF8String &title) const ++{ ++ GPosition pos; ++ return title_to_file(title, pos); + } + + Index: patches/patch-libdjvu_DjVuDocument_cpp =================================================================== RCS file: patches/patch-libdjvu_DjVuDocument_cpp diff -N patches/patch-libdjvu_DjVuDocument_cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-libdjvu_DjVuDocument_cpp 3 Feb 2016 01:53:18 -0000 @@ -0,0 +1,37 @@ +$OpenBSD$ + +"accept documents with duplicate page titles" + +http://sourceforge.net/p/djvu/djvulibre-git/ci/77a4dca8dd3acd0acc1680fa14a352c11084e25d/ +https://bitbucket.org/jwilk/pdf2djvu/issues/113/duplicate-page-title-1 + +--- libdjvu/DjVuDocument.cpp.orig Mon Sep 22 00:06:03 2014 ++++ libdjvu/DjVuDocument.cpp Wed Feb 3 01:51:28 2016 +@@ -805,11 +805,9 @@ DjVuDocument::id_to_url(const GUTF8String & id) const + { + GP<DjVmDir::File> file=djvm_dir->id_to_file(id); + if (!file) +- { + file=djvm_dir->name_to_file(id); +- if (!file) +- file=djvm_dir->title_to_file(id); +- } ++ if (!file) ++ file=djvm_dir->title_to_file(id); + if (file) + return GURL::UTF8(file->get_load_name(),init_url); + } +@@ -819,11 +817,9 @@ DjVuDocument::id_to_url(const GUTF8String & id) const + { + GP<DjVmDir::File> file=djvm_dir->id_to_file(id); + if (!file) +- { + file=djvm_dir->name_to_file(id); +- if (!file) +- file=djvm_dir->title_to_file(id); +- } ++ if (!file) ++ file=djvm_dir->title_to_file(id); + if (file) + return GURL::UTF8(file->get_load_name(),init_url.base()); + } Index: patches/patch-libdjvu_DjVuDocument_h =================================================================== RCS file: patches/patch-libdjvu_DjVuDocument_h diff -N patches/patch-libdjvu_DjVuDocument_h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-libdjvu_DjVuDocument_h 3 Feb 2016 01:53:18 -0000 @@ -0,0 +1,17 @@ +$OpenBSD$ + +"accept documents with duplicate page titles" + +http://sourceforge.net/p/djvu/djvulibre-git/ci/77a4dca8dd3acd0acc1680fa14a352c11084e25d/ +https://bitbucket.org/jwilk/pdf2djvu/issues/113/duplicate-page-title-1 + +--- libdjvu/DjVuDocument.h.orig Tue Jul 8 23:15:07 2014 ++++ libdjvu/DjVuDocument.h Wed Feb 3 01:51:28 2016 +@@ -524,7 +524,6 @@ class DJVUAPI DjVuDocument : public DjVuPort (public) + \begin{enumerate} + \item File ID from the \Ref{DjVmDir} + \item File name from the \Ref{DjVmDir} +- \item File title from the \Ref{DjVmDir} + \end{enumerate} + Then for #BUNDLED# document the URL is obtained by + appending the #name# of the found file to the document's Index: patches/patch-libdjvu_DjVuMessageLite_h =================================================================== RCS file: patches/patch-libdjvu_DjVuMessageLite_h diff -N patches/patch-libdjvu_DjVuMessageLite_h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-libdjvu_DjVuMessageLite_h 3 Feb 2016 01:53:18 -0000 @@ -0,0 +1,20 @@ +$OpenBSD$ + +"accept documents with duplicate page titles" + +http://sourceforge.net/p/djvu/djvulibre-git/ci/77a4dca8dd3acd0acc1680fa14a352c11084e25d/ +https://bitbucket.org/jwilk/pdf2djvu/issues/113/duplicate-page-title-1 + +--- libdjvu/DjVuMessageLite.h.orig Tue Jul 8 23:15:07 2014 ++++ libdjvu/DjVuMessageLite.h Wed Feb 3 01:51:28 2016 +@@ -89,8 +89,8 @@ class ByteStream; + separator ::= newline | + newline | separator + +- single_message ::= message_ID | +- message_ID parameters ++ single_message ::= CTRLC message_ID | ++ CTRLC message_ID parameters + + parameters ::= tab string | + tab string parameters Index: patches/patch-tools_djvused_cpp =================================================================== RCS file: patches/patch-tools_djvused_cpp diff -N patches/patch-tools_djvused_cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-tools_djvused_cpp 3 Feb 2016 01:53:18 -0000 @@ -0,0 +1,27 @@ +$OpenBSD$ + +"accept documents with duplicate page titles" + +http://sourceforge.net/p/djvu/djvulibre-git/ci/77a4dca8dd3acd0acc1680fa14a352c11084e25d/ +https://bitbucket.org/jwilk/pdf2djvu/issues/113/duplicate-page-title-1 + +--- tools/djvused.cpp.orig Sun Feb 8 20:39:42 2015 ++++ tools/djvused.cpp Wed Feb 3 01:51:28 2016 +@@ -66,6 +66,7 @@ + #include "GString.h" + #include "DjVuDocEditor.h" + #include "DjVuDumpHelper.h" ++#include "DjVuMessageLite.h" + #include "BSByteStream.h" + #include "DjVuText.h" + #include "DjVuAnno.h" +@@ -2315,7 +2316,8 @@ execute() + G_CATCH(ex) + { + vprint("Error (%s): %s", +- (const char*)ToNative(token), ex.get_cause()); ++ (const char*)ToNative(token), ++ (const char *)DjVuMessageLite::LookUpUTF8(ex.get_cause())); + if (! verbose) + G_RETHROW; + }