lilypond-1.3.74
[lilypond.git] / lily / paper-outputter.cc
blob39d1b49c0edccbce6fa06c66991e3417e3745de7
1 /*
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>
8 */
10 #include <time.h>
11 #include <fstream.h>
12 #include <math.h>
13 #include <iostream.h>
15 #include "dimensions.hh"
16 #include "virtual-methods.hh"
17 #include "paper-outputter.hh"
18 #include "paper-stream.hh"
19 #include "molecule.hh"
20 #include "array.hh"
21 #include "string-convert.hh"
22 #include "debug.hh"
23 #include "lookup.hh"
24 #include "main.hh"
25 #include "scope.hh"
26 #include "identifier.hh"
27 #include "lily-version.hh"
31 Ugh, this is messy.
34 Paper_outputter::Paper_outputter (Paper_stream * ps )
37 lilypond -f scm x.ly
38 guile -s x.scm
40 verbatim_scheme_b_ = output_global_ch == String ("scm");
42 if (verbatim_scheme_b_)
44 *ps << ""
45 ";;; Usage: guile -s x.scm > x.tex\n"
46 "(primitive-load-path 'lily.scm)\n"
47 "(scm-tex-output)\n"
48 ";(scm-ps-output)\n"
49 "(map (lambda (x) (display (eval x))) '(\n"
53 stream_p_ = ps;
56 Paper_outputter::~Paper_outputter ()
58 if (verbatim_scheme_b_)
60 *stream_p_ << "))";
62 delete stream_p_;
66 void
67 Paper_outputter::output_header ()
69 if (safe_global_b)
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")),
76 SCM_UNDEFINED);
77 exp = scm_eval (exp);
78 scm_eval (exp);
80 String creator;
81 if (no_timestamps_global_b)
82 creator = gnu_lilypond_str ();
83 else
84 creator = gnu_lilypond_version_str ();
86 String generate;
87 if (no_timestamps_global_b)
88 generate = ".";
89 else
91 generate = _ (", at ");
92 time_t t (time (0));
93 generate += ctime (&t);
94 generate = generate.left_str (generate.length_i () - 1);
97 SCM args_scm =
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);
103 output_scheme (scm);
108 void
109 Paper_outputter::output_comment (String str)
111 output_scheme (gh_list (ly_symbol2scm ("comment"),
112 ly_str02scm ((char*)str.ch_C()),
113 SCM_UNDEFINED)
118 void
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.
125 dump_scheme (scm);
130 UGH.
132 Should probably change interface to do less eval ( symbol ), and more
133 apply (procedure, args)
135 void
136 Paper_outputter::dump_scheme (SCM s)
138 if (verbatim_scheme_b_)
140 SCM result = scm_eval (scm_listify (ly_symbol2scm ("scm->string"),
141 ly_quote_scm (gh_car (s)), SCM_UNDEFINED));
143 *stream_p_ << ly_scm2string (result);
145 else
147 SCM result = scm_eval (s);
148 char *c=gh_scm2newstr (result, NULL);
150 *stream_p_ << c;
151 free (c);
154 void
155 Paper_outputter::output_scope (Scope *scope, String prefix)
157 SCM al = scope->to_alist ();
158 for (SCM s = al ; gh_pair_p (s); s = gh_cdr (s))
160 SCM k = gh_caar (s);
161 SCM v = gh_cdar (s);
162 String s = ly_symbol2string (k);
165 if (gh_string_p (v))
167 output_String_def (prefix + s, ly_scm2string (v));
169 else if (scm_integer_p (v) == SCM_BOOL_T)
171 output_int_def (prefix + s, gh_scm2int (v));
173 else if (gh_number_p (v))
175 output_Real_def (prefix + s, gh_scm2double (v));
180 void
181 Paper_outputter::output_version ()
183 String id_str = "Lily was here";
184 if (no_timestamps_global_b)
185 id_str += ".";
186 else
187 id_str += String (", ") + version_str ();
189 output_String_def ( "mudelatagline", id_str);
190 output_String_def ( "LilyPondVersion", version_str ());
195 void
196 Paper_outputter::output_font_def (int i, String str)
198 SCM scm = gh_list (ly_symbol2scm ("font-def"),
199 gh_int2scm (i),
200 ly_str02scm (str.ch_l ()),
201 SCM_UNDEFINED);
203 output_scheme (scm);
206 void
207 Paper_outputter::output_Real_def (String k, Real v)
210 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
211 ly_str02scm (k.ch_l ()),
212 ly_str02scm (to_str(v).ch_l ()),
213 SCM_UNDEFINED);
214 output_scheme (scm);
217 void
218 Paper_outputter::output_String_def (String k, String v)
221 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
222 ly_str02scm (k.ch_l ()),
223 ly_str02scm (v.ch_l ()),
224 SCM_UNDEFINED);
225 output_scheme (scm);
228 void
229 Paper_outputter::output_int_def (String k, int v)
231 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
232 ly_str02scm (k.ch_l ()),
233 ly_str02scm (to_str (v).ch_l ()),
234 SCM_UNDEFINED);
235 output_scheme (scm);
240 void
241 Paper_outputter::output_string (SCM str)
243 *stream_p_ << ly_scm2string (str);