]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/paper-outputter.cc
* lily/lily-parser.cc (LY_DEFINE): Remove "Now " from message.
[lilypond.git] / lily / paper-outputter.cc
index 7affc64bb41f0be58cdca4c0aa2c974fa128fb4f..0a28aa242eceb5cbb1afca6ba81c8d463006999c 100644 (file)
 
 #include "array.hh"
 #include "dimensions.hh"
+#include "file-name.hh"
 #include "font-metric.hh"
 #include "input-smob.hh"
 #include "lily-guile.hh"
 #include "lily-version.hh"
 #include "ly-module.hh"
 #include "main.hh"
-#include "page.hh"
-#include "paper-book.hh"
 #include "output-def.hh"
-#include "paper-line.hh"
+#include "paper-book.hh"
 #include "paper-outputter.hh"
-#include "file-name.hh"
+#include "paper-system.hh"
 #include "scm-hash.hh"
 #include "stencil.hh"
 #include "string-convert.hh"
 #include "warn.hh"
 
-// JUNKME
-extern SCM stencil2line (Stencil *stil, bool is_title = false);
+#include "ly-smobs.icc"
+
 
 Paper_outputter::Paper_outputter (String filename, String format)
 {
@@ -39,9 +38,6 @@ Paper_outputter::Paper_outputter (String filename, String format)
   smobify_self ();
   
   filename_ = filename;
-  file_ = scm_open_file (scm_makfrom0str (filename.to_str0 ()),
-                        scm_makfrom0str ("w"));
-
   String module_name = "scm output-" + format;
   output_module_ = scm_c_resolve_module (module_name.to_str0 ());
 }
@@ -50,7 +46,6 @@ Paper_outputter::~Paper_outputter ()
 {
 }
 
-#include "ly-smobs.icc"
 
 IMPLEMENT_SMOBS (Paper_outputter);
 IMPLEMENT_DEFAULT_EQUAL_P (Paper_outputter);
@@ -66,14 +61,27 @@ Paper_outputter::mark_smob (SCM x)
 int
 Paper_outputter::print_smob (SCM x, SCM p, scm_print_state*)
 {
+  (void) x;
   scm_puts ("#<Paper_outputter>", p);
   return 1;
 }
 
+SCM
+Paper_outputter::file ()
+{
+  if (file_ == SCM_EOL)
+    if (filename_ == "-")
+      file_ = scm_current_output_port();
+    else
+      file_ = scm_open_file (scm_makfrom0str (filename_.to_str0 ()),
+                            scm_makfrom0str ("w"));
+  return file_;
+}
+
 SCM
 Paper_outputter::dump_string (SCM scm)
 {
-  return scm_display (scm, file_);
+  return scm_display (scm, file ());
 }
 
 SCM
@@ -99,16 +107,16 @@ void
 Paper_outputter::output_stencil (Stencil stil)
 {
   interpret_stencil_expression (stil.expr (), paper_outputter_dump,
-                               (void*) this, Offset (0,0));
+                                (void*) this, Offset (0,0));
 }
 
 Paper_outputter *
 get_paper_outputter (String outname, String f) 
 {
-  progress_indication (_f ("paper output to `%s'...",
+  progress_indication (_f ("Layout output to `%s'...",
                           outname == "-" ? String ("<stdout>") : outname));
+  progress_indication ("\n");
   return new Paper_outputter (outname, f);
-
 }
 
 /* FIXME: why is output_* wrapper called dump?  */
@@ -116,14 +124,11 @@ LY_DEFINE (ly_outputter_dump_stencil, "ly:outputter-dump-stencil",
           2, 0, 0, (SCM outputter, SCM stencil),
           "Dump stencil @var{expr} onto @var{outputter}.")
 {
-  Paper_outputter *po = unsmob_outputter  (outputter);
+  Paper_outputter *po = unsmob_outputter (outputter);
   Stencil *st = unsmob_stencil (stencil);
-  
   SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter");
   SCM_ASSERT_TYPE (st, stencil, SCM_ARG1, __FUNCTION__, "Paper_outputter");
-
   po->output_stencil (*st);
-
   return SCM_UNSPECIFIED;
 }
 
@@ -131,9 +136,15 @@ LY_DEFINE (ly_outputter_dump_string, "ly:outputter-dump-string",
           2, 0, 0, (SCM outputter, SCM str),
           "Dump @var{str} onto @var{outputter}.")
 {
-  Paper_outputter *po = unsmob_outputter  (outputter);
+  Paper_outputter *po = unsmob_outputter (outputter);
   SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter");
-  SCM_ASSERT_TYPE (ly_c_string_p (str), str, SCM_ARG1, __FUNCTION__, "Paper_outputter");
+  SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, __FUNCTION__, "Paper_outputter");
   
   return po->dump_string (str);
 }
+
+void
+Paper_outputter::close ()
+{
+  scm_close_port (file_);
+}