X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fprogram-option.cc;h=9ec4901c857bbadcfd8d7673d8ed944232dd0ada;hb=f9d4fe7ed96d0695bfef20278c9592bc4d7ceadb;hp=2887a022786cffa481879ab42f4cf78af3a2ac6f;hpb=e46cbbbced813e7db293d5303da0d8162f6fa67a;p=lilypond.git diff --git a/lily/program-option.cc b/lily/program-option.cc index 2887a02278..9ec4901c85 100644 --- a/lily/program-option.cc +++ b/lily/program-option.cc @@ -3,70 +3,52 @@ source file of the GNU LilyPond music typesetter - (c) 2001--2005 Han-Wen Nienhuys + (c) 2001--2006 Han-Wen Nienhuys */ #include "program-option.hh" #include -#include +#include +using namespace std; -#include "string-convert.hh" -#include "protected-scm.hh" +#include "international.hh" +#include "main.hh" #include "parse-scm.hh" +#include "string-convert.hh" #include "warn.hh" -#include "main.hh" - /* Write midi as formatted ascii stream? */ bool do_midi_debugging_global; +bool use_object_keys; /* Backwards compatibility. */ bool lily_1_8_relative = false; bool lily_1_8_compatibility_used = false; - +bool profile_property_accesses = false; /* crash if internally the wrong type is used for a grob property. */ bool do_internal_type_checking_global; +bool strict_infinity_checking = false; -static Lilypond_option_init options[] = { - {"point-and-click", "#t", - "use point & click"}, - {"midi-debug", "#f", - "generate human readable MIDI",}, - {"internal-type-checking", "#f", - "check every property assignment for types"}, - {"parse-protect", "#t", - "continue when finding errors in inline\n" - "scheme are caught in the parser. If off, halt \n" - "on errors, and print a stack trace."}, - {"old-relative", "#f", - "relative for simultaneous music works\n" - "similar to chord syntax"}, - {"resolution", "90", - "resolution for generating bitmaps"}, - {"preview-include-book-title", "#t", - "include book-titles in preview images."}, - {"gs-font-load", "#f", - "load fonts via Ghostscript."}, - {"delete-intermediate-files", "#f", - "delete unusable PostScript files"}, - {"ttf-verbosity", "0", - "how much verbosity for TTF font embedding?"}, - {0,0,0}, -}; - -Protected_scm option_hash_; +static SCM option_hash; void internal_set_option (SCM var, SCM val) { - scm_hashq_set_x (option_hash_, var, val); - - if (var == ly_symbol2scm ("midi-debug")) + scm_hashq_set_x (option_hash, var, val); + + if (0) + ; + else if (var == ly_symbol2scm ("profile-property-accesses")) + { + profile_property_accesses = to_boolean (val); + val = scm_from_bool (to_boolean (val)); + } + else if (var == ly_symbol2scm ("debug-midi")) { do_midi_debugging_global = to_boolean (val); val = scm_from_bool (to_boolean (val)); @@ -76,12 +58,12 @@ void internal_set_option (SCM var, SCM val) point_and_click_global = to_boolean (val); val = scm_from_bool (to_boolean (val)); } - else if (var == ly_symbol2scm ("parse-protect")) + else if (var == ly_symbol2scm ("protected-scheme-parsing")) { parse_protect_global = to_boolean (val); val = scm_from_bool (to_boolean (val)); } - else if (var == ly_symbol2scm ("internal-type-checking")) + else if (var == ly_symbol2scm ("check-internal-types")) { do_internal_type_checking_global = to_boolean (val); val = scm_from_bool (to_boolean (val)); @@ -93,25 +75,43 @@ void internal_set_option (SCM var, SCM val) lily_1_8_compatibility_used = to_boolean (val); val = scm_from_bool (to_boolean (val)); } + else if (var == ly_symbol2scm ("object-keys")) + { + use_object_keys = to_boolean (val); + val = scm_from_bool (to_boolean (val)); + } + else if (var == ly_symbol2scm ("strict-infinity-checking")) + { + strict_infinity_checking = to_boolean (val); + val = scm_from_bool (to_boolean (val)); + } } -const int HELP_INDENT = 30; -const int INDENT = 2; -const int SEPARATION = 5; +ssize const HELP_INDENT = 30; +ssize const INDENT = 2; +ssize const SEPARATION = 5; -static String +/* + Hmmm. should do in SCM / C++ ? +*/ +static string get_help_string () { - String help ("Options supported by ly:set-option\n\n"); - for (Lilypond_option_init *p = options; p->name_; p ++) + SCM alist = ly_hash2alist (option_hash); + SCM convertor = ly_lily_module_constant ("scm->string"); + + vector opts; + + for (SCM s = alist; scm_is_pair (s); s = scm_cdr (s)) { - String opt_spec = - String_convert::char_string (' ', INDENT) - + String (p->name_) + SCM sym = scm_caar (s); + SCM val = scm_cdar (s); + string opt_spec + = String_convert::char_string (' ', INDENT) + + ly_symbol2string (sym) + " (" - + String (p->init_) + + ly_scm2string (scm_call_1 (convertor, val)) + ")"; - if (opt_spec.length () + SEPARATION > HELP_INDENT) { @@ -120,59 +120,54 @@ get_help_string () } else opt_spec += String_convert::char_string (' ', HELP_INDENT - opt_spec.length ()); - - String opt_help = p->descr_; - opt_help.substitute (String ("\n"), - String ("\n") - + String_convert::char_string (' ', HELP_INDENT)); - - help += opt_spec + opt_help + "\n"; - } - - help += String ("\n"); - return help; -} - -static void -init_program_options () -{ - option_hash_ = scm_c_make_hash_table (11); - for (Lilypond_option_init *p = options; p->name_; p ++) - { - SCM sym = ly_symbol2scm (p->name_); - SCM val = scm_c_eval_string (p->init_); + SCM opt_help_scm + = scm_object_property (sym, ly_symbol2scm ("program-option-documentation")); + string opt_help = ly_scm2string (opt_help_scm); + replace_all (opt_help, + string ("\n"), + string ("\n") + + String_convert::char_string (' ', HELP_INDENT)); - internal_set_option (sym, val); + opts.push_back (opt_spec + opt_help + "\n"); } - String help = get_help_string (); - + string help ("Options supported by ly:set-option\n\n"); + vector_sort (opts, less ()); + for (vsize i = 0; i < opts.size (); i++) + help += opts[i]; - - internal_set_option (ly_symbol2scm ("help"), - scm_makfrom0str (help.to_str0 ())); + help += string ("\n"); + return help; } -ADD_SCM_INIT_FUNC(scm_option, init_program_options); +LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (), + "Print ly:set-option usage") +{ + string help = get_help_string (); + fputs (help.c_str (), stdout); + exit (0); + return SCM_UNSPECIFIED; +} -/* - This interface to option setting is meant for setting options are - useful to a limited audience. The reason for this interface is that - making command line options clutters up the command-line option name - space. +LY_DEFINE (ly_add_option, "ly:add-option", 3, 0, 0, + (SCM sym, SCM val, SCM description), + "Add a program option @var{sym} with default @var{val}.") +{ + if (!option_hash) + { + option_hash = scm_permanent_object (scm_c_make_hash_table (11)); + } + SCM_ASSERT_TYPE (scm_is_symbol (sym), sym, SCM_ARG1, __FUNCTION__, "symbol"); + SCM_ASSERT_TYPE (scm_is_string (description), description, + SCM_ARG3, __FUNCTION__, "string"); -*/ + internal_set_option (sym, val); -Protected_scm command_line_settings = SCM_EOL; + scm_set_object_property_x (sym, ly_symbol2scm ("program-option-documentation"), + description); -LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (), - "Print ly:set-option usage") -{ - SCM stdout = scm_current_output_port(); - scm_display (ly_get_option (ly_symbol2scm ("help")), stdout); - exit (0); return SCM_UNSPECIFIED; } @@ -180,37 +175,39 @@ LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val), "Set a program option. Try setting 'help for a help string.") { SCM_ASSERT_TYPE (scm_is_symbol (var), var, SCM_ARG1, - __FUNCTION__, "symbol"); + __FUNCTION__, "symbol"); if (ly_symbol2scm ("help") == var) - { - ly_option_usage (); - } + ly_option_usage (); if (val == SCM_UNDEFINED) val = SCM_BOOL_T; - String varstr = ly_scm2string (scm_symbol_to_string (var)); - if (varstr.left_string (3) == String ("no-")) + string varstr = ly_scm2string (scm_symbol_to_string (var)); + if (varstr.substr (0, 3) == string ("no-")) { - var = ly_symbol2scm (varstr.nomid_string (0, 3).to_str0 ()); + var = ly_symbol2scm (varstr.substr (3, varstr.length () -3).c_str ()); val = scm_from_bool (!to_boolean (val)); } - - SCM handle = scm_hashq_get_handle (option_hash_, var); + + SCM handle = scm_hashq_get_handle (option_hash, var); if (handle == SCM_BOOL_F) - { - warning (_f ("no such internal option: %s", varstr.to_str0 ())); - } + warning (_f ("no such internal option: %s", varstr.c_str ())); internal_set_option (var, val); return SCM_UNSPECIFIED; } +LY_DEFINE (ly_command_line_verbose_p, "ly:command-line-verbose?", 0, 0, 0, (), + "Was be_verbose_global set?") +{ + return scm_from_bool (be_verbose_global); +} + LY_DEFINE (ly_get_option, "ly:get-option", 1, 0, 0, (SCM var), "Get a global option setting.") { SCM_ASSERT_TYPE (scm_is_symbol (var), var, - SCM_ARG1, __FUNCTION__, "symbol"); - return scm_hashq_ref (option_hash_, var, SCM_BOOL_F); -} + SCM_ARG1, __FUNCTION__, "symbol"); + return scm_hashq_ref (option_hash, var, SCM_BOOL_F); +}