]> git.donarmstrong.com Git - lilypond.git/blob - lily/scm-option.cc
Imported sources
[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 LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (SCM),
50                   "Print ly-set-option usage")
51 {  
52   printf ( _("lilypond -e EXPR means:").to_str0 ());
53   puts ("");
54   printf (_ ("  Evalute the Scheme EXPR before parsing any .ly files.").to_str0 ());
55   puts ("");
56   printf (_ ("  Multiple -e options may be given, they will be evaluated sequentially.").to_str0 ());
57   puts ("");
58   printf (_("  The function ly-set-option allows for access to some internal variables.").to_str0 ());
59   puts ("\n");
60   printf (_ ("Usage: lilypond -e \"(ly-set-option SYMBOL VAL)\"").to_str0 ());
61   puts ("\n");
62   printf (_ ("Where SYMBOL VAL pair is any of:").to_str0 ());
63   puts ("");
64   printf ( "  help ANY-SYMBOL\n"
65            "  internal-type-checking BOOLEAN\n"
66            "  midi-debug BOOLEAN\n"
67            "  parse-protect BOOLEAN\n"
68            "  testing-level INTEGER\n");
69   
70   exit (0);
71   return SCM_UNSPECIFIED;
72 }
73
74 /* Add these as well:
75
76 @item -T,--no-timestamps
77 don't timestamp the output
78
79 @item -t,--test
80 Switch on any experimental features.  Not for general public use. */
81 LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val),
82             "Set a global option value.  Supported options include\n"
83 "\n"
84 "@table @code\n"
85 "@item help\n"
86 "List all options.\n"
87 "@item midi-debug\n"
88 "If set to true, generate human readable MIDI\n"
89 "@item internal-type-checking\n"
90 "Set paranoia for property assignments\n"
91 "@item parse-protect\n"
92 "If protection is switched on, errors in inline scheme are caught in the parser. \n"
93 "If off, GUILE will halt on errors, and give a stack trace. Default is protected evaluation. \n"
94 "@item old-relative\n"
95 "Relative for simultaneous functions similar to chord syntax\n"
96 "@item new-relative\n"
97 "Relative for simultaneous functions similar to sequential music\n"
98 "@end table\n"
99 "\n"
100 "This function is useful to call from the command line: @code{lilypond -e\n"
101 "\"(ly-set-option 'midi-debug #t)\"}.\n")
102 {
103   if (val == SCM_UNDEFINED)
104     val = SCM_BOOL_T;
105
106   if (var == ly_symbol2scm ("help"))
107     {
108       /* lilypond -e "(ly-set-option 'help #t)" */
109       ly_option_usage (SCM_EOL);
110     }
111   else if (var == ly_symbol2scm ("midi-debug"))
112     {
113       midi_debug_global_b = to_boolean (val);
114     }
115   else if (var == ly_symbol2scm ("testing-level"))
116     {
117      testing_level_global = gh_scm2int (val); 
118     }
119   else if (var == ly_symbol2scm ("parse-protect" ))
120     {
121       parse_protect_global = to_boolean(val);
122     }
123   else if (var == ly_symbol2scm ("internal-type-checking"))
124     {
125      internal_type_checking_global_b = to_boolean (val); 
126     }
127   else if (var == ly_symbol2scm ("old-relative"))
128     {
129       lily_1_8_relative = true;
130       lily_1_8_compatibility_used = false; 
131     }
132   else if (var == ly_symbol2scm ("new-relative"))
133     {
134       lily_1_8_relative = false;
135     }
136   else if (var == ly_symbol2scm ("debug-beam"))
137     {
138       extern bool debug_beam_quanting_flag;
139       debug_beam_quanting_flag = true;
140     }
141   else
142     {
143       warning (_("Unknown internal option!"));
144     }
145
146   return SCM_UNSPECIFIED;
147 }
148
149
150 LY_DEFINE (ly_get_option, "ly:get-option", 1, 0, 0, (SCM var),
151             "Get a global option setting.  Supported options include\n"
152            "@table @code\n"
153            "@item old-relative-used\n"
154            "Report whether old-relative compatibility mode is necessary\n"
155            "@item old-relative\n"
156            "Report whether old-relative compatibility mode is used\n"
157            "@item verbose\n"
158            "Report whether we are running in verbose mode\n"
159            "@end table\n"
160            "\n")
161 {
162   if (var == ly_symbol2scm ("old-relative-used"))
163     {
164       return gh_bool2scm (lily_1_8_compatibility_used);
165     }
166   if (var == ly_symbol2scm ("old-relative"))
167     {
168       return gh_bool2scm (lily_1_8_relative);
169     }
170   if (var == ly_symbol2scm ("verbose"))
171     {
172       return gh_bool2scm (verbose_global_b);
173     }  
174   else
175     {
176       warning (_("Unknown internal option!"));
177     }
178
179   return SCM_UNSPECIFIED;
180 }