]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/source-file.cc
(set_spacing_rods): new
[lilypond.git] / lily / source-file.cc
index eb83b0e1de40308ac598ac1312a0d5232e8f6dd0..6957cc19c0217e18e2af538b9d1f8547a789adbb 100644 (file)
@@ -3,14 +3,15 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1997--2005 Jan Nieuwenhuizen <janneke@gnu.org>
   Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
-#include "config.h"
+#include "source-file.hh"
+
+#include "config.hh"
 
-#include <stdio.h>
-#include <assert.h>
+#include <cstdio>
 #if HAVE_SSTREAM
 #include <sstream>
 #else
 #define istringstream(x) istrstream(x, length ()) 
 #endif
 
-#include "string.hh"
-#include "flower-proto.hh"
 #include "warn.hh"
-#include "source-file.hh"
-#include "array.hh"
 
 void
 Source_file::load_stdin ()
@@ -67,9 +64,6 @@ gulp_file (String filename, int *filesize)
   return str;
 }
 
-/*
-  Unused.
- */
 Source_file::Source_file (String filename, String data)
 {
   name_ = filename;
@@ -78,6 +72,10 @@ Source_file::Source_file (String filename, String data)
   length_ = data.length ();
   pos_str0_ = to_str0 ();
   init_port ();
+
+  for (int i = 0; i < length_; i++)
+    if (contents_str0_[i] == '\n')
+      newline_locations_.push (contents_str0_ + i);
 }
 
 Source_file::Source_file (String filename_string)
@@ -103,12 +101,9 @@ Source_file::Source_file (String filename_string)
 void
 Source_file::init_port ()
 {
-  SCM str =scm_makfrom0str (contents_str0_);
-  
-  str_port_ = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_RDNG,
-                            __FUNCTION__);
-  scm_set_port_filename_x (str_port_,
-                          scm_makfrom0str (name_.get_str0()));
+  SCM str = scm_makfrom0str (contents_str0_);
+  str_port_ = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_RDNG, __FUNCTION__);
+  scm_set_port_filename_x (str_port_, scm_makfrom0str (name_.get_str0 ()));
 }
 
 int
@@ -161,7 +156,7 @@ Slice
 Source_file::line_slice (char const* pos_str0) const
 {
   if (!contains (pos_str0))
-    return Slice (0,0);
+    return Slice (0, 0);
 
   char const* data_str0 = to_str0 ();
   char const * eof_C_ = data_str0 + length ();
@@ -258,7 +253,7 @@ Source_file::get_line (char const* pos_str0) const
   if (!newline_locations_.size ())
     return 1;
   
-  int lo=0;
+  int lo = 0;
   int hi = newline_locations_.size ();
 
   if (newline_locations_[lo] > pos_str0)