Restore MIDI output for DrumStaff.
[lilypond/mpolesky.git] / lily / input.cc
blobf2ddedd4e8b619e61e45c933f8a8c25aa8170445
1 /*
2 input.cc -- implement Input
4 source file of the LilyPond music typesetter
6 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "input.hh"
11 #include <cstdio>
12 using namespace std;
14 #include "international.hh"
15 #include "program-option.hh"
16 #include "source-file.hh"
17 #include "sources.hh"
18 #include "warn.hh"
20 Input::Input (Input const &i)
22 source_file_ = i.source_file_;
23 start_ = i.start_;
24 end_ = i.end_;
27 Input::Input ()
29 source_file_ = 0;
30 start_ = 0;
31 end_ = 0;
34 Input
35 Input::spot () const
37 return *this;
40 void
41 Input::set_spot (Input const &i)
43 *this = i;
46 void
47 Input::step_forward ()
49 if (end_ == start_)
50 end_++;
51 start_++;
54 void
55 Input::set_location (Input const &i_start, Input const &i_end)
57 source_file_ = i_start.source_file_;
58 start_ = i_start.start_;
59 end_ = i_end.end_;
63 Produce GNU-compliant error message. Correcting lilypond source is
64 such a breeze if you ('re edidor) know (s) the error column too
66 Format:
68 [file:line:column:][warning:]message
70 void
71 Input::message (string s) const
73 if (source_file_)
74 s = location_string () + ": " + s + "\n"
75 + source_file_->quote_input (start_) + "\n";
76 ::message (s);
80 void
81 Input::programming_error (string s) const
83 if (get_program_option ("warning-as-error"))
84 ::error (s);
85 else {
86 message (_f ("programming error: %s", s.c_str ()));
87 message (_ ("continuing, cross fingers") + "\n");
92 void
93 Input::warning (string s) const
95 if (get_program_option ("warning-as-error"))
96 ::error (s);
97 else
98 message (_f ("warning: %s", s));
101 void
102 Input::error (string s) const
104 message (_f ("error: %s", s));
105 // UGH, fix naming or usage
106 // exit (1);
109 void
110 Input::non_fatal_error (string s) const
112 message (_f ("error: %s", s));
115 string
116 Input::location_string () const
118 if (source_file_)
119 return source_file_->file_line_column_string (start_);
120 return " (" + _ ("position unknown") + ")";
123 string
124 Input::line_number_string () const
126 if (source_file_)
127 return to_string (source_file_->get_line (start_));
128 return "?";
131 string
132 Input::file_string () const
134 if (source_file_)
135 return source_file_->name_string ();
136 return "";
140 Input::line_number () const
142 if (source_file_)
143 return source_file_->get_line (start_);
144 return 0;
148 Input::column_number () const
150 int line, chr, col = 0;
151 source_file_->get_counts (start_, &line, &chr, &col);
153 return col;
157 Input::end_line_number () const
159 if (source_file_)
160 return source_file_->get_line (end_);
161 return 0;
165 Input::end_column_number () const
167 int line, chr, col = 0;
168 source_file_->get_counts (end_, &line, &chr, &col);
170 return col;
173 void
174 Input::get_counts (int *line, int *chr, int *col) const
176 source_file_->get_counts (start_, line, chr, col);
179 void
180 Input::set (Source_file *sf, char const *start, char const *end)
182 source_file_ = sf;
183 start_ = start;
184 end_ = end;
187 Source_file *
188 Input::get_source_file () const
190 return source_file_;
193 char const *
194 Input::start () const
196 return start_;
199 char const *
200 Input::end () const
202 return end_;