]> git.donarmstrong.com Git - lilypond.git/blob - lily/input.cc
2003 -> 2004
[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 <stdio.h>
10
11 #include "flower-proto.hh"
12 #include "input.hh"
13 #include "string.hh"
14 #include "source.hh"
15 #include "source-file.hh"
16
17 Input::Input (Source_file*s, char const *cl)
18 {
19   source_file_=s;
20   defined_str0_=cl;
21 }
22
23 Input::Input ()
24 {
25   source_file_ = 0;
26   defined_str0_ = 0;
27 }
28
29 Input
30 Input::spot () const
31 {
32   return *this;
33 }
34
35 void
36 Input::set_spot (Input const &i)
37 {
38   *this = i;
39 }
40
41 /*
42   Produce GNU-compliant error message.  Correcting lilypond source is
43   such a breeze if you ('re edidor) know (s) the error column too
44   
45   Format:
46
47     [file:line:column:][warning:]message
48
49  */
50 void
51 Input::message (String message_string) 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_)
73     str += location_string () + String (": ");
74
75   str += message_string;
76   if (source_file_)
77    {
78     str += ":\n";
79     str += source_file_->error_string (defined_str0_);
80    }
81   fprintf (stderr, "%s\n", str.to_str0 ());
82   fflush (stderr);
83 }
84
85 void
86 Input::warning (String message_string) const
87 {
88   message (_ ("warning: ") + message_string);
89 }
90 void
91 Input::error (String s) const
92 {
93   message (_ ("error: ")+ s);
94 }
95
96 void
97 Input::non_fatal_error (String s) const
98 {
99   message (_ ("non fatal error: ") + s);
100 }
101 String
102 Input::location_string () const
103 {
104   if (source_file_)
105     return source_file_->file_line_column_string (defined_str0_);
106   else
107     return " (" + _ ("position unknown") + ")";
108 }
109
110 String
111 Input::line_number_string () const
112 {
113   if (source_file_)
114     return to_string (source_file_->get_line (defined_str0_));
115   else
116     return "?";
117 }
118
119 String
120 Input::file_string () const
121 {
122   if (source_file_)
123     return source_file_->name_string ();
124   else
125     return "";
126 }
127
128
129 int
130 Input::line_number () const
131 {
132   if (source_file_)
133     return source_file_->get_line (defined_str0_);
134   else
135     return 0;
136
137 }
138
139 int
140 Input::column_number () const
141 {
142   if (source_file_)
143     return source_file_->get_column (defined_str0_);
144   else
145     return 0;
146
147 }