X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Finput.cc;h=ea8bbe7813609d7bef0b1659090f182063ec5ae1;hb=47db9a3883d726ca53e2133a3b2298f78dd6a32e;hp=5b283837eca4ec99dc5a8dbadc5ffbb48f8030d6;hpb=57be7394ffa2e7d7ba6d60548dba563f3409d472;p=lilypond.git diff --git a/lily/input.cc b/lily/input.cc index 5b283837ec..ea8bbe7813 100644 --- a/lily/input.cc +++ b/lily/input.cc @@ -1,17 +1,31 @@ /* - input.cc -- implement Input + This file is part of LilyPond, the GNU music typesetter. - source file of the LilyPond music typesetter + Copyright (C) 1997--2015 Han-Wen Nienhuys - (c) 1997--2005 Han-Wen Nienhuys + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #include "input.hh" #include +using namespace std; -#include "source.hh" +#include "international.hh" +#include "program-option.hh" #include "source-file.hh" +#include "sources.hh" #include "warn.hh" Input::Input (Input const &i) @@ -64,36 +78,59 @@ Input::set_location (Input const &i_start, Input const &i_end) [file:line:column:][warning:]message */ -void -Input::message (String s) const +string +Input::message_string (const string &msg) const { if (source_file_) - s = location_string () + ": " + s + "\n" - + source_file_->error_string (start_); - ::message (s); + return msg + "\n" + source_file_->quote_input (start_); + else + return msg; } +string +Input::message_location () const +{ + return (source_file_) ? location_string () : ""; +} void -Input::warning (String s) const +Input::error (const string &s) const { - message (_f ("warning: %s", s)); + ::non_fatal_error (message_string (s), message_location ()); + // UGH, fix naming or usage (use non_fatal_error in most places, instead) + // exit (1); } void -Input::error (String s) const +Input::programming_error (const string &s) const { - message (_f ("error: %s", s)); - // UGH, fix naming or usage - // exit (1); + ::programming_error (message_string (s), message_location ()); +} + +void +Input::non_fatal_error (const string &s) const +{ + ::non_fatal_error (message_string (s), message_location ()); } void -Input::non_fatal_error (String s) const +Input::warning (const string &s) const { - message (_f ("error: %s", s)); + ::warning (message_string (s), message_location ()); } -String +void +Input::message (const string &s) const +{ + ::message (message_string (s), true, message_location ()); +} + +void +Input::debug_output (const string &s) const +{ + ::debug_output (message_string (s), true, message_location ()); +} + +string Input::location_string () const { if (source_file_) @@ -101,15 +138,15 @@ Input::location_string () const return " (" + _ ("position unknown") + ")"; } -String +string Input::line_number_string () const { if (source_file_) - return to_string (source_file_->get_line (start_)); + return ::to_string (source_file_->get_line (start_)); return "?"; } -String +string Input::file_string () const { if (source_file_) @@ -128,9 +165,10 @@ Input::line_number () const int Input::column_number () const { - if (source_file_) - return source_file_->get_column (start_); - return 0; + int line, chr, col, offset = 0; + source_file_->get_counts (start_, &line, &chr, &col, &offset); + + return col; } int @@ -144,7 +182,40 @@ Input::end_line_number () const int Input::end_column_number () const { - if (source_file_) - return source_file_->get_column (end_); - return 0; + int line, chr, col, offset = 0; + source_file_->get_counts (end_, &line, &chr, &col, &offset); + + return col; +} + +void +Input::get_counts (int *line, int *chr, int *col, int *offset) const +{ + source_file_->get_counts (start_, line, chr, col, offset); +} + +void +Input::set (Source_file *sf, char const *start, char const *end) +{ + source_file_ = sf; + start_ = start; + end_ = end; +} + +Source_file * +Input::get_source_file () const +{ + return source_file_; +} + +char const * +Input::start () const +{ + return start_; +} + +char const * +Input::end () const +{ + return end_; }