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