]> git.donarmstrong.com Git - lilypond.git/blob - lib/input.cc
release: 1.1.62
[lilypond.git] / lib / input.cc
1 /*
2  input.cc -- implement Input
3
4  source file of the LilyPond music typesetter
5
6  (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "proto.hh"
9 #include "input.hh"
10 #include "string.hh"
11 #include "source.hh"
12 #include "source-file.hh"
13
14 Input::Input (Source_file*s, char const *cl)
15 {
16   source_file_l_=s;
17   defined_ch_C_=cl;
18 }
19
20 Input::Input ()
21 {
22   source_file_l_ = 0;
23   defined_ch_C_ = 0;
24 }
25
26 Input
27 Input::spot () const
28 {
29   return *this;
30 }
31
32 void
33 Input::set_spot (Input const &i)
34 {
35   *this = i;
36 }
37
38 /*
39   Produce almost GNU-compliant error message.  Lily used to be rather
40   GNU-compliant in this too, but correcting mudela is such a breeze if 
41   you('re edidor) know(s) the error column too (there's no GNU standard
42   on columns, is there?).
43
44   Format:
45
46     [file:line:column:][warning:]message
47
48  */
49 void
50 Input::message (String message_str) 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_l_)
72     str += location_str () + String (": ");
73
74   str += message_str;
75   if (source_file_l_)
76    {
77     str += ":\n";
78     str += source_file_l_->error_str (defined_ch_C_);
79    }
80   cerr << str << endl;
81 }
82
83 void
84 Input::warning (String message_str) const
85 {
86   message (_ ("warning: ") + message_str);
87 }
88 void
89 Input::error (String s) const
90 {
91   message (_ ("error: ")+ s);
92 }
93
94 void
95 Input::non_fatal_error (String s) const
96 {
97   message (_ ("Non fatal error: ") + s);
98 }
99 String
100 Input::location_str () const
101 {
102   if (source_file_l_)
103     return source_file_l_->file_line_column_str (defined_ch_C_);
104   else
105     return "(" + _ ("position unknown") + ")";
106 }
107