From 70dd774f11220425a3c32443e4ca22ac8d4dc03c Mon Sep 17 00:00:00 2001
From: janneke <janneke>
Date: Tue, 9 Mar 2004 22:35:48 +0000
Subject: [PATCH] * lily/score.cc (default_rendering): Protect paper-book
 members.

* lily/paper-def.cc (smobbed_copy): New method.
---
 ChangeLog                  |  4 ++++
 lily/include/paper-book.hh | 10 ++++++++++
 lily/include/paper-def.hh  | 27 ++++++++++++--------------
 lily/input-file-results.cc |  2 +-
 lily/lexer.ll              |  2 +-
 lily/paper-book.cc         | 39 +++++++++++++++++++++++++++++++++++---
 lily/paper-def.cc          |  6 ++++++
 lily/parser.yy             |  2 +-
 lily/score.cc              | 14 ++++++++++++--
 scm/output-ps.scm          |  1 +
 10 files changed, 84 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7fe6375e3a..244859490a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2004-03-09  Jan Nieuwenhuizen  <janneke@gnu.org>
 
+	* lily/score.cc (default_rendering): Protect paper-book members.
+
+	* lily/paper-def.cc (smobbed_copy): New method.
+
 	* lily/include/paper-book.hh (PAGE_LAYOUT): Define as "ps"; make
 	switch runtime.
 
diff --git a/lily/include/paper-book.hh b/lily/include/paper-book.hh
index 0a18454979..1f481c2dd4 100644
--- a/lily/include/paper-book.hh
+++ b/lily/include/paper-book.hh
@@ -12,13 +12,16 @@
 #include "lily-guile.hh"
 #include "parray.hh"
 #include "protected-scm.hh"
+#include "smobs.hh"
 
 #define PAGE_LAYOUT "ps"
 
 class Paper_book
 {
 public:
+  Protected_scm protect_;
   Array<SCM> headers_;
+  Array<SCM> global_headers_;
   Link_array<Paper_def> papers_;
   Array<SCM> scores_;
 
@@ -28,7 +31,14 @@ public:
   Stencil* get_title (int);
   void output (String);
   void classic_output (String);
+
+  SCM smobbed_copy () const;
+
+private:
+  DECLARE_SIMPLE_SMOBS (Paper_book, )
 };
 
+DECLARE_UNSMOB (Paper_book, paper_book)
+
 #endif /* PAPER_BOOK_HH */
 
diff --git a/lily/include/paper-def.hh b/lily/include/paper-def.hh
index aad477aaf4..06b9761e79 100644
--- a/lily/include/paper-def.hh
+++ b/lily/include/paper-def.hh
@@ -49,31 +49,28 @@ protected:
   VIRTUAL_COPY_CONSTRUCTOR (Music_output_def, Paper_def);
 
 public:    
-  Paper_outputter* get_paper_outputter (String)  const;
-
-  SCM font_descriptions ()const;
-  virtual ~Paper_def ();
   static int score_count_;
   
-  /*
-    JUNKME
-   */
-  Real get_realvar (SCM symbol) const;
-  void reinit ();
   Paper_def ();
   Paper_def (Paper_def const&);
-
+  virtual ~Paper_def ();
+  
+  Paper_outputter* get_paper_outputter (String) const;
+  SCM font_descriptions () const;
+  void reinit ();
   Interval line_dimensions_int (int) const;
-
   void output_settings (Paper_outputter*) const;
-
-  Font_metric * find_font (SCM name, Real mag);
+  Font_metric *find_font (SCM name, Real mag);
+  
+  /* JUNKME   */
+  Real get_realvar (SCM symbol) const;
+  
+  SCM smobbed_copy () const;
   
-  // urg
   friend int yyparse (void*);
 };
 
 Paper_def * unsmob_paper (SCM x);
 Font_metric *select_font (Paper_def *paper, SCM chain);
 
-#endif // Paper_def_HH
+#endif /* PAPER_DEF_HH */
diff --git a/lily/input-file-results.cc b/lily/input-file-results.cc
index 17a67cba57..05729cf669 100644
--- a/lily/input-file-results.cc
+++ b/lily/input-file-results.cc
@@ -123,7 +123,7 @@ Input_file_results::~Input_file_results ()
   if (header_)
     header_ = SCM_EOL;
 
-  global_input_file =0;
+  global_input_file = 0;
 
   ly_clear_anonymous_modules ();
 }
diff --git a/lily/lexer.ll b/lily/lexer.ll
index 70e62160f9..ea5ed739e4 100644
--- a/lily/lexer.ll
+++ b/lily/lexer.ll
@@ -230,7 +230,7 @@ HYPHEN		--
 	String s (YYText ()+1);
 	s = s.left_string (s.index_last ('"'));
 
-	new_input (s, &global_input_file->sources_ );
+	new_input (s, &global_input_file->sources_);
 	yy_pop_state ();
 }
 <incl>\\{BLACK}*;?{WHITE} { /* got the include identifier */
diff --git a/lily/paper-book.cc b/lily/paper-book.cc
index 0aa137a6b7..0394a1c3c9 100644
--- a/lily/paper-book.cc
+++ b/lily/paper-book.cc
@@ -8,7 +8,6 @@
 
 #include <stdio.h>
 
-#include "input-file-results.hh"
 #include "ly-module.hh"
 #include "main.hh"
 #include "paper-book.hh"
@@ -85,6 +84,7 @@ Paper_book *paper_book;
 
 Paper_book::Paper_book ()
 {
+  protect_ = SCM_EOL;
 }
 
 void
@@ -110,8 +110,8 @@ Paper_book::get_scopes (int i)
   SCM scopes = SCM_EOL;
   if (headers_[i])
     scopes = scm_cons (headers_[i], scopes);
-  if (global_input_file->header_ && global_input_file->header_ != headers_[i])
-    scopes = scm_cons (global_input_file->header_, scopes);
+  if (global_headers_[i] && global_headers_[i] != headers_[i])
+    scopes = scm_cons (global_headers_[i], scopes);
   return scopes;
 }
 
@@ -231,3 +231,36 @@ Paper_book::classic_output (String outname)
   out->output_scheme (scm_list_1 (ly_symbol2scm ("end-output")));
   progress_indication ("\n");
 }
+
+
+#include "ly-smobs.icc"
+
+IMPLEMENT_DEFAULT_EQUAL_P (Paper_book);
+IMPLEMENT_SIMPLE_SMOBS (Paper_book)
+IMPLEMENT_TYPE_P (Paper_book, "ly:paper_book?")
+
+SCM
+Paper_book::mark_smob (SCM)
+{
+  return SCM_EOL;
+}
+
+int
+Paper_book::print_smob (SCM smob, SCM port, scm_print_state*)
+{
+  Paper_book *b = (Paper_book*) ly_cdr (smob);
+     
+  scm_puts ("#<", port);
+  scm_puts (classname (b), port);
+  scm_puts (" ", port);
+  //scm_puts (b->, port);
+  scm_puts (">", port);
+  return 1;
+}
+
+SCM
+Paper_book::smobbed_copy () const
+{
+  Paper_book *b = new Paper_book (*this);
+  return b->smobbed_self ();
+}
diff --git a/lily/paper-def.cc b/lily/paper-def.cc
index 3d32542868..198cd00e6e 100644
--- a/lily/paper-def.cc
+++ b/lily/paper-def.cc
@@ -150,4 +150,10 @@ unsmob_paper (SCM x)
   return dynamic_cast<Paper_def*> (unsmob_music_output_def (x));
 }
 
+SCM
+Paper_def::smobbed_copy () const
+{
+  Paper_def *p = new Paper_def (*this);
+  return p->smobbed_self ();
+}
   
diff --git a/lily/parser.yy b/lily/parser.yy
index fed1f4469c..d60f1f6590 100644
--- a/lily/parser.yy
+++ b/lily/parser.yy
@@ -492,7 +492,7 @@ lilypond_header_body:
 
 lilypond_header:
 	HEADER '{' lilypond_header_body '}'	{
-		$$ = THIS->lexer_-> remove_scope ();
+		$$ = THIS->lexer_->remove_scope ();
 	}
 	;
 
diff --git a/lily/score.cc b/lily/score.cc
index a83573b7b2..089d4b5df1 100644
--- a/lily/score.cc
+++ b/lily/score.cc
@@ -24,6 +24,7 @@
 #include "ly-module.hh"
 #include "paper-book.hh"
 #include "paper-score.hh"
+#include "input-file-results.hh"
 
 
 /*
@@ -174,10 +175,19 @@ default_rendering (SCM music, SCM outdef, SCM header, SCM outname)
       Music_output *output = g->get_output ();
       if (systems != SCM_UNDEFINED)
 	{
-	  paper_book->scores_.push (systems);
-	  paper_book->headers_.push (header);
 	  Paper_score *ps = dynamic_cast<Paper_score*> (output);
+	  // Hmmr
+	  paper_book->protect_ = scm_cons (systems, paper_book->protect_);
+	  paper_book->protect_ = scm_cons (global_input_file->header_,
+					   paper_book->protect_);
+	  paper_book->protect_ = scm_cons (header, paper_book->protect_);
+	  paper_book->protect_ = scm_cons (ps->paper_->smobbed_copy (),
+					   paper_book->protect_);
+
 	  paper_book->papers_.push (ps->paper_);
+	  paper_book->scores_.push (systems);
+	  paper_book->global_headers_.push (global_input_file->header_);
+	  paper_book->headers_.push (header);
 	  if (output_format_global != PAGE_LAYOUT)
 	    paper_book->classic_output (ly_scm2string (outname));
 	}
diff --git a/scm/output-ps.scm b/scm/output-ps.scm
index 7553e2f1de..ffc971cc8f 100644
--- a/scm/output-ps.scm
+++ b/scm/output-ps.scm
@@ -267,6 +267,7 @@
 	  (begin
 	    (ly:warn
 	     (format "Programming error: No such font: ~S" name-mag-pair))
+	    (write font-name-alist)
 	    ""))))
   
   (string-append (select-font name-mag-pair) exp))
-- 
2.39.5