2 scm-option.cc -- implement option setting from Scheme
4 source file of the GNU LilyPond music typesetter
6 (c) 2001--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "scm-option.hh"
13 #include "parse-scm.hh"
18 This interface to option setting is meant for setting options are
19 useful to a limited audience. The reason for this interface is that
20 making command line options clutters up the command-line option name
24 preferably, also dont use TESTING_LEVEL_GLOBAL, since it defeats
25 another purpose of this very versatile interface, which is to
26 support multiple debug/testing options concurrently.
29 /* Write midi as formatted ascii stream? */
30 bool midi_debug_global_b;
32 int preview_resolution_global = 90;
34 /* General purpose testing flag */
35 int testing_level_global;
38 Backwards compatibility.
40 bool lily_1_8_relative = false;
41 bool lily_1_8_compatibility_used = false;
44 crash if internally the wrong type is used for a grob property.
46 bool do_internal_type_checking_global;
49 What is this function for ?
51 LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (SCM),
52 "Print ly:set-option usage")
54 printf (_ ("lilypond -e EXPR means:").to_str0 ());
56 printf (_ (" Evalute the Scheme EXPR before parsing any .ly files.").to_str0 ());
58 printf (_ (" Multiple -e options may be given, they will be evaluated sequentially.").to_str0 ());
60 printf (_ (" The function ly:set-option allows for access to some internal variables.").to_str0 ());
62 printf (_ ("Usage: lilypond -e \"(ly:set - option SYMBOL VAL)\"").to_str0 ());
64 printf (_ ("Use help as SYMBOL to get online help.").to_str0 ());
67 return SCM_UNSPECIFIED;
72 @item -T, --no-timestamps
73 don't timestamp the output
76 Switch on any experimental features. Not for general public use.
79 LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val),
80 "Set a global option value. Supported options include\n"
86 "If set to true, generate human readable MIDI\n"
87 "@item internal-type-checking\n"
88 "Set paranoia for property assignments\n"
89 "@item parse-protect\n"
90 "If protection is switched on, errors in inline scheme are caught in the parser. \n"
91 "If off, GUILE will halt on errors, and give a stack trace. Default is protected evaluation. \n"
92 "@item old-relative\n"
93 "Relative for simultaneous music functions similar to chord syntax\n"
94 "@item new-relative\n"
95 "Relative for simultaneous music functions similar to sequential music\n"
98 "This function is useful to call from the command line: @code{lilypond -e\n"
99 "\"(ly:set - option 'midi-debug #t)\"}.\n")
101 if (val == SCM_UNDEFINED)
104 if (var == ly_symbol2scm ("help"))
105 /* lilypond -e "(ly:set-option 'help #t)" */
106 ly_option_usage (SCM_EOL);
107 else if (var == ly_symbol2scm ("midi-debug"))
108 midi_debug_global_b = to_boolean (val);
109 else if (var == ly_symbol2scm ("testing-level"))
110 testing_level_global = scm_to_int (val);
111 else if (var == ly_symbol2scm ("parse-protect"))
112 parse_protect_global = to_boolean (val);
113 else if (var == ly_symbol2scm ("internal-type-checking"))
114 do_internal_type_checking_global = to_boolean (val);
115 else if (var == ly_symbol2scm ("old-relative"))
117 lily_1_8_relative = true;
118 /* Needs to be reset for each file that uses this option. */
119 lily_1_8_compatibility_used = false;
121 else if (var == ly_symbol2scm ("resolution"))
122 preview_resolution_global = robust_scm2int (val, 90);
123 else if (var == ly_symbol2scm ("new-relative"))
124 lily_1_8_relative = false;
127 if (scm_is_symbol (var))
128 var = scm_symbol_to_string (var);
130 warning (_f ("No such internal option: %s", ly_scm2string (var)));
132 return SCM_UNSPECIFIED;
135 LY_DEFINE (ly_get_option, "ly:get-option", 1, 0, 0, (SCM var),
136 "Get a global option setting. Supported options include\n"
138 "@item old-relative-used\n"
139 "Report whether old-relative compatibility mode is necessary\n"
140 "@item old-relative\n"
141 "Report whether old-relative compatibility mode is used\n"
143 "Report whether we are running in verbose mode\n"
145 "Resolution for the PNG output."
149 SCM o = SCM_UNSPECIFIED;
151 if (var == ly_symbol2scm ("safe")) // heavily used; put in front.
152 o = ly_bool2scm (be_safe_global);
153 else if (var == ly_symbol2scm ("old-relative-used"))
154 o = ly_bool2scm (lily_1_8_compatibility_used);
155 else if (var == ly_symbol2scm ("old-relative"))
156 o = ly_bool2scm (lily_1_8_relative);
157 else if (var == ly_symbol2scm ("verbose"))
158 o = ly_bool2scm (be_verbose_global);
159 else if (var == ly_symbol2scm ("resolution"))
160 o = scm_from_int (preview_resolution_global);
163 if (scm_is_symbol (var))
164 var = scm_symbol_to_string (var);
166 String s = ly_scm2string (var);
168 warning (_f ("No such internal option: %s", s.to_str0 ()));