summaryrefslogtreecommitdiff
path: root/lily/input.cc
blob: 77c5c14b2c06fb8f42510fbbc65a52b829fc2396 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 input.cc -- implement Input

 source file of the LilyPond music typesetter

  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/

#include <stdio.h>

#include "flower-proto.hh"
#include "input.hh"
#include "string.hh"
#include "source.hh"
#include "source-file.hh"

Input::Input (Source_file*s, char const *cl)
{
  source_file_=s;
  defined_str0_=cl;
}

Input::Input ()
{
  source_file_ = 0;
  defined_str0_ = 0;
}

Input
Input::spot () const
{
  return *this;
}

void
Input::set_spot (Input const &i)
{
  *this = i;
}

/*
  Produce GNU-compliant error message.  Correcting lilypond source is
  such a breeze if you ('re edidor) know (s) the error column too
  
  Format:

    [file:line:column:][warning:]message

 */
void
Input::message (String message_string) const
{
  String str;
  
  /*
    marked "Work in prgress" in GNU iostream 
      libg++ 2.7.2.8
      libstdc++ 2.8.1

    why not just return always -1 (unknown), 
    iso breaking the interface?

  int col = cerr.rdbuf ()->column ();

   */

  // well, we don't want to loose first warning...
  int col = 1;
  if (col > 0)
    str += "\n";
  
  if (source_file_)
    str += location_string () + String (": ");

  str += message_string;
  if (source_file_)
   {
    str += ":\n";
    str += source_file_->error_string (defined_str0_);
   }
  fprintf (stderr, "%s\n", str.to_str0 ());
  fflush (stderr);
}

void
Input::warning (String message_string) const
{
  message (_ ("warning: ") + message_string);
}
void
Input::error (String s) const
{
  message (_ ("error: ")+ s);
}

void
Input::non_fatal_error (String s) const
{
  message (_ ("non fatal error: ") + s);
}
String
Input::location_string () const
{
  if (source_file_)
    return source_file_->file_line_column_string (defined_str0_);
  else
    return " (" + _ ("position unknown") + ")";
}

String
Input::line_number_string () const
{
  if (source_file_)
    return to_string (source_file_->get_line (defined_str0_));
  else
    return "?";
}

String
Input::file_string () const
{
  if (source_file_)
    return source_file_->name_string ();
  else
    return "";
}


int
Input::line_number () const
{
  if (source_file_)
    return source_file_->get_line (defined_str0_);
  else
    return 0;

}

int
Input::column_number () const
{
  if (source_file_)
    return source_file_->get_column (defined_str0_);
  else
    return 0;

}