]> git.donarmstrong.com Git - lilypond.git/blob - lily/scm-option.cc
7ac4df60a72a88bcf240a6a86faf4d25e4f7681c
[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
10 #include "scm-option.hh"
11
12 #include <cstdio>
13
14 #include "parse-scm.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 int preview_resolution_global = 90;
36
37
38 /* General purpose testing flag */
39 int testing_level_global;
40
41 /*
42   Backwards compatibility.
43  */
44 bool lily_1_8_relative = false;
45 bool lily_1_8_compatibility_used = false;
46
47 /*
48   crash if internally the wrong type is used for a grob property.
49  */
50 bool do_internal_type_checking_global;
51
52
53 /*
54   What is this function for ? 
55  */
56 LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (SCM),
57                   "Print ly:set-option usage")
58 {
59   printf ( _("lilypond -e EXPR means:").to_str0 ());
60   puts ("");
61   printf (_ ("  Evalute the Scheme EXPR before parsing any .ly files.").to_str0 ());
62   puts ("");
63   printf (_ ("  Multiple -e options may be given, they will be evaluated sequentially.").to_str0 ());
64   puts ("");
65   printf (_("  The function ly:set-option allows for access to some internal variables.").to_str0 ());
66   puts ("\n");
67   printf (_ ("Usage: lilypond -e \"(ly:set-option SYMBOL VAL)\"").to_str0 ());
68   puts ("\n");
69   printf (_ ("Use help as  SYMBOL to get online help.").to_str0 ());
70
71   exit (0);
72   return SCM_UNSPECIFIED;
73 }
74
75 /* Add these as well:
76
77 @item -T, --no-timestamps
78 don't timestamp the output
79
80 @item -t, --test
81 Switch on any experimental features.  Not for general public use.
82
83 */
84
85
86 LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val),
87             "Set a global option value.  Supported options include\n"
88 "\n"
89 "@table @code\n"
90 "@item help\n"
91 "List all options.\n"
92 "@item midi-debug\n"
93 "If set to true, generate human readable MIDI\n"
94 "@item internal-type-checking\n"
95 "Set paranoia for property assignments\n"
96 "@item parse-protect\n"
97 "If protection is switched on, errors in inline scheme are caught in the parser. \n"
98 "If off, GUILE will halt on errors, and give a stack trace. Default is protected evaluation. \n"
99 "@item old-relative\n"
100 "Relative for simultaneous music functions similar to chord syntax\n"
101 "@item new-relative\n"
102 "Relative for simultaneous music functions similar to sequential music\n"
103 "@end table\n"
104 "\n"
105 "This function is useful to call from the command line: @code{lilypond -e\n"
106 "\"(ly:set-option 'midi-debug #t)\"}.\n")
107 {
108   if (val == SCM_UNDEFINED)
109     val = SCM_BOOL_T;
110
111   if (var == ly_symbol2scm ("help"))
112     /* lilypond -e "(ly:set-option 'help #t)" */
113     ly_option_usage (SCM_EOL);
114   else if (var == ly_symbol2scm ("midi-debug"))
115     midi_debug_global_b = to_boolean (val);
116   else if (var == ly_symbol2scm ("testing-level"))
117     testing_level_global = scm_to_int (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 ("resolution"))
129     preview_resolution_global = robust_scm2int (val, 90);
130   else if (var == ly_symbol2scm ("new-relative"))
131     lily_1_8_relative = false;
132   else
133     {
134       if (scm_is_symbol (var))
135         var = scm_symbol_to_string (var);
136       
137       warning (_f ("No such internal option: %s", ly_scm2string (var)));
138     }
139   return SCM_UNSPECIFIED;
140 }
141
142 LY_DEFINE (ly_get_option, "ly:get-option", 1, 0, 0, (SCM var),
143             "Get a global option setting.  Supported options include\n"
144            "@table @code\n"
145            "@item old-relative-used\n"
146            "Report whether old-relative compatibility mode is necessary\n"
147            "@item old-relative\n"
148            "Report whether old-relative compatibility mode is used\n"
149            "@item verbose\n"
150            "Report whether we are running in verbose mode\n"
151            "@item resolution\n"
152            "Resolution for the PNG output."
153            "@end table\n"
154            "\n")
155 {
156   SCM o = SCM_UNSPECIFIED;
157   
158   if (var == ly_symbol2scm ("safe")) // heavily used; put in front. 
159     o = ly_bool2scm (be_safe_global);
160   else  if (var == ly_symbol2scm ("old-relative-used"))
161     o = ly_bool2scm (lily_1_8_compatibility_used);
162   else if (var == ly_symbol2scm ("old-relative"))
163     o = ly_bool2scm (lily_1_8_relative);
164   else if (var == ly_symbol2scm ("verbose"))
165     o = ly_bool2scm (be_verbose_global);
166   else if ( var == ly_symbol2scm ("resolution"))
167     o = scm_from_int (preview_resolution_global);
168   else
169     {
170       if (scm_is_symbol (var))
171         var = scm_symbol_to_string (var);
172
173       String s = ly_scm2string (var);
174       
175       warning (_f ("No such internal option: %s", s.to_str0() ));
176     }
177   return o;
178 }