From da000980e554ce4c2a4095d68c1a2be6bc714f7f Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Tue, 27 Apr 2004 16:23:29 +0000 Subject: [PATCH] * lily/paper-outputter.cc (output_stencil): New method. * lily/my-lily-parser.cc (distill_inname): Remove. * flower/include/file-name.hh: * flower/file-name.cc: New file. Change users. * flower/file-path.cc [CYGWIN]: Junk testing code. Remove Path. (find): New method of same name. * lily/scm-option.cc (ly:set-option, ly:get-option): Bugfix: constant error message. --- ChangeLog | 15 ++ flower/file-name.cc | 103 ++++++++++++++ flower/file-path.cc | 245 ++++++++++---------------------- flower/include/file-name.hh | 29 ++++ flower/include/file-path.hh | 31 ++-- flower/include/flower-proto.hh | 3 +- input/test/blank-paper.ly | 27 ++-- lily/include/paper-outputter.hh | 15 +- lily/main.cc | 32 ++--- lily/my-lily-parser.cc | 72 +++------- lily/paper-def.cc | 7 +- lily/paper-outputter.cc | 46 +++--- lily/performance.cc | 23 +-- lily/scm-option.cc | 72 ++++------ scm/lily.scm | 4 - 15 files changed, 359 insertions(+), 365 deletions(-) create mode 100644 flower/file-name.cc create mode 100644 flower/include/file-name.hh diff --git a/ChangeLog b/ChangeLog index 03c9693c74..96f8e74482 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-04-27 Jan Nieuwenhuizen + + * lily/paper-outputter.cc (output_stencil): New method. + + * lily/my-lily-parser.cc (distill_inname): Remove. + + * flower/include/file-name.hh: + * flower/file-name.cc: New file. Change users. + + * flower/file-path.cc [CYGWIN]: Junk testing code. Remove Path. + (find): New method of same name. + + * lily/scm-option.cc (ly:set-option, ly:get-option): Bugfix: + constant error message. + 2004-04-27 Heikki Junes * input/test/{blank-notes.ly,staff-container.ly}: typos. diff --git a/flower/file-name.cc b/flower/file-name.cc new file mode 100644 index 0000000000..c26562664a --- /dev/null +++ b/flower/file-name.cc @@ -0,0 +1,103 @@ +/* + file-name.cc - implement File_name + + source file of the Flower Library + + (c) 1997--2004 Han-Wen Nienhuys + Jan Nieuwenhuizen +*/ + +#include "config.h" +#include +#include +#include + +#if HAVE_SYS_STAT_H +#include +#endif + +#ifdef __CYGWIN__ +#include +#endif + +#include "file-name.hh" + +/* We don't have multiple roots, set this to '\0'? */ +#ifndef ROOTSEP +#define ROOTSEP ':' +#endif + +#ifndef DIRSEP +#define DIRSEP '/' +#endif + +#ifndef EXTSEP +#define EXTSEP '.' +#endif + +#ifdef __CYGWIN__ +static String +dos_to_posix (String file_name) +{ + char buf[PATH_MAX]; + char *s = file_name.get_copy_str0 (); + /* urg, wtf? char const* argument gets modified! */ + cygwin_conv_to_posix_path (s, buf); + delete s; + return buf; +} +#endif /* __CYGWIN__ */ + +/* Join components to full file_name. */ +String +File_name::to_string () const +{ + String s; + if (!root_.is_empty ()) + s = root_ + ::to_string (ROOTSEP); + if (!dir_.is_empty ()) + s += dir_ + ::to_string (DIRSEP); + s += base_; + if (!ext_.is_empty ()) + s += ::to_string (EXTSEP) + ext_; + return s; +} + +char const* +File_name::to_str0 () const +{ + return to_string ().to_str0 (); +} + +File_name::File_name (String file_name) +{ +#ifdef __CYGWIN__ + /* All system functions would work, even if we don't convert to + posix file_name, but we'd think that \foe\bar\baz.ly is in the cwd. + On by default. */ + file_name = dos_to_posix (file_name); +#endif + + int i = file_name.index (ROOTSEP); + if (i >= 0) + { + root_ = file_name.left_string (i); + file_name = file_name.right_string (file_name.length () - i - 1); + } + + i = file_name.index_last (DIRSEP); + if (i >= 0) + { + dir_ = file_name.left_string (i); + file_name = file_name.right_string (file_name.length () - i - 1); + } + + i = file_name.index_last ('.'); + if (i >= 0) + { + base_ = file_name.left_string (i); + ext_ = file_name.right_string (file_name.length () - i - 1); + } + else + base_ = file_name; +} diff --git a/flower/file-path.cc b/flower/file-path.cc index c59d218cd1..c6bd1248aa 100644 --- a/flower/file-path.cc +++ b/flower/file-path.cc @@ -1,5 +1,10 @@ /* - path.cc - manipulation of paths and filenames. + file-path.cc - implement File_path + + source file of the Flower Library + + (c) 1997--2004 Han-Wen Nienhuys + Jan Nieuwenhuizen */ #include "config.h" @@ -13,171 +18,56 @@ #ifdef __CYGWIN__ #include - -// URGURG -#include "../lily/include/scm-option.hh" #endif +#include "file-name.hh" #include "file-path.hh" - #ifndef PATHSEP #define PATHSEP ':' #endif -/* We don't have multiple roots, set this to '\0'? */ -#ifndef ROOTSEP -#define ROOTSEP ':' -#endif - -#ifndef DIRSEP -#define DIRSEP '/' -#endif - -#ifndef EXTSEP -#define EXTSEP '.' -#endif - - - -#ifdef __CYGWIN__ -static String -dos_to_posix (String path) -{ - char buf[PATH_MAX]; - char *filename = path.get_copy_str0 (); - /* urg, wtf? char const* argument gets modified! */ - cygwin_conv_to_posix_path (filename, buf); - delete filename; - return buf; -} - -static String -dos_to_posix_list (String path) -{ - char *filename = path.get_copy_str0 (); - int len = cygwin_win32_to_posix_path_list_buf_size (filename); - if (len < PATH_MAX) - len = PATH_MAX; - char *buf = new char[len]; - /* urg, wtf? char const* argument gets modified! */ - cygwin_win32_to_posix_path_list (filename, buf); - delete filename; - - String ret = buf; - delete buf; - return ret; -} -#endif /* __CYGWIN__ */ - -/* Join components to full path. */ -String -Path::to_string () const -{ - String s; - if (!root.is_empty ()) - s = root + ::to_string (ROOTSEP); - if (!dir.is_empty ()) - s += dir + ::to_string (DIRSEP); - s += base; - if (!ext.is_empty ()) - s += ::to_string (EXTSEP) + ext; - return s; -} - -/** - @param path the original full filename - @return 4 components of the path. They can be empty -*/ -Path -split_path (String path) -{ -#ifdef __CYGWIN__ - /* All system functions would work, even if we don't convert to - posix path, but we'd think that \foe\bar\baz.ly is in the cwd. - On by default. */ - if (!(testing_level_global & 1)) - path = dos_to_posix (path); -#endif - - Path p; - int i = path.index (ROOTSEP); - if (i >= 0) - { - p.root = path.left_string (i); - path = path.right_string (path.length () - i - 1); - } - - i = path.index_last (DIRSEP); - if (i >= 0) - { - p.dir = path.left_string (i); - path = path.right_string (path.length () - i - 1); - } - - i = path.index_last ('.'); - if (i >= 0) - { - p.base = path.left_string (i); - p.ext = path.right_string (path.length () - i - 1); - } - else - p.base = path; - return p; -} - void File_path::parse_path (String p) { -#ifdef __CYGWIN__ - if (testing_level_global & 4) - p = dos_to_posix_list (p); -#endif - - int l; - - while ((l = p.length ()) ) + int len; + while ((len = p.length ()) ) { int i = p.index (PATHSEP); if (i <0) - i = l; - add (p.left_string (i)); - p = p.right_string (l- i - 1); + i = len; + append (p.left_string (i)); + p = p.right_string (len - i - 1); } } - - - /** Find a file. - It will search in the current dir, in the construction-arg, and - in any other added path, in this order. + + Seach in the current dir (DUH! FIXME?), in the construction-arg + (what's that?, and in any other appended directory, in this order. @return - The full path if found, or empty string if not found - */ + The file name if found, or empty string if not found. */ + String -File_path::find (String nm) const +File_path::find (String name) const { - if (!nm.length () || (nm == "-") ) - return nm; - for (int i=0; i < size (); i++) + if (!name.length () || (name == "-") ) + return name; + int n = size (); + for (int i = 0; i < n; i++) { - String path = elem (i); + String file_name = elem (i); String sep = ::to_string (DIRSEP); - String right (path.right_string (1)); - if (path.length () && right != sep) - path += ::to_string (DIRSEP); - - path += nm; + String right (file_name.right_string (1)); + if (file_name.length () && right != sep) + file_name += ::to_string (DIRSEP); + file_name += name; -#if 0 - /* - Check if directory. TODO: encapsulate for autoconf - */ +#if 0 /* Check if directory. TODO: encapsulate for autoconf */ struct stat sbuf; - if (stat (path.to_str0 (), &sbuf) != 0) + if (stat (file_name.to_str0 (), &sbuf) != 0) continue; if (! (sbuf.st_mode & __S_IFREG)) @@ -186,59 +76,82 @@ File_path::find (String nm) const #if !STAT_MACROS_BROKEN struct stat sbuf; - if (stat (path.to_str0 (), &sbuf) != 0) + if (stat (file_name.to_str0 (), &sbuf) != 0) continue; if (S_ISDIR (sbuf.st_mode)) continue; #endif - FILE *f = fopen (path.to_str0 (), "r"); // ugh! + /* ugh */ + FILE *f = fopen (file_name.to_str0 (), "r"); if (f) { fclose (f); - return path; + return file_name; } } return ""; } -/** - Add a directory, return false if failed - */ -bool -File_path::try_add (String s) -{ - if (s == "") - s = "."; - FILE * f = fopen (s.to_str0 (), "r"); - if (!f) - return false; - fclose (f); +/** Find a file. - add (s); - return true; -} + Seach in the current dir (DUH! FIXME?), in the construction-arg + (what's that?, and in any other appended directory, in this order. -void -File_path::add (String s) + Search for NAME, or name without extension, or name with any of + EXTENSIONS, in that order. + + @return + The file name if found, or empty string if not found. */ +String +File_path::find (String name, char const *extensions[]) { -#ifdef __CYGWIN__ - if (testing_level_global & 2) - s = dos_to_posix (s); -#endif + File_name file_name (name); + if (name.is_empty () || name == "-") + file_name.base_ = "-"; + else + { + String orig_ext = file_name.ext_; + for (int i = 0; extensions[i]; i++) + { + file_name.ext_ = orig_ext; + if (*extensions[i] && !file_name.ext_.is_empty ()) + file_name.ext_ += "."; + file_name.ext_ += extensions[i]; + if (!find (file_name.to_string ()).is_empty ()) + break; + } + /* Reshuffle extension */ + file_name = File_name (file_name.to_string ()); + } + return file_name.to_string (); +} - push (s); +/** Append a directory, return false if failed. */ +bool +File_path::try_append (String s) +{ + if (s == "") + s = "."; + if (FILE *f = fopen (s.to_str0 (), "r")) + { + fclose (f); + append (s); + return true; + } + return false; } String File_path::to_string () const { String s; - for (int i=0; i< size (); i++) + int n = size (); + for (int i = 0; i < n; i++) { s = s + elem (i); - if (i < size () -1 ) + if (i < n - 1) s += ":"; } return s; diff --git a/flower/include/file-name.hh b/flower/include/file-name.hh new file mode 100644 index 0000000000..f05ec44227 --- /dev/null +++ b/flower/include/file-name.hh @@ -0,0 +1,29 @@ +/* + file-name.hh -- declare File_name + + source file of the Flower Library + + (c) 1997--2004 Han-Wen Nienhuys +*/ + +#ifndef FILE_NAME_HH +#define FILE_NAME_HH + +#include "array.hh" +#include "string.hh" + +class File_name +{ +public: + String root_; + String dir_; + String base_; + String ext_; + + File_name (String); + + String to_string () const; + char const *to_str0 () const; +}; + +#endif /* FILE_NAME */ diff --git a/flower/include/file-path.hh b/flower/include/file-path.hh index 40579d00fe..7cd81496f3 100644 --- a/flower/include/file-path.hh +++ b/flower/include/file-path.hh @@ -1,5 +1,5 @@ /* - file-path.hh -- declare Path and File_path + file-path.hh -- declare File_name and File_path source file of the Flower Library @@ -9,9 +9,8 @@ #ifndef FILE_PATH_HH #define FILE_PATH_HH -#include "string.hh" #include "array.hh" - +#include "string.hh" /** search in directories for a file. @@ -22,30 +21,16 @@ TODO: add a unix style PATH interface */ -class Path -{ -public: - String root; - String dir; - String base; - String ext; - - String to_string () const; -}; - class File_path : private Array { public: - String find (String nm) const; - - Array::push; - void prepend (String str) { Array::insert (str, 0); } - String to_string ()const; - bool try_add (String str); - void add (String); + String find (String name) const; + String find (String name, char const *extensions[]); + String to_string () const; + bool try_append (String str); + void append (String str) { Array::push (str); } void parse_path (String); + void prepend (String str) { Array::insert (str, 0); } }; -Path split_path (String path); - #endif /* FILE_PATH */ diff --git a/flower/include/flower-proto.hh b/flower/include/flower-proto.hh index 84b6280521..e75cdba670 100644 --- a/flower/include/flower-proto.hh +++ b/flower/include/flower-proto.hh @@ -28,7 +28,8 @@ typedef Interval_t Slice; // junkme. struct Offset; struct Long_option_init; struct Rational; -struct File_path; +class File_name; +class File_path; struct Getopt_long; struct String_data; struct String_handle; diff --git a/input/test/blank-paper.ly b/input/test/blank-paper.ly index f6d9b5b67d..b81ebbb885 100644 --- a/input/test/blank-paper.ly +++ b/input/test/blank-paper.ly @@ -1,4 +1,4 @@ -\version "2.2.0" +\version "2.3.0" \header { texidoc="@cindex Blank Paper @@ -6,20 +6,19 @@ A blank music paper can be produced also by using invisible notes, and removing @code{Bar_number_engraver}. " } -\score { - \notes { - % \clef violin + + +\score \with { + \override TimeSignature #'transparent = ##t + \override NoteHead #'transparent = ##t + defaultBarType = #"" + \remove Bar_number_engraver +} + +{ + %% \clef treble \clef bass \repeat unfold 3 { c1 \break } - } - \paper { - \context { - \ScoreContext - \override TimeSignature #'transparent = ##t - \override NoteHead #'transparent = ##t - defaultBarType = #"" - \remove Bar_number_engraver - } - } } + diff --git a/lily/include/paper-outputter.hh b/lily/include/paper-outputter.hh index 824618db5e..e232f26a27 100644 --- a/lily/include/paper-outputter.hh +++ b/lily/include/paper-outputter.hh @@ -27,20 +27,21 @@ class Paper_outputter { bool verbatim_scheme_b_; - -public: SCM output_module_; Protected_scm file_; - String basename_; + String filename_; + + void output_expr (SCM expr, Offset o); + void output_metadata (Paper_def*, SCM); + void output_music_output_def (Music_output_def* odef); +public: Paper_outputter (String nm); ~Paper_outputter (); - + void dump_scheme (SCM); - void output_metadata (Paper_def*, SCM); - void output_music_output_def (Music_output_def* odef); void output_scheme (SCM scm); - void output_expr (SCM expr, Offset o); + void output_stencil (Stencil*); void output_header (Paper_def*, SCM, int, bool); void output_line (SCM, Offset*, bool); }; diff --git a/lily/main.cc b/lily/main.cc index 0c8ce247e3..a3b89c6020 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -18,20 +18,20 @@ #include #endif -#include "lily-guile.hh" -#include "lily-version.hh" #include "all-font-metrics.hh" +#include "file-name.hh" +#include "file-path.hh" #include "getopt-long.hh" +#include "global-ctor.hh" +#include "kpath.hh" +#include "lily-guile.hh" +#include "lily-version.hh" +#include "main.hh" +#include "midi-def.hh" #include "misc.hh" +#include "paper-def.hh" #include "string.hh" -#include "main.hh" -#include "file-path.hh" #include "warn.hh" -#include "lily-guile.hh" -#include "paper-def.hh" -#include "midi-def.hh" -#include "global-ctor.hh" -#include "kpath.hh" /* * Global options that can be overridden through command line. @@ -212,7 +212,7 @@ setup_paths () if (char const *lilypond_prefix = getenv ("LILYPONDPREFIX")) prefix_directory[1] = lilypond_prefix; - global_path.add (""); + global_path.append (""); /* Adding mf/out make lilypond unchanged source directory, when setting LILYPONDPREFIX to lilypond-x.y.z */ @@ -318,7 +318,7 @@ parse_argv (int argc, char **argv) { bool help_b = false; option_parser = new Getopt_long (argc, argv, options_static); - while (Long_option_init const * opt = (*option_parser) ()) + while (Long_option_init const *opt = (*option_parser) ()) { switch (opt->shortname_char_) { @@ -329,10 +329,10 @@ parse_argv (int argc, char **argv) case 'o': { String s = option_parser->optional_argument_str0_; - Path p = split_path (s); - if (s != "-" && p.ext.is_empty ()) - p.ext = output_format_global; - output_name_global = p.to_string (); + File_name file_name (s); + if (s != "-" && file_name.ext_.is_empty ()) + file_name.ext_ = output_format_global; + output_name_global = file_name.to_string (); } break; case 'e': @@ -356,7 +356,7 @@ parse_argv (int argc, char **argv) .push (option_parser->optional_argument_str0_); break; case 'I': - global_path.push (option_parser->optional_argument_str0_); + global_path.append (option_parser->optional_argument_str0_); break; case 'i': init_name_global = option_parser->optional_argument_str0_; diff --git a/lily/my-lily-parser.cc b/lily/my-lily-parser.cc index c34351f65d..6922d69d12 100644 --- a/lily/my-lily-parser.cc +++ b/lily/my-lily-parser.cc @@ -8,6 +8,7 @@ */ #include "book.hh" +#include "file-name.hh" #include "file-path.hh" #include "lily-version.hh" #include "ly-module.hh" @@ -221,35 +222,6 @@ LY_DEFINE (ly_set_point_and_click, "ly:set-point-and-click", 1, 0, 0, return SCM_UNSPECIFIED; } - -/* Distill full input file name from command argument. PATH describes - file name with added default extension, ".ly" if none. "-" is - STDIN. */ -Path -distill_inname (String str) -{ - Path p = split_path (str); - if (str.is_empty () || str == "-") - p.base = "-"; - else - { - String orig_ext = p.ext; - char const *extensions[] = {"ly", "", 0}; - for (int i = 0; extensions[i]; i++) - { - p.ext = orig_ext; - if (*extensions[i] && !p.ext.is_empty ()) - p.ext += "."; - p.ext += extensions[i]; - if (!global_path.find (p.to_string ()).is_empty ()) - break; - } - /* Reshuffle extension */ - p = split_path (p.to_string ()); - } - return p; -} - LY_DEFINE (ly_parse_file, "ly:parse-file", 1, 0, 0, (SCM name), @@ -258,22 +230,21 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", { SCM_ASSERT_TYPE (ly_c_string_p (name), name, SCM_ARG1, __FUNCTION__, "string"); char const *file = SCM_STRING_CHARS (name); - - String infile (file); - Path inpath = distill_inname (infile); + char const *extensions[] = {"ly", "", 0}; + String file_name = global_path.find (file, extensions); /* By default, use base name of input file for output file name */ - Path outpath = inpath; - if (inpath.to_string () != "-") - outpath.ext = output_format_global; + File_name out_file_name (file_name); + if (file_name != "-") + out_file_name.ext_ = output_format_global; /* By default, write output to cwd; do not copy directory part of input file name */ - outpath.root = ""; - outpath.dir = ""; + out_file_name.root_ = ""; + out_file_name.dir_ = ""; if (!output_name_global.is_empty ()) - outpath = split_path (output_name_global); + out_file_name = File_name (output_name_global); String init; if (!init_name_global.is_empty ()) @@ -281,9 +252,7 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", else init = "init.ly"; - String in_file = inpath.to_string (); - String out_file = outpath.to_string (); - + String out_file = out_file_name.to_string (); if (init.length () && global_path.find (init).is_empty ()) { @@ -292,30 +261,31 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", exit (2); } - if ((in_file != "-") && global_path.find (in_file).is_empty ()) + if ((file_name != "-") && global_path.find (file_name).is_empty ()) { - warning (_f ("can't find file: `%s'", in_file)); - scm_throw (ly_symbol2scm ("ly-file-failed"), scm_list_1 (scm_makfrom0str (in_file.to_str0 ()))); + warning (_f ("can't find file: `%s'", file_name)); + scm_throw (ly_symbol2scm ("ly-file-failed"), + scm_list_1 (scm_makfrom0str (file_name.to_str0 ()))); } else { Sources sources; sources.set_path (&global_path); - progress_indication (_f ("Now processing `%s'", in_file.to_str0 ())); + progress_indication (_f ("Now processing `%s'", file_name.to_str0 ())); progress_indication ("\n"); My_lily_parser *parser = new My_lily_parser (&sources); scm_module_define (global_lily_module, ly_symbol2scm ("parser"), parser->self_scm ()); - parser->parse_file (init, in_file, out_file); + parser->parse_file (init, file_name, out_file); bool error = parser->error_level_; parser = 0; if (error) /* TODO: pass renamed input file too. */ scm_throw (ly_symbol2scm ("ly-file-failed"), - scm_list_1 (scm_makfrom0str (in_file.to_str0 ()))); + scm_list_1 (scm_makfrom0str (file_name.to_str0 ()))); } return SCM_UNSPECIFIED; } @@ -386,10 +356,10 @@ LY_DEFINE (ly_parser_print_score, "ly:parser-print-score", SCM header = is_module (score->header_) ? score->header_ : parser->header_.to_SCM (); - Path outname = split_path (parser->output_basename_); + File_name outname (parser->output_basename_); int *c = &parser->book_count_; if (*c) - outname.base += "-" + to_string (*c); + outname.base_ += "-" + to_string (*c); (*c)++; SCM os = scm_makfrom0str (outname.to_string ().to_str0 ()); @@ -419,10 +389,10 @@ LY_DEFINE (ly_parser_print_book, "ly:parser-print-book", Book *book = unsmob_book (book_smob); SCM header = parser->header_; - Path outname = split_path (parser->output_basename_); + File_name outname (parser->output_basename_); int *c = &parser->book_count_; if (*c) - outname.base += "-" + to_string (*c); + outname.base_ += "-" + to_string (*c); (*c)++; Music_output_def *paper = get_paper (parser); book->process (outname.to_string (), paper, header); diff --git a/lily/paper-def.cc b/lily/paper-def.cc index d751a0eb87..acf580772b 100644 --- a/lily/paper-def.cc +++ b/lily/paper-def.cc @@ -78,12 +78,7 @@ Paper_def::get_paper_outputter (String outname) const { progress_indication (_f ("paper output to `%s'...", outname == "-" ? String ("") : outname)); - - Paper_outputter * po = new Paper_outputter (outname); - Path p = split_path (outname); - p.ext = ""; - po->basename_ = p.to_string (); - return po; + return new Paper_outputter (outname); } Font_metric* diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index a648426da8..7a7f7c0883 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -22,6 +22,7 @@ #include "paper-def.hh" #include "paper-line.hh" #include "paper-outputter.hh" +#include "file-name.hh" #include "scm-hash.hh" #include "stencil.hh" #include "string-convert.hh" @@ -30,12 +31,13 @@ Paper_outputter::Paper_outputter (String filename) { - if (safe_global_b) - scm_define (ly_symbol2scm ("safe-mode?"), SCM_BOOL_T); - + filename_ = filename; file_ = scm_open_file (scm_makfrom0str (filename.to_str0 ()), scm_makfrom0str ("w")); + if (safe_global_b) + scm_define (ly_symbol2scm ("safe-mode?"), SCM_BOOL_T); + String module_name = "scm output-" + output_format_global; if (safe_global_b) { @@ -116,11 +118,15 @@ Paper_outputter::output_metadata (Paper_def *paper, SCM scopes) fields = scm_cons (ly_symbol2scm (dump_header_fieldnames_global[i].to_str0 ()), fields); + + File_name file_name (filename_); + file_name.ext_ = ""; + String basename = file_name.to_string (); output_scheme (scm_list_n (ly_symbol2scm ("output-scopes"), paper->self_scm (), ly_quote_scm (scopes), ly_quote_scm (fields), - scm_makfrom0str (basename_.to_str0 ()), + scm_makfrom0str (basename.to_str0 ()), SCM_UNDEFINED)); } @@ -182,12 +188,17 @@ Paper_outputter::output_line (SCM line, Offset *origin, bool is_last) (*origin)[Y_AXIS] += dim[Y_AXIS]; } +void +Paper_outputter::output_music_output_def (Music_output_def *odef) +{ + output_scheme (scm_list_2 (ly_symbol2scm ("output-paper-def"), + odef->self_scm ())); +} void -Paper_outputter::output_music_output_def (Music_output_def* odef) +Paper_outputter::output_stencil (Stencil *stil) { - output_scheme (scm_list_n (ly_symbol2scm ("output-paper-def"), - odef->self_scm (), SCM_UNDEFINED)); + output_expr (stil->get_expr (), stil->origin ()); } /* TODO: replaceme/rewriteme, see output-ps.scm: output-stencil */ @@ -202,18 +213,17 @@ Paper_outputter::output_expr (SCM expr, Offset o) SCM head =ly_car (expr); if (unsmob_input (head)) { - Input * ip = unsmob_input (head); - - output_scheme (scm_list_n (ly_symbol2scm ("define-origin"), - scm_makfrom0str (ip->file_string ().to_str0 ()), - scm_int2num (ip->line_number ()), - scm_int2num (ip->column_number ()), - SCM_UNDEFINED)); + Input *ip = unsmob_input (head); + output_scheme (scm_list_4 (ly_symbol2scm ("define-origin"), + scm_makfrom0str (ip->file_string () + .to_str0 ()), + scm_int2num (ip->line_number ()), + scm_int2num (ip->column_number ()))); expr = ly_cadr (expr); } else if (head == ly_symbol2scm ("no-origin")) { - output_scheme (scm_list_n (head, SCM_UNDEFINED)); + output_scheme (scm_list_1 (head)); expr = ly_cadr (expr); } else if (head == ly_symbol2scm ("translate-stencil")) @@ -228,13 +238,11 @@ Paper_outputter::output_expr (SCM expr, Offset o) } else { - output_scheme (scm_list_n (ly_symbol2scm ("placebox"), + output_scheme (scm_list_4 (ly_symbol2scm ("placebox"), scm_make_real (o[X_AXIS]), scm_make_real (o[Y_AXIS]), - expr, - SCM_UNDEFINED)); + expr)); return; } } } - diff --git a/lily/performance.cc b/lily/performance.cc index bee85fb5f9..484c59f0c5 100644 --- a/lily/performance.cc +++ b/lily/performance.cc @@ -7,20 +7,21 @@ */ #include -#include "warn.hh" -#include "string.hh" -#include "string-convert.hh" + +#include "audio-column.hh" +#include "audio-item.hh" +#include "audio-staff.hh" +#include "file-name.hh" +#include "lily-version.hh" #include "main.hh" #include "midi-def.hh" #include "midi-item.hh" #include "midi-stream.hh" -#include "audio-column.hh" -#include "audio-item.hh" -#include "audio-staff.hh" #include "performance.hh" #include "score.hh" -#include "file-path.hh" -#include "lily-version.hh" +#include "string-convert.hh" +#include "string.hh" +#include "warn.hh" #include "killing-cons.tcc" @@ -163,9 +164,9 @@ Performance::process (String out) out = "lelie.midi"; /* Maybe a bit crude, but we had this before */ - Path p = split_path (out); - p.ext = "midi"; - out = p.to_string (); + File_name file_name (out); + file_name.ext_ = "midi"; + out = file_name.to_string (); Midi_stream midi_stream (out); progress_indication (_f ("MIDI output to `%s'...", out)); diff --git a/lily/scm-option.cc b/lily/scm-option.cc index a3d87f7e7a..aab7f1d48c 100644 --- a/lily/scm-option.cc +++ b/lily/scm-option.cc @@ -1,10 +1,10 @@ -/* +/* scm-option.cc -- implement option setting from Scheme - + source file of the GNU LilyPond music typesetter - + (c) 2001--2004 Han-Wen Nienhuys - + */ #include @@ -25,7 +25,7 @@ preferably, also dont use TESTING_LEVEL_GLOBAL, since it defeats another purpose of this very versatile interface, which is to support multiple debug/testing options concurrently. - + */ @@ -48,7 +48,7 @@ bool internal_type_checking_global_b; LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (SCM), "Print ly-set-option usage") -{ +{ printf ( _("lilypond -e EXPR means:").to_str0 ()); puts (""); printf (_ (" Evalute the Scheme EXPR before parsing any .ly files.").to_str0 ()); @@ -66,7 +66,7 @@ LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (SCM), " midi-debug BOOLEAN\n" " parse-protect BOOLEAN\n" " testing-level INTEGER\n"); - + exit (0); return SCM_UNSPECIFIED; } @@ -104,49 +104,35 @@ LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val), val = SCM_BOOL_T; if (var == ly_symbol2scm ("help")) - { - /* lilypond -e "(ly-set-option 'help #t)" */ - ly_option_usage (SCM_EOL); - } + /* lilypond -e "(ly-set-option 'help #t)" */ + ly_option_usage (SCM_EOL); else if (var == ly_symbol2scm ("midi-debug")) - { - midi_debug_global_b = to_boolean (val); - } + midi_debug_global_b = to_boolean (val); else if (var == ly_symbol2scm ("testing-level")) - { - testing_level_global = ly_scm2int (val); - } + testing_level_global = ly_scm2int (val); else if (var == ly_symbol2scm ("parse-protect" )) - { - parse_protect_global = to_boolean (val); - } + parse_protect_global = to_boolean (val); else if (var == ly_symbol2scm ("internal-type-checking")) - { - internal_type_checking_global_b = to_boolean (val); - } + internal_type_checking_global_b = to_boolean (val); else if (var == ly_symbol2scm ("old-relative")) { lily_1_8_relative = true; - lily_1_8_compatibility_used = false; + /* Needs to be reset for each file that uses this option. */ + lily_1_8_compatibility_used = false; } else if (var == ly_symbol2scm ("new-relative")) - { - lily_1_8_relative = false; - } + lily_1_8_relative = false; else if (var == ly_symbol2scm ("debug-beam")) { extern bool debug_beam_quanting_flag; debug_beam_quanting_flag = true; } else - { - warning (_("Unknown internal option!")); - } + warning (_f ("No such internal option: %s", ly_scm2string (var))); return SCM_UNSPECIFIED; } - LY_DEFINE (ly_get_option, "ly:get-option", 1, 0, 0, (SCM var), "Get a global option setting. Supported options include\n" "@table @code\n" @@ -159,22 +145,14 @@ LY_DEFINE (ly_get_option, "ly:get-option", 1, 0, 0, (SCM var), "@end table\n" "\n") { + SCM o = SCM_UNSPECIFIED; if (var == ly_symbol2scm ("old-relative-used")) - { - return ly_bool2scm (lily_1_8_compatibility_used); - } - if (var == ly_symbol2scm ("old-relative")) - { - return ly_bool2scm (lily_1_8_relative); - } - if (var == ly_symbol2scm ("verbose")) - { - return ly_bool2scm (verbose_global_b); - } + o = ly_bool2scm (lily_1_8_compatibility_used); + else if (var == ly_symbol2scm ("old-relative")) + o = ly_bool2scm (lily_1_8_relative); + else if (var == ly_symbol2scm ("verbose")) + o = ly_bool2scm (verbose_global_b); else - { - warning (_("Unknown internal option!")); - } - - return SCM_UNSPECIFIED; + warning (_f ("No such internal option: %s", ly_scm2string (var))); + return o; } diff --git a/scm/lily.scm b/scm/lily.scm index 1c80008611..e22e5a5acd 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -115,10 +115,6 @@ (define-public default-toplevel-music-handler print-music-as-book) (define-public default-toplevel-book-handler ly:parser-print-book) (define-public default-toplevel-score-handler print-score-as-book) -;;(define-public toplevel-music-handler print-music-as-book) -;;(define-public toplevel-music-handler toplevel-music-functions) -;;(define-public toplevel-music-handler -;; (lambda (x y) (print-music-as-book x y))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -- 2.39.5