]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/paper-outputter.cc
parser.yy: give check_scheme_arg optional argument for error display
[lilypond.git] / lily / paper-outputter.cc
index 9e2b0978a6af3742b2754520dc6283401f30e793..57efb2fb35be2c547ab963c8ab0726ee62c296b0 100644 (file)
 /*
-  paper-outputter.cc -- implement Paper_outputter
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
-
-  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
   Jan Nieuwenhuizen <janneke@gnu.org>
+
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LilyPond is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <time.h>
 #include "paper-outputter.hh"
-#include "paper-stream.hh"
-#include "molecule.hh"
-#include "atom.hh"
-#include "array.hh"
-#include "string-convert.hh"
-#include "debug.hh"
-#include "lookup.hh"
+
+#include <cmath>
+#include <ctime>
+
+using namespace std;
+
+#include "dimensions.hh"
+#include "file-name.hh"
+#include "font-metric.hh"
+#include "input.hh"
+#include "lily-version.hh"
 #include "main.hh"
+#include "output-def.hh"
+#include "paper-book.hh"
+#include "paper-system.hh"
+#include "scm-hash.hh"
+#include "string-convert.hh"
+#include "warn.hh"
 
-Paper_outputter::Paper_outputter (Paper_stream *s)
+#include "ly-smobs.icc"
+
+Paper_outputter::Paper_outputter (SCM port, string format)
 {
-  outstream_l_ = s;
-  output_header ();
+  file_ = port;
+  output_module_ = SCM_EOL;
+  smobify_self ();
+
+  string module_name = "scm output-" + format;
+  output_module_ = scm_c_resolve_module (module_name.c_str ());
+
+  /*
+    Enable errors for undefined stencil routines if
+     -dwarning-as-error is specified; else enable warnings.
+  */
+  SCM proc = ly_lily_module_constant ("backend-testing");
+  scm_call_1 (proc, output_module_);
 }
 
 Paper_outputter::~Paper_outputter ()
 {
-  SCM scm =
-    ly_append (ly_lambda_o (),
-    ly_list1 (ly_append (ly_func_o ("end-output"), SCM_EOL)));
-
-  output_scheme (scm);
 }
 
-void
-Paper_outputter::output_header ()
-{
-  String creator;
-  if (no_timestamps_global_b)
-    creator = "GNU LilyPond\n";
-  else
-    creator = get_version_str ();
-  String generate;
-  if (no_timestamps_global_b)
-    generate = ".";
-  else
-    {
-      generate = _ (", at ");
-      time_t t (time (0));
-      generate += ctime (&t);
-      //urg
-    }
+IMPLEMENT_SMOBS (Paper_outputter);
+IMPLEMENT_DEFAULT_EQUAL_P (Paper_outputter);
 
-  SCM args_scm = 
-    gh_cons (gh_str02scm (creator.ch_l ()),
-    gh_cons (gh_str02scm (generate.ch_l ()), SCM_EOL));
-
-#ifndef NPRINT
-  DOUT << "output_header\n";
-  if (check_debug && !monitor->silent_b ("Guile"))
-    {
-      gh_display (args_scm); gh_newline ();
-    }
-#endif
-
-  SCM scm =
-    ly_append (ly_lambda_o (),
-    ly_list1 (ly_append (ly_func_o ("header"), args_scm)));
-
-  output_scheme (scm);
+SCM
+Paper_outputter::mark_smob (SCM x)
+{
+  Paper_outputter *p = (Paper_outputter *) SCM_CELL_WORD_1 (x);
+  scm_gc_mark (p->output_module_);
+  return p->file_;
 }
 
-void
-Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm)
+int
+Paper_outputter::print_smob (SCM /* x */,
+                             SCM p,
+                             scm_print_state *)
 {
-  if (check_debug)
-    *outstream_l_ << String ("\n%start: ") << nm << "\n";
-
-  for (PCursor <Atom*> i (m->atoms_); i.ok (); i++)
-    {
-      Offset a_off = i->offset ();
-      a_off += o;
-
-      if (!i->lambda_)
-        {
-         // urg
-         i->lambda_ = 
-           ly_append (ly_lambda_o (), 
-           ly_list1 (ly_func_o ("empty")));
-       }
-
-      switch_to_font (i->font_);
-
-#ifndef NPRINT
-      if (check_debug && !monitor->silent_b ("Guile"))
-       {
-         gh_display (i->lambda_); gh_newline ();
-       }
-#endif
-
-      SCM args_scm = 
-       gh_cons (gh_double2scm (a_off.x ()), 
-       gh_cons (gh_double2scm (a_off.y ()), 
-       gh_cons (i->lambda_, SCM_EOL)));
-
-#ifndef NPRINT
-      if (check_debug && !monitor->silent_b ("Guile"))
-       {
-         gh_display (args_scm); gh_newline ();
-       }
-#endif
-
-      SCM box_scm =
-       ly_append (ly_lambda_o (),
-       ly_list1 (ly_append (ly_func_o ("placebox"), args_scm)));
-
-      output_scheme (box_scm);
-    }
+  scm_puts ("#<Paper_outputter>", p);
+  return 1;
 }
 
-void
-Paper_outputter::output_comment (String str)
+SCM
+Paper_outputter::file () const
 {
-  // urg
-  *outstream_l_ << "% " << str << "\n";
+  return file_;
 }
 
-
-void
-Paper_outputter::output_scheme (SCM scm)
+SCM
+Paper_outputter::dump_string (SCM scm)
 {
-  String o = String ("\'") + output_global_ch;
-#ifndef NPRINT
-  if (check_debug && !monitor->silent_b ("Guile"))
-    {
-      gh_display (scm); gh_newline ();
-    }
-#endif
-  SCM str_scm = gh_call1 (ly_eval (scm), gh_eval_str (o.ch_l ()));
-  char* c = gh_scm2newstr (str_scm, NULL);
-#ifndef NPRINT
-  if (check_debug && !monitor->silent_b ("Guile"))
-    {
-      gh_display (str_scm); gh_newline ();
-    }
-#endif
-  *outstream_l_ << c;
-  free (c);
+  return scm_display (scm, file ());
 }
 
-void
-Paper_outputter::output_string (String str)
+SCM
+Paper_outputter::scheme_to_string (SCM scm)
 {
-  // urg
-  *outstream_l_ << str;
+  return scm_eval (scm, output_module_);
 }
 
-void
-Paper_outputter::switch_to_font (String fontname)
+SCM
+Paper_outputter::module () const
 {
-  if (fontname.length_i () && (fontname != current_font_))
-    {
-      current_font_ = fontname;
-      int i=0;
-      bool new_b = false;
-      for (; i< font_arr_.size (); i++)
-       if (font_arr_[i] == fontname)
-         {
-           new_b = true;
-           break;
-         }
-
-      if (new_b)
-       {
-         font_arr_.push (fontname);
-         output_font_def (i, fontname);
-       }
-      output_font_switch (i);
-    }
-  return;
+  return output_module_;
 }
 
 void
-Paper_outputter::start_line ()
+Paper_outputter::output_scheme (SCM scm)
 {
-  SCM scm =
-    ly_append (ly_lambda_o (),
-    ly_list1 (ly_append (ly_func_o ("start-line"), SCM_EOL)));
-
-  output_scheme (scm);
+  dump_string (scheme_to_string (scm));
 }
 
-/*
-   26 fonts ought to be enough for anyone.
-*/
 void
-Paper_outputter::output_font_def (int i, String str)
+paper_outputter_dump (void *po, SCM x)
 {
-  //urg, broken with guile-1.3
-  //return;
-  SCM scm =
-    ly_append (ly_lambda_o (),
-    ly_list1 (ly_append (ly_func_o ("font-def"), 
-    gh_cons (gh_int2scm (i), gh_cons (gh_str02scm (str.ch_l ()), SCM_EOL)))));
-
-  output_scheme (scm);
+  Paper_outputter *me = (Paper_outputter *) po;
+  me->output_scheme (x);
 }
 
 void
-Paper_outputter::output_font_switch (int i)
+Paper_outputter::output_stencil (Stencil stil)
 {
-  //urg, broken with guile-1.2, 1.3
-  //return;
-  SCM scm =
-    ly_append (ly_lambda_o (),
-    ly_list1 (ly_append (ly_func_o ("font-switch"), 
-    gh_cons (gh_int2scm (i), SCM_EOL))));
-
-  output_scheme (scm);
+  interpret_stencil_expression (stil.expr (), paper_outputter_dump,
+                                (void *) this, Offset (0, 0));
 }
 
 void
-Paper_outputter::stop_line ()
+Paper_outputter::close ()
 {
-  SCM scm =
-    ly_append (ly_lambda_o (),
-    ly_list1 (ly_append (ly_func_o ("stop-line"), SCM_EOL)));
-
-  output_scheme (scm);
-
-  current_font_ = "";
-  font_arr_.clear ();
+  if (scm_port_p (file_) == SCM_BOOL_T)
+    {
+      scm_close_port (file_);
+      /*
+        Remove the "warning" definitions for missing stencil
+        expressions so that we start fresh with the next \book
+        block.  --pmccarty
+      */
+      SCM proc = ly_lily_module_constant ("remove-stencil-warnings");
+      scm_call_1 (proc, output_module_);
+    }
 }