Compile fix.
[lilypond.git] / lily / input.cc
blob09028d0858ea4a00fbaf39c24055c370c1e74dad
1 /*
2 input.cc -- implement Input
4 source file of the LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "input.hh"
11 #include <cstdio>
12 using namespace std;
14 #include "international.hh"
15 #include "source-file.hh"
16 #include "sources.hh"
17 #include "warn.hh"
19 Input::Input (Input const &i)
21 source_file_ = i.source_file_;
22 start_ = i.start_;
23 end_ = i.end_;
26 Input::Input ()
28 source_file_ = 0;
29 start_ = 0;
30 end_ = 0;
33 Input
34 Input::spot () const
36 return *this;
39 void
40 Input::set_spot (Input const &i)
42 *this = i;
45 void
46 Input::step_forward ()
48 if (end_ == start_)
49 end_++;
50 start_++;
53 void
54 Input::set_location (Input const &i_start, Input const &i_end)
56 source_file_ = i_start.source_file_;
57 start_ = i_start.start_;
58 end_ = i_end.end_;
62 Produce GNU-compliant error message. Correcting lilypond source is
63 such a breeze if you ('re edidor) know (s) the error column too
65 Format:
67 [file:line:column:][warning:]message
69 void
70 Input::message (string s) const
72 if (source_file_)
73 s = location_string () + ": " + s + "\n"
74 + source_file_->quote_input (start_) + "\n";
75 ::message (s);
79 void
80 Input::programming_error (string s) const
82 message (_f ("programming error: %s", s.c_str ()));
83 message (_ ("continuing, cross fingers") + "\n");
87 void
88 Input::warning (string s) const
90 message (_f ("warning: %s", s));
93 void
94 Input::error (string s) const
96 message (_f ("error: %s", s));
97 // UGH, fix naming or usage
98 // exit (1);
101 void
102 Input::non_fatal_error (string s) const
104 message (_f ("error: %s", s));
107 string
108 Input::location_string () const
110 if (source_file_)
111 return source_file_->file_line_column_string (start_);
112 return " (" + _ ("position unknown") + ")";
115 string
116 Input::line_number_string () const
118 if (source_file_)
119 return to_string (source_file_->get_line (start_));
120 return "?";
123 string
124 Input::file_string () const
126 if (source_file_)
127 return source_file_->name_string ();
128 return "";
132 Input::line_number () const
134 if (source_file_)
135 return source_file_->get_line (start_);
136 return 0;
140 Input::column_number () const
142 int line, chr, col = 0;
143 source_file_->get_counts (start_, &line, &chr, &col);
145 return col;
149 Input::end_line_number () const
151 if (source_file_)
152 return source_file_->get_line (end_);
153 return 0;
157 Input::end_column_number () const
159 int line, chr, col = 0;
160 source_file_->get_counts (end_, &line, &chr, &col);
162 return col;
165 void
166 Input::get_counts (int *line, int *chr, int *col) const
168 source_file_->get_counts (start_, line, chr, col);
171 void
172 Input::set (Source_file *sf, char const *start, char const *end)
174 source_file_ = sf;
175 start_ = start;
176 end_ = end;
179 Source_file *
180 Input::get_source_file () const
182 return source_file_;
185 char const *
186 Input::start () const
188 return start_;
191 char const *
192 Input::end () const
194 return end_;