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 "program-option.hh"
14 #include "string-convert.hh"
15 #include "protected-scm.hh"
16 #include "parse-scm.hh"
21 /* Write midi as formatted ascii stream? */
22 bool do_midi_debugging_global;
25 Backwards compatibility.
27 bool lily_1_8_relative = false;
28 bool lily_1_8_compatibility_used = false;
31 crash if internally the wrong type is used for a grob property.
33 bool do_internal_type_checking_global;
36 static Lilypond_option_init options[] = {
37 {"point-and-click", "#t",
40 "generate human readable MIDI",},
41 {"internal-type-checking", "#f",
42 "check every property assignment for types"},
43 {"parse-protect", "#t",
44 "continue when finding errors in inline\n"
45 "scheme are caught in the parser. If off, halt \n"
46 "on errors, and print a stack trace."},
47 {"old-relative", "#f",
48 "relative for simultaneous music works\n"
49 "similar to chord syntax"},
51 "resolution for generating bitmaps"},
52 {"preview-include-book-title", "#t",
53 "include book-titles in preview images."},
54 {"gs-font-load", "#f",
55 "load fonts via Ghostscript."},
56 {"delete-intermediate-files", "#f",
57 "delete unusable PostScript files"},
58 {"verbose", "#f", "value for the --verbose flag"},
59 {"ttf-verbosity", "0",
60 "how much verbosity for TTF font embedding?"},
62 "dump GC protection info"},
66 Protected_scm option_hash_;
68 void internal_set_option (SCM var, SCM val)
70 scm_hashq_set_x (option_hash_, var, val);
72 if (var == ly_symbol2scm ("midi-debug"))
74 do_midi_debugging_global = to_boolean (val);
75 val = scm_from_bool (to_boolean (val));
77 else if (var == ly_symbol2scm ("point-and-click"))
79 point_and_click_global = to_boolean (val);
80 val = scm_from_bool (to_boolean (val));
82 else if (var == ly_symbol2scm ("parse-protect"))
84 parse_protect_global = to_boolean (val);
85 val = scm_from_bool (to_boolean (val));
87 else if (var == ly_symbol2scm ("internal-type-checking"))
89 do_internal_type_checking_global = to_boolean (val);
90 val = scm_from_bool (to_boolean (val));
92 else if (var == ly_symbol2scm ("old-relative"))
94 lily_1_8_relative = to_boolean (val);
95 /* Needs to be reset for each file that uses this option. */
96 lily_1_8_compatibility_used = to_boolean (val);
97 val = scm_from_bool (to_boolean (val));
101 const int HELP_INDENT = 30;
102 const int INDENT = 2;
103 const int SEPARATION = 5;
108 String help ("Options supported by ly:set-option\n\n");
109 for (Lilypond_option_init *p = options; p->name_; p ++)
112 String_convert::char_string (' ', INDENT)
119 if (opt_spec.length () + SEPARATION > HELP_INDENT)
122 + String_convert::char_string (' ', HELP_INDENT);
125 opt_spec += String_convert::char_string (' ', HELP_INDENT - opt_spec.length ());
127 String opt_help = p->descr_;
128 opt_help.substitute (String ("\n"),
130 + String_convert::char_string (' ', HELP_INDENT));
132 help += opt_spec + opt_help + "\n";
135 help += String ("\n");
140 init_program_options ()
142 option_hash_ = scm_c_make_hash_table (11);
144 for (Lilypond_option_init *p = options; p->name_; p ++)
146 SCM sym = ly_symbol2scm (p->name_);
147 SCM val = scm_c_eval_string (p->init_);
149 internal_set_option (sym, val);
152 String help = get_help_string ();
156 internal_set_option (ly_symbol2scm ("help"),
157 scm_makfrom0str (help.to_str0 ()));
160 ADD_SCM_INIT_FUNC(scm_option, init_program_options);
164 This interface to option setting is meant for setting options are
165 useful to a limited audience. The reason for this interface is that
166 making command line options clutters up the command-line option name
171 Protected_scm command_line_settings = SCM_EOL;
173 LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (),
174 "Print ly:set-option usage")
176 SCM scm_stdout = scm_current_output_port();
177 scm_display (ly_get_option (ly_symbol2scm ("help")), scm_stdout);
179 return SCM_UNSPECIFIED;
182 LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val),
183 "Set a program option. Try setting 'help for a help string.")
185 SCM_ASSERT_TYPE (scm_is_symbol (var), var, SCM_ARG1,
186 __FUNCTION__, "symbol");
188 if (ly_symbol2scm ("help") == var)
193 if (val == SCM_UNDEFINED)
196 String varstr = ly_scm2string (scm_symbol_to_string (var));
197 if (varstr.left_string (3) == String ("no-"))
199 var = ly_symbol2scm (varstr.nomid_string (0, 3).to_str0 ());
200 val = scm_from_bool (!to_boolean (val));
203 SCM handle = scm_hashq_get_handle (option_hash_, var);
204 if (handle == SCM_BOOL_F)
206 warning (_f ("no such internal option: %s", varstr.to_str0 ()));
209 internal_set_option (var, val);
210 return SCM_UNSPECIFIED;
213 LY_DEFINE (ly_get_option, "ly:get-option", 1, 0, 0, (SCM var),
214 "Get a global option setting.")
216 SCM_ASSERT_TYPE (scm_is_symbol (var), var,
217 SCM_ARG1, __FUNCTION__, "symbol");
218 return scm_hashq_ref (option_hash_, var, SCM_BOOL_F);