]> git.donarmstrong.com Git - lilypond.git/blob - lily/input.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / input.cc
1 /*
2   input.cc -- implement Input
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997--2006 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 "source.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_);
75   ::message (s);
76 }
77
78 void
79 Input::warning (string s) const
80 {
81   message (_f ("warning: %s", s));
82 }
83
84 void
85 Input::error (string s) const
86 {
87   message (_f ("error: %s", s));
88   // UGH, fix naming or usage
89   // exit (1);
90 }
91
92 void
93 Input::non_fatal_error (string s) const
94 {
95   message (_f ("error: %s", s));
96 }
97
98 string
99 Input::location_string () const
100 {
101   if (source_file_)
102     return source_file_->file_line_column_string (start_);
103   return " (" + _ ("position unknown") + ")";
104 }
105
106 string
107 Input::line_number_string () const
108 {
109   if (source_file_)
110     return to_string (source_file_->get_line (start_));
111   return "?";
112 }
113
114 string
115 Input::file_string () const
116 {
117   if (source_file_)
118     return source_file_->name_string ();
119   return "";
120 }
121
122 int
123 Input::line_number () const
124 {
125   if (source_file_)
126     return source_file_->get_line (start_);
127   return 0;
128 }
129
130 int
131 Input::column_number () const
132 {
133   int line, chr, col = 0;
134   source_file_->get_counts (start_, &line, &chr, &col);
135
136   return col;
137 }
138
139 int
140 Input::end_line_number () const
141 {
142   if (source_file_)
143     return source_file_->get_line (end_);
144   return 0;
145 }
146
147 int
148 Input::end_column_number () const
149 {
150   int line, chr, col = 0;
151   source_file_->get_counts (end_, &line, &chr, &col);
152
153   return col;
154 }
155
156 void
157 Input::get_counts (int *line, int *chr, int *col) const
158 {
159   source_file_->get_counts (start_, line, chr, col);
160 }
161
162 void
163 Input::set (Source_file *sf, char const *start, char const *end)
164 {
165   source_file_ = sf;
166   start_ = start;
167   end_ = end;
168 }
169
170 Source_file *
171 Input::get_source_file () const
172 {
173   return source_file_;
174 }
175
176 char const *
177 Input::start () const
178 {
179   return start_;
180 }
181
182 char const *
183 Input::end () const
184 {
185   return end_;
186 }