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