From 84f8fad65295bbb2324b59de7c6c71084c817810 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 14 Mar 2004 21:27:31 +0000 Subject: [PATCH] * scm/output-tex.scm (ps-output-expression): Eval embedded-ps instructions in output-ps module. * scm/lily.scm: Do not load output-ps module. * lily/paper-outputter.cc (Paper_outputter): Attempt to eval output-ps in safe mode. --- ChangeLog | 10 ++++++++ lily/include/ly-module.hh | 2 +- lily/ly-module.cc | 28 +++++++++++--------- lily/music-output-def.cc | 2 +- lily/paper-outputter.cc | 54 ++++++++++++++++++++++++++++++++++----- lily/score.cc | 2 +- scm/lily.scm | 8 +----- scm/output-lib.scm | 6 ++--- scm/output-ps.scm | 21 +++------------ scm/output-tex.scm | 20 ++++++++------- 10 files changed, 94 insertions(+), 59 deletions(-) diff --git a/ChangeLog b/ChangeLog index f2325a9733..7440e861b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-03-14 Jan Nieuwenhuizen + + * scm/output-tex.scm (ps-output-expression): Eval embedded-ps + instructions in output-ps module. + + * scm/lily.scm: Do not load output-ps module. + + * lily/paper-outputter.cc (Paper_outputter): Attempt to eval + output-ps in safe mode. + 2004-03-14 Han-Wen Nienhuys * lily/span-dynamic-performer.cc (process_music): remove spurious diff --git a/lily/include/ly-module.hh b/lily/include/ly-module.hh index c486a4e927..463cea79ae 100644 --- a/lily/include/ly-module.hh +++ b/lily/include/ly-module.hh @@ -13,7 +13,7 @@ #include "lily-guile.hh" SCM ly_make_anonymous_module (); -void ly_copy_module_variables (SCM dest, SCM src); +void ly_import_module (SCM dest, SCM src); SCM ly_module_to_alist (SCM mod); SCM ly_module_lookup (SCM module, SCM sym); SCM ly_modules_lookup (SCM modules, SCM sym); diff --git a/lily/ly-module.cc b/lily/ly-module.cc index dd204fa938..ea0e7c67f8 100644 --- a/lily/ly-module.cc +++ b/lily/ly-module.cc @@ -19,6 +19,7 @@ static int module_count; void ly_init_anonymous_module (void * data) { + (void) data; scm_c_use_module ("lily"); } @@ -50,11 +51,12 @@ ly_clear_anonymous_modules () #define FUNC_NAME __FUNCTION__ -SCM -define_one_var (void * closure, SCM key, SCM val, SCM result) +static SCM +ly_module_define (void *closure, SCM key, SCM val, SCM result) { - SCM dest = (SCM) closure; - scm_module_define (dest, key, scm_variable_ref (val)); + (void) result; + SCM module = (SCM) closure; + scm_module_define (module, key, scm_variable_ref (val)); return SCM_EOL; } @@ -62,17 +64,18 @@ define_one_var (void * closure, SCM key, SCM val, SCM result) typedef SCM (*Hash_cl_func)(); void -ly_copy_module_variables (SCM dest, SCM src) +ly_import_module (SCM dest, SCM src) { SCM_VALIDATE_MODULE (1, src); - - SCM obarr= SCM_MODULE_OBARRAY (src); - scm_internal_hash_fold ((Hash_cl_func) &define_one_var, (void*) dest, SCM_EOL, obarr); + scm_internal_hash_fold ((Hash_cl_func) &ly_module_define, (void*) dest, + SCM_EOL, SCM_MODULE_OBARRAY (src)); } -SCM -accumulate_symbol (void * closure, SCM key, SCM val, SCM result) +static SCM +accumulate_symbol (void *closure, SCM key, SCM val, SCM result) { + (void) closure; + (void) val; return scm_cons (key, result); } @@ -86,9 +89,10 @@ ly_module_symbols (SCM mod) NULL, SCM_EOL, obarr); } -SCM -entry_to_alist (void * closure, SCM key, SCM val, SCM result) +static SCM +entry_to_alist (void *closure, SCM key, SCM val, SCM result) { + (void) closure; return scm_cons (scm_cons (key, scm_variable_ref (val)), result); } diff --git a/lily/music-output-def.cc b/lily/music-output-def.cc index 08d31e48c9..e2c32b6dd2 100644 --- a/lily/music-output-def.cc +++ b/lily/music-output-def.cc @@ -48,7 +48,7 @@ Music_output_def::Music_output_def (Music_output_def const &s) scope_= ly_make_anonymous_module (); if (ly_module_p (s.scope_)) - ly_copy_module_variables (scope_, s.scope_); + ly_import_module (scope_, s.scope_); } diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 0e9d30eb91..134b19bc4c 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -39,16 +39,56 @@ Paper_outputter::Paper_outputter (String name) if (output_format_global == PAGE_LAYOUT) { output_func_ = SCM_UNDEFINED; - output_module_ - = scm_call_1 (scm_primitive_eval (ly_symbol2scm ("get-output-module")), - scm_makfrom0str (output_format_global.to_str0 ())); + String name = "scm output-" + output_format_global; if (safe_global_b) { - SCM safe_module = scm_primitive_eval (ly_symbol2scm ("safe-module")); - SCM m = scm_set_current_module (safe_module); - scm_c_use_module (("output-" + output_format_global).to_str0 ()); - output_module_ = scm_set_current_module (m); + /* In safe mode, start from a GUILE safe-module and import + all symbols from the output module. */ + scm_c_use_module ("ice-9 safe"); + SCM msm = scm_primitive_eval (ly_symbol2scm ("make-safe-module")); + output_module_ = scm_call_0 (msm); + ly_import_module (output_module_, + scm_c_resolve_module (name.to_str0 ())); + } + else + output_module_ = scm_c_resolve_module (name.to_str0 ()); + +#define IMPORT_LESS 1 // only import the list of IMPORTS +#if IMPORT_LESS + scm_c_use_module ("lily"); + scm_c_use_module ("ice-9 regex"); + scm_c_use_module ("srfi srfi-13"); +#endif + char const *imports[] = { + "lilypond-version", /* from lily */ + "ly:output-def-scope", + "ly:gulp-file", + "ly:number->string", + "assoc-get", + "number-pair->string", + "inexact->string", + "numbers->string", +#if IMPORT_LESS + "string-index", /* from srfi srfi-13 */ + "regexp-substitute/global", /* from (ice9 regex) */ +#endif + 0, + }; + + for (int i = 0; imports[i]; i++) + { + SCM s = ly_symbol2scm (imports[i]); + scm_module_define (output_module_, s, scm_primitive_eval (s)); } +#ifndef IMPORT_LESS // rather crude, esp for safe-mode let's not + SCM m = scm_set_current_module (output_module_); + /* not present in current module*/ + scm_c_use_module ("ice-9 regex"); + scm_c_use_module ("srfi srfi-13"); + /* Need only a few of these, see above + scm_c_use_module ("lily"); */ + scm_set_current_module (m); +#endif } else { diff --git a/lily/score.cc b/lily/score.cc index d007e2a2a2..71afe0f2aa 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -95,7 +95,7 @@ Score::Score (Score const &s) header_ = ly_make_anonymous_module (); if (ly_module_p (s.header_)) - ly_copy_module_variables (header_, s.header_); + ly_import_module (header_, s.header_); } LY_DEFINE (ly_run_translator, "ly:run-translator", diff --git a/scm/lily.scm b/scm/lily.scm index 7729fdf613..cc54d9c961 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -367,11 +367,9 @@ L1 is copied, L2 not. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; output (use-modules (scm output-tex) - (scm output-ps) (scm output-sketch) (scm output-sodipodi) - (scm output-pdftex) - ) + (scm output-pdftex)) (define output-alist `( @@ -396,10 +394,6 @@ L1 is copied, L2 not. (caddr d) (scm-error "Could not find dumper for format ~s" format)))) -(define-public (get-output-module output-format) - (resolve-module `(scm ,(string->symbol - (string-append "output-" output-format))))) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; other files. diff --git a/scm/output-lib.scm b/scm/output-lib.scm index 805e571124..b31d0bed13 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -107,10 +107,8 @@ ;; do nothing in .scm output (define-public (comment s) "") -(define-public (numbers->string l) - (apply string-append (map ly:number->string l))) - -; (define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x)) +(define-public (numbers->string lst) + (apply string-append (map ly:number->string lst))) (define (number->octal-string x) (let* ((n (inexact->exact x)) diff --git a/scm/output-ps.scm b/scm/output-ps.scm index 36d9dffbcd..d538cf0747 100644 --- a/scm/output-ps.scm +++ b/scm/output-ps.scm @@ -16,26 +16,13 @@ ;;;; * text setting, kerning. ;;;; * document output-interface -;;(if (not safe-mode?) -;; (debug-enable 'backtrace)) (debug-enable 'backtrace) (define-module (scm output-ps)) -(define this-module (current-module)) - -(use-modules - (guile) - (ice-9 regex) - (srfi srfi-13) - (lily)) - -(define (expression->string expr) - (eval expr this-module)) - -;;; Output interface entry -(define (output-expression expr port) - (display (expression->string expr) port)) - +(use-modules (guile) + (ice-9 regex) + (srfi srfi-13) + (lily)) ;;; Global vars ;; alist containing fontname -> fontcommand assoc (both strings) diff --git a/scm/output-tex.scm b/scm/output-tex.scm index f86cc53699..41d48ef03b 100644 --- a/scm/output-tex.scm +++ b/scm/output-tex.scm @@ -6,24 +6,26 @@ ;;;; Han-Wen Nienhuys -(define-module (scm output-tex) ) -; (debug-enable 'backtrace) -(use-modules (scm output-ps) - (ice-9 regex) +;; (debug-enable 'backtrace) +(define-module (scm output-tex)) +(use-modules (ice-9 regex) (ice-9 string-fun) (ice-9 format) (guile) (srfi srfi-13) - (lily) - ) + (lily)) (define this-module (current-module)) ;; dumper-compatibility - +(define output-ps #f) (define (ps-output-expression expr port) - (let ((output-ps (resolve-module '(scm output-ps)))) - (display (eval expr output-ps) port))) + (if (not output-ps) + (let ((ps-module (resolve-module '(scm output-ps)))) + (eval '(use-modules (guile) (ice-9 regex) (srfi srfi-13) (lily)) + ps-module) + (set! output-ps ps-module))) + (display (eval expr output-ps) port)) ;;; Output interface entry (define-public (tex-output-expression expr port) -- 2.39.5