source file of the GNU LilyPond music typesetter
- (c) 1997--2006 Jan Nieuwenhuizen <janneke@gnu.org>
+ (c) 1997--2007 Jan Nieuwenhuizen <janneke@gnu.org>
Han-Wen Nienhuys <hanwen@xs4all.nl>
*/
int c;
while ((c = fgetc (stdin)) != EOF)
characters_.push_back (c);
-
- characters_.push_back (0);
}
+/*
+ return contents of FILENAME. *Not 0-terminated!*
+ */
vector<char>
gulp_file (string filename, int desired_size)
{
FILE *f = fopen (filename.c_str (), "rb");
if (!f)
{
- warning (_f ("can't open file: `%s'", filename.c_str ()));
+ warning (_f ("cannot open file: `%s'", filename.c_str ()));
vector<char> cxx_arr;
return cxx_arr;
name_ = filename;
characters_.resize (data.length ());
-
copy (data.begin (), data.end (), characters_.begin ());
+ characters_.push_back (0);
+
init_port ();
for (vsize i = 0; i < characters_.size (); i++)
else
{
characters_ = gulp_file (filename_string, -1);
- characters_.push_back (0);
}
+ characters_.push_back (0);
+
init_port ();
for (vsize i = 0; i < characters_.size (); i++)
void
Source_file::init_port ()
{
- SCM str = scm_makfrom0str (c_str ());
+ SCM str = scm_from_locale_string (c_str ());
str_port_ = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_RDNG, __FUNCTION__);
- scm_set_port_filename_x (str_port_, scm_makfrom0str (name_.c_str ()));
+ scm_set_port_filename_x (str_port_, ly_string2scm (name_));
}
Source_file::~Source_file ()
{
delete istream_;
- istream_ = 0;
}
Slice
while (left > 0)
{
- wchar_t multibyte[2];
-
/*
FIXME, this is apparently locale dependent.
*/
#if HAVE_MBRTOWC
+ wchar_t multibyte[2];
size_t thislen = mbrtowc (multibyte, line_chars, left, &state);
#else
size_t thislen = 1;
if (!newline_locations_.size ())
return 1;
- vsize lo = 0;
- vsize hi = newline_locations_.size ();
-
- if (newline_locations_[lo] > pos_str0)
- return 1;
-
- if (newline_locations_[hi - 1] < pos_str0)
- return hi;
-
- binary_search_bounds (newline_locations_,
- (char const*&)pos_str0,
- default_compare,
- &lo, &hi);
+ /* this will find the '\n' character at the end of our line */
+ vsize lo = lower_bound (newline_locations_,
+ pos_str0,
+ less<char const*> ());
- if (*pos_str0 == '\n')
- lo--;
- return lo + 2 + line_offset_;
+ /* the return value will be indexed from 1 */
+ return lo + 1 + line_offset_;
}
void