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.
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
* 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
+++ /dev/null
-/*
- 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;
-}
-
-
+++ /dev/null
-//
-// 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
+++ /dev/null
-/*
- 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
+++ /dev/null
-/*
- 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 */
-
+++ /dev/null
-/*
- 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 */
-
+++ /dev/null
-
-#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 //
-
+++ /dev/null
-//
-// 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 //
+++ /dev/null
-/*
- 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 */
-
+++ /dev/null
-/*
- 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;
-
-}
+++ /dev/null
-#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
+++ /dev/null
-/*
- 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_;
-}
+++ /dev/null
-/*
- 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;
-}
+++ /dev/null
-/*
- 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;
-}
-
--- /dev/null
+/*
+ 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;
+}
+
+
yy_switch_to_buffer (yy_create_buffer (sl->get_istream (), YY_BUF_SIZE));
}
+
void
Includable_lexer::new_input (String name, String data, Sources* sources)
{
--- /dev/null
+//
+// 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
+++ /dev/null
-/*
- 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 */
-
--- /dev/null
+/*
+ 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 */
+
--- /dev/null
+/*
+ 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
class Hyphen_req;
class Includable_lexer;
-class Input_file_settings;
+class Input_file_results;
class Input;
class Item;
class Key_change_req;
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 ();
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_;
{
char const* str;
int nchars;
- Input start_location;
+ Input start_location_;
};
SCM catch_protected_parse_body (void *);
Link_array<Music_output_def> defs_;
SCM music_;
Scheme_hash_table * header_;
- Input_file_settings* input_file_;
+ Input_file_results* input_file_;
int errorlevel_;
--- /dev/null
+
+#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 //
+
--- /dev/null
+//
+// 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 //
--- /dev/null
+/*
+ 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);
+}
--- /dev/null
+/*
+ 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;
+
+}
#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"
#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"
#include "interval.hh"
#include "pitch.hh"
#include "dimensions.hh"
-
+#include "source-file.hh"
// #define TEST_GC
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;
}
#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"
#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"
#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;
#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"
/*
#include "scm-hash.hh"
#include "lily-version.hh"
#include "paper-def.hh"
-#include "file-results.hh"
+#include "input-file-results.hh"
/*
#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"
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_)
+#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;
{
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());
{
Parse_start ps ;
ps.str = s;
- ps.start_location = i;
+ ps.start_location_ = i;
SCM ans = protected_ly_parse_scm (&ps);
*n = ps.nchars;
#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"
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);
#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"
+++ /dev/null
-/*
- 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);
-}
--- /dev/null
+/*
+ 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;
+}
--- /dev/null
+/*
+ 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;
+}
+