]> git.donarmstrong.com Git - lilypond.git/blob - lily/input.cc
* lily/include/input.hh (class Input): new `end_' slot for end of
[lilypond.git] / lily / input.cc
1 /*
2  input.cc -- implement Input
3
4  source file of the LilyPond music typesetter
5
6   (c) 1997--2004 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  */
67 void
68 Input::message (String message_string) const
69 {
70   String str;
71   
72   /*
73     marked "Work in prgress" in GNU iostream 
74       libg++ 2.7.2.8
75       libstdc++ 2.8.1
76
77     why not just return always -1 (unknown), 
78     iso breaking the interface?
79
80   int col = cerr.rdbuf ()->column ();
81
82    */
83
84   // well, we don't want to loose first warning...
85   int col = 1;
86   if (col > 0)
87     str += "\n";
88   
89   if (source_file_)
90     str += location_string () + String (": ");
91
92   str += message_string;
93   if (source_file_)
94    {
95     str += ":\n";
96     str += source_file_->error_string (start_);
97    }
98   fprintf (stderr, "%s\n", str.to_str0 ());
99   fflush (stderr);
100 }
101
102 void
103 Input::warning (String message_string) const
104 {
105   message (_ ("warning: ") + message_string);
106 }
107 void
108 Input::error (String s) const
109 {
110   message (_ ("error: ")+ s);
111 }
112
113 void
114 Input::non_fatal_error (String s) const
115 {
116   message (_ ("non fatal error: ") + s);
117 }
118 String
119 Input::location_string () const
120 {
121   if (source_file_)
122     return source_file_->file_line_column_string (start_);
123   else
124     return " (" + _ ("position unknown") + ")";
125 }
126
127 String
128 Input::line_number_string () const
129 {
130   if (source_file_)
131     return to_string (source_file_->get_line (start_));
132   else
133     return "?";
134 }
135
136 String
137 Input::file_string () const
138 {
139   if (source_file_)
140     return source_file_->name_string ();
141   else
142     return "";
143 }
144
145
146 int
147 Input::line_number () const
148 {
149   if (source_file_)
150     return source_file_->get_line (start_);
151   else
152     return 0;
153
154 }
155
156 int
157 Input::column_number () const
158 {
159   if (source_file_)
160     return source_file_->get_column (start_);
161   else
162     return 0;
163
164 }
165
166 int
167 Input::end_line_number () const
168 {
169   if (source_file_)
170     return source_file_->get_line (end_);
171   else
172     return 0;
173
174 }
175
176 int
177 Input::end_column_number () const
178 {
179   if (source_file_)
180     return source_file_->get_column (end_);
181   else
182     return 0;
183
184 }