From effd4a850ed79b4626c62ddf7b7a2216526eae67 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Wed, 10 Jan 2007 16:56:02 +0100 Subject: [PATCH] Evaluate -d option setting and -e code inside GUILE. --- lily/include/main.hh | 3 +++ lily/main.cc | 35 +++++++---------------------------- lily/program-option.cc | 12 ++++++++++++ scm/layout-beam.scm | 1 + scm/lily.scm | 34 +++++++++++++++++++++++++++------- 5 files changed, 50 insertions(+), 35 deletions(-) diff --git a/lily/include/main.hh b/lily/include/main.hh index 29b08a3f40..08194ca22f 100644 --- a/lily/include/main.hh +++ b/lily/include/main.hh @@ -38,6 +38,9 @@ extern bool point_and_click_global; extern string prefix_directory; extern bool use_object_keys; extern bool strict_infinity_checking; +extern string init_scheme_code_string_global; +extern string init_scheme_variables_global; + /* todo: collect in Output_option struct? */ diff --git a/lily/main.cc b/lily/main.cc index 2b715cdcb7..9161511e68 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -77,8 +77,8 @@ bool be_verbose_global = false; /* Scheme code to execute before parsing, after .scm init. This is where -e arguments are appended to. */ -string init_scheme_code_string; -string init_scheme_variables; +string init_scheme_code_string_global; +string init_scheme_variables_global; /* Generate preview of first system. */ bool make_preview = false; @@ -178,8 +178,6 @@ static Long_option_init options_static[] {_i ("FILE"), "output", 'o', _i ("write output to FILE (suffix will be added)")}, {0, "preview", 'p', _i ("generate a preview of the first system")}, {0, "relocate", 0, _i ("relocate using directory of lilypond program")}, - {0, "safe-mode", 's', _i ("disallow unsafe Scheme and PostScript\n" - "operations")}, {0, "version", 'v', _i ("show version number and exit")}, {0, "verbose", 'V', _i ("be verbose")}, {0, "warranty", 'w', _i ("show warranty and copyright")}, @@ -388,6 +386,8 @@ main_with_guile (void *, int, char **) || output_backend_global == "texstr"); is_pango_format_global = !is_TeX_format_global; + init_scheme_variables_global = "(list " + init_scheme_variables_global + ")"; + init_scheme_code_global = "(begin " + init_scheme_code_global + ")"; ly_c_init_guile (); call_constructors (); @@ -396,24 +396,6 @@ main_with_guile (void *, int, char **) init_freetype (); ly_reset_all_fonts (); - if (!init_scheme_variables.empty () - || !init_scheme_code_string.empty ()) - { - init_scheme_variables = "(map (lambda (x) (ly:set-option (car x) (cdr x))) (list " - + init_scheme_variables + "))"; - - init_scheme_code_string - = "(begin #t " - + init_scheme_variables - + init_scheme_code_string - + ")"; - - char const *str0 = init_scheme_code_string.c_str (); - - if (be_verbose_global) - progress_indication (_f ("Evaluating %s", str0)); - scm_c_eval_string ((char *) str0); - } /* We accept multiple independent music files on the command line to reduce compile time when processing lots of small files. @@ -508,7 +490,7 @@ parse_argv (int argc, char **argv) val = arg.substr (eq + 1, arg.length () - 1); } - init_scheme_variables + init_scheme_variables_global += "(cons \'" + key + " " + val + ")\n"; } break; @@ -527,8 +509,9 @@ parse_argv (int argc, char **argv) case 'j': jail_spec = option_parser->optional_argument_str0_; break; + case 'e': - init_scheme_code_string += option_parser->optional_argument_str0_; + init_scheme_code_string_global += option_parser->optional_argument_str0_ + string (" "); break; case 'w': warranty (); @@ -564,10 +547,6 @@ parse_argv (int argc, char **argv) case 'V': be_verbose_global = true; break; - case 's': - init_scheme_variables - += "(cons \'safe #t)\n"; - break; case 'p': make_preview = true; break; diff --git a/lily/program-option.cc b/lily/program-option.cc index 80930efbf3..64318c00a8 100644 --- a/lily/program-option.cc +++ b/lily/program-option.cc @@ -210,6 +210,18 @@ LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val), return SCM_UNSPECIFIED; } +LY_DEFINE (ly_command_line_options, "ly:command-line-options", 0, 0, 0, (), + "The Scheme specified on command-line with @samp{-d}.") +{ + return ly_string2scm (init_scheme_variables_global); +} + +LY_DEFINE (ly_command_line_code, "ly:command-line-code", 0, 0, 0, (), + "The Scheme specified on command-line with @samp{-e}.") +{ + return ly_string2scm (init_scheme_code_string_global); +} + LY_DEFINE (ly_command_line_verbose_p, "ly:command-line-verbose?", 0, 0, 0, (), "Was be_verbose_global set?") { diff --git a/scm/layout-beam.scm b/scm/layout-beam.scm index 1ee840aa0b..8edfd9c757 100644 --- a/scm/layout-beam.scm +++ b/scm/layout-beam.scm @@ -68,3 +68,4 @@ ly:beam::quanting (check-beam-slope-sign comparison) )) + diff --git a/scm/lily.scm b/scm/lily.scm index d4e05a4af1..e10b4b7d33 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -14,6 +14,10 @@ ;; Abbrv-PWR! (defmacro-public _i (x) x) +(read-enable 'positions) +(debug-enable 'debug) + + (define (define-scheme-options) (for-each (lambda (x) (ly:add-option (car x) (cadr x) (caddr x))) @@ -72,7 +76,12 @@ on errors, and print a stack trace.") (show-available-fonts #f "List font names available.") (verbose ,(ly:command-line-verbose?) "value for the --verbose flag") - ))) + )) + + (map + (lambda (x) + (ly:set-option (car x) (cdr x))) + (eval-string (ly:command-line-options)))) ;; need to do this in the beginning. Other parts of the @@ -80,6 +89,8 @@ on errors, and print a stack trace.") ;; (define-scheme-options) + + (debug-set! stack 0) (if (defined? 'set-debug-cell-accesses!) @@ -265,9 +276,10 @@ The syntax is the same as `define*-public'." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; other files. -(for-each ly:load - ;; load-from-path - '("lily-library.scm" + +(define + init-scheme-files + '("lily-library.scm" "file-cache.scm" "define-event-classes.scm" "define-music-types.scm" @@ -314,6 +326,11 @@ The syntax is the same as `define*-public'." "safe-lily.scm")) + + +(for-each ly:load init-scheme-files) + + (set! type-p-name-alist `( (,boolean-or-symbol? . "boolean or symbol") @@ -482,11 +499,13 @@ The syntax is the same as `define*-public'." (define-public (lilypond-main files) "Entry point for LilyPond." - + (define (no-files-handler) (ly:usage) (exit 2)) + (eval-string (ly:command-line-code)) + (if (ly:get-option 'gui) (gui-main files)) @@ -561,6 +580,7 @@ The syntax is the same as `define*-public'." (if (string-or-symbol? (ly:get-option 'log-file)) (ly:stderr-redirect (format "~a.log" (ly:get-option 'log-file)) "w")) + (let ((failed (lilypond-all files))) (if (pair? failed) @@ -573,7 +593,7 @@ The syntax is the same as `define*-public'." (exit 0))))) (define-public (lilypond-all files) - + (if (ly:get-option 'show-available-fonts) (begin @@ -631,7 +651,7 @@ The syntax is the same as `define*-public'." (if (ly:get-option 'dump-profile) (dump-profile "lily-run-total" '(0 0) (profile-measurements))) - + failed)) (define (lilypond-file handler file-name) -- 2.39.5