]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-outputter.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / paper-outputter.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 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 #include "lily-imports.hh"
41
42 using std::string;
43
44 Paper_outputter::Paper_outputter (SCM port, const string &format)
45 {
46   file_ = port;
47   output_module_ = SCM_EOL;
48   smobify_self ();
49
50   string module_name = "scm output-" + format;
51   output_module_ = scm_c_resolve_module (module_name.c_str ());
52
53   /*
54     Enable errors for undefined stencil routines if
55      -dwarning-as-error is specified; else enable warnings.
56   */
57   Lily::backend_testing (output_module_);
58 }
59
60 Paper_outputter::~Paper_outputter ()
61 {
62 }
63
64
65 SCM
66 Paper_outputter::mark_smob () const
67 {
68   scm_gc_mark (output_module_);
69   return file_;
70 }
71
72 SCM
73 Paper_outputter::file () const
74 {
75   return file_;
76 }
77
78 SCM
79 Paper_outputter::dump_string (SCM scm)
80 {
81   return scm_display (scm, file ());
82 }
83
84 SCM
85 Paper_outputter::scheme_to_string (SCM scm)
86 {
87   return scm_eval (scm, output_module_);
88 }
89
90 SCM
91 Paper_outputter::module () const
92 {
93   return output_module_;
94 }
95
96 SCM
97 Paper_outputter::output_scheme (SCM scm)
98 {
99   SCM str = scheme_to_string (scm);
100   if (scm_is_string (str))
101     dump_string (str);
102   return str;
103 }
104
105 SCM
106 paper_outputter_dump (void *po, SCM x)
107 {
108   Paper_outputter *me = (Paper_outputter *) po;
109   return me->output_scheme (x);
110 }
111
112 void
113 Paper_outputter::output_stencil (Stencil stil)
114 {
115   interpret_stencil_expression (stil.expr (), paper_outputter_dump,
116                                 (void *) this, Offset (0, 0));
117 }
118
119 void
120 Paper_outputter::close ()
121 {
122   if (ly_is_port (file_))
123     {
124       scm_close_port (file_);
125       /*
126         Remove the "warning" definitions for missing stencil
127         expressions so that we start fresh with the next \book
128         block.  --pmccarty
129       */
130       Lily::remove_stencil_warnings (output_module_);
131     }
132 }