]> git.donarmstrong.com Git - lilypond.git/blob - lily/warn.cc
release: 0.0.46.jcn1
[lilypond.git] / lily / warn.cc
1 /*
2   warn.cc -- implement warning and error messages. Needs cleanup.
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "proto.hh"
10 #include "plist.hh"
11 #include "debug.hh"
12 #include "my-lily-lexer.hh"
13 #include "moment.hh"
14 #include "time-description.hh"
15 #include "source-file.hh"
16 #include "source.hh"
17 #include "main.hh"
18 #include "input.hh"
19
20 ostream &warnout (cerr);
21 ostream *mlog(&cerr);
22
23
24 void
25 error(String s)
26 {
27     cerr <<  "error: " << s << "\n";
28         
29     exit(1);
30 }
31
32 void
33 error_t(String const & s, Moment const & r)
34 {
35     String t_mom = String(trunc(r)) + String(r - Moment(trunc(r)));
36     String e=s+ " (t = " +  t_mom + ")";
37     error(e);
38 }
39
40 void
41 error_t(String const & s, Time_description const &t_tdes)
42 {
43     String e=s+ " (at t=" + String(t_tdes.bars_i_) + ": " + String(t_tdes.whole_in_measure_) + ")\n";
44     error(e);
45 }
46
47 void
48 message( String message_str, char const* context_ch_C )
49 {
50     String str = "";
51     Source_file* sourcefile_l = source_l_g->sourcefile_l( context_ch_C );
52     if ( sourcefile_l ) {
53         str += sourcefile_l->file_line_no_str(context_ch_C) + String(": ");
54     }
55     str += message_str;
56     if ( sourcefile_l ) {
57         str += ":\n";
58         str += sourcefile_l->error_str( context_ch_C );
59     }
60     if ( busy_parsing() )
61         cerr << endl;
62     cerr << str << endl;
63 }
64
65 void
66 warning( String message_str, char const* context_ch_C )
67 {
68     message( "warning: " + message_str, context_ch_C );
69 }
70
71 void
72 error( String message_str, char const* context_ch_C )
73 {
74     message( message_str, context_ch_C );
75     // since when exits error again?
76     // i-d say: error: errorlevel |= 1; -> no output upon error
77     //          warning: recovery -> output (possibly wrong)
78 /*    if ( lexer )
79         lexer->errorlevel_i_ |= 1;*/
80 //    exit( 1 );
81 }
82
83
84 void
85 warning(String m)
86 {
87     warning(m, (char*)0);
88 }
89
90 void
91 message(String m)
92 {
93     error(m, (char*)0);
94 }