]> git.donarmstrong.com Git - lilypond.git/blob - lily/input.cc
* configure.in: Test for and accept lmodern if EC fonts not found.
[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 (Source_file*s, char const *cl)
17 {
18   source_file_=s;
19   defined_str0_=cl;
20 }
21
22 Input::Input ()
23 {
24   source_file_ = 0;
25   defined_str0_ = 0;
26 }
27
28 Input
29 Input::spot () const
30 {
31   return *this;
32 }
33
34 void
35 Input::set_spot (Input const &i)
36 {
37   *this = i;
38 }
39
40 /*
41   Produce GNU-compliant error message.  Correcting lilypond source is
42   such a breeze if you ('re edidor) know (s) the error column too
43   
44   Format:
45
46     [file:line:column:][warning:]message
47
48  */
49 void
50 Input::message (String message_string) const
51 {
52   String str;
53   
54   /*
55     marked "Work in prgress" in GNU iostream 
56       libg++ 2.7.2.8
57       libstdc++ 2.8.1
58
59     why not just return always -1 (unknown), 
60     iso breaking the interface?
61
62   int col = cerr.rdbuf ()->column ();
63
64    */
65
66   // well, we don't want to loose first warning...
67   int col = 1;
68   if (col > 0)
69     str += "\n";
70   
71   if (source_file_)
72     str += location_string () + String (": ");
73
74   str += message_string;
75   if (source_file_)
76    {
77     str += ":\n";
78     str += source_file_->error_string (defined_str0_);
79    }
80   fprintf (stderr, "%s\n", str.to_str0 ());
81   fflush (stderr);
82 }
83
84 void
85 Input::warning (String message_string) const
86 {
87   message (_ ("warning: ") + message_string);
88 }
89 void
90 Input::error (String s) const
91 {
92   message (_ ("error: ")+ s);
93 }
94
95 void
96 Input::non_fatal_error (String s) const
97 {
98   message (_ ("non fatal error: ") + s);
99 }
100 String
101 Input::location_string () const
102 {
103   if (source_file_)
104     return source_file_->file_line_column_string (defined_str0_);
105   else
106     return " (" + _ ("position unknown") + ")";
107 }
108
109 String
110 Input::line_number_string () const
111 {
112   if (source_file_)
113     return to_string (source_file_->get_line (defined_str0_));
114   else
115     return "?";
116 }
117
118 String
119 Input::file_string () const
120 {
121   if (source_file_)
122     return source_file_->name_string ();
123   else
124     return "";
125 }
126
127
128 int
129 Input::line_number () const
130 {
131   if (source_file_)
132     return source_file_->get_line (defined_str0_);
133   else
134     return 0;
135
136 }
137
138 int
139 Input::column_number () const
140 {
141   if (source_file_)
142     return source_file_->get_column (defined_str0_);
143   else
144     return 0;
145
146 }