2 paper-outputter.cc -- implement Paper_outputter
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 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"
27 #include "lily-version.hh"
28 #include "paper-def.hh"
29 #include "file-results.hh"
36 Paper_outputter::Paper_outputter (String name)
38 stream_p_ = new Paper_stream (name);
44 verbatim_scheme_b_ = output_format_global == "scm";
46 if (verbatim_scheme_b_)
49 ";;; Usage: guile -s x.scm > x.tex\n"
50 " (primitive-load-path 'standalone.scm)\n"
51 "; (scm-tex-output)\n"
53 " (map (lambda (x) (display (ly-eval x))) ' (\n"
59 Paper_outputter::~Paper_outputter ()
61 if (verbatim_scheme_b_)
70 Paper_outputter::output_header ()
74 gh_define ("security-paranoia", SCM_BOOL_T);
77 SCM exp = gh_list (ly_symbol2scm ((output_format_global + "-scm").ch_C ()),
78 ly_quote_scm (ly_symbol2scm ("all-definitions")),
80 exp = scm_eval2 (exp, SCM_EOL);
81 scm_eval2 (exp, SCM_EOL);
84 if (no_timestamps_global_b)
85 creator = gnu_lilypond_str ();
87 creator = gnu_lilypond_version_str ();
90 if (no_timestamps_global_b)
94 generate = _ (", at ");
96 generate += ctime (&t);
97 generate = generate.left_str (generate.length_i () - 1);
101 Make fixed length time stamps
103 generate = generate + to_str (' ' * (120 - generate.length_i ())>? 0) ;
106 gh_list (ly_str02scm (creator.ch_l ()),
107 ly_str02scm (generate.ch_l ()), SCM_UNDEFINED);
110 SCM scm = gh_cons (ly_symbol2scm ("header"), args_scm);
117 Paper_outputter::output_comment (String str)
119 output_scheme (gh_list (ly_symbol2scm ("comment"),
120 ly_str02scm ((char*)str.ch_C ()),
127 Paper_outputter::output_scheme (SCM scm)
130 we don't rename dump_scheme, because we might in the future want
131 to remember Scheme. We don't now, because it sucks up a lot of memory.
140 Should probably change interface to do less eval (symbol), and more
141 apply (procedure, args)
144 Paper_outputter::dump_scheme (SCM s)
146 if (verbatim_scheme_b_)
148 *stream_p_ << ly_scm2string (ly_write2scm (s));
152 SCM result = scm_eval2 (s, SCM_EOL);
153 char *c=gh_scm2newstr (result, NULL);
161 Paper_outputter::output_scope (Scope *scope, String prefix)
163 SCM al = scope->to_alist ();
164 for (SCM s = al ; gh_pair_p (s); s = gh_cdr (s))
168 String s = ly_symbol2string (k);
173 output_String_def (prefix + s, ly_scm2string (v));
175 else if (scm_integer_p (v) == SCM_BOOL_T)
177 output_int_def (prefix + s, gh_scm2int (v));
179 else if (gh_number_p (v))
181 output_Real_def (prefix + s, gh_scm2double (v));
187 Paper_outputter::output_version ()
189 String id_str = "Lily was here";
190 if (no_timestamps_global_b)
193 id_str += String (", ") + version_str ();
195 output_String_def ("lilypondtagline", id_str);
196 output_String_def ("LilyPondVersion", version_str ());
203 Paper_outputter::output_Real_def (String k, Real v)
206 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
207 ly_str02scm (k.ch_l ()),
208 ly_str02scm (to_str (v).ch_l ()),
214 Paper_outputter::output_String_def (String k, String v)
217 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
218 ly_str02scm (k.ch_l ()),
219 ly_str02scm (v.ch_l ()),
225 Paper_outputter::output_int_def (String k, int v)
227 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
228 ly_str02scm (k.ch_l ()),
229 ly_str02scm (to_str (v).ch_l ()),
235 Paper_outputter::output_string (SCM str)
237 *stream_p_ << ly_scm2string (str);
241 Paper_outputter::write_header_field_to_file (String filename, String key, String value)
244 filename += String (".") + key;
245 progress_indication (_f ("writing header field %s to %s...",
247 filename == "-" ? String ("<stdout>") : filename));
249 ostream *os = open_file_stream (filename);
251 close_file_stream (os);
252 progress_indication ("\n");
256 Paper_outputter::write_header_fields_to_file (Scope * header)
258 if (dump_header_fieldnames_global.size ())
260 SCM fields = header->to_alist ();
261 for (int i = 0; i < dump_header_fieldnames_global.size (); i++)
263 String key = dump_header_fieldnames_global[i];
264 SCM val = gh_assoc (ly_symbol2scm (key.ch_C ()), fields);
266 /* Only write header field to file if it exists */
269 s = ly_scm2string (gh_cdr (val));
270 /* Always write header field file, even if string is empty ... */
271 write_header_field_to_file (basename_, key, s);