]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/input.cc
Massive changes - see ChangeLog.
[lilypond.git] / lily / input.cc
index 1ff4e8624431809cb2092c3b175a54af61ac75b7..d5bfe1e958a3987bff9c27dfcee8eb1b478a6cf4 100644 (file)
 /*
 input.cc -- implement Input
+ input.cc -- implement Input
 
 source file of the LilyPond music typesetter
+ source file of the LilyPond music typesetter
 
-  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
-#include "proto.hh"
+
+#include <stdio.h>
+
+#include "flower-proto.hh"
 #include "input.hh"
 #include "string.hh"
 #include "source.hh"
 #include "source-file.hh"
 
-Input::Input(Sources*s, char const *cl)
+Input::Input (Source_file*s, char const *cl)
 {
-    sources_l_=s;
-    defined_ch_C_=cl;
+  source_file_=s;
+  defined_str0_=cl;
 }
 
-Input::Input()
+Input::Input ()
 {
-    sources_l_ = 0;
-    defined_ch_C_ = 0;
+  source_file_ = 0;
+  defined_str0_ = 0;
 }
 
-Input::Input(Input const &s)
+Input
+Input::spot () const
 {
-    sources_l_ = s.sources_l_;
-    defined_ch_C_ = s.defined_ch_C_;
+  return *this;
 }
 
 void
-Input::set_spot(Input const &i)
+Input::set_spot (Input const &i)
 {
-    *this  = 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_str)const
+Input::message (String message_string) const
 {
-    String str = "";
-    Source_file* sourcefile_l=0;
-    
-    if (sources_l_) 
-       sourcefile_l = sources_l_->sourcefile_l( defined_ch_C_ );
-    
-    if ( sourcefile_l ) {
-       str += sourcefile_l->file_line_no_str(defined_ch_C_) + String(": ");
-    }
-    
-    str += message_str;
-    if ( sourcefile_l ) {
-       str += ":\n";
-       str += sourcefile_l->error_str( defined_ch_C_);
-    }
-    /*
-    if ( busy_parsing() )
-       cerr << endl;
-       */
-    cerr << str << endl;
+  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_str)const
+Input::warning (String message_string) const
 {
-    message( "warning: " + message_str);
+  message (_ ("warning: ") + message_string);
 }
 void
-Input::error(String s)const
+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
 {
-    message("error: "+ s);
-    exit (1);
+  if (source_file_)
+    return to_string (source_file_->get_line (defined_str0_));
+  else
+    return "?";
 }
 
 String
-Input::location_str()const
+Input::file_string () const
 {
-    Source_file * sourcefile_l=0;
-    if (sources_l_)
-       sourcefile_l = sources_l_->sourcefile_l (defined_ch_C_);
-    if (sourcefile_l) 
-       return sourcefile_l->file_line_no_str(defined_ch_C_);
-    else
-       return "(location unknown)";
+  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;
+
 }