2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 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 "program-option.hh"
27 #include "source-file.hh"
31 Input::Input (Input const &i)
33 source_file_ = i.source_file_;
52 Input::set_spot (Input const &i)
58 Input::step_forward ()
66 Input::set_location (Input const &i_start, Input const &i_end)
68 source_file_ = i_start.source_file_;
69 start_ = i_start.start_;
74 Produce GNU-compliant error message. Correcting lilypond source is
75 such a breeze if you ('re edidor) know (s) the error column too
79 [file:line:column:][warning:]message
82 Input::print_message (int level, string s) const
86 ::print_message (level, location_string (),
87 s + "\n" + source_file_->quote_input (start_) + "\n");
89 ::print_message (level, "", s);
93 Input::error (string s) const
95 print_message (LOG_ERROR, _f ("error: %s", s));
96 // UGH, fix naming or usage (use non_fatal_error in most places, instead)
101 Input::programming_error (string s) const
103 if (get_program_option ("warning-as-error"))
107 print_message (LOG_ERROR, _f ("programming error: %s", s));
108 print_message (LOG_ERROR, _ ("continuing, cross fingers") + "\n");
113 Input::non_fatal_error (string s) const
115 print_message (LOG_ERROR, _f ("error: %s", s));
119 Input::warning (string s) const
121 if (get_program_option ("warning-as-error"))
124 print_message (LOG_WARN, _f ("warning: %s", s));
128 Input::message (string s) const
130 print_message (LOG_INFO, s);
134 Input::debug_output (string s) const
136 print_message (LOG_DEBUG, s);
140 Input::location_string () const
143 return source_file_->file_line_column_string (start_);
144 return " (" + _ ("position unknown") + ")";
148 Input::line_number_string () const
151 return to_string (source_file_->get_line (start_));
156 Input::file_string () const
159 return source_file_->name_string ();
164 Input::line_number () const
167 return source_file_->get_line (start_);
172 Input::column_number () const
174 int line, chr, col, offset = 0;
175 source_file_->get_counts (start_, &line, &chr, &col, &offset);
181 Input::end_line_number () const
184 return source_file_->get_line (end_);
189 Input::end_column_number () const
191 int line, chr, col, offset = 0;
192 source_file_->get_counts (end_, &line, &chr, &col, &offset);
198 Input::get_counts (int *line, int *chr, int *col, int *offset) const
200 source_file_->get_counts (start_, line, chr, col, offset);
204 Input::set (Source_file *sf, char const *start, char const *end)
212 Input::get_source_file () const
218 Input::start () const