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 "dictionary-iter.hh"
17 #include "virtual-methods.hh"
18 #include "paper-outputter.hh"
19 #include "paper-stream.hh"
20 #include "molecule.hh"
22 #include "string-convert.hh"
27 #include "identifier.hh"
28 #include "lily-version.hh"
35 Paper_outputter::Paper_outputter ()
37 molecules_ = gh_cons (SCM_EOL, SCM_EOL);
38 last_cons_ = molecules_;
43 Paper_outputter::output_header ()
47 gh_define ("security-paranoia", SCM_BOOL_T);
50 SCM exp = gh_list (ly_symbol2scm ((String (output_global_ch) + "-scm").ch_C()),
51 ly_quote_scm (ly_symbol2scm ("all-definitions")),
57 if (no_timestamps_global_b)
58 creator = gnu_lilypond_str ();
60 creator = gnu_lilypond_version_str ();
63 if (no_timestamps_global_b)
67 generate = _ (", at ");
69 generate += ctime (&t);
70 generate = generate.left_str (generate.length_i () - 1);
74 gh_list (ly_str02scm (creator.ch_l ()),
75 ly_str02scm (generate.ch_l ()), SCM_UNDEFINED);
78 SCM scm = gh_cons (ly_symbol2scm ("header"), args_scm);
85 Paper_outputter::output_comment (String str)
87 output_scheme (gh_list (ly_symbol2scm ("comment"),
88 ly_str02scm ((char*)str.ch_C()),
95 Paper_outputter::output_scheme (SCM scm)
97 SCM c = gh_cons (scm,gh_cdr (last_cons_));
98 gh_set_cdr_x(last_cons_, c);
104 Paper_outputter::dump_onto (Paper_stream *ps)
106 if (String (output_global_ch) == "scm")
107 #if 1 // both are fine
113 if (ofstream* of = dynamic_cast<ofstream*> (ps->os))
114 fd = of->rdbuf ()->fd ();
115 SCM port = scm_fdes_to_port (fd, "a", SCM_EOL);
121 scm_display (gh_str02scm (
122 ";;; Usage: guile -s x.scm > x.tex\n"
123 "(primitive-load-path 'lily.scm)\n"
125 ";(scm-tex-output)\n"
127 "(map (lambda (x) (display (eval x))) '(\n"
130 SCM newline = gh_str02scm ("\n");
131 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
133 scm_write (gh_car (s), port);
134 scm_display (newline, port);
137 scm_display (gh_str02scm ("))"), port);
138 scm_display (newline, port);
140 scm_close_port (port);
148 if (output_global_ch == String ("scm"))
150 ";;; Usage: guile -s x.scm > x.tex\n"
151 "(primitive-load-path 'lily.scm)\n"
154 "(map (lambda (x) (display (eval x))) '(\n"
156 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
158 SCM result = scm_eval (scm_listify (ly_symbol2scm ("scm->string"),
159 ly_quote_scm (gh_car (s)), SCM_UNDEFINED));
161 *ps << ly_scm2string (result);
169 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
171 SCM result = scm_eval (gh_car (s));
172 char *c=gh_scm2newstr (result, NULL);
181 Paper_outputter::output_scope (Scope *scope, String prefix)
183 for (Scope_iter i (*scope); i.ok (); i++)
185 if (dynamic_cast<String_identifier*> (i.val ()))
187 String val = *i.val()->access_content_String (false);
189 output_String_def (prefix + i.key (), val);
191 else if(dynamic_cast<Real_identifier*> (i.val ()))
193 Real val = *i.val ()->access_content_Real (false);
195 output_Real_def (prefix + i.key (), val);
197 else if (dynamic_cast<int_identifier*> (i.val ()))
199 int val = *i.val ()->access_content_int (false);
201 output_int_def (prefix + i.key (), val);
207 Paper_outputter::output_version ()
209 String id_str = "Lily was here";
210 if (no_timestamps_global_b)
213 id_str += String (", ") + version_str ();
215 output_String_def ( "mudelatagline", id_str);
216 output_String_def ( "LilyPondVersion", version_str ());
222 Paper_outputter::output_font_def (int i, String str)
224 SCM scm = gh_list (ly_symbol2scm ("font-def"),
226 ly_str02scm (str.ch_l ()),
233 Paper_outputter::output_Real_def (String k, Real v)
236 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
237 ly_str02scm (k.ch_l ()),
238 ly_str02scm (to_str(v).ch_l ()),
242 // gh_define (k.ch_l (), gh_double2scm (v));
246 Paper_outputter::output_String_def (String k, String v)
249 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
250 ly_str02scm (k.ch_l ()),
251 ly_str02scm (v.ch_l ()),
255 // gh_define (k.ch_l (), ly_str02scm (v.ch_l ()));
259 Paper_outputter::output_int_def (String k, int v)
261 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
262 ly_str02scm (k.ch_l ()),
263 ly_str02scm (to_str (v).ch_l ()),
267 // gh_define (k.ch_l (), gh_int2scm (v));