]> git.donarmstrong.com Git - lilypond.git/blob - lily/input-file-results.cc
2003 -> 2004
[lilypond.git] / lily / input-file-results.cc
1 /*
2   scores.cc -- implement some globals
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "config.h"
9
10 #include <errno.h>
11 #include <sys/types.h>
12 #include <stdio.h>
13
14
15 #if HAVE_SYS_STAT_H 
16 #include <sys/stat.h>
17 #endif
18 #include <unistd.h>
19
20
21 #include "main.hh"
22 #include "score.hh"
23 #include "string.hh"
24 #include "paper-def.hh"
25 #include "warn.hh"
26 #include "parray.hh"
27 #include "file-path.hh"
28 #include "input-file-results.hh"
29 #include "my-lily-parser.hh"
30 #include "source.hh"
31 #include "lily-version.hh"
32 #include "scm-hash.hh"
33 #include "ly-modules.hh"
34
35 bool store_locations_global_b;
36
37
38 /*
39   no ! suffix since it doesn't modify 1st argument.
40  */
41 LY_DEFINE(ly_set_point_and_click, "ly:set-point-and-click", 1, 0, 0,
42           (SCM what),
43           "Set the options for Point-and-click source specials output. The\n"
44 "argument is a symbol.  Possible options are @code{none} (no source specials),\n"
45 "@code{line} and @code{line-column}")
46 {
47   /*
48     UGH.
49    */
50   SCM val = SCM_BOOL_F;
51   if (ly_symbol2scm ("line-column") == what)
52     val = gh_eval_str ("line-column-location");
53   else if (what == ly_symbol2scm ("line"))
54     val = gh_eval_str ("line-location");
55
56   extern SCM lily_module; 
57   scm_module_define (lily_module, ly_symbol2scm ("point-and-click"), val);
58
59   store_locations_global_b =gh_procedure_p (val);
60   return SCM_UNSPECIFIED;
61 }
62
63 void
64 write_dependency_file (String fn,
65                        Array<String> targets,
66                        Array<String> deps)
67 {
68   const int WRAPWIDTH = 65;
69
70   progress_indication (_f ("dependencies output to `%s'...", fn.to_str0 ()));
71   progress_indication ("\n");
72   FILE * f = fopen  (fn.to_str0 (), "w");
73   if (!f)
74     warning (_f ("can't open file: `%s'", fn));
75
76   fprintf (f, "# Generated automatically by: %s\n", gnu_lilypond_version_string ().to_str0 ());
77   
78   String out;
79   for (int i=0; i < targets.size (); i ++)
80      out += dependency_prefix_global + targets[i] + " ";
81   out +=  ": ";
82
83   for (int i=0; i < deps.size (); i ++)
84     {
85       if (out.length () > WRAPWIDTH)
86         {
87           fprintf (f, "%s\\\n", out.to_str0 ());
88           out = "  ";
89         }
90       String dep = deps[i];
91       if (!dependency_prefix_global.is_empty ())
92         {
93           if (dep.index ('/') < 0)
94             dep = dependency_prefix_global + dep;
95         }
96       out  += " " +  dep;
97     }
98   fprintf (f, "%s\n",  out.to_str0 ());
99 }
100
101
102 void
103 Input_file_results::do_deps (String output)
104 {
105   if (dependency_global_b)
106     {
107       Path p = split_path (output);
108       p.ext = "dep";
109       write_dependency_file (p.to_string (),
110                              target_strings_,
111                              inclusion_names_);
112     }
113 }
114
115 Input_file_results::~Input_file_results ()
116 {
117   inclusion_names_.clear ();
118   if (header_)
119     header_ = SCM_EOL;
120
121   global_input_file =0;
122
123   ly_clear_anonymous_modules();
124 }
125
126
127
128 Input_file_results* global_input_file;
129
130 Input_file_results::Input_file_results (String init, String in_file, String out_file)
131 {
132   header_ = ly_make_anonymous_module ();
133   global_input_file = this;
134   score_count_ = 0;
135   sources_.set_path (&global_path);
136   
137
138   progress_indication (_f ("Now processing: `%s'", in_file.to_str0 ()));
139   progress_indication ("\n");
140
141   My_lily_parser parser (this);
142   parser.parse_file (init, in_file, out_file);
143   
144   if (parser.error_level_)
145     {
146       exit_status_global  = 1;
147       failed_files.push (in_file);
148     }
149
150   
151   do_deps (out_file);
152 }
153
154
155 void
156 do_one_file (String init, String in_file, String out_file) 
157 {
158   if (init.length () && global_path.find (init).is_empty ())
159     {
160       warning (_f ("can't find file: `%s'", init));
161       warning (_f ("(search path: `%s')", global_path.to_string ().to_str0 ()));
162       return;
163     }
164
165   if ((in_file != "-") && global_path.find (in_file).is_empty ())
166     {
167       warning (_f ("can't find file: `%s'", in_file));
168       return;
169     }
170
171   Input_file_results inp_file (init, in_file, out_file);
172 }