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/>.
24 #include "international.hh"
25 #include "lily-imports.hh"
26 #include "program-option.hh"
27 #include "source-file.hh"
33 Input::Input (Input const &i)
35 source_file_ = i.source_file_;
54 Input::set_spot (Input const &i)
60 Input::step_forward ()
68 Input::set_location (Input const &i_start, Input const &i_end)
70 source_file_ = i_start.source_file_;
71 start_ = i_start.start_;
76 Produce GNU-compliant error message. Correcting lilypond source is
77 such a breeze if you ('re edidor) know (s) the error column too
81 [file:line:column:][warning:]message
84 Input::message_string (const string &msg) const
87 return msg + "\n" + source_file_->quote_input (start_);
93 Input::message_location () const
95 return (source_file_) ? location_string () : "";
99 Input::error (const string &s) const
101 ::error (message_string (s), message_location ());
105 Input::programming_error (const string &s) const
107 ::programming_error (message_string (s), message_location ());
111 Input::non_fatal_error (const string &s) const
113 ::non_fatal_error (message_string (s), message_location ());
117 Input::warning (const string &s) const
119 ::warning (message_string (s), message_location ());
123 Input::message (const string &s) const
125 ::message (message_string (s), true, message_location ());
129 Input::debug_output (const string &s) const
131 ::debug_output (message_string (s), true, message_location ());
135 Input::location_string () const
138 return source_file_->file_line_column_string (start_);
139 return " (" + _ ("position unknown") + ")";
143 Input::line_number_string () const
146 return ::to_string (source_file_->get_line (start_));
151 Input::file_string () const
154 return source_file_->name_string ();
159 Input::line_number () const
162 return source_file_->get_line (start_);
167 Input::column_number () const
169 int line, chr, col, offset = 0;
170 source_file_->get_counts (start_, &line, &chr, &col, &offset);
176 Input::end_line_number () const
179 return source_file_->get_line (end_);
184 Input::end_column_number () const
186 int line, chr, col, offset = 0;
187 source_file_->get_counts (end_, &line, &chr, &col, &offset);
193 Input::get_counts (int *line, int *chr, int *col, int *offset) const
195 source_file_->get_counts (start_, line, chr, col, offset);
199 Input::set (Source_file *sf, char const *start, char const *end)
207 Input::get_source_file () const
213 Input::start () const
225 with_location_hook_0 (void *it)
227 SCM *args = static_cast <SCM *> (it);
228 return scm_call_0 (args[0]);
232 with_location (SCM loc, SCM proc)
234 return scm_c_with_fluid (Lily::f_location,
235 unsmob<Input> (loc) ? loc : SCM_BOOL_F,
236 with_location_hook_0,
237 static_cast <void *> (&proc));
241 with_location_hook_1 (void *it)
243 SCM *args = static_cast <SCM *> (it);
244 return scm_call_1 (args[0], args[1]);
248 with_location (SCM loc, SCM proc, SCM arg1)
250 SCM args[] = { proc, arg1 };
251 return scm_c_with_fluid (Lily::f_location,
252 unsmob<Input> (loc) ? loc : SCM_BOOL_F,
253 with_location_hook_1,
254 static_cast <void *> (&args));
258 with_location_hook_2 (void *it)
260 SCM *args = static_cast <SCM *> (it);
261 return scm_call_2 (args[0], args[1], args[2]);
265 with_location (SCM loc, SCM proc, SCM arg1, SCM arg2)
267 SCM args[] = { proc, arg1, arg2 };
268 return scm_c_with_fluid (Lily::f_location,
269 unsmob<Input> (loc) ? loc : SCM_BOOL_F,
270 with_location_hook_2,
271 static_cast <void *> (&args));
275 with_location_hook_3 (void *it)
277 SCM *args = static_cast <SCM *> (it);
278 return scm_call_3 (args[0], args[1], args[2], args[3]);
282 with_location (SCM loc, SCM proc, SCM arg1, SCM arg2, SCM arg3)
284 SCM args[] = { proc, arg1, arg2, arg3 };
285 return scm_c_with_fluid (Lily::f_location,
286 unsmob<Input> (loc) ? loc : SCM_BOOL_F,
287 with_location_hook_3,
288 static_cast <void *> (&args));
292 with_location_hook_4 (void *it)
294 SCM *args = static_cast <SCM *> (it);
295 return scm_call_4 (args[0], args[1], args[2], args[3], args[4]);
299 with_location (SCM loc, SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4)
301 SCM args[] = { proc, arg1, arg2, arg3, arg4 };
302 return scm_c_with_fluid (Lily::f_location,
303 unsmob<Input> (loc) ? loc : SCM_BOOL_F,
304 with_location_hook_4,
305 static_cast <void *> (&args));
309 with_location_hook_n (void *it)
311 SCM *args = static_cast <SCM *> (it);
312 return scm_apply_0 (args[0], args[1]);
316 with_location (SCM loc, SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4, SCM arg5)
318 SCM args[] = { proc, scm_list_5 (arg1, arg2, arg3, arg4, arg5) };
319 return scm_c_with_fluid (Lily::f_location,
320 unsmob<Input> (loc) ? loc : SCM_BOOL_F,
321 with_location_hook_n,
322 static_cast <void *> (&args));