(editor-command-template-alist): Use char iso
[lilypond/patrick.git] / lily / input.cc
bloba9ad1c970e56b239c4c3d41339badd5c16602271
1 /*
2 input.cc -- implement Input
4 source file of the LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "input.hh"
11 #include <cstdio>
13 #include "source.hh"
14 #include "source-file.hh"
15 #include "warn.hh"
17 Input::Input (Input const &i)
19 source_file_ = i.source_file_;
20 start_ = i.start_;
21 end_ = i.end_;
24 Input::Input ()
26 source_file_ = 0;
27 start_ = 0;
28 end_ = 0;
31 Input
32 Input::spot () const
34 return *this;
37 void
38 Input::set_spot (Input const &i)
40 *this = i;
43 void
44 Input::step_forward ()
46 if (end_ == start_)
47 end_++;
48 start_++;
51 void
52 Input::set_location (Input const &i_start, Input const &i_end)
54 source_file_ = i_start.source_file_;
55 start_ = i_start.start_;
56 end_ = i_end.end_;
60 Produce GNU-compliant error message. Correcting lilypond source is
61 such a breeze if you ('re edidor) know (s) the error column too
63 Format:
65 [file:line:column:][warning:]message
67 void
68 Input::message (String s) const
70 if (source_file_)
71 s = location_string () + ": " + s + "\n"
72 + source_file_->quote_input (start_);
73 ::message (s);
76 void
77 Input::warning (String s) const
79 message (_f ("warning: %s", s));
82 void
83 Input::error (String s) const
85 message (_f ("error: %s", s));
86 // UGH, fix naming or usage
87 // exit (1);
90 void
91 Input::non_fatal_error (String s) const
93 message (_f ("error: %s", s));
96 String
97 Input::location_string () const
99 if (source_file_)
100 return source_file_->file_line_column_string (start_);
101 return " (" + _ ("position unknown") + ")";
104 String
105 Input::line_number_string () const
107 if (source_file_)
108 return to_string (source_file_->get_line (start_));
109 return "?";
112 String
113 Input::file_string () const
115 if (source_file_)
116 return source_file_->name_string ();
117 return "";
121 Input::line_number () const
123 if (source_file_)
124 return source_file_->get_line (start_);
125 return 0;
129 Input::column_number () const
131 int line, chr, col = 0;
132 source_file_->get_counts (start_, &line, &chr, &col);
134 return col;
138 Input::end_line_number () const
140 if (source_file_)
141 return source_file_->get_line (end_);
142 return 0;
146 Input::end_column_number () const
148 int line, chr, col = 0;
149 source_file_->get_counts (end_, &line, &chr, &col);
151 return col;
154 void
155 Input::get_counts (int *line, int *chr, int*col) const
157 source_file_->get_counts (start_, line, chr, col);
160 void
161 Input::set (Source_file *sf, char const *start, char const *end)
163 source_file_ = sf;
164 start_ = start;
165 end_ = end;
168 Source_file*
169 Input::get_source_file () const
171 return source_file_;
175 char const *
176 Input::start () const
178 return start_;
181 char const *
182 Input::end () const
184 return end_;