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 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
#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);
void
ly_init_anonymous_module (void * data)
{
+ (void) data;
scm_c_use_module ("lily");
}
#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;
}
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);
}
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);
}
scope_= ly_make_anonymous_module ();
if (ly_module_p (s.scope_))
- ly_copy_module_variables (scope_, s.scope_);
+ ly_import_module (scope_, s.scope_);
}
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
{
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",
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; output
(use-modules (scm output-tex)
- (scm output-ps)
(scm output-sketch)
(scm output-sodipodi)
- (scm output-pdftex)
- )
+ (scm output-pdftex))
(define output-alist
`(
(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.
;; 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))
;;;; * 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)
;;;; 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)