]> git.donarmstrong.com Git - lilypond.git/blob - flower/input.cc
release: 1.3.24
[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 "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 almost GNU-compliant error message.  Lily used to be rather
41   GNU-compliant in this too, but correcting mudela is such a breeze if 
42   you('re edidor) know(s) the error column too (there's no GNU standard
43   on columns, is there?).
44
45   Format:
46
47     [file:line:column:][warning:]message
48
49  */
50 void
51 Input::message (String message_str) const
52 {
53   String str;
54   
55   /*
56     marked "Work in prgress" in GNU iostream 
57       libg++ 2.7.2.8
58       libstdc++ 2.8.1
59
60     why not just return always -1 (unknown), 
61     iso breaking the interface?
62
63   int col = cerr.rdbuf ()->column ();
64
65    */
66
67   // well, we don't want to loose first warning...
68   int col = 1;
69   if (col > 0)
70     str += "\n";
71   
72   if (source_file_l_)
73     str += location_str () + String (": ");
74
75   str += message_str;
76   if (source_file_l_)
77    {
78     str += ":\n";
79     str += source_file_l_->error_str (defined_ch_C_);
80    }
81   cerr << str << endl;
82 }
83
84 void
85 Input::warning (String message_str) const
86 {
87   message (_ ("warning: ") + message_str);
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_str () const
102 {
103   if (source_file_l_)
104     return source_file_l_->file_line_column_str (defined_ch_C_);
105   else
106     return "(" + _ ("position unknown") + ")";
107 }
108
109 String
110 Input::line_number_str () const
111 {
112   if (source_file_l_)
113     return to_str (source_file_l_->line_i (defined_ch_C_));
114   else
115     return "?";
116 }