]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-outputter.cc
release: 1.3.53
[lilypond.git] / lily / paper-outputter.cc
1 /*
2   paper-outputter.cc -- implement Paper_outputter
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include <time.h>
11 #include <fstream.h>
12 #include <math.h>
13 #include <iostream.h>
14
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"
21 #include "array.hh"
22 #include "string-convert.hh"
23 #include "debug.hh"
24 #include "lookup.hh"
25 #include "main.hh"
26 #include "scope.hh"
27 #include "identifier.hh"
28 #include "lily-version.hh"
29
30
31 /*
32   Ugh, this is messy.
33  */
34
35 Paper_outputter::Paper_outputter (Paper_stream  * ps )
36 {
37 #if 0 
38   molecules_ = gh_cons (SCM_EOL, SCM_EOL);
39   last_cons_ = molecules_;
40 #endif
41
42  /*
43    lilypond -f scm x.ly
44    guile -s x.scm
45   */
46   verbatim_scheme_b_ =  output_global_ch == String ("scm");
47
48   if (verbatim_scheme_b_)
49     {
50         *ps << ""
51           ";;; Usage: guile -s x.scm > x.tex\n"
52           "(primitive-load-path 'lily.scm)\n"
53           "(scm-tex-output)\n"
54           ";(scm-ps-output)\n"
55           "(map (lambda (x) (display (eval x))) '(\n"
56         ;
57     }
58
59   stream_p_ = ps;
60 }
61
62 Paper_outputter::~Paper_outputter ()
63 {
64   if (verbatim_scheme_b_)
65     {
66       *stream_p_ << "))";
67     }
68   delete stream_p_;
69 }
70
71
72 void
73 Paper_outputter::output_header ()
74 {
75   if (safe_global_b)
76     {
77       gh_define ("security-paranoia", SCM_BOOL_T);      
78     }
79
80   SCM exp = gh_list (ly_symbol2scm ((String (output_global_ch) + "-scm").ch_C()),
81                      ly_quote_scm (ly_symbol2scm ("all-definitions")),
82                      SCM_UNDEFINED);
83   exp = scm_eval (exp);
84   scm_eval (exp);
85   
86   String creator;
87   if (no_timestamps_global_b)
88     creator = gnu_lilypond_str ();
89   else
90     creator = gnu_lilypond_version_str ();
91   
92   String generate;
93   if (no_timestamps_global_b)
94     generate = ".";
95   else
96     {
97       generate = _ (", at ");
98       time_t t (time (0));
99       generate += ctime (&t);
100       generate = generate.left_str (generate.length_i () - 1);
101     }
102
103   SCM args_scm = 
104     gh_list (ly_str02scm (creator.ch_l ()),
105              ly_str02scm (generate.ch_l ()), SCM_UNDEFINED);
106
107
108   SCM scm = gh_cons (ly_symbol2scm ("header"), args_scm);
109   output_scheme (scm);
110 }
111
112
113
114 void
115 Paper_outputter::output_comment (String str)
116 {
117   output_scheme (gh_list (ly_symbol2scm ("comment"),
118                           ly_str02scm ((char*)str.ch_C()),
119                           SCM_UNDEFINED)
120                  );
121 }
122
123
124 void
125 Paper_outputter::output_scheme (SCM scm)
126 {
127 #if 0
128   SCM c = gh_cons (scm,gh_cdr (last_cons_));
129   gh_set_cdr_x(last_cons_, c);
130   last_cons_ = c;
131 #endif
132
133   dump_scheme (scm);
134 }
135
136
137 #if 0
138 void
139 Paper_outputter::dump ()
140 {
141
142   for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
143     {
144       dump_scheme (gh_car (s));
145     }
146 }
147 #endif
148
149 void
150 Paper_outputter::dump_scheme (SCM s)
151 {
152   if  (verbatim_scheme_b_)
153     {
154       SCM result =  scm_eval (scm_listify (ly_symbol2scm ("scm->string"),
155                                            ly_quote_scm (gh_car (s)), SCM_UNDEFINED));
156           
157       *stream_p_ << ly_scm2string (result);
158     }
159   else
160     {
161       SCM result = scm_eval (s);
162       char *c=gh_scm2newstr (result, NULL);
163   
164       *stream_p_ << c;
165       free (c);
166     }
167 }
168 void
169 Paper_outputter::output_scope (Scope *scope, String prefix)
170 {
171   for (Scope_iter i (*scope); i.ok (); i++)
172     {
173       if (dynamic_cast<String_identifier*> (i.val ()))
174         {
175           String val = *i.val()->access_content_String (false);
176
177           output_String_def (prefix + i.key (), val);
178         }
179       else if(dynamic_cast<Real_identifier*> (i.val ()))
180         {
181           Real val  = *i.val ()->access_content_Real (false);
182
183           output_Real_def (prefix + i.key (), val);       
184         }
185       else if (dynamic_cast<int_identifier*> (i.val ()))
186         {
187           int val  = *i.val ()->access_content_int (false);       
188           
189           output_int_def (prefix + i.key (), val);        
190         }
191     }
192 }
193
194 void
195 Paper_outputter::output_version ()
196 {
197   String id_str = "Lily was here";
198   if (no_timestamps_global_b)
199     id_str += ".";
200   else
201     id_str += String (", ") + version_str ();
202
203   output_String_def ( "mudelatagline", id_str);
204   output_String_def ( "LilyPondVersion", version_str ());
205 }
206
207
208
209 void
210 Paper_outputter::output_font_def (int i, String str)
211 {
212   SCM scm = gh_list (ly_symbol2scm ("font-def"),
213                      gh_int2scm (i),
214                      ly_str02scm (str.ch_l ()),
215                      SCM_UNDEFINED);
216
217   output_scheme (scm);
218 }
219
220 void
221 Paper_outputter::output_Real_def (String k, Real v)
222 {
223   
224   SCM scm = gh_list (ly_symbol2scm ("lily-def"),
225                      ly_str02scm (k.ch_l ()),
226                      ly_str02scm (to_str(v).ch_l ()),
227                      SCM_UNDEFINED);
228   output_scheme (scm);
229 }
230
231 void
232 Paper_outputter::output_String_def (String k, String v)
233 {
234   
235   SCM scm = gh_list (ly_symbol2scm ("lily-def"),
236                      ly_str02scm (k.ch_l ()),
237                      ly_str02scm (v.ch_l ()),
238                      SCM_UNDEFINED);
239   output_scheme (scm);
240 }
241
242 void
243 Paper_outputter::output_int_def (String k, int v)
244 {
245   SCM scm = gh_list (ly_symbol2scm ("lily-def"),
246                      ly_str02scm (k.ch_l ()),
247                      ly_str02scm (to_str (v).ch_l ()),
248                      SCM_UNDEFINED);
249   output_scheme (scm);
250 }
251
252
253
254
255