]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-outputter.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / paper-outputter.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5   Jan Nieuwenhuizen <janneke@gnu.org>
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "paper-outputter.hh"
22
23 #include <cmath>
24 #include <ctime>
25
26 using namespace std;
27
28 #include "dimensions.hh"
29 #include "file-name.hh"
30 #include "font-metric.hh"
31 #include "input.hh"
32 #include "lily-version.hh"
33 #include "main.hh"
34 #include "output-def.hh"
35 #include "paper-book.hh"
36 #include "paper-system.hh"
37 #include "scm-hash.hh"
38 #include "string-convert.hh"
39 #include "warn.hh"
40
41 #include "ly-smobs.icc"
42
43 Paper_outputter::Paper_outputter (SCM port, const string &format)
44 {
45   file_ = port;
46   output_module_ = SCM_EOL;
47   smobify_self ();
48
49   string module_name = "scm output-" + format;
50   output_module_ = scm_c_resolve_module (module_name.c_str ());
51
52   /*
53     Enable errors for undefined stencil routines if
54      -dwarning-as-error is specified; else enable warnings.
55   */
56   SCM proc = ly_lily_module_constant ("backend-testing");
57   scm_call_1 (proc, output_module_);
58 }
59
60 Paper_outputter::~Paper_outputter ()
61 {
62 }
63
64 IMPLEMENT_SMOBS (Paper_outputter);
65 IMPLEMENT_DEFAULT_EQUAL_P (Paper_outputter);
66
67 SCM
68 Paper_outputter::mark_smob (SCM x)
69 {
70   Paper_outputter *p = (Paper_outputter *) SCM_CELL_WORD_1 (x);
71   scm_gc_mark (p->output_module_);
72   return p->file_;
73 }
74
75 int
76 Paper_outputter::print_smob (SCM /* x */,
77                              SCM p,
78                              scm_print_state *)
79 {
80   scm_puts ("#<Paper_outputter>", p);
81   return 1;
82 }
83
84 SCM
85 Paper_outputter::file () const
86 {
87   return file_;
88 }
89
90 SCM
91 Paper_outputter::dump_string (SCM scm)
92 {
93   return scm_display (scm, file ());
94 }
95
96 SCM
97 Paper_outputter::scheme_to_string (SCM scm)
98 {
99   return scm_eval (scm, output_module_);
100 }
101
102 SCM
103 Paper_outputter::module () const
104 {
105   return output_module_;
106 }
107
108 SCM
109 Paper_outputter::output_scheme (SCM scm)
110 {
111   SCM str = scheme_to_string (scm);
112   if (scm_is_string (str))
113     dump_string (str);
114   return str;
115 }
116
117 SCM
118 paper_outputter_dump (void *po, SCM x)
119 {
120   Paper_outputter *me = (Paper_outputter *) po;
121   return me->output_scheme (x);
122 }
123
124 void
125 Paper_outputter::output_stencil (Stencil stil)
126 {
127   interpret_stencil_expression (stil.expr (), paper_outputter_dump,
128                                 (void *) this, Offset (0, 0));
129 }
130
131 void
132 Paper_outputter::close ()
133 {
134   if (scm_port_p (file_) == SCM_BOOL_T)
135     {
136       scm_close_port (file_);
137       /*
138         Remove the "warning" definitions for missing stencil
139         expressions so that we start fresh with the next \book
140         block.  --pmccarty
141       */
142       SCM proc = ly_lily_module_constant ("remove-stencil-warnings");
143       scm_call_1 (proc, output_module_);
144     }
145 }