]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/source-file.cc (init_port): add an SCM port to the
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 17 Aug 2002 01:30:28 +0000 (01:30 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 17 Aug 2002 01:30:28 +0000 (01:30 +0000)
sourcefile as well.

* lily/parse-scm.cc (parse_handler): don't construct a new strport
for every parsing.

* lily/include/input-file-results.hh: move from
file-results. Rename Input_file_settings to Input_file_results.

42 files changed:
ChangeLog
flower/binary-source-file.cc [deleted file]
flower/include/binary-source-file.hh [deleted file]
flower/include/input.hh [deleted file]
flower/include/mapped-file-storage.hh [deleted file]
flower/include/simple-file-storage.hh [deleted file]
flower/include/source-file.hh [deleted file]
flower/include/source.hh [deleted file]
flower/include/string-storage.hh [deleted file]
flower/input.cc [deleted file]
flower/mapped-file-storage.cc [deleted file]
flower/simple-file-storage.cc [deleted file]
flower/source-file.cc [deleted file]
flower/source.cc [deleted file]
lily/binary-source-file.cc [new file with mode: 0644]
lily/includable-lexer.cc
lily/include/binary-source-file.hh [new file with mode: 0644]
lily/include/file-results.hh [deleted file]
lily/include/input-file-results.hh [new file with mode: 0644]
lily/include/input.hh [new file with mode: 0644]
lily/include/lily-proto.hh
lily/include/my-lily-parser.hh
lily/include/parse-scm.hh
lily/include/score.hh
lily/include/source-file.hh [new file with mode: 0644]
lily/include/source.hh [new file with mode: 0644]
lily/input-file-results.cc [new file with mode: 0644]
lily/input.cc [new file with mode: 0644]
lily/lexer.ll
lily/lily-guile.cc
lily/main.cc
lily/my-lily-lexer.cc
lily/my-lily-parser.cc
lily/paper-def.cc
lily/paper-outputter.cc
lily/paper-score.cc
lily/parse-scm.cc
lily/parser.yy
lily/performance.cc
lily/scores.cc [deleted file]
lily/source-file.cc [new file with mode: 0644]
lily/source.cc [new file with mode: 0644]

index aaaa0c6aea1a7be450397912d845296ccbf02825..4e948b5c3804ae3c24e1aa220d66bc9e95d1f32b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2002-08-17  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
 
+       * lily/source-file.cc (init_port): add an SCM port to the
+       sourcefile as well.
+
+       * lily/parse-scm.cc (parse_handler): don't construct a new strport
+       for every parsing.
+
+       * lily/include/input-file-results.hh: move from
+       file-results. Rename Input_file_settings to Input_file_results.
+
+       * flower/ : remove simple-file-storage, mapped-file-storage,
+       string-storage. Move source-file, binary-source-file to lily/
+
        * Documentation/header.html.in: remove FAQ
 
        * Documentation/index.texi (Top): reorganise
@@ -8,8 +20,6 @@
 
        * Documentation/topdocs/FAQ.texi: remove.
 
-       
-
        * stepmake/stepmake/documentation-targets.make (footify): must
        depend on all .html files, otherwise rebuilds are broken due to
        the time stamps 
diff --git a/flower/binary-source-file.cc b/flower/binary-source-file.cc
deleted file mode 100644 (file)
index bd6a4f8..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
-  binary-source-file.cc -- implement Binary_source_file
-
-  source file of the LilyPond music typesetter
-
-  (c)  1997--2000 Jan Nieuwenhuizen
-*/
-
-
-#include <limits.h>            // INT_MAX
-#include <assert.h>
-
-#include "flower-proto.hh"
-#include "string.hh"
-#include "source-file.hh"
-#include "binary-source-file.hh"
-#include "string-convert.hh"
-
-Binary_source_file::Binary_source_file (String& filename_string)
-  : Source_file (filename_string)
-{
-}
-
-Binary_source_file::~Binary_source_file ()
-{
-}
-
-String
-Binary_source_file::error_string (char const* pos_str0) const
-{
-  assert (this);
-  if (!in_b (pos_str0))
-    return "";
-
-  char const* begin_str0 = pos_str0 - 8 >? to_str0 ();
-  char const* end_str0 = pos_str0 + 7 <? to_str0 () + length ();
-
-  String pre_string ((Byte const*)begin_str0, pos_str0 - begin_str0);
-  pre_string = String_convert::bin2hex (pre_string);
-  for (int i = 2; i < pre_string.length (); i += 3)
-    pre_string = pre_string.left_string (i) + " " + pre_string.cut_string (i, INT_MAX);
-  String post_string ((Byte const*)pos_str0, end_str0 - pos_str0);
-  post_string = String_convert::bin2hex (post_string);
-  for (int i = 2; i < post_string.length (); i += 3)
-    post_string = post_string.left_string (i) + " " + post_string.cut_string (i, INT_MAX);
-
-  String str = pre_string
-    + to_string ('\n')
-    + to_string (' ', pre_string.length () + 1) 
-    + post_string;
-  return str;
-}
-
-int
-Binary_source_file::get_line (char const* pos_str0) const
-{
-  if (!in_b (pos_str0))
-    return 0;
-
-  return pos_str0 - to_str0 ();
-}
-
-U8
-Binary_source_file::get_U8 ()
-{
-  return * (U8*)forward_str0 (1);
-}
-
-
-U16
-Binary_source_file::get_U16 ()
-{
-  U16 b;
-
-  b = get_U8 () << 8;
-  b |= get_U8 ();
-
-  return b;
-}
-
-
-U32
-Binary_source_file::get_U32 ()
-{
-  U32 b;
-  
-  b = get_U8 () << 24;
-  b |= get_U8 () << 16;
-  b |= get_U8 () << 8;
-  b |= get_U8 ();
-
-  return b;
-}
-
-
diff --git a/flower/include/binary-source-file.hh b/flower/include/binary-source-file.hh
deleted file mode 100644 (file)
index 639e05c..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-//
-//  binary-source-file.hh -- declare Binary_source_file
-//
-//  copyright 1997 Jan Nieuwenhuizen <janneke@gnu.org>
-
-#ifndef BINARY_SOURCE_FILE_HH
-#define BINARY_SOURCE_FILE_HH
-
-#include "source-file.hh"
-
-class Binary_source_file : public Source_file
-{
-public:
-  Binary_source_file (String& filename_string );
-  virtual ~Binary_source_file ();
-
-  U8 get_U8 (); 
-  U16 get_U16 ();
-  U32 get_U32 ();
-  Byte get_Byte () {return get_U8 (); }
-  int get_int () { return get_U32 (); }
-  
-  virtual String error_string (char const* pos_str0 ) const;
-  virtual int get_line (char const* pos_str0 ) const;
-};
-
-#endif // BINARY_SOURCE_FILE_HH
diff --git a/flower/include/input.hh b/flower/include/input.hh
deleted file mode 100644 (file)
index 4b12e25..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
-  input.hh -- declare Input
-
-  source file of the LilyPond music typesetter
-
-  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-*/
-
-
-#ifndef INPUT_HH
-#define INPUT_HH
-
-#include "flower-proto.hh"
-
-/**
-  Base class for anything that records its poisition in the parse file.
- */
-class Input {
-  char const *defined_str0_ ;
-  Source_file * source_file_;
-public:
-    
-  void warning (String) const; // should use member func?
-  void non_fatal_error (String) const;
-  void error (String) const;
-  void message (String) const;
-  void set_spot (Input const &);
-  Input spot () const;
-  String location_string () const;
-  String line_number_string () const;
-
-
-  String file_string ()const;
-  int line_number ()const;
-  int column_number ()const;
-
-  
-  Input (Source_file*, char const*);
-  Input ();
-};
-
-#endif // INPUT_HH
diff --git a/flower/include/mapped-file-storage.hh b/flower/include/mapped-file-storage.hh
deleted file mode 100644 (file)
index a936401..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*   
-  mapped-file-storage.hh -- declare Mapped_file_storage
-  
-  source file of the GNU LilyPond music typesetter
-  
-  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  
- */
-
-#ifndef MAPPED_FILE_STORAGE_HH
-#define MAPPED_FILE_STORAGE_HH
-
-
-
-#include "file-storage.hh"
-
-/**
-  Use mmap to "copy"  a file into memory
- */
-class Mapped_file_storage:public File_storage
-{
-public:
-  Mapped_file_storage (String);    
-protected:
-  virtual char const* to_str0 () const;
-  virtual int length () const;
-  virtual ~Mapped_file_storage ();
-private:
-  void open (String name);
-  void close ();
-
-  void map ();
-  void unmap ();
-  int fildes_;
-  off_t size_off_;
-  caddr_t data_caddr_;
-};
-
-#endif /* MAPPED_FILE_STORAGE_HH */
-
diff --git a/flower/include/simple-file-storage.hh b/flower/include/simple-file-storage.hh
deleted file mode 100644 (file)
index f551ed8..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*   
-  simple-file-storage.hh -- declare 
-  
-  source file of the GNU LilyPond music typesetter
-  
-  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  
- */
-
-#ifndef SIMPLE_FILE_STORAGE_HH
-#define SIMPLE_FILE_STORAGE_HH
-
-#include "file-storage.hh"
-
-/**
-  read file char by char and copy into a malloc array.
- */
-class Simple_file_storage  : public File_storage
-{
-  char * data_;
-  int len_;
-
-  void load_stdin ();
-  void load_file (String);
-public:
-  virtual char const*to_str0 () const;
-  virtual int length () const;
-  virtual ~Simple_file_storage ();
-  Simple_file_storage (String);
-};
-
-#endif /* SIMPLE_FILE_STORAGE_HH */
-
diff --git a/flower/include/source-file.hh b/flower/include/source-file.hh
deleted file mode 100644 (file)
index 9e9d8c3..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-
-#ifndef SOURCE_FILE_HH
-#define SOURCE_FILE_HH
-
-#include <iostream>
-
-#include "flower-proto.hh"
-#include "string.hh"
-#include "interval.hh"
-
-/**
-  class for reading and mapping a file. 
-
-  duplicates a lot of Data_file and Text_stream.
-  should look at including Data_file's functionality:
-  get_line (), get_word () here.
-*/
-
-class Source_file
-{
-public:
-  /** Ugh! filename gets changed! The path to the opened file may
-    change, since it might be searched in multiple directories.  */
-  Source_file (String filename_string_r );
-
-  Source_file (String name_string, String data_string);
-  virtual ~Source_file ();
-
-  char const* to_str0 () const;
-  virtual String error_string (char const* pos_str0 ) const;
-  std::istream * get_istream ();
-  bool in_b (char const* pos_str0 ) const;
-  int length () const;
-  virtual int get_line (char const* pos_str0 ) const;
-  String name_string () const;
-  String file_line_column_string (char const* str0 ) const;
-
-  // return start + n
-  char const* seek_str0 (int n);
-  // return here + n bytes
-  char const* forward_str0 (int n);
-  char const* pos_str0 () { return pos_str0_; }
-  String get_string (int n);
-  void set_pos (char const * pos_str0);
-public:
-  Slice line_slice (char const* pos_str0) const;
-  String line_string (char const* pos_str0) const;
-  int get_column (char const* pos_str0) const;
-  int get_char (char const* pos_str0) const;
-
-  /*
-    DOCUMENT-ME
-   */
-  char const* pos_str0_;
-
-private:
-  String name_string_;
-  std::istream* istream_;
-  File_storage * storage_;
-};
-
-#endif // SOURCE_FILE_HH //
-
diff --git a/flower/include/source.hh b/flower/include/source.hh
deleted file mode 100644 (file)
index 82b557b..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-//
-//  source.hh -- part of LilyPond
-//
-//  copyright 1997 Jan Nieuwenhuizen <janneke@gnu.org>
-
-#ifndef SOURCE_HH
-#define SOURCE_HH
-#include "cons.hh"
-#include "flower-proto.hh"
-
-/**
-   a set of sourcefiles.
-
-   TODO: 
- */
-class Sources 
-{
-  Sources (Sources const&) {}
-public:
-  Sources ();
-  ~Sources ();
-
-  Source_file * get_file (String &filename );
-  Source_file* get_sourcefile (char const* str0 );
-  void add (Source_file* sourcefile );
-  void set_path (File_path*p);
-  void set_binary (bool);
-
-  const File_path * path_C_;
-private:
-  Cons<Source_file> *sourcefile_p_list_;
-  bool binary_b_ ;
-};
-
-
-
-#endif // SOURCE_HH //
diff --git a/flower/include/string-storage.hh b/flower/include/string-storage.hh
deleted file mode 100644 (file)
index dfe49c8..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*   
-  string-storage.hh -- declare String_storage
-  
-  source file of the GNU LilyPond music typesetter
-  
-  (c) 1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
-  
- */
-
-#ifndef STRING_STORAGE_HH
-#define STRING_STORAGE_HH
-
-#include "string.hh"
-#include "file-storage.hh"
-
-/**
- Urg, let String act as file storage.
- */
-class String_storage : public File_storage, protected String
-{
-public:
-  String_storage (String s) : String (s) { }
-
-protected:    
-  virtual char const* to_str0 () const { return String::to_str0 (); }
-  virtual int length () const { return String::length (); }
-};
-
-#endif /* STRING_STORAGE_HH */
-
diff --git a/flower/input.cc b/flower/input.cc
deleted file mode 100644 (file)
index 381907d..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- input.cc -- implement Input
-
- source file of the LilyPond music typesetter
-
-  (c) 1997--2000 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 ());
-}
-
-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;
-
-}
diff --git a/flower/mapped-file-storage.cc b/flower/mapped-file-storage.cc
deleted file mode 100644 (file)
index f9baca9..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-#ifdef HAIRY_STUFF
-
-/*
-  file-storage.cc -- implement Mapped_file_storage
-
-  source file of the GNU LilyPond music typesetter
-
-  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  Jan Nieuwenhuizen <janneke@gnu.org>.
-
-  Nextstep fixes by tiggr@ics.ele.tue.nl
-*/
-
-#include <sys/types.h>         // open, mmap
-#include <sys/stat.h>          // open
-#include <sys/mman.h>          // mmap
-#include <limits.h>            // INT_MAX
-#include <fcntl.h>             // open
-#include <unistd.h>            // close, stat
-#include <stdio.h>             // fdopen
-#include <string.h>            // strerror
-#include <errno.h>             // errno
-
-
-
-#ifdef __NeXT__
-#include <mach/mach.h>
-#include <mach/mach_traps.h>
-#include <mach/mach_error.h>
-#endif
-
-#include "string.hh"
-#include "flower-proto.hh"
-#include "warn.hh"
-#include "file-storage.hh"
-
-Mapped_file_storage::Mapped_file_storage (String s)
-{
-  data_caddr_ = 0;
-  fildes_ = 0;
-  size_off_ = 0;
-  open (s);
-}
-
-char const*
-Mapped_file_storage::to_str0 () const
-{
-  return (char const*)data_caddr_;
-}
-
-void
-Mapped_file_storage::map ()
-{
-  if (fildes_ == -1)
-    return;
-  
-#ifdef __NeXT__
-   /* Should be #if !HAVE_MMAP && HAVE_MAP_FD...  */
-   {
-     vm_offset_t address;
-     kern_return_t r;
-     r = map_fd (fildes_, (vm_offset_t) 0, &address, TRUE, size_off_);
-     if (r != KERN_SUCCESS)
-       warning (String ("map_fd: ") + mach_error_string (r));
-     else
-       data_caddr_ = (char *) address;
-   }
-#else
-
-  data_caddr_ = (caddr_t)mmap ((void*)0, size_off_, PROT_READ, MAP_SHARED, fildes_, 0);
-
-  if ((int)data_caddr_ == -1)
-    warning (_ ("can't map file") + ": " + strerror (errno));
-
-#endif
-}
-
-
-void
-Mapped_file_storage::open (String name_string)
-{
-  fildes_ = ::open (name_string.to_str0 (), O_RDONLY);
-
-  if (fildes_ == -1)
-    {
-      warning (_f ("can't open file: `%s'", name_string)
-       + ": " + strerror (errno));
-      return;
-    }
-
-  struct stat file_stat;
-  fstat (fildes_, &file_stat);
-  size_off_ = file_stat.st_size;
-  map ();
-}
-
-void
-Mapped_file_storage::unmap ()
-{
-  if (data_caddr_)
-    {
-#ifdef __NeXT__
-       kern_return_t r;
-       r = vm_deallocate (task_self (), (vm_address_t) data_caddr_, 
-size_off_);
-       if (r != KERN_SUCCESS)
-       warning (String ("vm_deallocate: ") + mach_error_string (r));
-#else
-       munmap (data_caddr_, size_off_);
-#endif
-       
-      data_caddr_ = 0;
-      size_off_ = 0;
-    }
-}
-
-void
-Mapped_file_storage::close ()
-{
-  unmap ();
-  if (fildes_)
-    {
-      ::close (fildes_);
-      fildes_ = 0;
-    }
-}
-
-int
-Mapped_file_storage::length () const
-{
-  return size_off_;
-}
-
-Mapped_file_storage::~Mapped_file_storage ()
-{
-  close ();
-}
-#endif
diff --git a/flower/simple-file-storage.cc b/flower/simple-file-storage.cc
deleted file mode 100644 (file)
index 10fd790..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
-  simple-file-storage.cc -- implement Simple_file_storage
-
-  source file of the GNU LilyPond music typesetter
-
-  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-*/
-
-#include <stdio.h>
-
-#ifndef SEEK_END
-#define SEEK_END 2
-#endif
-
-#include "simple-file-storage.hh"
-#include "array.hh"
-#include "string.hh"
-#include "warn.hh"
-
-void
-Simple_file_storage::load_stdin ()
-{
-  len_ = 0;
-
-  int c;
-  Array<char> chs;
-  while ((c = fgetc (stdin)) != EOF)
-    chs.push (c);
-  len_ = chs.size ();
-  data_ = chs.remove_array ();
-}
-
-void
-Simple_file_storage::load_file (String s)
-{
-  /*
-    let's hope that "b" opens anything binary, and does not apply
-    CR/LF translation
-    */
-  FILE * f =  fopen (s.to_str0 (), "rb");
-
-  if (!f)
-    {
-      warning (_f ("can't open file: `%s'", s));
-      return ;
-    }
-
-  int ret = fseek (f, 0, SEEK_END);
-  len_ = ftell (f);
-  rewind (f);
-  data_ = new char[len_+1];
-  data_[len_] = 0;
-  ret = fread (data_, sizeof (char), len_, f);
-
-  if (ret!=len_)
-    warning (_f ("Huh?  Got %d, expected %d characters", ret, len_));
-
-  fclose (f);
-}
-
-/**
-  Stupid but foolproof way of opening files.
-
-  TODO
-  Should check IO status
-
-  This is of course a build it yourself version of mmap, so we should
-  have been using that..., but this is simple & portable
-  
-*/
-
-Simple_file_storage::Simple_file_storage (String s)
-{
-  data_ = 0;
-  len_ = 0;
-
-  if ((s == "-"))
-    load_stdin ();
-  else
-    load_file (s);
-}
-
-char const*
-Simple_file_storage::to_str0 () const
-{
-  return data_;
-}
-
-int
-Simple_file_storage::length () const
-{
-  return len_;
-}
-
-
-Simple_file_storage::~Simple_file_storage ()
-{
-  delete []data_;
-}
diff --git a/flower/source-file.cc b/flower/source-file.cc
deleted file mode 100644 (file)
index a27e1f7..0000000
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
-  source-file.cc -- implement Source_file
-
-  source file of the GNU LilyPond music typesetter
-
-  (c)  1997--2000 Jan Nieuwenhuizen <janneke@gnu.org>
-  & Han-Wen Nienhuys <hanwen@cs.uu.nl>
-*/
-
-
-#include <assert.h>
-#if HAVE_SSTREAM
-#include <sstream>
-#else
-#include <strstream.h>
-#define istringstream(x) istrstream(x, length ()) 
-#endif
-
-#include "string.hh"
-#include "flower-proto.hh"
-#include "warn.hh"
-#include "source-file.hh"
-#include "simple-file-storage.hh"
-#include "string-storage.hh"
-
-Source_file::Source_file (String filename_string)
-{
-  name_string_ = filename_string;
-  istream_ = 0;
-  storage_ = new Simple_file_storage (filename_string);
-  pos_str0_ = to_str0 ();
-}
-
-Source_file::Source_file (String name_string, String data_string)
-{
-  name_string_ = name_string;
-  istream_ = 0;
-  storage_ = new String_storage (data_string);
-  pos_str0_ = to_str0 ();
-}
-
-std::istream*
-Source_file::get_istream ()
-{
-  /*
-    if (!name_string_.length ())
-      return &cin;
-    */
-
-  if (!istream_)
-    {
-      if (length ()) // can-t this be done without such a hack?
-       istream_ = new std::istringstream (to_str0 ());
-      else
-       {
-         istream_ = new std::istringstream ("");
-         istream_->setstate (std::ios::eofbit);
-         //      istream_->set (ios::eofbit);
-       }
-    }
-  return istream_;
-}
-
-String
-Source_file::file_line_column_string (char const *context_str0) const
-{
-  if (!to_str0 ())
-    return " (" + _ ("position unknown") + ")";
-  else
-    return name_string () + ":" + to_string (get_line (context_str0))
-      + ":" + to_string (get_char (context_str0));
-}
-
-String
-Source_file::name_string () const
-{
-  return name_string_;
-}
-
-Source_file::~Source_file ()
-{
-  delete istream_;
-  istream_ = 0;
-  delete storage_;
-}
-
-Slice
-Source_file::line_slice (char const* pos_str0) const
-{
-  if (!in_b (pos_str0))
-    return Slice (0,0);
-
-  char const* data_str0 = to_str0 ();
-  char const * eof_C_ = data_str0 + length ();
-
-  if (pos_str0 == eof_C_)
-    pos_str0 --;
-  char const* begin_str0 = pos_str0;
-  while (begin_str0 > data_str0)
-    if (*--begin_str0 == '\n')
-      {
-       begin_str0++;
-       break;
-      }
-
-  char const* end_str0 = pos_str0;
-  while (end_str0 < eof_C_)
-    if (*end_str0++ == '\n')
-      {
-       end_str0--;
-       break;
-      }
-
-  return Slice (begin_str0 - data_str0, end_str0 - data_str0);
-}
-
-String
-Source_file::line_string (char const* pos_str0) const
-{
-  if (!in_b (pos_str0))
-    return "";
-
-  Slice line = line_slice (pos_str0);
-  char const* data_str0 = to_str0 ();
-  return String ((Byte const*)data_str0 + line[LEFT], line.length ());
-}
-
-int
-Source_file::get_char (char const* pos_str0) const
-{
-  if (!in_b (pos_str0))
-    return 0;
-
-  char const* data_str0 = to_str0 ();
-  return pos_str0 - (line_slice (pos_str0)[SMALLER] + data_str0);
-}
-
-int
-Source_file::get_column (char const* pos_str0) const
-{
-  if (!in_b (pos_str0))
-    return 0;
-
-  int ch_i = get_char (pos_str0);
-  String line = line_string (pos_str0);
-
-  int col_i = 0;
-  for (int i = 0; i < ch_i; i++)
-    if (line[i] == '\t')
-      col_i = (col_i / 8 + 1) * 8;
-    else
-      col_i++;
-
-  return col_i;
-}
-
-String
-Source_file::error_string (char const* pos_str0) const
-{
-  if (!in_b (pos_str0))
-    return " (" + _ ("position unknown") + ")";
-
-  int ch_i = get_char (pos_str0);
-  String line = line_string (pos_str0);
-  String context = line.left_string (ch_i)
-    + to_string ('\n')
-    + to_string (' ', get_column (pos_str0))
-    + line.cut_string (ch_i, INT_MAX);
-
-  return context;
-}
-
-bool
-Source_file::in_b (char const* pos_str0) const
-{
-  return (pos_str0 && (pos_str0 >= to_str0 ()) && (pos_str0 <= to_str0 () + length ()));
-}
-
-int
-Source_file::get_line (char const* pos_str0) const
-{
-  if (!in_b (pos_str0))
-    return 0;
-
-  int i = 1;
-  char const* scan_str0 = to_str0 ();
-  if (!scan_str0)
-    return 0;
-
-  while (scan_str0 < pos_str0)
-    if (*scan_str0++ == '\n')
-      i++;
-  return i;
-}
-
-int
-Source_file::length () const
-{
-  return storage_->length ();
-}
-
-char const *
-Source_file::to_str0 () const
-{
-  return storage_->to_str0 ();
-}
-
-void
-Source_file::set_pos (char const * pos_str0)
-{
-  if (in_b (pos_str0))
-    pos_str0_ = pos_str0;
-  else
-    error (error_string (pos_str0) + "invalid pos");
-}
-
-char const*
-Source_file::seek_str0 (int n)
-{
-  char const* new_str0 = to_str0 () + n;
-  if (n < 0)
-    new_str0 += length ();
-  if (in_b (new_str0))
-    pos_str0_ = new_str0;
-  else
-    error (error_string (new_str0) + "seek past eof");
-
-  return pos_str0_;
-}
-
-char const*
-Source_file::forward_str0 (int n)
-{
-  char const* old_pos = pos_str0_;
-  char const* new_str0 = pos_str0_ + n;
-  if (in_b (new_str0))
-    pos_str0_ = new_str0;
-  else
-    error (error_string (new_str0)  + "forward past eof");
-
-  return old_pos;
-}
-
-String
-Source_file::get_string (int n)
-{
-  String str = String ((Byte const*)forward_str0 (n), n);
-  return str;
-}
diff --git a/flower/source.cc b/flower/source.cc
deleted file mode 100644 (file)
index cffc798..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
-  source.cc -- implement Sources
-
-  source file of the LilyPond music typesetter
-
-  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-*/
-
-
-#include <assert.h>
-#include "killing-cons.tcc"
-#include "binary-source-file.hh"
-#include "string.hh"
-#include "flower-proto.hh"
-#include "source-file.hh"
-#include "source.hh"
-#include "file-path.hh"
-
-Sources::Sources ()
-{
-  sourcefile_p_list_ = 0;
-  path_C_= 0;
-  binary_b_ = false;
-}
-
-void
-Sources::set_binary (bool bo)
-{
-  binary_b_ = bo;
-}
-
-void
-Sources::set_path (File_path *f)
-{
-  path_C_ = f;
-}
-
-/**
-  open a file
-
-  @param file_string the file to be opened, name might be changed if it
-  is found in a search path. UGH!
-
-  @return 0 if no file found
-  */
-Source_file*
-Sources::get_file (String &file_string) //UGH
-{
-  if ((file_string != "-") && path_C_)
-    {
-      String file_string_o = path_C_->find (file_string); 
-      if ((file_string_o == "") && (file_string != ""))
-       return 0;
-      file_string = file_string_o;
-    }
-  Source_file * f = (!binary_b_) ?
-    new Source_file (file_string) : new Binary_source_file (file_string);
-  add (f);
-  return f;
-}
-
-void
-Sources::add (Source_file* sourcefile)
-{
-  sourcefile_p_list_ = new Killing_cons<Source_file> (sourcefile, sourcefile_p_list_);
-}
-
-Sources::~Sources ()
-{
-  delete sourcefile_p_list_;
-}
-/**
-  search the list for file whose map contains pointer #str0#
-
-  @return 0 if not found.
-  */
-Source_file*
-Sources::get_sourcefile (char const* str0)
-{
-
-  for (Cons<Source_file> *i = sourcefile_p_list_; i; i = i->next_)
-    if (i->car_->in_b (str0))  
-      return i->car_;
-  return 0;
-}
-
diff --git a/lily/binary-source-file.cc b/lily/binary-source-file.cc
new file mode 100644 (file)
index 0000000..ab1c084
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+  binary-source-file.cc -- implement Binary_source_file
+
+  source file of the LilyPond music typesetter
+
+  (c)  1997--2000 Jan Nieuwenhuizen
+*/
+
+
+#include <limits.h>            // INT_MAX
+#include <assert.h>
+
+#include "flower-proto.hh"
+#include "string.hh"
+#include "source-file.hh"
+#include "binary-source-file.hh"
+#include "string-convert.hh"
+
+Binary_source_file::Binary_source_file (String& filename_string)
+  : Source_file (filename_string)
+{
+}
+
+Binary_source_file::~Binary_source_file ()
+{
+}
+
+String
+Binary_source_file::error_string (char const* pos_str0) const
+{
+  assert (this);
+  if (!in_b (pos_str0))
+    return "";
+
+  char const* begin_str0 = pos_str0 - 8 >? to_str0 ();
+  char const* end_str0 = pos_str0 + 7 <? to_str0 () + length ();
+
+  String pre_string ((Byte const*)begin_str0, pos_str0 - begin_str0);
+  pre_string = String_convert::bin2hex (pre_string);
+  for (int i = 2; i < pre_string.length (); i += 3)
+    pre_string = pre_string.left_string (i) + " " + pre_string.cut_string (i, INT_MAX);
+  String post_string ((Byte const*)pos_str0, end_str0 - pos_str0);
+  post_string = String_convert::bin2hex (post_string);
+  for (int i = 2; i < post_string.length (); i += 3)
+    post_string = post_string.left_string (i) + " " + post_string.cut_string (i, INT_MAX);
+
+  String str = pre_string
+    + to_string ('\n')
+    + to_string (' ', pre_string.length () + 1) 
+    + post_string;
+  return str;
+}
+
+int
+Binary_source_file::get_line (char const* pos_str0) const
+{
+  if (!in_b (pos_str0))
+    return 0;
+
+  return pos_str0 - to_str0 ();
+}
+
+U8
+Binary_source_file::get_U8 ()
+{
+  return * (U8*)forward_str0 (1);
+}
+
+
+U16
+Binary_source_file::get_U16 ()
+{
+  U16 b;
+
+  b = get_U8 () << 8;
+  b |= get_U8 ();
+
+  return b;
+}
+
+/*
+  naming is wrong. This is a UNIX-endian-32 (as opposed to xinu or ixun)
+ */
+
+U32
+Binary_source_file::get_U32 ()
+{
+  U32 b;
+  
+  b = get_U8 () << 24;
+  b |= get_U8 () << 16;
+  b |= get_U8 () << 8;
+  b |= get_U8 ();
+
+  return b;
+}
+
+
index 9da3464bc45ba532a591bba9381d25e75eb20deb..e8de059808ffa0e6ef686060362542098b340aa7 100644 (file)
@@ -75,6 +75,7 @@ Includable_lexer::new_input (String s, Sources  * global_sources)
   yy_switch_to_buffer (yy_create_buffer (sl->get_istream (), YY_BUF_SIZE));
 
 }
+
 void
 Includable_lexer::new_input (String name, String data, Sources* sources)
 {
diff --git a/lily/include/binary-source-file.hh b/lily/include/binary-source-file.hh
new file mode 100644 (file)
index 0000000..639e05c
--- /dev/null
@@ -0,0 +1,27 @@
+//
+//  binary-source-file.hh -- declare Binary_source_file
+//
+//  copyright 1997 Jan Nieuwenhuizen <janneke@gnu.org>
+
+#ifndef BINARY_SOURCE_FILE_HH
+#define BINARY_SOURCE_FILE_HH
+
+#include "source-file.hh"
+
+class Binary_source_file : public Source_file
+{
+public:
+  Binary_source_file (String& filename_string );
+  virtual ~Binary_source_file ();
+
+  U8 get_U8 (); 
+  U16 get_U16 ();
+  U32 get_U32 ();
+  Byte get_Byte () {return get_U8 (); }
+  int get_int () { return get_U32 (); }
+  
+  virtual String error_string (char const* pos_str0 ) const;
+  virtual int get_line (char const* pos_str0 ) const;
+};
+
+#endif // BINARY_SOURCE_FILE_HH
diff --git a/lily/include/file-results.hh b/lily/include/file-results.hh
deleted file mode 100644 (file)
index 669eefe..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*   
-  file-results.hh -- declare functions for processing one input file.
-  
-  source file of the GNU LilyPond music typesetter
-  
-  (c) 1998--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  
- */
-
-#ifndef FILE_RESULTS_HH
-#define FILE_RESULTS_HH
-
-#include "lily-proto.hh"
-#include "source.hh"
-#include "parray.hh"
-#include "scm-hash.hh"
-
-class Input_file_settings
-{
-public:
-  Sources sources_;
-  Array<String> inclusion_names_;
-  Array<String> target_strings_;
-  Link_array<Score> scores_;
-  /* Global? prefix is bit confusing */
-  Scheme_hash_table * global_header_;
-
-  void do_deps ();
-  void do_scores ();
-
-  Input_file_settings (String file, String init);
-  ~Input_file_settings ();
-  
-private:
-  /* Make sure we never get an implicit constructor.*/
-  Input_file_settings ();
-};
-
-extern Input_file_settings* global_input_file;
-
-void do_one_file (String init_string, String file_string);
-
-
-#endif /* FILE_RESULTS_HH */
-
diff --git a/lily/include/input-file-results.hh b/lily/include/input-file-results.hh
new file mode 100644 (file)
index 0000000..8b6e315
--- /dev/null
@@ -0,0 +1,45 @@
+/*   
+  file-results.hh -- declare functions for processing one input file.
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 1998--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  
+ */
+
+#ifndef FILE_RESULTS_HH
+#define FILE_RESULTS_HH
+
+#include "lily-proto.hh"
+#include "source.hh"
+#include "parray.hh"
+#include "scm-hash.hh"
+
+class Input_file_results
+{
+public:
+  Sources sources_;
+  Array<String> inclusion_names_;
+  Array<String> target_strings_;
+  Link_array<Score> scores_;
+  /* Global? prefix is bit confusing */
+  Scheme_hash_table * header_;
+
+  void do_deps ();
+  void do_scores ();
+
+  Input_file_results (String file, String init);
+  ~Input_file_results ();
+  
+private:
+  /* Make sure we never get an implicit constructor.*/
+  Input_file_results ();
+};
+
+extern Input_file_results* global_input_file;
+
+void do_one_file (String init_string, String file_string);
+
+
+#endif /* FILE_RESULTS_HH */
+
diff --git a/lily/include/input.hh b/lily/include/input.hh
new file mode 100644 (file)
index 0000000..7dc33b2
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+  input.hh -- declare Input
+
+  source file of the LilyPond music typesetter
+
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+
+#ifndef INPUT_HH
+#define INPUT_HH
+
+#include "flower-proto.hh"
+
+/**
+  Base class for anything that records its poisition in the parse file.
+ */
+class Input {
+public:
+  char const *defined_str0_ ;
+  Source_file * source_file_;
+    
+  void warning (String) const; // should use member func?
+  void non_fatal_error (String) const;
+  void error (String) const;
+  void message (String) const;
+  void set_spot (Input const &);
+  Input spot () const;
+  String location_string () const;
+  String line_number_string () const;
+
+
+  String file_string ()const;
+  int line_number ()const;
+  int column_number ()const;
+
+  
+  Input (Source_file*, char const*);
+  Input ();
+};
+
+#endif // INPUT_HH
index e09de5f1f62896543dba3b628a4cea148b59af75..e02c5120ab99e7fab56fc732450c82915b5a78f2 100644 (file)
@@ -68,7 +68,7 @@ class Hara_kiri_line_group_engraver;
 class Hyphen_req;
 
 class Includable_lexer;
-class Input_file_settings;
+class Input_file_results;
 class Input;
 class Item;
 class Key_change_req;
index 38d39ac4c327624a11d3ead95d92c2f2fd764ba2..d71a7832f174005bf9a2c811d7f2c87e109f5b56 100644 (file)
@@ -30,7 +30,7 @@
 class My_lily_parser 
 {
 public:
-  My_lily_parser (Input_file_settings * sources);
+  My_lily_parser (Input_file_results * sources);
   ~My_lily_parser ();
 
   void do_init_file ();
@@ -42,7 +42,7 @@ public:
   Scheme_hash_table *default_header_;
 
   int fatal_error_;
-  Input_file_settings * input_file_;
+  Input_file_results * input_file_;
   int error_level_;
 
   My_lily_lexer * lexer_;
index 9a33271b4ec39db75fe7208fb48021b26e7db280..3a51130e0a5a8e195b740213aba9e561aa427c8f 100644 (file)
@@ -9,7 +9,7 @@ struct Parse_start
 {
   char const* str;
   int nchars;
-  Input start_location;
+  Input start_location_;
 };
 
 SCM catch_protected_parse_body (void *);
index c401c57f73e8387f5640d1619ecf83322cf4904d..2af42321e5a2f574748c8b93a570e4729041d2c7 100644 (file)
@@ -23,7 +23,7 @@ public:
   Link_array<Music_output_def> defs_;
   SCM music_;
   Scheme_hash_table * header_;
-  Input_file_settings* input_file_;
+  Input_file_results* input_file_;
   
   int errorlevel_;
     
diff --git a/lily/include/source-file.hh b/lily/include/source-file.hh
new file mode 100644 (file)
index 0000000..b587a59
--- /dev/null
@@ -0,0 +1,73 @@
+
+#ifndef SOURCE_FILE_HH
+#define SOURCE_FILE_HH
+
+#include <iostream>
+
+#include "flower-proto.hh"
+#include "string.hh"
+#include "interval.hh"
+#include "protected-scm.hh"
+
+/**
+  class for reading and mapping a file. 
+
+  duplicates a lot of Data_file and Text_stream.
+  should look at including Data_file's functionality:
+  get_line (), get_word () here.
+*/
+
+class Source_file
+{
+public:
+  Source_file (String fn);
+  Source_file (String, String );
+
+  virtual ~Source_file ();
+
+  char const* to_str0 () const;
+  virtual String error_string (char const* pos_str0 ) const;
+  std::istream * get_istream ();
+  bool in_b (char const* pos_str0 ) const;
+  int length () const;
+  virtual int get_line (char const* pos_str0 ) const;
+  String name_string () const;
+  String file_line_column_string (char const* str0 ) const;
+
+  // return start + n
+  char const* seek_str0 (int n);
+
+  int tell () const;
+  // return here + n bytes
+  char const* forward_str0 (int n);
+  char const* pos_str0 () { return pos_str0_; }
+  String get_string (int n);
+  void set_pos (char const * pos_str0);
+public:
+  Slice line_slice (char const* pos_str0) const;
+  String line_string (char const* pos_str0) const;
+  int get_column (char const* pos_str0) const;
+  int get_char (char const* pos_str0) const;
+
+  /*
+    DOCUMENT-ME
+   */
+  char const* pos_str0_;
+
+  SCM get_port()const { return str_port_; }
+private:
+  String name_string_;
+  std::istream* istream_;
+  char  * contents_str0_;
+  int length_;
+  void load_stdin ();
+  void init_port ();
+  
+  Protected_scm str_port_;
+  
+};
+
+char * gulp_file (String fn, int *len);
+
+#endif // SOURCE_FILE_HH //
+
diff --git a/lily/include/source.hh b/lily/include/source.hh
new file mode 100644 (file)
index 0000000..82b557b
--- /dev/null
@@ -0,0 +1,37 @@
+//
+//  source.hh -- part of LilyPond
+//
+//  copyright 1997 Jan Nieuwenhuizen <janneke@gnu.org>
+
+#ifndef SOURCE_HH
+#define SOURCE_HH
+#include "cons.hh"
+#include "flower-proto.hh"
+
+/**
+   a set of sourcefiles.
+
+   TODO: 
+ */
+class Sources 
+{
+  Sources (Sources const&) {}
+public:
+  Sources ();
+  ~Sources ();
+
+  Source_file * get_file (String &filename );
+  Source_file* get_sourcefile (char const* str0 );
+  void add (Source_file* sourcefile );
+  void set_path (File_path*p);
+  void set_binary (bool);
+
+  const File_path * path_C_;
+private:
+  Cons<Source_file> *sourcefile_p_list_;
+  bool binary_b_ ;
+};
+
+
+
+#endif // SOURCE_HH //
diff --git a/lily/input-file-results.cc b/lily/input-file-results.cc
new file mode 100644 (file)
index 0000000..beb7892
--- /dev/null
@@ -0,0 +1,198 @@
+/*
+  scores.cc -- implement some globals
+
+  source file of the GNU LilyPond music typesetter
+
+  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+#include "config.h"
+
+#include <errno.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+
+#if HAVE_SYS_STAT_H 
+#include <sys/stat.h>
+#endif
+#include <unistd.h>
+
+
+#include "main.hh"
+#include "score.hh"
+#include "string.hh"
+#include "paper-def.hh"
+#include "warn.hh"
+#include "parray.hh"
+#include "file-path.hh"
+#include "input-file-results.hh"
+#include "my-lily-parser.hh"
+#include "source.hh"
+#include "lily-version.hh"
+#include "scm-hash.hh"
+
+
+LY_DEFINE(ly_set_point_and_click_x, "set-point-and-click!", 1, 0, 0,
+         (SCM what),
+         "Set the options for Point-and-click source specials output. The
+argument is a symbol.  Possible options are @code{none} (no source specials),
+@code{line} and @code{line-column}")
+{
+  /*
+    UGH.
+   */
+  SCM val = SCM_BOOL_F;
+  if (ly_symbol2scm ("line-column") == what)
+    val = gh_eval_str ("line-column-location");
+  else if (what == ly_symbol2scm ("line"))
+    val = gh_eval_str ("line-location");
+
+  /*
+    UGH.
+
+    How do you do set! from C ? 
+   */
+  scm_primitive_eval (scm_list_n (ly_symbol2scm ("set!"),
+                                 ly_symbol2scm ("point-and-click"), val, SCM_UNDEFINED));
+  return SCM_UNSPECIFIED;
+}
+
+void
+write_dependency_file (String fn,
+                      Array<String> targets,
+                      Array<String> deps)
+{
+  const int WRAPWIDTH = 65;
+
+  progress_indication (_f ("dependencies output to `%s'...", fn.to_str0 ()));
+  progress_indication ("\n");
+  FILE * f = fopen  (fn.to_str0 (), "w");
+  if (!f)
+    warning (_f ("can't open file: `%s'", fn));
+
+  fprintf (f, "# Generated automatically by: %s\n", gnu_lilypond_version_string ().to_str0 ());
+  
+  String out;
+  for (int i=0; i < targets.size (); i ++)
+     out += dependency_prefix_global + targets[i] + " ";
+  out +=  ": ";
+
+  for (int i=0; i < deps.size (); i ++)
+    {
+      if (out.length () > WRAPWIDTH)
+       {
+         fprintf (f, "%s\\\n", out.to_str0 ());
+         out = "  ";
+       }
+      String dep = deps[i];
+      if (!dependency_prefix_global.empty_b ())
+       {
+#if 0//thinko?
+         if (stat (dep.to_str0 (), &stat_buf) == -1 && errno == ENOENT)
+           ; //make emacs happy
+#else
+         if (dep.index ('/') < 0)
+#endif
+           dep = dependency_prefix_global + dep;
+       }
+      out  += " " +  dep;
+    }
+  fprintf (f, "%s\n",  out.to_str0 ());
+}
+
+
+void
+Input_file_results::do_deps ()
+{
+  if (dependency_global_b)
+    {
+      Path p = split_path (output_name_global);
+      p.ext = "dep";
+      write_dependency_file (p.string (),
+                            target_strings_,
+                            inclusion_names_);
+    }
+}
+
+
+void
+Input_file_results::do_scores ()
+{
+  if (!header_)
+    header_ = new Scheme_hash_table;
+
+  for (int i=0; i < scores_.size (); i++)
+    {
+      Score* is = scores_[i];
+      is->input_file_ = this;
+      
+      if (is->errorlevel_)
+       {
+         is->warning (_ ("Score contains errors; will not process it"));
+         exit_status_global |= 1;
+       }
+      else
+       {
+         is->process ();
+       }
+    }
+  do_deps ();
+}
+
+Input_file_results::~Input_file_results ()
+{
+  for (int i=0; i < scores_.size (); i++)
+    scm_gc_unprotect_object (scores_[i]->self_scm ());
+  scores_.clear ();
+  
+  inclusion_names_.clear ();
+  if (header_)
+    scm_gc_unprotect_object (header_ ->self_scm ());
+
+  global_input_file =0;
+}
+
+
+Input_file_results* global_input_file;
+
+Input_file_results::Input_file_results (String init_string, String file_string)
+{
+  header_ = 0;
+  global_input_file = this;
+  ly_set_point_and_click_x (SCM_BOOL_F);
+  
+  sources_.set_path (&global_path);
+  
+  My_lily_parser parser (this);
+
+  progress_indication (_f ("Now processing: `%s'", file_string.to_str0 ()));
+  progress_indication ("\n");
+  parser.parse_file (init_string, file_string);
+  
+  if (parser.error_level_)
+    {
+      exit_status_global  = 1;
+    }
+  else
+    do_scores ();
+  
+}
+
+
+void
+do_one_file (String init_string, String file_string) 
+{
+   if (init_string.length () && global_path.find (init_string).empty_b ())
+    {
+      warning (_f ("can't find file: `%s'", init_string));
+      warning (_f ("(search path: `%s')", global_path.string ().to_str0 ()));
+      return;
+    }
+  if ((file_string != "-") && global_path.find (file_string).empty_b ())
+    {
+      warning (_f ("can't find file: `%s'", file_string));
+      return;
+    }
+
+  Input_file_results inp_file(init_string, file_string);
+}
diff --git a/lily/input.cc b/lily/input.cc
new file mode 100644 (file)
index 0000000..381907d
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ input.cc -- implement Input
+
+ source file of the LilyPond music typesetter
+
+  (c) 1997--2000 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 ());
+}
+
+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;
+
+}
index e02376b9836000cde89a527f38aa10f5a78de2d8..d9b61340f6804daf1141d6f90bbe844371831abf 100644 (file)
@@ -34,7 +34,7 @@
 #include "string.hh"
 #include "string-convert.hh"
 #include "my-lily-lexer.hh"
-#include "file-results.hh"
+#include "input-file-results.hh"
 #include "interval.hh"
 #include "lily-guile.hh"
 #include "parser.hh"
index dc4886681c28e50f4dba81563e4a16afbb04e950..6b96a31315177fbfdd1e1df303b93f019155c2a7 100644 (file)
@@ -16,7 +16,6 @@
 #include "libc-extension.hh"
 #include "lily-guile.hh"
 #include "main.hh"
-#include "simple-file-storage.hh"
 #include "file-path.hh"
 #include "warn.hh"
 #include "direction.hh"
@@ -24,7 +23,7 @@
 #include "interval.hh"
 #include "pitch.hh"
 #include "dimensions.hh"
-
+#include "source-file.hh"
 
 // #define TEST_GC
 
@@ -104,10 +103,14 @@ gulp_file_to_string (String fn)
     progress_indication ("[" + s);
 
 
-  Simple_file_storage f (s);
-  String result (f.to_str0 ());
+  int n;
+  char * str = gulp_file (s, &n);
+  String result (str);
+  delete str;
+  
   if (verbose_global_b)
     progress_indication ("]");
+
   return result;
 }
 
index 1f992b0039bdff3365217f855430051767e8e438..6bf6435889e78bebfa17a9c3f3263761322ca502 100644 (file)
@@ -26,7 +26,7 @@
 #include "string.hh"
 #include "main.hh"
 #include "file-path.hh"
-#include "file-results.hh"
+#include "input-file-results.hh"
 #include "warn.hh"
 #include "lily-guile.hh"
 #include "paper-def.hh"
index 121d676de18fe92cb5c3367d089de19de2db11ba..cff5ae13e698f155b5d202334d2d4ba70eb61390 100644 (file)
@@ -13,7 +13,7 @@
 #include "lily-proto.hh"
 #include "scm-hash.hh"
 #include "interval.hh"
-#include "file-results.hh"
+#include "input-file-results.hh"
 #include "lily-guile.hh"
 #include "parser.hh"
 #include "keyword.hh"
index ee06d6bf3fd18565c3582dacc36e619b6760d63c..f935f0f7780db69404034d2988509a1e462e4e2b 100644 (file)
 #include "warn.hh"
 #include "main.hh"
 #include "parser.hh"
-#include "file-results.hh"
+#include "input-file-results.hh"
 #include "scm-hash.hh"
 
-My_lily_parser::My_lily_parser (Input_file_settings * source)
+My_lily_parser::My_lily_parser (Input_file_results * source)
 {
   input_file_ = source;
   lexer_ = 0;
index 03a4b322f88aacd4edb36b9ad6705913289b70ee..e00444cf5d6ae51224368376e917b53ae6c7f187 100644 (file)
@@ -16,7 +16,7 @@
 #include "scaled-font-metric.hh"
 #include "main.hh"
 #include "scm-hash.hh"
-#include "file-results.hh" // urg? header_global
+#include "input-file-results.hh" // urg? header_global
 #include "paper-outputter.hh"
 
 /*
index 74cd96acc5ef763f00b2d6cf154006c188c9dedb..2177afffcd08813f0be0441a2d65cbc61930475c 100644 (file)
@@ -22,7 +22,7 @@
 #include "scm-hash.hh"
 #include "lily-version.hh"
 #include "paper-def.hh"
-#include "file-results.hh"
+#include "input-file-results.hh"
 
 
 /*
index eb30b41a8155b6c2bfcc23c2024b8baaeb47044f..bf7ce0e0b54ea3098dc3e4caf56bf5aa5e2f4b7d 100644 (file)
@@ -19,7 +19,7 @@
 #include "scm-hash.hh"
 #include "gourlay-breaking.hh"
 #include "paper-outputter.hh"
-#include "file-results.hh"
+#include "input-file-results.hh"
 #include "misc.hh"
 #include "all-font-metrics.hh"
 
@@ -98,10 +98,10 @@ Paper_score::process ()
 
   progress_indication ("\n");
 
-  if (global_input_file->global_header_)
+  if (global_input_file->header_)
     {
-      outputter_->output_scope (global_input_file->global_header_, "lilypond");
-      outputter_->write_header_fields_to_file (global_input_file->global_header_);
+      outputter_->output_scope (global_input_file->header_, "lilypond");
+      outputter_->write_header_fields_to_file (global_input_file->header_);
     }
   
   if (header_)
index 7c50e772fc4e594e5cf2fc602de89aa47b1c46a3..9c49be4b5ef429a82fd6c606b9a7fcfedabac3b6 100644 (file)
@@ -1,8 +1,9 @@
+#include <stdio.h>
 
 #include "lily-guile.hh"
 #include "parse-scm.hh"
 #include "string.hh"
-
+#include "source-file.hh"
 
 /*
   Pass string to scm parser, evaluate one expression.
 SCM
 internal_ly_parse_scm (Parse_start * ps)
 {
-  /*
-    
-    This is actually pretty wasteful: we stuff the rest of the entire
-    file down GUILE, while we usually need only a bit of it.
+  Source_file* sf =ps->start_location_.source_file_;
+  SCM port = sf->get_port();
 
-    TODO: implement read_only_string_port(), (preferably in GUILE ?)
-    
-   */
-  SCM str = scm_makfrom0str (ps->str);
-  SCM port = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_RDNG,
-                            "ly_eval_scm_0str");
-
-  scm_set_port_filename_x (port, scm_makfrom0str (ps->start_location.file_string ().get_str0()));
-  scm_set_port_line_x (port,  gh_int2scm (ps->start_location.line_number ()));
-  scm_set_port_column_x (port,  gh_int2scm (ps->start_location.column_number()));
+  int off = ps->start_location_.defined_str0_ - sf->to_str0();
+  
   
+  scm_seek (port, scm_long2num (off), scm_long2num (SEEK_SET));
   SCM from = scm_ftell (port);
 
   SCM form;
@@ -85,7 +77,7 @@ parse_handler (void * data, SCM tag, SCM args)
 {
   Parse_start* ps = (Parse_start*) data;
 
-  ps->start_location.error (_("GUILE signaled an error for the expression begining here"));
+  ps->start_location_.error (_("GUILE signaled an error for the expression begining here"));
 
   if (scm_ilength (args) > 2)
     scm_display_error_message (gh_cadr (args), gh_caddr(args), scm_current_error_port());
@@ -127,7 +119,7 @@ ly_parse_scm (char const* s, int *n, Input i)
 {
   Parse_start ps ;
   ps.str = s;
-  ps.start_location = i;
+  ps.start_location_ = i;
 
   SCM ans = protected_ly_parse_scm (&ps);
   *n = ps.nchars;
index 9c1cee4c1787443c498931f9dd576e96e5859ad4..c314a96b171d04dc135f56bdb53b19002d91bebf 100644 (file)
@@ -44,7 +44,7 @@ this.
 #include "music-list.hh"
 #include "output-property-music-iterator.hh"
 #include "property-iterator.hh"
-#include "file-results.hh"
+#include "input-file-results.hh"
 #include "input.hh"
 #include "relative-music.hh"
 #include "lyric-combine-music.hh"
@@ -349,9 +349,9 @@ toplevel_expression:
                THIS->lexer_->chordmodifier_tab_  = $1;
        }
        | lilypond_header {
-               if (THIS->input_file_->global_header_)
-                       scm_gc_unprotect_object (THIS->input_file_->global_header_->self_scm ());
-               THIS->input_file_->global_header_ = $1;
+               if (THIS->input_file_->header_)
+                       scm_gc_unprotect_object (THIS->input_file_->header_->self_scm ());
+               THIS->input_file_->header_ = $1;
        }
        | score_block {
                THIS->input_file_->scores_.push ($1);
index f47aaa78d2b0e2ec95dd481b68789ef453f519d4..95268da54ff41bc2d032519b3e39a6119e10181b 100644 (file)
@@ -19,7 +19,7 @@
 #include "audio-staff.hh"
 #include "performance.hh"
 #include "score.hh"
-#include "file-results.hh"
+#include "input-file-results.hh"
 #include "file-path.hh"
 #include "lily-version.hh"
 
diff --git a/lily/scores.cc b/lily/scores.cc
deleted file mode 100644 (file)
index 44bc253..0000000
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
-  scores.cc -- implement some globals
-
-  source file of the GNU LilyPond music typesetter
-
-  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-*/
-#include "config.h"
-
-#include <errno.h>
-#include <sys/types.h>
-#include <stdio.h>
-
-
-#if HAVE_SYS_STAT_H 
-#include <sys/stat.h>
-#endif
-#include <unistd.h>
-
-
-#include "main.hh"
-#include "score.hh"
-#include "string.hh"
-#include "paper-def.hh"
-#include "warn.hh"
-#include "parray.hh"
-#include "file-path.hh"
-#include "file-results.hh"
-#include "my-lily-parser.hh"
-#include "source.hh"
-#include "lily-version.hh"
-#include "scm-hash.hh"
-
-
-LY_DEFINE(ly_set_point_and_click_x, "set-point-and-click!", 1, 0, 0,
-         (SCM what),
-         "Set the options for Point-and-click source specials output. The
-argument is a symbol.  Possible options are @code{none} (no source specials),
-@code{line} and @code{line-column}")
-{
-  /*
-    UGH.
-   */
-  SCM val = SCM_BOOL_F;
-  if (ly_symbol2scm ("line-column") == what)
-    val = gh_eval_str ("line-column-location");
-  else if (what == ly_symbol2scm ("line"))
-    val = gh_eval_str ("line-location");
-
-  /*
-    UGH.
-
-    How do you do set! from C ? 
-   */
-  scm_primitive_eval (scm_list_n (ly_symbol2scm ("set!"),
-                                 ly_symbol2scm ("point-and-click"), val, SCM_UNDEFINED));
-  return SCM_UNSPECIFIED;
-}
-
-void
-write_dependency_file (String fn,
-                      Array<String> targets,
-                      Array<String> deps)
-{
-  const int WRAPWIDTH = 65;
-
-  progress_indication (_f ("dependencies output to `%s'...", fn.to_str0 ()));
-  progress_indication ("\n");
-  FILE * f = fopen  (fn.to_str0 (), "w");
-  if (!f)
-    warning (_f ("can't open file: `%s'", fn));
-
-  fprintf (f, "# Generated automatically by: %s\n", gnu_lilypond_version_string ().to_str0 ());
-  
-  String out;
-  for (int i=0; i < targets.size (); i ++)
-     out += dependency_prefix_global + targets[i] + " ";
-  out +=  ": ";
-
-  for (int i=0; i < deps.size (); i ++)
-    {
-      if (out.length () > WRAPWIDTH)
-       {
-         fprintf (f, "%s\\\n", out.to_str0 ());
-         out = "  ";
-       }
-      String dep = deps[i];
-      if (!dependency_prefix_global.empty_b ())
-       {
-#if 0//thinko?
-         if (stat (dep.to_str0 (), &stat_buf) == -1 && errno == ENOENT)
-           ; //make emacs happy
-#else
-         if (dep.index ('/') < 0)
-#endif
-           dep = dependency_prefix_global + dep;
-       }
-      out  += " " +  dep;
-    }
-  fprintf (f, "%s\n",  out.to_str0 ());
-}
-
-
-void
-Input_file_settings::do_deps ()
-{
-  if (dependency_global_b)
-    {
-      Path p = split_path (output_name_global);
-      p.ext = "dep";
-      write_dependency_file (p.string (),
-                            target_strings_,
-                            inclusion_names_);
-    }
-}
-
-
-void
-Input_file_settings::do_scores ()
-{
-  if (!global_header_)
-    global_header_ = new Scheme_hash_table;
-
-  for (int i=0; i < scores_.size (); i++)
-    {
-      Score* is = scores_[i];
-      is->input_file_ = this;
-      
-      if (is->errorlevel_)
-       {
-         is->warning (_ ("Score contains errors; will not process it"));
-         exit_status_global |= 1;
-       }
-      else
-       {
-         is->process ();
-       }
-    }
-  do_deps ();
-}
-
-Input_file_settings::~Input_file_settings ()
-{
-  for (int i=0; i < scores_.size (); i++)
-    scm_gc_unprotect_object (scores_[i]->self_scm ());
-  scores_.clear ();
-  
-  inclusion_names_.clear ();
-  if (global_header_)
-    scm_gc_unprotect_object (global_header_ ->self_scm ());
-
-  global_input_file =0;
-}
-
-
-Input_file_settings* global_input_file;
-
-Input_file_settings::Input_file_settings (String init_string, String file_string)
-{
-  global_header_ = 0;
-  global_input_file = this;
-  ly_set_point_and_click_x (SCM_BOOL_F);
-  
-  sources_.set_path (&global_path);
-  
-  My_lily_parser parser (this);
-
-  progress_indication (_f ("Now processing: `%s'", file_string.to_str0 ()));
-  progress_indication ("\n");
-  parser.parse_file (init_string, file_string);
-  
-  if (parser.error_level_)
-    {
-      exit_status_global  = 1;
-    }
-  else
-    do_scores ();
-  
-}
-
-
-void
-do_one_file (String init_string, String file_string) 
-{
-   if (init_string.length () && global_path.find (init_string).empty_b ())
-    {
-      warning (_f ("can't find file: `%s'", init_string));
-      warning (_f ("(search path: `%s')", global_path.string ().to_str0 ()));
-      return;
-    }
-  if ((file_string != "-") && global_path.find (file_string).empty_b ())
-    {
-      warning (_f ("can't find file: `%s'", file_string));
-      return;
-    }
-
-  Input_file_settings inp_file(init_string, file_string);
-}
diff --git a/lily/source-file.cc b/lily/source-file.cc
new file mode 100644 (file)
index 0000000..cbe4967
--- /dev/null
@@ -0,0 +1,328 @@
+/*
+  source-file.cc -- implement Source_file
+
+  source file of the GNU LilyPond music typesetter
+
+  (c)  1997--2000 Jan Nieuwenhuizen <janneke@gnu.org>
+  & Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+#include <stdio.h>
+#include <assert.h>
+#if HAVE_SSTREAM
+#include <sstream>
+#else
+#include <strstream.h>
+#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 ()
+{
+  length_ = 0;
+
+  int c;
+  Array<char> chs;             // ugh.
+  while ((c = fgetc (stdin)) != EOF)
+    chs.push (c);
+
+  length_ = chs.size ();
+  contents_str0_ = chs.remove_array ();
+}
+
+
+
+char *
+gulp_file (String fn, int* len)
+{
+  /*
+    let's hope that "b" opens anything binary, and does not apply
+    CR/LF translation
+    */
+  FILE * f =  fopen (fn.to_str0 (), "rb");
+
+  if (!f)
+    {
+      warning (_f ("can't open file: `%s'", fn.to_str0 ()));
+      return 0;
+    }
+
+  int ret = fseek (f, 0, SEEK_END);
+
+  *len = ftell (f);
+  rewind (f);
+  char *  str = new char[*len+1];
+  str[*len] = 0;
+  ret = fread (str, sizeof (char), *len, f);
+
+  if (ret!=*len)
+    warning (_f ("Huh?  Got %d, expected %d characters", ret, *len));
+
+  fclose (f);
+
+
+  return str;
+}
+
+
+
+Source_file::Source_file (String filename, String data)
+{
+  name_string_ = "";
+  istream_ = 0;
+  contents_str0_ = data.get_copy_str0();
+  length_ = data.length();
+  pos_str0_ = to_str0 ();
+  init_port();
+}
+
+
+
+
+Source_file::Source_file (String filename_string)
+{
+  name_string_ = filename_string;
+  istream_ = 0;
+  contents_str0_ = 0;
+
+  if (filename_string == "-")
+    load_stdin ();
+  else
+    contents_str0_ = gulp_file (filename_string, &length_);
+  
+  pos_str0_ = to_str0 ();
+
+  init_port();
+}
+
+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_string_.get_str0()));
+}
+
+int
+Source_file::tell () const
+{
+  return pos_str0_  - contents_str0_; 
+}
+
+std::istream*
+Source_file::get_istream ()
+{
+  /*
+    if (!name_string_.length ())
+      return &cin;
+    */
+
+  if (!istream_)
+    {
+      if (length ()) // can-t this be done without such a hack?
+       istream_ = new std::istringstream (to_str0 ());
+      else
+       {
+         istream_ = new std::istringstream ("");
+         istream_->setstate (std::ios::eofbit);
+         //      istream_->set (ios::eofbit);
+       }
+    }
+  return istream_;
+}
+
+String
+Source_file::file_line_column_string (char const *context_str0) const
+{
+  if (!to_str0 ())
+    return " (" + _ ("position unknown") + ")";
+  else
+    return name_string () + ":" + to_string (get_line (context_str0))
+      + ":" + to_string (get_char (context_str0));
+}
+
+String
+Source_file::name_string () const
+{
+  return name_string_;
+}
+
+Source_file::~Source_file ()
+{
+  delete istream_;
+  istream_ = 0;
+  delete contents_str0_;
+}
+
+Slice
+Source_file::line_slice (char const* pos_str0) const
+{
+  if (!in_b (pos_str0))
+    return Slice (0,0);
+
+  char const* data_str0 = to_str0 ();
+  char const * eof_C_ = data_str0 + length ();
+
+  if (pos_str0 == eof_C_)
+    pos_str0 --;
+  char const* begin_str0 = pos_str0;
+  while (begin_str0 > data_str0)
+    if (*--begin_str0 == '\n')
+      {
+       begin_str0++;
+       break;
+      }
+
+  char const* end_str0 = pos_str0;
+  while (end_str0 < eof_C_)
+    if (*end_str0++ == '\n')
+      {
+       end_str0--;
+       break;
+      }
+
+  return Slice (begin_str0 - data_str0, end_str0 - data_str0);
+}
+
+String
+Source_file::line_string (char const* pos_str0) const
+{
+  if (!in_b (pos_str0))
+    return "";
+
+  Slice line = line_slice (pos_str0);
+  char const* data_str0 = to_str0 ();
+  return String ((Byte const*)data_str0 + line[LEFT], line.length ());
+}
+
+int
+Source_file::get_char (char const* pos_str0) const
+{
+  if (!in_b (pos_str0))
+    return 0;
+
+  char const* data_str0 = to_str0 ();
+  return pos_str0 - (line_slice (pos_str0)[SMALLER] + data_str0);
+}
+
+int
+Source_file::get_column (char const* pos_str0) const
+{
+  if (!in_b (pos_str0))
+    return 0;
+
+  int ch_i = get_char (pos_str0);
+  String line = line_string (pos_str0);
+
+  int col_i = 0;
+  for (int i = 0; i < ch_i; i++)
+    if (line[i] == '\t')
+      col_i = (col_i / 8 + 1) * 8;
+    else
+      col_i++;
+
+  return col_i;
+}
+
+String
+Source_file::error_string (char const* pos_str0) const
+{
+  if (!in_b (pos_str0))
+    return " (" + _ ("position unknown") + ")";
+
+  int ch_i = get_char (pos_str0);
+  String line = line_string (pos_str0);
+  String context = line.left_string (ch_i)
+    + to_string ('\n')
+    + to_string (' ', get_column (pos_str0))
+    + line.cut_string (ch_i, INT_MAX);
+
+  return context;
+}
+
+bool
+Source_file::in_b (char const* pos_str0) const
+{
+  return (pos_str0 && (pos_str0 >= to_str0 ()) && (pos_str0 <= to_str0 () + length ()));
+}
+
+int
+Source_file::get_line (char const* pos_str0) const
+{
+  if (!in_b (pos_str0))
+    return 0;
+
+  int i = 1;
+  char const* scan_str0 = to_str0 ();
+  if (!scan_str0)
+    return 0;
+
+  while (scan_str0 < pos_str0)
+    if (*scan_str0++ == '\n')
+      i++;
+  return i;
+}
+
+int
+Source_file::length () const
+{
+  return length_;
+}
+
+char const *
+Source_file::to_str0 () const
+{
+  return contents_str0_;
+}
+
+void
+Source_file::set_pos (char const * pos_str0)
+{
+  if (in_b (pos_str0))
+    pos_str0_ = pos_str0;
+  else
+    error (error_string (pos_str0) + "invalid pos");
+}
+
+char const*
+Source_file::seek_str0 (int n)
+{
+  char const* new_str0 = to_str0 () + n;
+  if (n < 0)
+    new_str0 += length ();
+  if (in_b (new_str0))
+    pos_str0_ = new_str0;
+  else
+    error (error_string (new_str0) + "seek past eof");
+
+  return pos_str0_;
+}
+
+char const*
+Source_file::forward_str0 (int n)
+{
+  char const* old_pos = pos_str0_;
+  char const* new_str0 = pos_str0_ + n;
+  if (in_b (new_str0))
+    pos_str0_ = new_str0;
+  else
+    error (error_string (new_str0)  + "forward past eof");
+
+  return old_pos;
+}
+
+String
+Source_file::get_string (int n)
+{
+  String str = String ((Byte const*)forward_str0 (n), n);
+  return str;
+}
diff --git a/lily/source.cc b/lily/source.cc
new file mode 100644 (file)
index 0000000..c4dde1c
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+  source.cc -- implement Sources
+
+  source file of the LilyPond music typesetter
+
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+
+#include <assert.h>
+
+#include "killing-cons.tcc"
+#include "string.hh"
+#include "flower-proto.hh"
+#include "source-file.hh"
+#include "source.hh"
+#include "file-path.hh"
+
+Sources::Sources ()
+{
+  sourcefile_p_list_ = 0;
+  path_C_= 0;
+  binary_b_ = false;
+}
+
+void
+Sources::set_binary (bool bo)
+{
+  binary_b_ = bo;
+}
+
+void
+Sources::set_path (File_path *f)
+{
+  path_C_ = f;
+}
+
+/**
+  open a file
+
+  @param file_string the file to be opened, name might be changed if it
+  is found in a search path. UGH!
+
+  @return 0 if no file found
+  */
+Source_file*
+Sources::get_file (String &file_string) //UGH
+{
+  if ((file_string != "-") && path_C_)
+    {
+      String file_string_o = path_C_->find (file_string); 
+      if ((file_string_o == "") && (file_string != ""))
+       return 0;
+      file_string = file_string_o;
+    }
+  Source_file * f = new Source_file (file_string) ;
+  add (f);
+  return f;
+}
+
+void
+Sources::add (Source_file* sourcefile)
+{
+  sourcefile_p_list_ = new Killing_cons<Source_file> (sourcefile, sourcefile_p_list_);
+}
+
+Sources::~Sources ()
+{
+  delete sourcefile_p_list_;
+}
+/**
+  search the list for file whose map contains pointer #str0#
+
+  @return 0 if not found.
+  */
+Source_file*
+Sources::get_sourcefile (char const* str0)
+{
+
+  for (Cons<Source_file> *i = sourcefile_p_list_; i; i = i->next_)
+    if (i->car_->in_b (str0))  
+      return i->car_;
+  return 0;
+}
+