2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
25 #include "international.hh"
26 #include "lily-imports.hh"
27 #include "program-option.hh"
28 #include "source-file.hh"
34 Input::Input (Input const &i)
36 source_file_ = i.source_file_;
55 Input::set_spot (Input const &i)
61 Input::step_forward ()
69 Input::set_location (Input const &i_start, Input const &i_end)
71 source_file_ = i_start.source_file_;
72 start_ = i_start.start_;
77 Produce GNU-compliant error message. Correcting lilypond source is
78 such a breeze if you ('re edidor) know (s) the error column too
82 [file:line:column:][warning:]message
85 Input::message_string (const string &msg) const
88 return msg + "\n" + source_file_->quote_input (start_);
94 Input::message_location () const
96 return (source_file_) ? location_string () : "";
100 Input::error (const string &s) const
102 ::error (message_string (s), message_location ());
106 Input::programming_error (const string &s) const
108 ::programming_error (message_string (s), message_location ());
112 Input::non_fatal_error (const string &s) const
114 ::non_fatal_error (message_string (s), message_location ());
118 Input::warning (const string &s) const
120 ::warning (message_string (s), message_location ());
124 Input::message (const string &s) const
126 ::message (message_string (s), true, message_location ());
130 Input::debug_output (const string &s) const
132 ::debug_output (message_string (s), true, message_location ());
136 Input::location_string () const
139 return source_file_->file_line_column_string (start_);
140 return " (" + _ ("position unknown") + ")";
144 Input::line_number_string () const
147 return ::to_string (source_file_->get_line (start_));
152 Input::file_string () const
155 return source_file_->name_string ();
160 Input::line_number () const
163 return source_file_->get_line (start_);
168 Input::column_number () const
170 int line, chr, col, offset = 0;
171 source_file_->get_counts (start_, &line, &chr, &col, &offset);
177 Input::end_line_number () const
180 return source_file_->get_line (end_);
185 Input::end_column_number () const
187 int line, chr, col, offset = 0;
188 source_file_->get_counts (end_, &line, &chr, &col, &offset);
194 Input::get_counts (int *line, int *chr, int *col, int *offset) const
196 source_file_->get_counts (start_, line, chr, col, offset);
200 Input::set (Source_file *sf, char const *start, char const *end)
208 Input::get_source_file () const
214 Input::start () const
226 with_location_hook_0 (void *it)
228 SCM *args = static_cast <SCM *> (it);
229 return scm_call_0 (args[0]);
233 with_location (SCM loc, SCM proc)
235 return scm_c_with_fluid (Lily::f_location,
236 unsmob<Input> (loc) ? loc : SCM_BOOL_F,
237 with_location_hook_0,
238 static_cast <void *> (&proc));
242 with_location_hook_1 (void *it)
244 SCM *args = static_cast <SCM *> (it);
245 return scm_call_1 (args[0], args[1]);
249 with_location (SCM loc, SCM proc, SCM arg1)
251 SCM args[] = { proc, arg1 };
252 return scm_c_with_fluid (Lily::f_location,
253 unsmob<Input> (loc) ? loc : SCM_BOOL_F,
254 with_location_hook_1,
255 static_cast <void *> (&args));
259 with_location_hook_2 (void *it)
261 SCM *args = static_cast <SCM *> (it);
262 return scm_call_2 (args[0], args[1], args[2]);
266 with_location (SCM loc, SCM proc, SCM arg1, SCM arg2)
268 SCM args[] = { proc, arg1, arg2 };
269 return scm_c_with_fluid (Lily::f_location,
270 unsmob<Input> (loc) ? loc : SCM_BOOL_F,
271 with_location_hook_2,
272 static_cast <void *> (&args));
276 with_location_hook_3 (void *it)
278 SCM *args = static_cast <SCM *> (it);
279 return scm_call_3 (args[0], args[1], args[2], args[3]);
283 with_location (SCM loc, SCM proc, SCM arg1, SCM arg2, SCM arg3)
285 SCM args[] = { proc, arg1, arg2, arg3 };
286 return scm_c_with_fluid (Lily::f_location,
287 unsmob<Input> (loc) ? loc : SCM_BOOL_F,
288 with_location_hook_3,
289 static_cast <void *> (&args));
293 with_location_hook_4 (void *it)
295 SCM *args = static_cast <SCM *> (it);
296 return scm_call_4 (args[0], args[1], args[2], args[3], args[4]);
300 with_location (SCM loc, SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4)
302 SCM args[] = { proc, arg1, arg2, arg3, arg4 };
303 return scm_c_with_fluid (Lily::f_location,
304 unsmob<Input> (loc) ? loc : SCM_BOOL_F,
305 with_location_hook_4,
306 static_cast <void *> (&args));
310 with_location_hook_n (void *it)
312 SCM *args = static_cast <SCM *> (it);
313 return scm_apply_0 (args[0], args[1]);
317 with_location (SCM loc, SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4, SCM arg5)
319 SCM args[] = { proc, scm_list_5 (arg1, arg2, arg3, arg4, arg5) };
320 return scm_c_with_fluid (Lily::f_location,
321 unsmob<Input> (loc) ? loc : SCM_BOOL_F,
322 with_location_hook_n,
323 static_cast <void *> (&args));