]> git.donarmstrong.com Git - lilypond.git/blob - lily/input.cc
Remove mbrtowc(), and use utf8_char_len() instead.
[lilypond.git] / lily / input.cc
1 /*
2   input.cc -- implement Input
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "input.hh"
10
11 #include <cstdio>
12 using namespace std;
13
14 #include "international.hh"
15 #include "program-option.hh"
16 #include "source-file.hh"
17 #include "sources.hh"
18 #include "warn.hh"
19
20 Input::Input (Input const &i)
21 {
22   source_file_ = i.source_file_;
23   start_ = i.start_;
24   end_ = i.end_;
25 }
26
27 Input::Input ()
28 {
29   source_file_ = 0;
30   start_ = 0;
31   end_ = 0;
32 }
33
34 Input
35 Input::spot () const
36 {
37   return *this;
38 }
39
40 void
41 Input::set_spot (Input const &i)
42 {
43   *this = i;
44 }
45
46 void
47 Input::step_forward ()
48 {
49   if (end_ == start_)
50     end_++;
51   start_++;
52 }
53
54 void
55 Input::set_location (Input const &i_start, Input const &i_end)
56 {
57   source_file_ = i_start.source_file_;
58   start_ = i_start.start_;
59   end_ = i_end.end_;
60 }
61
62 /*
63   Produce GNU-compliant error message.  Correcting lilypond source is
64   such a breeze if you ('re edidor) know (s) the error column too
65
66   Format:
67
68   [file:line:column:][warning:]message
69 */
70 void
71 Input::message (string s) const
72 {
73   if (source_file_)
74     s = location_string () + ": " + s + "\n"
75       + source_file_->quote_input (start_) + "\n";
76   ::message (s);
77 }
78
79
80 void
81 Input::programming_error (string s) const
82 {
83   if (get_program_option ("warning-as-error"))
84     ::error (s);
85   else {
86     message (_f ("programming error: %s", s.c_str ()));
87     message (_ ("continuing, cross fingers") + "\n");
88   }
89 }
90
91
92 void
93 Input::warning (string s) const
94 {
95   if (get_program_option ("warning-as-error"))
96     ::error (s);
97   else
98     message (_f ("warning: %s", s));
99 }
100
101 void
102 Input::error (string s) const
103 {
104   message (_f ("error: %s", s));
105   // UGH, fix naming or usage
106   // exit (1);
107 }
108
109 void
110 Input::non_fatal_error (string s) const
111 {
112   message (_f ("error: %s", s));
113 }
114
115 string
116 Input::location_string () const
117 {
118   if (source_file_)
119     return source_file_->file_line_column_string (start_);
120   return " (" + _ ("position unknown") + ")";
121 }
122
123 string
124 Input::line_number_string () const
125 {
126   if (source_file_)
127     return to_string (source_file_->get_line (start_));
128   return "?";
129 }
130
131 string
132 Input::file_string () const
133 {
134   if (source_file_)
135     return source_file_->name_string ();
136   return "";
137 }
138
139 int
140 Input::line_number () const
141 {
142   if (source_file_)
143     return source_file_->get_line (start_);
144   return 0;
145 }
146
147 int
148 Input::column_number () const
149 {
150   int line, chr, col, offset = 0;
151   source_file_->get_counts (start_, &line, &chr, &col, &offset);
152
153   return col;
154 }
155
156 int
157 Input::end_line_number () const
158 {
159   if (source_file_)
160     return source_file_->get_line (end_);
161   return 0;
162 }
163
164 int
165 Input::end_column_number () const
166 {
167   int line, chr, col, offset = 0;
168   source_file_->get_counts (end_, &line, &chr, &col, &offset);
169
170   return col;
171 }
172
173 void
174 Input::get_counts (int *line, int *chr, int *col, int *offset) const
175 {
176   source_file_->get_counts (start_, line, chr, col, offset);
177 }
178
179 void
180 Input::set (Source_file *sf, char const *start, char const *end)
181 {
182   source_file_ = sf;
183   start_ = start;
184   end_ = end;
185 }
186
187 Source_file *
188 Input::get_source_file () const
189 {
190   return source_file_;
191 }
192
193 char const *
194 Input::start () const
195 {
196   return start_;
197 }
198
199 char const *
200 Input::end () const
201 {
202   return end_;
203 }