lilypond-1.3.141
[lilypond.git] / flower / input.cc
blobd45f81b9d32a62d37c4a61913d9bf9d871bb4632
1 /*
2 input.cc -- implement Input
4 source file of the LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include <iostream.h>
9 #include "flower-proto.hh"
10 #include "input.hh"
11 #include "string.hh"
12 #include "source.hh"
13 #include "source-file.hh"
15 Input::Input (Source_file*s, char const *cl)
17 source_file_l_=s;
18 defined_ch_C_=cl;
21 Input::Input ()
23 source_file_l_ = 0;
24 defined_ch_C_ = 0;
27 Input
28 Input::spot () const
30 return *this;
33 void
34 Input::set_spot (Input const &i)
36 *this = i;
40 Produce GNU-compliant error message. Correcting lilypond source is
41 such a breeze if you ('re edidor) know (s) the error column too
43 Format:
45 [file:line:column:][warning:]message
48 void
49 Input::message (String message_str) const
51 String str;
54 marked "Work in prgress" in GNU iostream
55 libg++ 2.7.2.8
56 libstdc++ 2.8.1
58 why not just return always -1 (unknown),
59 iso breaking the interface?
61 int col = cerr.rdbuf ()->column ();
65 // well, we don't want to loose first warning...
66 int col = 1;
67 if (col > 0)
68 str += "\n";
70 if (source_file_l_)
71 str += location_str () + String (": ");
73 str += message_str;
74 if (source_file_l_)
76 str += ":\n";
77 str += source_file_l_->error_str (defined_ch_C_);
79 cerr << str << endl;
82 void
83 Input::warning (String message_str) const
85 message (_ ("warning: ") + message_str);
87 void
88 Input::error (String s) const
90 message (_ ("error: ")+ s);
93 void
94 Input::non_fatal_error (String s) const
96 message (_ ("non fatal error: ") + s);
98 String
99 Input::location_str () const
101 if (source_file_l_)
102 return source_file_l_->file_line_column_str (defined_ch_C_);
103 else
104 return " (" + _ ("position unknown") + ")";
107 String
108 Input::line_number_str () const
110 if (source_file_l_)
111 return to_str (source_file_l_->line_i (defined_ch_C_));
112 else
113 return "?";
116 String
117 Input::file_str () const
119 if (source_file_l_)
120 return source_file_l_->name_str ();
121 else
122 return "";
127 Input::line_number () const
129 if (source_file_l_)
130 return source_file_l_->line_i (defined_ch_C_);
131 else
132 return 0;
137 Input::column_number () const
139 if (source_file_l_)
140 return source_file_l_->column_i (defined_ch_C_);
141 else
142 return 0;