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 ()
return str;
}
-/*
- Unused.
- */
Source_file::Source_file (String filename, String data)
{
name_ = filename;
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)
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
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 ();
if (!newline_locations_.size ())
return 1;
- int lo=0;
+ int lo = 0;
int hi = newline_locations_.size ();
if (newline_locations_[lo] > pos_str0)