Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / input.cc
blobcbb609941fb6924d0a0b9cd33e475da78f5b79d9
1 /*
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/>.
20 #include "input.hh"
22 #include <cstdio>
23 using namespace std;
25 #include "international.hh"
26 #include "program-option.hh"
27 #include "source-file.hh"
28 #include "sources.hh"
29 #include "warn.hh"
31 Input::Input (Input const &i)
33 source_file_ = i.source_file_;
34 start_ = i.start_;
35 end_ = i.end_;
38 Input::Input ()
40 source_file_ = 0;
41 start_ = 0;
42 end_ = 0;
45 Input
46 Input::spot () const
48 return *this;
51 void
52 Input::set_spot (Input const &i)
54 *this = i;
57 void
58 Input::step_forward ()
60 if (end_ == start_)
61 end_++;
62 start_++;
65 void
66 Input::set_location (Input const &i_start, Input const &i_end)
68 source_file_ = i_start.source_file_;
69 start_ = i_start.start_;
70 end_ = i_end.end_;
74 Produce GNU-compliant error message. Correcting lilypond source is
75 such a breeze if you ('re edidor) know (s) the error column too
77 Format:
79 [file:line:column:][warning:]message
81 void
82 Input::message (string s) const
84 if (source_file_)
85 s = location_string () + ": " + s + "\n"
86 + source_file_->quote_input (start_) + "\n";
87 ::message (s);
91 void
92 Input::programming_error (string s) const
94 if (get_program_option ("warning-as-error"))
95 ::error (s);
96 else {
97 message (_f ("programming error: %s", s.c_str ()));
98 message (_ ("continuing, cross fingers") + "\n");
103 void
104 Input::warning (string s) const
106 if (get_program_option ("warning-as-error"))
107 ::error (s);
108 else
109 message (_f ("warning: %s", s));
112 void
113 Input::error (string s) const
115 message (_f ("error: %s", s));
116 // UGH, fix naming or usage
117 // exit (1);
120 void
121 Input::non_fatal_error (string s) const
123 message (_f ("error: %s", s));
126 string
127 Input::location_string () const
129 if (source_file_)
130 return source_file_->file_line_column_string (start_);
131 return " (" + _ ("position unknown") + ")";
134 string
135 Input::line_number_string () const
137 if (source_file_)
138 return to_string (source_file_->get_line (start_));
139 return "?";
142 string
143 Input::file_string () const
145 if (source_file_)
146 return source_file_->name_string ();
147 return "";
151 Input::line_number () const
153 if (source_file_)
154 return source_file_->get_line (start_);
155 return 0;
159 Input::column_number () const
161 int line, chr, col, offset = 0;
162 source_file_->get_counts (start_, &line, &chr, &col, &offset);
164 return col;
168 Input::end_line_number () const
170 if (source_file_)
171 return source_file_->get_line (end_);
172 return 0;
176 Input::end_column_number () const
178 int line, chr, col, offset = 0;
179 source_file_->get_counts (end_, &line, &chr, &col, &offset);
181 return col;
184 void
185 Input::get_counts (int *line, int *chr, int *col, int *offset) const
187 source_file_->get_counts (start_, line, chr, col, offset);
190 void
191 Input::set (Source_file *sf, char const *start, char const *end)
193 source_file_ = sf;
194 start_ = start;
195 end_ = end;
198 Source_file *
199 Input::get_source_file () const
201 return source_file_;
204 char const *
205 Input::start () const
207 return start_;
210 char const *
211 Input::end () const
213 return end_;