]> git.donarmstrong.com Git - lilypond.git/blob - lily/scm-option.cc
* python/lilylib.py (make_ps_images): bugfixes; GS can produce
[lilypond.git] / lily / scm-option.cc
1 /*
2   scm-option.cc -- implement option setting from Scheme
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2001--2005  Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include <cstdio>
10
11 #include "scm-option.hh"
12 #include "protected-scm.hh"
13 #include "parse-scm.hh"
14 #include "warn.hh"
15 #include "main.hh"
16
17 /*
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
21   space.
22
23
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.
27 */
28
29 /* Write midi as formatted ascii stream? */
30 bool midi_debug_global_b;
31
32 /* General purpose testing flag */
33 int testing_level_global;
34
35 /*
36   Backwards compatibility.
37 */
38 bool lily_1_8_relative = false;
39 bool lily_1_8_compatibility_used = false;
40
41 /*
42   crash if internally the wrong type is used for a grob property.
43 */
44 bool do_internal_type_checking_global;
45
46 Protected_scm command_line_settings = SCM_EOL;
47
48 /*
49   What is this function for ?
50 */
51 LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (SCM),
52            "Print ly:set-option usage")
53 {
54   printf (_ ("lilypond -e EXPR means:").to_str0 ());
55   puts ("");
56   printf (_ ("  Evalute the Scheme EXPR before parsing any .ly files.").to_str0 ());
57   puts ("");
58   printf (_ ("  Multiple -e options may be given, they will be evaluated sequentially.").to_str0 ());
59   puts ("");
60   printf (_ ("  The function ly:set-option allows for access to some internal variables.").to_str0 ());
61   puts ("\n");
62   printf (_ ("Usage: lilypond -e \"(ly:set-option SYMBOL VAL)\"").to_str0 ());
63   puts ("\n");
64   printf (_ ("Use help as SYMBOL to get online help.").to_str0 ());
65   puts ("\n");
66
67   exit (0);
68   return SCM_UNSPECIFIED;
69 }
70
71 /* Add these as well:
72
73 @item -T, --no-timestamps
74 don't timestamp the output
75
76 @item -t, --test
77 Switch on any experimental features.  Not for general public use.
78 */
79
80 LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val),
81            "Set a global option value.  Supported options include\n"
82            "\n"
83            "@table @code\n"
84            "@item help\n"
85            "List all options.\n"
86            "@item point-and-click\n"
87            "Switch point & click on or off.\n"
88            "@item midi-debug\n"
89            "If set to true, generate human readable MIDI\n"
90            "@item internal-type-checking\n"
91            "Set paranoia for property assignments\n"
92            "@item parse-protect\n"
93            "If protection is switched on, errors in inline scheme are caught in the parser. \n"
94            "If off, GUILE will halt on errors, and give a stack trace. Default is protected evaluation. \n"
95            "@item old-relative\n"
96            "Relative for simultaneous music functions similar to chord syntax\n"
97            "@item new-relative\n"
98            "Relative for simultaneous music functions similar to sequential music\n"
99            "@item command-line-settings\n"
100            "An alist of generic key/value pairs\n"
101            "@end table\n"
102            "\n"
103            "This function is useful to call from the command line: @code{lilypond -e\n"
104            "\"(ly:set-option 'midi-debug #t)\"}.\n")
105 {
106   if (val == SCM_UNDEFINED)
107     val = SCM_BOOL_T;
108
109   if (var == ly_symbol2scm ("help"))
110     /* lilypond -e "(ly:set-option 'help #t)" */
111     ly_option_usage (SCM_EOL);
112   else if (var == ly_symbol2scm ("midi-debug"))
113     midi_debug_global_b = to_boolean (val);
114   else if (var == ly_symbol2scm ("testing-level"))
115     testing_level_global = scm_to_int (val);
116   else if (var == ly_symbol2scm ("point-and-click"))
117     point_and_click_global = to_boolean (val);
118   else if (var == ly_symbol2scm ("parse-protect"))
119     parse_protect_global = to_boolean (val);
120   else if (var == ly_symbol2scm ("internal-type-checking"))
121     do_internal_type_checking_global = to_boolean (val);
122   else if (var == ly_symbol2scm ("old-relative"))
123     {
124       lily_1_8_relative = true;
125       /*  Needs to be reset for each file that uses this option.  */
126       lily_1_8_compatibility_used = false;
127     }
128   else if (var == ly_symbol2scm ("new-relative"))
129     lily_1_8_relative = false;
130   else if (var == ly_symbol2scm ("command-line-settings"))
131     {
132       SCM_ASSERT_TYPE(scm_list_p (val) == SCM_BOOL_T,
133                       val, SCM_ARG2, __FUNCTION__, "alist");
134       command_line_settings = scm_append (scm_list_2 (val, command_line_settings));
135     }
136   else
137     {
138       if (scm_is_symbol (var))
139         var = scm_symbol_to_string (var);
140
141       warning (_f ("no such internal option: %s", ly_scm2string (var)));
142     }
143   return SCM_UNSPECIFIED;
144 }
145
146 LY_DEFINE (ly_get_option, "ly:get-option", 1, 0, 0, (SCM var),
147            "Get a global option setting.  Supported options include\n"
148            "@table @code\n"
149            "@item old-relative-used\n"
150            "Report whether old-relative compatibility mode is necessary\n"
151            "@item point-and-click\n"
152            "Report whether point & click is switched on.\n"
153            "@item old-relative\n"
154            "Report whether old-relative compatibility mode is used\n"
155            "@item verbose\n"
156            "Report whether we are running in verbose mode\n"
157            "@item command-line-settings\n"
158            
159            "@end table\n"
160            "\n")
161 {
162   SCM o = SCM_UNSPECIFIED;
163
164   if (var == ly_symbol2scm ("safe")) // heavily used; put in front. 
165     o = ly_bool2scm (be_safe_global);
166   else if (var == ly_symbol2scm ("old-relative-used"))
167     o = ly_bool2scm (lily_1_8_compatibility_used);
168   else if (var == ly_symbol2scm ("old-relative"))
169     o = ly_bool2scm (lily_1_8_relative);
170   else if (var == ly_symbol2scm ("verbose"))
171     o = ly_bool2scm (be_verbose_global);
172   else if (var == ly_symbol2scm ("command-line-settings"))
173     {
174       o = command_line_settings;
175     }
176   else
177     {
178       if (scm_is_symbol (var))
179         var = scm_symbol_to_string (var);
180
181       String s = ly_scm2string (var);
182
183       warning (_f ("no such internal option: %s", s.to_str0 ()));
184     }
185   return o;
186 }