]> git.donarmstrong.com Git - lilypond.git/commitdiff
* scm/output-tex.scm (ps-output-expression): Eval embedded-ps
authorJan Nieuwenhuizen <janneke@gnu.org>
Sun, 14 Mar 2004 21:27:31 +0000 (21:27 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Sun, 14 Mar 2004 21:27:31 +0000 (21:27 +0000)
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
lily/include/ly-module.hh
lily/ly-module.cc
lily/music-output-def.cc
lily/paper-outputter.cc
lily/score.cc
scm/lily.scm
scm/output-lib.scm
scm/output-ps.scm
scm/output-tex.scm

index f2325a9733ea172dce680af58b7f066d1ff44cd0..7440e861b131e3d077f03d0ef23e9d2c641e1f0d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2004-03-14  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * 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   <hanwen@xs4all.nl>
 
        * lily/span-dynamic-performer.cc (process_music): remove spurious
index c486a4e9271ff3b0696d79294a130262428dcc5a..463cea79aeb185b4d69e751f5427eb67bfe93969 100644 (file)
@@ -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);
index dd204fa938dce606c8ca5ccf55d243de72bccf16..ea0e7c67f899625ee4345baf2b42dfb3c5d38b81 100644 (file)
@@ -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);
 }
 
index 08d31e48c9ccde69600fc00d4eb88218e43b4b9c..e2c32b6dd25a6cffa1119369c0f78d1ff917eb80 100644 (file)
@@ -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_);
 }
 
 
index 0e9d30eb913afe9f9d70e8d366c115fe345726da..134b19bc4c01f30d6c1f545d431bfc8219b1e5a4 100644 (file)
@@ -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
     {
index d007e2a2a2e509230d7a7860b25d1da75931dc77..71afe0f2aa44b3744ba62a247ec278f6a8624763 100644 (file)
@@ -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", 
index 7729fdf6133f7e7aa129f2ec048e7b684d8877bf..cc54d9c9617fc1a053da13ef19c725d57f61f0af 100644 (file)
@@ -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.
 
index 805e5711242aa9560e556c3ad4f898cd4803bbca..b31d0bed133e757eea1f0eb62a2c1533e9a6b8a8 100644 (file)
 ;; 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))
index 36d9dffbcde6f1247302642919ca62d0fedfec90..d538cf07478eae8e3ff9498cbf21a3c2497d32b4 100644 (file)
 ;;;;   * 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)
index f86cc536997c76802b980b07ec0580c1c96d11e5..41d48ef03bcdfbe6ccd9f08c009a67918638098c 100644 (file)
@@ -6,24 +6,26 @@
 ;;;;                  Han-Wen Nienhuys <hanwen@cs.uu.nl>
 
 
-(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)