From a517dce054511941847288622f7840ff9d2bd353 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sat, 17 Aug 2002 01:30:28 +0000 Subject: [PATCH] * 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. --- ChangeLog | 14 +- flower/include/mapped-file-storage.hh | 40 ----- flower/include/simple-file-storage.hh | 33 ----- flower/include/string-storage.hh | 30 ---- flower/mapped-file-storage.cc | 140 ------------------ flower/simple-file-storage.cc | 99 ------------- {flower => lily}/binary-source-file.cc | 3 + lily/includable-lexer.cc | 1 + .../include/binary-source-file.hh | 0 ...{file-results.hh => input-file-results.hh} | 12 +- {flower => lily}/include/input.hh | 2 +- lily/include/lily-proto.hh | 2 +- lily/include/my-lily-parser.hh | 4 +- lily/include/parse-scm.hh | 2 +- lily/include/score.hh | 2 +- {flower => lily}/include/source-file.hh | 20 ++- {flower => lily}/include/source.hh | 0 lily/{scores.cc => input-file-results.cc} | 24 +-- {flower => lily}/input.cc | 0 lily/lexer.ll | 2 +- lily/lily-guile.cc | 11 +- lily/main.cc | 2 +- lily/my-lily-lexer.cc | 2 +- lily/my-lily-parser.cc | 4 +- lily/paper-def.cc | 2 +- lily/paper-outputter.cc | 2 +- lily/paper-score.cc | 8 +- lily/parse-scm.cc | 26 ++-- lily/parser.yy | 8 +- lily/performance.cc | 2 +- {flower => lily}/source-file.cc | 103 +++++++++++-- {flower => lily}/source.cc | 5 +- 32 files changed, 180 insertions(+), 425 deletions(-) delete mode 100644 flower/include/mapped-file-storage.hh delete mode 100644 flower/include/simple-file-storage.hh delete mode 100644 flower/include/string-storage.hh delete mode 100644 flower/mapped-file-storage.cc delete mode 100644 flower/simple-file-storage.cc rename {flower => lily}/binary-source-file.cc (95%) rename {flower => lily}/include/binary-source-file.hh (100%) rename lily/include/{file-results.hh => input-file-results.hh} (76%) rename {flower => lily}/include/input.hh (100%) rename {flower => lily}/include/source-file.hh (80%) rename {flower => lily}/include/source.hh (100%) rename lily/{scores.cc => input-file-results.cc} (88%) rename {flower => lily}/input.cc (100%) rename {flower => lily}/source-file.cc (74%) rename {flower => lily}/source.cc (91%) diff --git a/ChangeLog b/ChangeLog index aaaa0c6aea..4e948b5c38 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2002-08-17 Han-Wen Nienhuys + * 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/include/mapped-file-storage.hh b/flower/include/mapped-file-storage.hh deleted file mode 100644 index a936401b6d..0000000000 --- a/flower/include/mapped-file-storage.hh +++ /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 - - */ - -#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 index f551ed8c57..0000000000 --- a/flower/include/simple-file-storage.hh +++ /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 - - */ - -#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/string-storage.hh b/flower/include/string-storage.hh deleted file mode 100644 index dfe49c8c47..0000000000 --- a/flower/include/string-storage.hh +++ /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 - - */ - -#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/mapped-file-storage.cc b/flower/mapped-file-storage.cc deleted file mode 100644 index f9baca9a5a..0000000000 --- a/flower/mapped-file-storage.cc +++ /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 - Jan Nieuwenhuizen . - - Nextstep fixes by tiggr@ics.ele.tue.nl -*/ - -#include // open, mmap -#include // open -#include // mmap -#include // INT_MAX -#include // open -#include // close, stat -#include // fdopen -#include // strerror -#include // errno - - - -#ifdef __NeXT__ -#include -#include -#include -#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 index 10fd7902ff..0000000000 --- a/flower/simple-file-storage.cc +++ /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 -*/ - -#include - -#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 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/binary-source-file.cc b/lily/binary-source-file.cc similarity index 95% rename from flower/binary-source-file.cc rename to lily/binary-source-file.cc index bd6a4f84d3..ab1c08488d 100644 --- a/flower/binary-source-file.cc +++ b/lily/binary-source-file.cc @@ -78,6 +78,9 @@ Binary_source_file::get_U16 () return b; } +/* + naming is wrong. This is a UNIX-endian-32 (as opposed to xinu or ixun) + */ U32 Binary_source_file::get_U32 () diff --git a/lily/includable-lexer.cc b/lily/includable-lexer.cc index 9da3464bc4..e8de059808 100644 --- a/lily/includable-lexer.cc +++ b/lily/includable-lexer.cc @@ -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/flower/include/binary-source-file.hh b/lily/include/binary-source-file.hh similarity index 100% rename from flower/include/binary-source-file.hh rename to lily/include/binary-source-file.hh diff --git a/lily/include/file-results.hh b/lily/include/input-file-results.hh similarity index 76% rename from lily/include/file-results.hh rename to lily/include/input-file-results.hh index 669eefe99e..8b6e31582c 100644 --- a/lily/include/file-results.hh +++ b/lily/include/input-file-results.hh @@ -15,7 +15,7 @@ #include "parray.hh" #include "scm-hash.hh" -class Input_file_settings +class Input_file_results { public: Sources sources_; @@ -23,20 +23,20 @@ public: Array target_strings_; Link_array scores_; /* Global? prefix is bit confusing */ - Scheme_hash_table * global_header_; + Scheme_hash_table * header_; void do_deps (); void do_scores (); - Input_file_settings (String file, String init); - ~Input_file_settings (); + Input_file_results (String file, String init); + ~Input_file_results (); private: /* Make sure we never get an implicit constructor.*/ - Input_file_settings (); + Input_file_results (); }; -extern Input_file_settings* global_input_file; +extern Input_file_results* global_input_file; void do_one_file (String init_string, String file_string); diff --git a/flower/include/input.hh b/lily/include/input.hh similarity index 100% rename from flower/include/input.hh rename to lily/include/input.hh index 4b12e25fb8..7dc33b2df1 100644 --- a/flower/include/input.hh +++ b/lily/include/input.hh @@ -16,9 +16,9 @@ Base class for anything that records its poisition in the parse file. */ class Input { +public: char const *defined_str0_ ; Source_file * source_file_; -public: void warning (String) const; // should use member func? void non_fatal_error (String) const; diff --git a/lily/include/lily-proto.hh b/lily/include/lily-proto.hh index e09de5f1f6..e02c5120ab 100644 --- a/lily/include/lily-proto.hh +++ b/lily/include/lily-proto.hh @@ -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; diff --git a/lily/include/my-lily-parser.hh b/lily/include/my-lily-parser.hh index 38d39ac4c3..d71a7832f1 100644 --- a/lily/include/my-lily-parser.hh +++ b/lily/include/my-lily-parser.hh @@ -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_; diff --git a/lily/include/parse-scm.hh b/lily/include/parse-scm.hh index 9a33271b4e..3a51130e0a 100644 --- a/lily/include/parse-scm.hh +++ b/lily/include/parse-scm.hh @@ -9,7 +9,7 @@ struct Parse_start { char const* str; int nchars; - Input start_location; + Input start_location_; }; SCM catch_protected_parse_body (void *); diff --git a/lily/include/score.hh b/lily/include/score.hh index c401c57f73..2af42321e5 100644 --- a/lily/include/score.hh +++ b/lily/include/score.hh @@ -23,7 +23,7 @@ public: Link_array defs_; SCM music_; Scheme_hash_table * header_; - Input_file_settings* input_file_; + Input_file_results* input_file_; int errorlevel_; diff --git a/flower/include/source-file.hh b/lily/include/source-file.hh similarity index 80% rename from flower/include/source-file.hh rename to lily/include/source-file.hh index 9e9d8c34c2..b587a594fd 100644 --- a/flower/include/source-file.hh +++ b/lily/include/source-file.hh @@ -7,6 +7,7 @@ #include "flower-proto.hh" #include "string.hh" #include "interval.hh" +#include "protected-scm.hh" /** class for reading and mapping a file. @@ -19,11 +20,9 @@ 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 fn); + Source_file (String, String ); - Source_file (String name_string, String data_string); virtual ~Source_file (); char const* to_str0 () const; @@ -37,6 +36,8 @@ public: // 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_; } @@ -53,11 +54,20 @@ public: */ char const* pos_str0_; + SCM get_port()const { return str_port_; } private: String name_string_; std::istream* istream_; - File_storage * storage_; + 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/flower/include/source.hh b/lily/include/source.hh similarity index 100% rename from flower/include/source.hh rename to lily/include/source.hh diff --git a/lily/scores.cc b/lily/input-file-results.cc similarity index 88% rename from lily/scores.cc rename to lily/input-file-results.cc index 44bc253fce..beb789209b 100644 --- a/lily/scores.cc +++ b/lily/input-file-results.cc @@ -25,7 +25,7 @@ #include "warn.hh" #include "parray.hh" #include "file-path.hh" -#include "file-results.hh" +#include "input-file-results.hh" #include "my-lily-parser.hh" #include "source.hh" #include "lily-version.hh" @@ -102,7 +102,7 @@ write_dependency_file (String fn, void -Input_file_settings::do_deps () +Input_file_results::do_deps () { if (dependency_global_b) { @@ -116,10 +116,10 @@ Input_file_settings::do_deps () void -Input_file_settings::do_scores () +Input_file_results::do_scores () { - if (!global_header_) - global_header_ = new Scheme_hash_table; + if (!header_) + header_ = new Scheme_hash_table; for (int i=0; i < scores_.size (); i++) { @@ -139,25 +139,25 @@ Input_file_settings::do_scores () do_deps (); } -Input_file_settings::~Input_file_settings () +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 (global_header_) - scm_gc_unprotect_object (global_header_ ->self_scm ()); + if (header_) + scm_gc_unprotect_object (header_ ->self_scm ()); global_input_file =0; } -Input_file_settings* global_input_file; +Input_file_results* global_input_file; -Input_file_settings::Input_file_settings (String init_string, String file_string) +Input_file_results::Input_file_results (String init_string, String file_string) { - global_header_ = 0; + header_ = 0; global_input_file = this; ly_set_point_and_click_x (SCM_BOOL_F); @@ -194,5 +194,5 @@ do_one_file (String init_string, String file_string) return; } - Input_file_settings inp_file(init_string, file_string); + Input_file_results inp_file(init_string, file_string); } diff --git a/flower/input.cc b/lily/input.cc similarity index 100% rename from flower/input.cc rename to lily/input.cc diff --git a/lily/lexer.ll b/lily/lexer.ll index e02376b983..d9b61340f6 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -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" diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index dc4886681c..6b96a31315 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -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; } diff --git a/lily/main.cc b/lily/main.cc index 1f992b0039..6bf6435889 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -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" diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index 121d676de1..cff5ae13e6 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -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" diff --git a/lily/my-lily-parser.cc b/lily/my-lily-parser.cc index ee06d6bf3f..f935f0f778 100644 --- a/lily/my-lily-parser.cc +++ b/lily/my-lily-parser.cc @@ -12,10 +12,10 @@ #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; diff --git a/lily/paper-def.cc b/lily/paper-def.cc index 03a4b322f8..e00444cf5d 100644 --- a/lily/paper-def.cc +++ b/lily/paper-def.cc @@ -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" /* diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 74cd96acc5..2177afffcd 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -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" /* diff --git a/lily/paper-score.cc b/lily/paper-score.cc index eb30b41a81..bf7ce0e0b5 100644 --- a/lily/paper-score.cc +++ b/lily/paper-score.cc @@ -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_) diff --git a/lily/parse-scm.cc b/lily/parse-scm.cc index 7c50e772fc..9c49be4b5e 100644 --- a/lily/parse-scm.cc +++ b/lily/parse-scm.cc @@ -1,8 +1,9 @@ +#include #include "lily-guile.hh" #include "parse-scm.hh" #include "string.hh" - +#include "source-file.hh" /* Pass string to scm parser, evaluate one expression. @@ -15,22 +16,13 @@ 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; diff --git a/lily/parser.yy b/lily/parser.yy index 9c1cee4c17..c314a96b17 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -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); diff --git a/lily/performance.cc b/lily/performance.cc index f47aaa78d2..95268da54f 100644 --- a/lily/performance.cc +++ b/lily/performance.cc @@ -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/flower/source-file.cc b/lily/source-file.cc similarity index 74% rename from flower/source-file.cc rename to lily/source-file.cc index a27e1f7780..cbe4967b52 100644 --- a/flower/source-file.cc +++ b/lily/source-file.cc @@ -7,7 +7,7 @@ & Han-Wen Nienhuys */ - +#include #include #if HAVE_SSTREAM #include @@ -20,23 +20,102 @@ #include "flower-proto.hh" #include "warn.hh" #include "source-file.hh" -#include "simple-file-storage.hh" -#include "string-storage.hh" +#include "array.hh" -Source_file::Source_file (String filename_string) +void +Source_file::load_stdin () { - name_string_ = filename_string; + length_ = 0; + + int c; + Array 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; - storage_ = new Simple_file_storage (filename_string); + contents_str0_ = data.get_copy_str0(); + length_ = data.length(); pos_str0_ = to_str0 (); + init_port(); } -Source_file::Source_file (String name_string, String data_string) + + + +Source_file::Source_file (String filename_string) { - name_string_ = name_string; + name_string_ = filename_string; istream_ = 0; - storage_ = new String_storage (data_string); + 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* @@ -81,7 +160,7 @@ Source_file::~Source_file () { delete istream_; istream_ = 0; - delete storage_; + delete contents_str0_; } Slice @@ -196,13 +275,13 @@ Source_file::get_line (char const* pos_str0) const int Source_file::length () const { - return storage_->length (); + return length_; } char const * Source_file::to_str0 () const { - return storage_->to_str0 (); + return contents_str0_; } void diff --git a/flower/source.cc b/lily/source.cc similarity index 91% rename from flower/source.cc rename to lily/source.cc index cffc7989ab..c4dde1cd14 100644 --- a/flower/source.cc +++ b/lily/source.cc @@ -8,8 +8,8 @@ #include + #include "killing-cons.tcc" -#include "binary-source-file.hh" #include "string.hh" #include "flower-proto.hh" #include "source-file.hh" @@ -53,8 +53,7 @@ Sources::get_file (String &file_string) //UGH return 0; file_string = file_string_o; } - Source_file * f = (!binary_b_) ? - new Source_file (file_string) : new Binary_source_file (file_string); + Source_file * f = new Source_file (file_string) ; add (f); return f; } -- 2.39.5