]> git.donarmstrong.com Git - lilypond.git/blob - lily/input.cc
* Documentation/topdocs/INSTALL.texi (Top): Remove information
[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
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
119 String
120 Input::location_string () const
121 {
122   if (source_file_)
123     return source_file_->file_line_column_string (start_);
124   else
125     return " (" + _ ("position unknown") + ")";
126 }
127
128 String
129 Input::line_number_string () const
130 {
131   if (source_file_)
132     return to_string (source_file_->get_line (start_));
133   else
134     return "?";
135 }
136
137 String
138 Input::file_string () const
139 {
140   if (source_file_)
141     return source_file_->name_string ();
142   else
143     return "";
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 int
156 Input::column_number () const
157 {
158   if (source_file_)
159     return source_file_->get_column (start_);
160   else
161     return 0;
162 }
163
164 int
165 Input::end_line_number () const
166 {
167   if (source_file_)
168     return source_file_->get_line (end_);
169   else
170     return 0;
171 }
172
173 int
174 Input::end_column_number () const
175 {
176   if (source_file_)
177     return source_file_->get_column (end_);
178   else
179     return 0;
180 }