2 paper-outputter.cc -- implement Paper_outputter
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
15 #include "dimensions.hh"
16 #include "virtual-methods.hh"
17 #include "paper-outputter.hh"
18 #include "paper-stream.hh"
19 #include "molecule.hh"
21 #include "string-convert.hh"
23 #include "font-metric.hh"
26 #include "identifier.hh"
27 #include "lily-version.hh"
34 Paper_outputter::Paper_outputter (Paper_stream * ps )
40 verbatim_scheme_b_ = output_global_ch == String ("scm");
42 if (verbatim_scheme_b_)
45 ";;; Usage: guile -s x.scm > x.tex\n"
46 "(primitive-load-path 'lily.scm)\n"
49 "(map (lambda (x) (display (eval x))) '(\n"
56 Paper_outputter::~Paper_outputter ()
58 if (verbatim_scheme_b_)
67 Paper_outputter::output_header ()
71 gh_define ("security-paranoia", SCM_BOOL_T);
74 SCM exp = gh_list (ly_symbol2scm ((String (output_global_ch) + "-scm").ch_C()),
75 ly_quote_scm (ly_symbol2scm ("all-definitions")),
77 exp = scm_eval2 (exp, SCM_EOL);
78 scm_eval2 (exp, SCM_EOL);
81 if (no_timestamps_global_b)
82 creator = gnu_lilypond_str ();
84 creator = gnu_lilypond_version_str ();
87 if (no_timestamps_global_b)
91 generate = _ (", at ");
93 generate += ctime (&t);
94 generate = generate.left_str (generate.length_i () - 1);
98 gh_list (ly_str02scm (creator.ch_l ()),
99 ly_str02scm (generate.ch_l ()), SCM_UNDEFINED);
102 SCM scm = gh_cons (ly_symbol2scm ("header"), args_scm);
109 Paper_outputter::output_comment (String str)
111 output_scheme (gh_list (ly_symbol2scm ("comment"),
112 ly_str02scm ((char*)str.ch_C()),
119 Paper_outputter::output_scheme (SCM scm)
122 we don't rename dump_scheme, because we might in the future want
123 to remember Scheme. We don't now, because it sucks up a lot of memory.
132 Should probably change interface to do less eval ( symbol ), and more
133 apply (procedure, args)
136 Paper_outputter::dump_scheme (SCM s)
138 if (verbatim_scheme_b_)
142 p = scm_mkstrport (SCM_INUM0,
143 scm_make_string (SCM_INUM0, SCM_UNDEFINED),
145 "Paper_outputter::dump_scheme()");
147 SCM wr =scm_eval2 (ly_symbol2scm ("write"), SCM_EOL);
148 scm_apply (wr, s, gh_list (p, SCM_UNDEFINED));
150 SCM result = scm_strport_to_string (p);
151 *stream_p_ << ly_scm2string (result);
155 SCM result = scm_eval2 (s, SCM_EOL);
156 char *c=gh_scm2newstr (result, NULL);
163 Paper_outputter::output_scope (Scope *scope, String prefix)
165 SCM al = scope->to_alist ();
166 for (SCM s = al ; gh_pair_p (s); s = gh_cdr (s))
170 String s = ly_symbol2string (k);
175 output_String_def (prefix + s, ly_scm2string (v));
177 else if (scm_integer_p (v) == SCM_BOOL_T)
179 output_int_def (prefix + s, gh_scm2int (v));
181 else if (gh_number_p (v))
183 output_Real_def (prefix + s, gh_scm2double (v));
189 Paper_outputter::output_version ()
191 String id_str = "Lily was here";
192 if (no_timestamps_global_b)
195 id_str += String (", ") + version_str ();
197 output_String_def ( "lilypondtagline", id_str);
198 output_String_def ( "LilyPondVersion", version_str ());
205 Paper_outputter::output_Real_def (String k, Real v)
208 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
209 ly_str02scm (k.ch_l ()),
210 ly_str02scm (to_str(v).ch_l ()),
216 Paper_outputter::output_String_def (String k, String v)
219 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
220 ly_str02scm (k.ch_l ()),
221 ly_str02scm (v.ch_l ()),
227 Paper_outputter::output_int_def (String k, int v)
229 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
230 ly_str02scm (k.ch_l ()),
231 ly_str02scm (to_str (v).ch_l ()),
239 Paper_outputter::output_string (SCM str)
241 *stream_p_ << ly_scm2string (str);