]> git.donarmstrong.com Git - lilypond.git/blob - lily/scm-option.cc
ddcfecb6f7c75afacdb491a1301dfefd05653844
[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--2002  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
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
30
31 /* Write midi as formatted ascii stream? */
32 bool midi_debug_global_b;
33
34 /* General purpose testing flag */
35 int testing_level_global;
36
37 /*
38   crash if internally the wrong type is used for a grob property.
39  */
40 bool internal_type_checking_global_b;
41
42 LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (SCM),
43                   "Print ly-set-option usage")
44 {  
45   printf ( _("lilypond -e EXPR means:").to_str0 ());
46   puts ("");
47   printf (_ ("  Evalute the Scheme EXPR before parsing any .ly files.").to_str0 ());
48   puts ("");
49   printf (_ ("  Multiple -e options may be given, they will be evaluated sequentially.").to_str0 ());
50   puts ("");
51   printf (_("  The function ly-set-option allows for access to some internal variables.").to_str0 ());
52   puts ("\n");
53   printf (_ ("Usage: lilypond -e \"(ly-set-option SYMBOL VAL)\"").to_str0 ());
54   puts ("\n");
55   printf (_ ("Where SYMBOL VAL pair is any of:").to_str0 ());
56   puts ("");
57   printf ( "  help ANY-SYMBOL\n"
58            "  internal-type-checking BOOLEAN\n"
59            "  midi-debug BOOLEAN\n"
60            "  parse-protect BOOLEAN\n"
61            "  testing-level INTEGER\n");
62   
63   exit (0);
64   return SCM_UNSPECIFIED;
65 }
66
67 /* Add these as well:
68
69 @item -T,--no-timestamps
70 don't timestamp the output
71
72 @item -t,--test
73 Switch on any experimental features.  Not for general public use. */
74 LY_DEFINE (ly_set_option, "ly:set-option", 2, 0, 0, (SCM var, SCM val),
75             "Set a global option value.  Supported options include\n"
76 "\n"
77 "@table @code\n"
78 "@item help\n"
79 "List all options.\n"
80 "@item midi-debug\n"
81 "If set to true, generate human readable MIDI\n"
82 "@item internal-type-checking\n"
83 "Set paranoia for property assignments\n"
84 "@item parse-protect\n"
85 "If protection is switched on, errors in inline scheme are caught in the parser. \n"
86 "If off, GUILE will halt on errors, and give a stack trace. Default is protected evaluation. \n"
87 "@end table\n"
88 "\n"
89 "This function is useful to call from the command line: @code{lilypond -e\n"
90 "\"(ly-set-option 'midi-debug #t)\"}.\n")
91 {
92   if (var == ly_symbol2scm ("help"))
93     {
94       /* lilypond -e "(ly-set-option 'help #t)" */
95       ly_option_usage (SCM_EOL);
96     }
97   else if (var == ly_symbol2scm ("midi-debug"))
98     {
99       midi_debug_global_b = to_boolean (val);
100     }
101   else if (var == ly_symbol2scm ("testing-level"))
102     {
103      testing_level_global = gh_scm2int (val); 
104     }
105   else if (var == ly_symbol2scm ("parse-protect" ))
106     {
107       parse_protect_global = to_boolean(val);
108     }
109   else if (var == ly_symbol2scm ("internal-type-checking"))
110     {
111      internal_type_checking_global_b = to_boolean (val); 
112     }
113   else if (var == ly_symbol2scm ("find-old-relative"))
114     {
115       /*
116         Seems to have been broken for some time!
117         
118         @item  -Q,--find-old-relative
119         show all changes needed to convert a file to  relative octave syntax.
120
121
122         
123       */
124       ;
125     }
126   else
127     {
128       warning (_("Unknown internal option!"));
129     }
130
131   return SCM_UNSPECIFIED;
132 }
133
134