]> git.donarmstrong.com Git - lilypond.git/blob - lily/scores.cc
release: 0.1.62
[lilypond.git] / lily / scores.cc
1 /*
2   scores.cc -- implement some globals
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8 #include <fstream.h>
9 #include "main.hh"
10 #include "score.hh"
11 #include "string.hh"
12 #include "paper-def.hh"
13 #include "header.hh"
14 #include "debug.hh"
15 #include "parray.hh"
16 #include "file-path.hh"
17 #include "file-results.hh"
18 #include "my-lily-parser.hh"
19 #include "source.hh"
20
21 Sources* source_global_l = 0;
22 Array<String> inclusion_global_array;
23 Array<String> target_str_global_array;
24 Link_array<Score> score_global_array;
25
26
27 void write_dependency_file (String fn, Array<String> targets,
28                             Array<String> deps)
29 {
30   const int WRAPWIDTH = 65;
31
32
33   cout << "Writing dependency file " << fn << " ...\n";
34   ofstream f (fn.ch_C ());
35   if (!f)
36     warning ( _("Can't open dependency file `" + fn + "\'"));
37
38   f << "# Automatically generated by " << get_version_str ()  << "\n";
39   String out;
40   for (int i=0; i < targets.size (); i ++)
41      out += targets[i] + " ";
42   out +=  ": ";
43   for (int i=0; i < deps.size (); i ++)
44     {
45       if (out.length_i() > WRAPWIDTH)
46         {
47           f << out << "\\\n";
48           out = "  ";
49         }
50       out  += " " +  deps[i];
51     }
52   f << out << endl; 
53 }
54
55 void
56 do_deps()
57 {
58   if (dependency_global_b)
59     {
60       write_dependency_file (default_outname_base_global  + ".dep", target_str_global_array,
61                              inclusion_global_array);
62     }
63 }
64
65
66 void
67 do_scores()
68 {
69   for (int i=0; i < score_global_array.size(); i++)
70     {
71       Score* is_p = score_global_array[i];
72       if (!is_p->header_p_)
73         is_p->header_p_ = new Header;
74       
75                 
76       is_p->header_p_->lily_id_str_ = "Lily was here, " +
77         get_version_number_str();
78       if (is_p->errorlevel_i_)
79         {
80           is_p->warning (_("Score contains errors. Will not process it. "));
81           exit_status_i_ |= 1;
82         }
83       else
84         {
85           is_p->process();
86         }
87     }
88   do_deps ();
89 }
90
91 void
92 clear_scores ()
93 {
94   for (int i=0; i < score_global_array.size(); i++)
95     {
96       delete score_global_array[i];
97     }
98   score_global_array.clear();
99   inclusion_global_array.clear ();
100 }
101
102 extern File_path path;
103
104 void
105 do_one_file (String init_str, String file_str)
106 {
107   if (init_str.length_i () && path.find (init_str).empty_b ())
108     {
109       warning (_("Can not find `") + init_str +"\'");
110       return ;
111     }
112   if (file_str.length_i () && path.find (file_str).empty_b ())
113     {
114       warning (_("Can not find `") + file_str + "'");
115       return ;
116     }
117
118   Sources sources;
119   source_global_l = &sources;
120   source_global_l->set_path (&path);
121   {
122     My_lily_parser parser (source_global_l);
123     parser.set_version_check (version_ignore_global_b);
124     parser.parse_file (init_str, file_str);
125
126     
127     if (file_str.length_i () && file_str[0] != '-')
128       {
129         String a,b,c,d;
130         split_path (file_str, a, b, c, d);
131         default_outname_base_global = c;
132       }
133     else
134       default_outname_base_global = "lelie";
135   
136     if (parser.error_level_i_)
137       {
138         exit_status_i_  = 1;
139       }
140     else
141       do_scores ();
142     clear_scores ();
143   }
144   source_global_l = 0;
145 }