]> git.donarmstrong.com Git - lilypond.git/blob - lily/input.cc
Update.
[lilypond.git] / lily / input.cc
1 /*
2   input.cc -- implement Input
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "input.hh"
10
11 #include <cstdio>
12
13 #include "source.hh"
14 #include "source-file.hh"
15
16 Input::Input (Input const &i)
17 {
18   source_file_ = i.source_file_;
19   start_ = i.start_;
20   end_ = i.end_;
21 }
22
23 Input::Input ()
24 {
25   source_file_ = 0;
26   start_ = 0;
27   end_ = 0;
28 }
29
30 Input
31 Input::spot () const
32 {
33   return *this;
34 }
35
36 void
37 Input::set_spot (Input const &i)
38 {
39   *this = i;
40 }
41
42 void
43 Input::step_forward ()
44 {
45   if (end_ == start_)
46     end_++;
47   start_++;
48 }
49
50 void
51 Input::set_location (Input const &i_start, Input const &i_end)
52 {
53   source_file_ = i_start.source_file_;
54   start_ = i_start.start_;
55   end_ = i_end.end_;
56 }
57
58 /*
59   Produce GNU-compliant error message.  Correcting lilypond source is
60   such a breeze if you ('re edidor) know (s) the error column too
61
62   Format:
63
64   [file:line:column:][warning:]message
65 */
66 void
67 Input::message (String message_string) const
68 {
69   String str;
70
71   /*
72     marked "Work in prgress" in GNU iostream
73     libg++ 2.7.2.8
74     libstdc++ 2.8.1
75
76     why not just return always -1 (unknown),
77     iso breaking the interface?
78
79     int col = cerr.rdbuf ()->column ();
80
81   */
82
83   // well, we don't want to loose first warning...
84   int col = 1;
85   if (col > 0)
86     str += "\n";
87
88   if (source_file_)
89     str += location_string () + String (": ");
90
91   str += message_string;
92   if (source_file_)
93     {
94       str += ":\n";
95       str += source_file_->error_string (start_);
96     }
97   fprintf (stderr, "%s\n", str.to_str0 ());
98   fflush (stderr);
99 }
100
101 void
102 Input::warning (String message_string) const
103 {
104   message (_ ("warning: ") + message_string);
105 }
106 void
107 Input::error (String s) const
108 {
109   message (_ ("error: ")+ s);
110 }
111
112 void
113 Input::non_fatal_error (String s) const
114 {
115   message (_ ("non fatal error: ") + s);
116 }
117 String
118 Input::location_string () const
119 {
120   if (source_file_)
121     return source_file_->file_line_column_string (start_);
122   else
123     return " (" + _ ("position unknown") + ")";
124 }
125
126 String
127 Input::line_number_string () const
128 {
129   if (source_file_)
130     return to_string (source_file_->get_line (start_));
131   else
132     return "?";
133 }
134
135 String
136 Input::file_string () const
137 {
138   if (source_file_)
139     return source_file_->name_string ();
140   else
141     return "";
142 }
143
144 int
145 Input::line_number () const
146 {
147   if (source_file_)
148     return source_file_->get_line (start_);
149   else
150     return 0;
151 }
152
153 int
154 Input::column_number () const
155 {
156   if (source_file_)
157     return source_file_->get_column (start_);
158   else
159     return 0;
160 }
161
162 int
163 Input::end_line_number () const
164 {
165   if (source_file_)
166     return source_file_->get_line (end_);
167   else
168     return 0;
169 }
170
171 int
172 Input::end_column_number () const
173 {
174   if (source_file_)
175     return source_file_->get_column (end_);
176   else
177     return 0;
178 }