bound.
+2004-05-09 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+ * lily/ly-module.cc (ly_module_define): only define variable if
+ bound.
+
2004-05-08 Han-Wen Nienhuys <hanwen@xs4all.nl>
* scripts/lilypond-book.py (compose_ly): remove FRAGMENT_LY.
The default value is one octave below middle C.
@c update-me? formal definition of newaddlyrics, once it works
-@item Combining lyrics with music can be @code{newlyrics}
+@item Combining lyrics with music can be @code{\newlyrics}
@example
<<
>>
@end example
-Syntactically, @code{\newlyrics} acts like an infix operator
+Syntactically, @code{\newlyrics} acts like an infix operator.
@item The parser is encapsulated in a Scheme function
@code{ly:parse-file}, so the following fragment processes two files
@end example
@c TODO: use relative mode, verbatim, junk \transpose and above @example
+
+
+
@lilypond[quote,noindent,linewidth=50\staffspace]
-\transpose c c' {
+\transpose c c' {
\time 4/4
\key g \minor
\clef violin
gis2 r2
}
@end lilypond
+
@cindex accidentals
+
@noindent
There are some interesting points to note in this example. Bar lines
and beams are drawn automatically. Line breaks are calculated
#include "lily-guile.hh"
-SCM ly_make_anonymous_module ();
+SCM ly_make_anonymous_module (bool safe);
void ly_import_module (SCM dest, SCM src);
SCM ly_module_to_alist (SCM mod);
SCM ly_module_lookup (SCM module, SCM sym);
void ly_reexport_module (SCM mod);
inline bool is_module (SCM x) { return SCM_MODULEP(x); }
void ly_clear_anonymous_modules ();
-
+SCM ly_use_module (SCM mod, SCM used);
#endif /* LY_MODULE_HH */
return SCM_UNDEFINED;
}
+/*
+ TODO: rename this function. ly:input-location? vs ly:input-location
+ */
LY_DEFINE (ly_input_location, "ly:input-location", 1, 0, 0, (SCM sip),
"Return input location in @var{sip} as (filename line column).")
{
*/
+#include "main.hh"
#include "string.hh"
#include "lily-guile.hh"
#include "ly-module.hh"
ly_init_anonymous_module (void *data)
{
(void) data;
- scm_c_use_module ("lily");
}
SCM
-ly_make_anonymous_module ()
+ly_make_anonymous_module (bool safe)
{
- String s = "*anonymous-ly-" + to_string (module_count++) + "*";
- SCM mod = scm_c_define_module (s.to_str0 (), ly_init_anonymous_module, 0);
+ SCM mod = SCM_EOL;
+ if (!safe)
+ {
+
+ String s = "*anonymous-ly-" + to_string (module_count++) + "*";
+ mod = scm_c_define_module (s.to_str0 (), ly_init_anonymous_module, 0);
+
+ ly_use_module (mod, global_lily_module);
+ }
+ else
+ {
+ SCM proc = ly_scheme_function ("make-safe-lilypond-module");
+
+ mod = scm_call_0 (proc);
+ }
return mod;
}
+SCM
+ly_use_module (SCM mod, SCM used)
+{
+ SCM expr
+ = scm_list_3 (ly_symbol2scm ("module-use!"),
+ mod,
+ scm_list_2 (ly_symbol2scm ("module-public-interface"),
+ used));
+
+ return scm_eval (expr, global_lily_module);
+}
+
#define FUNC_NAME __FUNCTION__
static SCM
{
(void) result;
SCM module = (SCM) closure;
- scm_module_define (module, key, scm_variable_ref (val));
+ if (scm_variable_bound_p (val) == SCM_BOOL_T)
+ scm_module_define (module, key, scm_variable_ref (val));
return SCM_EOL;
}
smobify_self ();
scm_gc_unprotect_object (translator_tab_->self_scm ());
- scope_ = ly_make_anonymous_module ();
+ scope_ = ly_make_anonymous_module (false);
}
Music_output_def::~Music_output_def ()
translator_tab_ = new Scheme_hash_table (*s.translator_tab_);
scm_gc_unprotect_object (translator_tab_->self_scm ());
- scope_= ly_make_anonymous_module ();
+ scope_= ly_make_anonymous_module (safe_global_b);
if (is_module (s.scope_))
ly_import_module (scope_, s.scope_);
}
error_level_ = 0;
main_input_b_ = false;
- add_scope (ly_make_anonymous_module ());
+ add_scope (ly_make_anonymous_module (safe_global_b));
}
My_lily_lexer::My_lily_lexer (My_lily_lexer const &src)
return encoding_ ;
}
+
void
My_lily_lexer::add_scope (SCM module)
{
scm_set_current_module (module);
for (SCM s = scopes_; ly_c_pair_p (s); s = ly_cdr (s))
{
- /* UGH. how to do this more neatly? */
- SCM expr
- = scm_list_3 (ly_symbol2scm ("module-use!"),
- module,
- scm_list_2 (ly_symbol2scm ("module-public-interface"),
- ly_car (s)));
- scm_primitive_eval (expr);
+ ly_use_module (module, ly_car (s));
}
scopes_ = scm_cons (module, scopes_);
}
last_beam_start_ = SCM_EOL;
header_ = SCM_EOL;
- header_ = ly_make_anonymous_module ();
+ header_ = ly_make_anonymous_module (safe_global_b);
smobify_self ();
}
file_ = scm_open_file (scm_makfrom0str (filename.to_str0 ()),
scm_makfrom0str ("w"));
+ /*
+ UGH. -> global variable.
+ */
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)
- {
- /* 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 (module_name.to_str0 ()));
- }
- else
- output_module_ = scm_c_resolve_module (module_name.to_str0 ());
+ output_module_ = scm_c_resolve_module (module_name.to_str0 ());
- /* FIXME: output-lib should be module, that can be imported. */
-#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-1");
- 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",
- "ly:ragged-page-breaks",
- "ly:optimal-page-breaks",
-
- "ly:number-pair->string", /* output-lib.scm */
- "ly:numbers->string",
- "ly:inexact->string",
-
- "assoc-get",
-#if IMPORT_LESS
- "remove", /* from srfi srfi-1 */
- "string-index", /* from srfi srfi-13 */
- "string-join",
- "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
}
Paper_outputter::~Paper_outputter ()
Thanks to Gary Houston <ghouston@freewire.co.uk> */
SCM
-internal_ly_parse_scm (Parse_start * ps, bool safe)
+internal_ly_parse_scm (Parse_start * ps)
{
Source_file* sf =ps->start_location_.source_file_;
SCM port = sf->get_port ();
/* Read expression from port */
if (!SCM_EOF_OBJECT_P (form = scm_read (port)))
{
- if (safe)
- {
- static SCM safe_module;
- if (!safe_module)
- {
- safe_module = scm_primitive_eval (ly_symbol2scm ("safe-module"));
- ly_import_module (safe_module, scm_c_resolve_module ("lily"));
- }
- answer = scm_eval (form, safe_module);
- }
- else
answer = scm_primitive_eval (form);
}
catch_protected_parse_body (void *p)
{
Parse_start *ps = (Parse_start*) p;
- return internal_ly_parse_scm (ps, false);
+ return internal_ly_parse_scm (ps);
}
SCM
safe_catch_protected_parse_body (void *p)
{
Parse_start *ps = (Parse_start*) p;
- return internal_ly_parse_scm (ps, true);
+ return internal_ly_parse_scm (ps);
}
SCM
#endif
SCM
-protected_ly_parse_scm (Parse_start *ps, bool safe)
+protected_ly_parse_scm (Parse_start *ps)
{
return scm_internal_catch (ly_symbol2scm (READ_ERROR),
- (safe ? &safe_catch_protected_parse_body
- : catch_protected_parse_body),
+ &catch_protected_parse_body,
(void*) ps,
&parse_handler, (void*) ps);
}
ps.str = s;
ps.start_location_ = i;
- SCM ans = parse_protect_global ? protected_ly_parse_scm (&ps, safe)
- : internal_ly_parse_scm (&ps, safe);
+ SCM ans = parse_protect_global ? protected_ly_parse_scm (&ps)
+ : internal_ly_parse_scm (&ps);
*n = ps.nchars;
return ans;
lilypond_header_body:
{
- $$ = ly_make_anonymous_module ();
+ $$ = ly_make_anonymous_module (safe_global_b);
THIS->lexer_->add_scope ($$);
}
| lilypond_header_body assignment {
*/
bool internal_type_checking_global_b;
+
+/*
+ What is this function for ?
+ */
LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (SCM),
- "Print ly-set-option usage")
+ "Print ly:set-option usage")
{
printf ( _("lilypond -e EXPR means:").to_str0 ());
puts ("");
puts ("");
printf (_ (" Multiple -e options may be given, they will be evaluated sequentially.").to_str0 ());
puts ("");
- printf (_(" The function ly-set-option allows for access to some internal variables.").to_str0 ());
+ printf (_(" The function ly:set-option allows for access to some internal variables.").to_str0 ());
puts ("\n");
printf (_ ("Usage: lilypond-bin -e \"(ly-set-option SYMBOL VAL)\"").to_str0 ());
puts ("\n");
- printf (_ ("Where SYMBOL VAL pair is any of:").to_str0 ());
- puts ("");
- printf ( " help ANY-SYMBOL\n"
- " internal-type-checking BOOLEAN\n"
- " midi-debug BOOLEAN\n"
- " parse-protect BOOLEAN\n"
- " testing-level INTEGER\n");
+ printf (_ ("Use help as SYMBOL to get online help.").to_str0 ());
exit (0);
return SCM_UNSPECIFIED;
don't timestamp the output
@item -t,--test
-Switch on any experimental features. Not for general public use. */
+Switch on any experimental features. Not for general public use.
+
+*/
+
+
LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val),
"Set a global option value. Supported options include\n"
"\n"
for (int i = 0; i < s.defs_.size (); i++)
defs_.push (s.defs_[i]->clone ());
- header_ = ly_make_anonymous_module ();
+ header_ = ly_make_anonymous_module (safe_global_b);
if (is_module (s.header_))
ly_import_module (header_, s.header_);
}
chordmodifiers = #default-chord-modifier-list
-whiteTriangleMarkup = #(make-override-markup
- '(font-encoding . TeX-math) (make-simple-markup "M"))
+whiteTriangleMarkup = \markup { \override #'(font-encoding . TeX-math) "M" }
-blackTriangleMarkup = #(make-override-markup
- '(font-encoding . TeX-math) (make-simple-markup "N"))
+blackTriangleMarkup = \markup { \override #'(font-encoding . TeX-math) "N" }
ignatzekExceptionMusic = \notes{
<c e gis>1-\markup { "+" }
% Toplevel initialisation file.
#(define-public point-and-click #f)
-#(define-public midi-debug #f)
+#(define-public midi-debug #f)
\version "2.2.0"
(srfi srfi-1) ; lists
(srfi srfi-13)) ; strings
-(define-public safe-module (make-safe-module))
(define-public (myd k v) (display k) (display ": ") (display v) (display ", "))
(define-public safe-mode? #f)
+
+
+
;; parser stuff.
(define-public (print-music-as-book parser music)
(let* ((score (ly:music-scorify music))
(define-public (ps-output-expression expr port)
(display (eval expr output-ps-module) port))
+
(define output-alist
`(
("tex" . ("TeX output. The default output form." ,tex-output-expression))
(caddr d)
(scm-error "Could not find dumper for format ~s" format))))
+
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; other files.
"translation-functions.scm"
"script.scm"
"midi.scm"
-
"beam.scm"
"clef.scm"
"slur.scm"
"define-grob-interfaces.scm"
"page-layout.scm"
"paper.scm"
+
+ ; last:
+ "safe-lily.scm"
))
(define-public (ly:optimal-page-breaks lines book-height text-height
first-diff last-diff)
-
+ "DOCME"
;; FIXME: may need some tweaking: square, cubic
(define (height-score available used)
(let* ((empty (- available used))