]> git.donarmstrong.com Git - lilypond.git/blob - lily/scm-option.cc
* lily/slur-quanting.cc (score_extra_encompass): Bigger penalty
[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--2004  Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8  */
9 #include <stdio.h>
10
11 #include "parse-scm.hh"
12 #include "string.hh"
13 #include "lily-guile.hh"
14 #include "scm-option.hh"
15 #include "warn.hh"
16 #include "main.hh"
17
18 /*
19   This interface to option setting is meant for setting options are
20   useful to a limited audience. The reason for this interface is that
21   making command line options clutters up the command-line option name
22   space.
23
24
25   preferably, also dont use TESTING_LEVEL_GLOBAL, since it defeats
26   another purpose of this very versatile interface, which is to
27   support multiple debug/testing options concurrently.
28
29  */
30
31
32 /* Write midi as formatted ascii stream? */
33 bool midi_debug_global_b;
34
35 /* General purpose testing flag */
36 int testing_level_global;
37
38 /*
39   Backwards compatibility.
40  */
41 bool lily_1_8_relative = false;
42 bool lily_1_8_compatibility_used = false;
43
44 /*
45   crash if internally the wrong type is used for a grob property.
46  */
47 bool internal_type_checking_global_b;
48
49
50 /*
51   What is this function for ? 
52  */
53 LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (SCM),
54                   "Print ly:set-option usage")
55 {
56   printf ( _("lilypond -e EXPR means:").to_str0 ());
57   puts ("");
58   printf (_ ("  Evalute the Scheme EXPR before parsing any .ly files.").to_str0 ());
59   puts ("");
60   printf (_ ("  Multiple -e options may be given, they will be evaluated sequentially.").to_str0 ());
61   puts ("");
62   printf (_("  The function ly:set-option allows for access to some internal variables.").to_str0 ());
63   puts ("\n");
64   printf (_ ("Usage: lilypond-bin -e \"(ly:set-option SYMBOL VAL)\"").to_str0 ());
65   puts ("\n");
66   printf (_ ("Use help as  SYMBOL to get online help.").to_str0 ());
67
68   exit (0);
69   return SCM_UNSPECIFIED;
70 }
71
72 /* Add these as well:
73
74 @item -T,--no-timestamps
75 don't timestamp the output
76
77 @item -t,--test
78 Switch on any experimental features.  Not for general public use.
79
80 */
81
82
83 LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val),
84             "Set a global option value.  Supported options include\n"
85 "\n"
86 "@table @code\n"
87 "@item help\n"
88 "List all options.\n"
89 "@item midi-debug\n"
90 "If set to true, generate human readable MIDI\n"
91 "@item internal-type-checking\n"
92 "Set paranoia for property assignments\n"
93 "@item parse-protect\n"
94 "If protection is switched on, errors in inline scheme are caught in the parser. \n"
95 "If off, GUILE will halt on errors, and give a stack trace. Default is protected evaluation. \n"
96 "@item old-relative\n"
97 "Relative for simultaneous music functions similar to chord syntax\n"
98 "@item new-relative\n"
99 "Relative for simultaneous music functions similar to sequential music\n"
100 "@end table\n"
101 "\n"
102 "This function is useful to call from the command line: @code{lilypond -e\n"
103 "\"(ly:set-option 'midi-debug #t)\"}.\n")
104 {
105   if (val == SCM_UNDEFINED)
106     val = SCM_BOOL_T;
107
108   if (var == ly_symbol2scm ("help"))
109     /* lilypond -e "(ly:set-option 'help #t)" */
110     ly_option_usage (SCM_EOL);
111   else if (var == ly_symbol2scm ("midi-debug"))
112     midi_debug_global_b = to_boolean (val);
113   else if (var == ly_symbol2scm ("testing-level"))
114     testing_level_global = ly_scm2int (val);
115   else if (var == ly_symbol2scm ("parse-protect" ))
116     parse_protect_global = to_boolean (val);
117   else if (var == ly_symbol2scm ("internal-type-checking"))
118     internal_type_checking_global_b = to_boolean (val);
119   else if (var == ly_symbol2scm ("old-relative"))
120     {
121       lily_1_8_relative = true;
122       /*  Needs to be reset for each file that uses this option.  */
123       lily_1_8_compatibility_used = false;
124     }
125   else if (var == ly_symbol2scm ("new-relative"))
126     lily_1_8_relative = false;
127   else
128     {
129       if (ly_c_symbol_p (var))
130         var = scm_symbol_to_string (var);
131       
132       warning (_f ("No such internal option: %s", ly_scm2string (var)));
133     }
134   return SCM_UNSPECIFIED;
135 }
136
137 LY_DEFINE (ly_get_option, "ly:get-option", 1, 0, 0, (SCM var),
138             "Get a global option setting.  Supported options include\n"
139            "@table @code\n"
140            "@item old-relative-used\n"
141            "Report whether old-relative compatibility mode is necessary\n"
142            "@item old-relative\n"
143            "Report whether old-relative compatibility mode is used\n"
144            "@item verbose\n"
145            "Report whether we are running in verbose mode\n"
146            "@end table\n"
147            "\n")
148 {
149   SCM o = SCM_UNSPECIFIED;
150   
151   if (var == ly_symbol2scm ("safe")) // heavily used; put in front. 
152     o = ly_bool2scm (safe_global_b);
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 (verbose_global_b);
159   else
160     warning (_f ("No such internal option: %s", ly_scm2string (var)));
161   return o;
162 }