Description: update from stretch toward buster
 Upstream develops the book on a Debian stable platform, which now
 is Debian 9 stretch.  Upstream therefore supplies the book's source as
 packaged for Debian stable.  The present patch updates the source for
 building on Debian sid and for packaging on sid toward buster.
 .
 It is expected that upstream will incorporate the patch after buster
 is stable.
 .
   * Reconfigured and rebuilt for upload to Debian sid.
   * Conformed btool/ to sid's Poppler, version 0.69 (closes: #884476).
     Required at least this version of Poppler to build.
Author: Thaddeus H. Black <thb@debian.org>
Bug-Debian: https://bugs.debian.org/884476
Forwarded: not-needed
Last-Update: 2019-01-05

--- derivations-0.56.20180123.1.orig/btool/PDF/PDF.cc
+++ derivations-0.56.20180123.1/btool/PDF/PDF.cc
@@ -181,14 +181,12 @@ PDF::PDF::PDF( const std::string &filena
     rep->trailer = obj->getDict();
   }
   {
-    Object obj;
-    { char s[] = "Size"; rep->trailer->lookup( s, &obj ); }
+    Object obj = rep->trailer->lookup( "Size", 0 );
     if ( !obj.isInt() ) throw Exc_PDF();
     rep->n_obj1 = obj.getInt();
   }
   {
-    rep->catalog_obj = new Object();
-    rep->xref->getCatalog( rep->catalog_obj );
+    rep->catalog_obj = new Object( rep->xref->getCatalog() );
     if ( !rep->catalog_obj->isDict() ) throw Exc_PDF();
     rep->catalog = rep->catalog_obj->getDict();
   }
@@ -197,18 +195,14 @@ PDF::PDF::PDF( const std::string &filena
     if ( !rep->catalog2->isOk() ) throw Exc_PDF();
   }
   {
-    Object obj;
-    { char s[] = "Info"; rep->trailer->lookupNF( s, &obj ); }
+    Object obj( rep->trailer->lookupNF( "Info"  ) );
     if ( !obj.isRef() ) throw Exc_PDF();
     const Ref ref = obj.getRef();
     rep->info_iref = Iref( ref.num, ref.gen );
   }
   {
-    rep->info_obj = new Object();
-    rep->xref->fetch(
-      rep->info_iref.i,
-      rep->info_iref.gen,
-      rep->info_obj
+    rep->info_obj = new Object(
+      rep->xref->fetch( rep->info_iref.i, rep->info_iref.gen, 0 )
     );
     if ( !rep->info_obj->isDict() ) throw Exc_PDF();
     rep->info = rep->info_obj->getDict();
--- derivations-0.56.20180123.1.orig/btool/PDF/README
+++ derivations-0.56.20180123.1/btool/PDF/README
@@ -1,3 +1,42 @@
 
 Here are source files to interpret and modify PDF.
 
+In Jan. 2019, with Debian buster then in a late
+prerelease stage of development, update_catalog.cc
+and PDF.cc were minimally but still fairly extensively
+revised to track libpoppler-private-dev, version 0.69.
+The combination of [a] layered revisions over
+decades (during which standard C++ has significantly
+advanced) to track an advertisedly unstable
+private Poppler API and [b] Thaddeus H. Black's once
+immature C++ coding style (for this code was one of the
+projects by which Thaddeus first learned C++) leaves
+the code in an interesting state, doesn't it?
+Realistically, the code will probably never be cleaned
+up.  It works.
+
+Compared against version 0.48 of
+libpoppler-private-dev (issued with Debian stretch),
+version 0.69 handles its Object type differently,
+inverting the Object's manner of association to types
+like Dict.  This seems to represent an improvement but
+of course such improvements will break code like the
+present code that relies upon them.  For better or
+worse, one suspects that more such breaking changes
+will come.  For one, types like Dict might be made to
+inherit from Object (will they?  unknown, but they
+might).  Derivations shall have to keep up.
+
+In case Poppler's developers or package maintainers
+read this, Thaddeus' view is that breaking changes of
+the aforementioned kind are right, though Thaddeus does
+not particularly enjoy tracking them!  At some future
+date, it would be nice if the private Poppler API would
+stabilize (presumably then becoming nonprivate), but
+Poppler probably wants more development before
+that occurs.  Poppler is useful software, devs.  Keep
+working on it.
+
+For information, it appears that the code in the
+present directory was first introduced in Sept. 2007.
+
--- derivations-0.56.20180123.1.orig/btool/PDF/update_catalog.cc
+++ derivations-0.56.20180123.1/btool/PDF/update_catalog.cc
@@ -1,5 +1,6 @@
 
 #include "update_catalog.h"
+#include <utility>
 #include <set>
 #include <string>
 #include <sstream>
@@ -11,6 +12,7 @@
 #include "PDF.h"
 #include "PDF_rep.h"
 
+using std::move;
 using std::string;
 typedef std::set<string> set;
 const int magic = 0x9f05; // deprecated
@@ -19,6 +21,40 @@ const int magic = 0x9f05; // deprecated
 // feed it.  In an earlier Libpoppler, didn't it used to?  Maybe not; I can't
 // clearly remember.  In any case, letting the key-string go out of scope now
 // invalidates the Dict.  ---THB, March 2010---
+//
+// Well, Poppler's hardly documented private API has changed again.
+//
+// I do not critcize, of course.  On the contrary, one appreciates Poppler's
+// continued development, nor would now (nor maybe ever) seem a good time for
+// Poppler's developers to document the private API in question.  Premature
+// stabilization of an API can cause much trouble, after all.  If and when the
+// time comes to stabilize and to document, they'll know.  Meanwhile, for me at
+// least, access to Poppler's source suffices, yet the observation that little
+// private-API documentation exists remains an observation of fact as far
+// as I know.  The fact, or at any rate the observation, incidentally affects
+// the present program as follows.
+//
+// I am unlikely to relearn Poppler's latest pattern of memory allocation with
+// each version-0.* Poppler release.  Maybe when 1.0 arrives?  Maybe never.
+// Meanwhile, I am letting the program leak some memory.  For a program of this
+// kind, whose execution time is short and resource needs are modest, such
+// leaking probably has no practical effect, for of course the kernel
+// automatically reclaims all leaked memory as soon as the program exits.
+// Still, on principle, leaking is not neat, is it?
+//
+// Where you see below a construct like
+//
+//     Dict &dict = *( new Dict( static_cast<XRef*>(0) ) );
+//
+// the construct's purpose is to delay or prevent a destructor of Poppler's.
+// As far as I know, this is wrong, or is at any rate a workaround, but insofar
+// as I am unlikely to relearn Poppler's latest pattern of memory allocation
+// with each version-0.* Poppler release, especially while Poppler's
+// private API (understandably) remains so little documented, why, such a
+// construct does what the present program needs it
+// to do.  ---THB, Jan. 2019---
+//
+//
 
 namespace {
 
@@ -33,11 +69,9 @@ namespace {
   ) {
     const int size = src->getLength();
     for ( int i = 0; i < size; ++i ) {
-      char *const key = src->getKey(i);
+      const char *const key = src->getKey(i);
       if ( keys.count(key) ) continue;
-      Object obj;
-      src ->getValNF( i  , &obj );
-      dest->add     ( key, &obj );
+      dest->add( key, Object( src->getValNF( i ) ) );
     }
     return size;
   }
@@ -54,65 +88,33 @@ string PDF::update_catalog(
   // To understand this code, refer to the Libpoppler headers and
   // to Adobe's PDF Reference 1.7, sect. 8.3.1.
 
-  Object catalog_obj;
-  catalog_obj.initDict(static_cast<XRef*>(0));
-  Dict *catalog = catalog_obj.getDict();
+  Dict &catalog = *( new Dict ( static_cast<XRef*>(0) ) );
   {
     set keys;
     { char s[] = "PageLabels"; keys.insert(s); }
     { char s[] = "Outlines"  ; keys.insert(s); }
-    copy_but( catalog, rep->catalog, keys );
+    copy_but( &catalog, rep->catalog, keys );
   }
 
-  Object dict_Roman_obj;
-  char s_Roman[] = "S";
-  {
-    dict_Roman_obj.initDict(static_cast<XRef*>(0));
-    Dict *const dict_Roman = dict_Roman_obj.getDict();
-    Object name_Roman;
-    { char s[] = "r"; name_Roman.initName(s); }
-    dict_Roman->add( s_Roman, &name_Roman );
-  }
+  Dict &dict_Roman = *( new Dict( static_cast<XRef*>(0) ) );
+  dict_Roman.add( "S", Object( objName, "r" ) );
 
-  Object dict_Arabic_obj;
-  char s_Arabic[] = "S";
-  {
-    dict_Arabic_obj.initDict(static_cast<XRef*>(0));
-    Dict *const dict_Arabic = dict_Arabic_obj.getDict();
-    Object name_Arabic;
-    { char s[] = "D"; name_Arabic.initName(s); }
-    dict_Arabic->add( s_Arabic, &name_Arabic );
-  }
+  Dict &dict_Arabic = *( new Dict( ( static_cast<XRef*>(0) ) ) );
+  dict_Arabic.add( "S", Object( objName, "D" ) );
 
-  Object array_obj;
-  {
-    Object zero;
-    zero.initInt( 0 );
-    Object n_page;
-    n_page.initInt( nog.count_prefatory_page() );
-    array_obj.initArray(static_cast<XRef*>(0));
-    Array *const array = array_obj.getArray();
-    array->add( &zero            );
-    array->add( &dict_Roman_obj  );
-    array->add( &n_page          );
-    array->add( &dict_Arabic_obj );
-  }
+  Array &array = *( new Array( static_cast<XRef*>(0) ) );
+  array.add( Object( 0                          ) );
+  array.add( Object( &dict_Roman                ) );
+  array.add( Object( nog.count_prefatory_page() ) );
+  array.add( Object( &dict_Arabic               ) );
 
-  Object dict_obj;
-  char s_Nums[] = "Nums";
-  {
-    dict_obj.initDict(static_cast<XRef*>(0));
-    Dict *const dict = dict_obj.getDict();
-    dict->add( s_Nums, &array_obj );
-  }
+  Dict &dict = *( new Dict( static_cast<XRef*>(0) ) );
+  dict.add( "Nums", Object( &array ) );
 
-  Object ref_obj;
-  ref_obj.initRef( n_obj(pdf), 0 );
+  Object ref( n_obj(pdf), 0 );
 
-  char s_PageLabels[] = "PageLabels";
-  char s_Outlines  [] = "Outlines"  ;
-  catalog->add( s_PageLabels, &dict_obj );
-  catalog->add( s_Outlines  , &ref_obj  );
+  catalog.add( "PageLabels", Object(&dict) );
+  catalog.add( "Outlines"  , move(ref)     );
 
   string res;
   {
@@ -125,6 +127,7 @@ string PDF::update_catalog(
   }
 
   // Do print() to a string rather than to stdout or a file.
+  Object catalog_obj( &catalog );
   {
     int fd[2];
     pipe(fd);
@@ -154,25 +157,19 @@ string PDF::add_title_to_info(
 
   PDF_rep *const rep = pdf.get_PDF_rep(magic);
 
-  Object info_obj;
-  info_obj.initDict(static_cast<XRef*>(0));
-  Dict *info = info_obj.getDict();
+  Dict &info = *( new Dict( static_cast<XRef*>(0) ) );
   {
     set keys;
-    copy_but( info, rep->info, keys );
+    copy_but( &info, rep->info, keys );
   }
 
-  char s_Title[] = "Title";
+  GooString &gs = *( new GooString );
+  const char s_Title[] = "Title";
   {
-    Object obj_old;
-    info->lookup( s_Title, &obj_old );
+    Object &obj_old = *( new Object( info.lookup( s_Title, 0 ) ) );
     if ( obj_old.isNull() ) {
-      Object obj_new;
-      {
-        GooString &gs = *( new GooString( title.c_str() ) );
-        obj_new.initString( &gs );
-      }
-      info->add( s_Title, &obj_new );
+      gs.Set( title.c_str() );
+      info.add( s_Title, Object( &gs ) );
     }
   }
 
@@ -187,6 +184,7 @@ string PDF::add_title_to_info(
   }
 
   // Do print() to a string rather than to stdout or a file.
+  Object info_obj( &info );
   {
     int fd[2];
     pipe(fd);
@@ -221,34 +219,22 @@ string PDF::update_trailer(
   // To understand this code, refer to the Libpoppler headers and
   // to Adobe's PDF Reference 1.7, sect. 3.4.4.
 
-  Object new_trailer_obj;
-  new_trailer_obj.initDict(static_cast<XRef*>(0));
-  Dict *new_trailer = new_trailer_obj.getDict();
+  Dict &new_trailer = *( new Dict( static_cast<XRef*>(0) ) );
   {
     set keys;
     { char s[] = "Size"; keys.insert(s); }
     { char s[] = "Prev"; keys.insert(s); }
     { char s[] = "ID"  ; keys.insert(s); }
-    copy_but( new_trailer, rep->trailer, keys );
-  }
-
-  char s_Size[] = "Size";
-  {
-    Object obj;
-    obj.initInt( n_pdf_obj );
-    new_trailer->add( s_Size, &obj );
+    copy_but( &new_trailer, rep->trailer, keys );
   }
 
-  char s_Prev[] = "Prev";
-  {
-    Object obj;
-    obj.initInt( offset_last_xref_table(pdf_filename) );
-    new_trailer->add( s_Prev, &obj );
-  }
+  new_trailer.add( "Size", Object( n_pdf_obj ) );
+  new_trailer.add( "Prev", Object( offset_last_xref_table(pdf_filename) ) );
 
   string res = "trailer\n";
 
   // Do print() to a string rather than to stdout or a file.
+  Object new_trailer_obj( &new_trailer );
   {
     int fd[2];
     pipe(fd);
--- derivations-0.56.20180123.1.orig/btool/fill-toc-ends
+++ derivations-0.56.20180123.1/btool/fill-toc-ends
@@ -25,7 +25,7 @@ function toc_line {
 }
 
 toc_line Contents
-cat $OLDTOC
+sed -re 's/%?[[:space:]]*$//' $OLDTOC
 toc_line Bibliography
 toc_line Index
 
