2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2001--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "program-option.hh"
27 #include "international.hh"
29 #include "parse-scm.hh"
30 #include "string-convert.hh"
34 bool debug_property_callbacks;
35 bool debug_page_breaking_scoring;
37 bool music_strings_to_paths;
38 bool relative_includes;
41 Backwards compatibility.
43 bool lily_1_8_relative = false;
44 bool lily_1_8_compatibility_used = false;
45 bool profile_property_accesses = false;
47 crash if internally the wrong type is used for a grob property.
49 bool do_internal_type_checking_global;
50 bool strict_infinity_checking = false;
52 static SCM option_hash;
55 internal_set_option (SCM var,
58 string varstr = robust_symbol2string (var, "");
59 bool valbool = to_boolean (val);
60 SCM val_scm_bool = scm_from_bool (valbool);
63 else if (varstr == "profile-property-accesses")
65 profile_property_accesses = valbool;
68 else if (varstr == "protected-scheme-parsing")
70 parse_protect_global = valbool;
73 else if (varstr == "check-internal-types")
75 do_internal_type_checking_global = valbool;
78 else if (varstr == "debug-gc-assert-parsed-dead")
80 parsed_objects_should_be_dead = valbool;
83 else if (varstr == "safe")
85 be_safe_global = valbool;
88 else if (varstr == "old-relative")
90 lily_1_8_relative = valbool;
91 /* Needs to be reset for each file that uses this option. */
92 lily_1_8_compatibility_used = valbool;
95 else if (varstr == "strict-infinity-checking")
97 strict_infinity_checking = valbool;
100 else if (varstr == "debug-skylines")
102 debug_skylines = valbool;
105 else if (varstr == "debug-property-callbacks")
107 debug_property_callbacks = valbool;
110 else if (varstr == "debug-page-breaking-scoring")
112 debug_page_breaking_scoring = valbool;
115 else if (varstr == "datadir")
117 /* ignore input value. */
118 val = ly_string2scm (lilypond_datadir);
120 else if (varstr == "relative-includes")
122 relative_includes = valbool;
125 else if (varstr == "warning-as-error")
127 else if (varstr == "music-strings-to-paths")
129 music_strings_to_paths = valbool;
133 scm_hashq_set_x (option_hash, var, val);
136 ssize const HELP_INDENT = 30;
137 ssize const INDENT = 2;
138 ssize const SEPARATION = 5;
141 Hmmm. should do in SCM / C++ ?
146 SCM alist = ly_hash2alist (option_hash);
147 SCM converter = ly_lily_module_constant ("scm->string");
151 for (SCM s = alist; scm_is_pair (s); s = scm_cdr (s))
153 SCM sym = scm_caar (s);
154 SCM val = scm_cdar (s);
155 string opt_spec = String_convert::char_string (' ', INDENT)
156 + ly_symbol2string (sym)
158 + ly_scm2string (scm_call_1 (converter, val))
161 if (opt_spec.length () + SEPARATION > HELP_INDENT)
162 opt_spec += "\n" + String_convert::char_string (' ', HELP_INDENT);
164 opt_spec += String_convert::char_string (' ', HELP_INDENT
165 - opt_spec.length ());
168 = scm_object_property (sym,
169 ly_symbol2scm ("program-option-documentation"));
170 string opt_help = ly_scm2string (opt_help_scm);
171 replace_all (&opt_help,
174 + String_convert::char_string (' ', HELP_INDENT));
176 opts.push_back (opt_spec + opt_help + "\n");
179 string help ("Options supported by `ly:set-option':\n\n");
180 vector_sort (opts, less<string> ());
181 for (vsize i = 0; i < opts.size (); i++)
186 LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (),
187 "Print @code{ly:set-option} usage.")
189 string help = get_help_string ();
190 puts (help.c_str ());
193 return SCM_UNSPECIFIED;
196 LY_DEFINE (ly_add_option, "ly:add-option", 3, 0, 0,
197 (SCM sym, SCM val, SCM description),
198 "Add a program option @var{sym}. @var{val} is the default"
199 " value and @var{description} is a string description.")
202 option_hash = scm_permanent_object (scm_c_make_hash_table (11));
203 LY_ASSERT_TYPE (ly_is_symbol, sym, 1);
204 LY_ASSERT_TYPE (scm_is_string, description, 3);
206 internal_set_option (sym, val);
208 scm_set_object_property_x (sym, ly_symbol2scm ("program-option-documentation"),
211 return SCM_UNSPECIFIED;
214 LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val),
215 "Set a program option.")
217 LY_ASSERT_TYPE (ly_is_symbol, var, 1);
219 if (val == SCM_UNDEFINED)
222 string varstr = robust_symbol2string (var, "");
223 if (varstr.substr (0, 3) == string ("no-"))
225 var = ly_symbol2scm (varstr.substr (3, varstr.length () - 3).c_str ());
226 val = scm_from_bool (!to_boolean (val));
229 SCM handle = scm_hashq_get_handle (option_hash, var);
230 if (handle == SCM_BOOL_F)
231 warning (_f ("no such internal option: %s", varstr.c_str ()));
233 internal_set_option (var, val);
234 return SCM_UNSPECIFIED;
237 LY_DEFINE (ly_command_line_options, "ly:command-line-options", 0, 0, 0, (),
238 "The Scheme options specified on command-line with @option{-d}.")
240 return ly_string2scm (init_scheme_variables_global);
243 LY_DEFINE (ly_command_line_code, "ly:command-line-code", 0, 0, 0, (),
244 "The Scheme code specified on command-line with @option{-e}.")
246 return ly_string2scm (init_scheme_code_global);
249 LY_DEFINE (ly_verbose_output_p, "ly:verbose-output?", 0, 0, 0, (),
250 "Was verbose output requested, i.e. loglevel at least @code{DEBUG}?")
252 return scm_from_bool (is_loglevel (LOG_DEBUG));
255 LY_DEFINE (ly_all_options, "ly:all-options",
257 "Get all option settings in an alist.")
259 return ly_hash2alist (option_hash);
262 LY_DEFINE (ly_get_option, "ly:get-option", 1, 0, 0, (SCM var),
263 "Get a global option setting.")
265 LY_ASSERT_TYPE (ly_is_symbol, var, 1);
266 return scm_hashq_ref (option_hash, var, SCM_BOOL_F);