X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fprogram-option-scheme.cc;h=88d16e167f94e904b99e0a6f111776e9c05d70f4;hb=926115ff42def8bc1ce767029e4f03c8072994ba;hp=976d51062c2169eb872b307f363cd195edc2398b;hpb=bb8a0a5387af94dd2702877256334b160575a730;p=lilypond.git diff --git a/lily/program-option-scheme.cc b/lily/program-option-scheme.cc index 976d51062c..88d16e167f 100644 --- a/lily/program-option-scheme.cc +++ b/lily/program-option-scheme.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 2001--2011 Han-Wen Nienhuys + Copyright (C) 2001--2015 Han-Wen Nienhuys LilyPond is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,6 +29,8 @@ using namespace std; #include "parse-scm.hh" #include "string-convert.hh" #include "warn.hh" +#include "lily-imports.hh" +#include "protected-scm.hh" bool debug_skylines; bool debug_property_callbacks; @@ -37,11 +39,6 @@ bool debug_page_breaking_scoring; bool music_strings_to_paths; bool relative_includes; -/* - 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. @@ -49,87 +46,82 @@ bool profile_property_accesses = false; bool do_internal_type_checking_global; bool strict_infinity_checking = false; -static SCM option_hash; +static Protected_scm option_hash; void internal_set_option (SCM var, SCM val) { + string varstr = robust_symbol2string (var, ""); + bool valbool = to_boolean (val); + SCM val_scm_bool = scm_from_bool (valbool); 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 ("point-and-click")) + else if (varstr == "profile-property-accesses") { - point_and_click_global = to_boolean (val); - val = scm_from_bool (to_boolean (val)); + profile_property_accesses = valbool; + val = val_scm_bool; } - else if (var == ly_symbol2scm ("protected-scheme-parsing")) + else if (varstr == "protected-scheme-parsing") { - parse_protect_global = to_boolean (val); - val = scm_from_bool (to_boolean (val)); + parse_protect_global = valbool; + val = val_scm_bool; } - else if (var == ly_symbol2scm ("check-internal-types")) + else if (varstr == "check-internal-types") { - do_internal_type_checking_global = to_boolean (val); - val = scm_from_bool (to_boolean (val)); + do_internal_type_checking_global = valbool; + val = val_scm_bool; } - else if (var == ly_symbol2scm ("debug-gc-assert-parsed-dead")) + else if (varstr == "debug-gc-assert-parsed-dead") { - parsed_objects_should_be_dead = to_boolean (val); - val = scm_from_bool (parsed_objects_should_be_dead); + parsed_objects_should_be_dead = valbool; + val = val_scm_bool; } - else if (var == ly_symbol2scm ("safe")) + else if (varstr == "safe") { - be_safe_global = to_boolean (val); - val = scm_from_bool (be_safe_global); + be_safe_global = valbool; + val = val_scm_bool; } - else if (var == ly_symbol2scm ("old-relative")) + else if (varstr == "strict-infinity-checking") { - lily_1_8_relative = to_boolean (val); - /* Needs to be reset for each file that uses this option. */ - lily_1_8_compatibility_used = to_boolean (val); - val = scm_from_bool (to_boolean (val)); + strict_infinity_checking = valbool; + val = val_scm_bool; } - else if (var == ly_symbol2scm ("strict-infinity-checking")) + else if (varstr == "debug-skylines") { - strict_infinity_checking = to_boolean (val); - val = scm_from_bool (to_boolean (val)); + debug_skylines = valbool; + val = val_scm_bool; } - else if (var == ly_symbol2scm ("debug-skylines")) + else if (varstr == "debug-property-callbacks") { - debug_skylines = to_boolean (val); - val = scm_from_bool (to_boolean (val)); + debug_property_callbacks = valbool; + val = val_scm_bool; } - else if (var == ly_symbol2scm ("debug-property-callbacks")) + else if (varstr == "debug-page-breaking-scoring") { - debug_property_callbacks = to_boolean (val); - val = scm_from_bool (to_boolean (val)); + debug_page_breaking_scoring = valbool; + val = val_scm_bool; } - else if (var == ly_symbol2scm ("debug-page-breaking-scoring")) - { - debug_page_breaking_scoring = to_boolean (val); - val = scm_from_bool (to_boolean (val)); - } - else if (var == ly_symbol2scm ("datadir")) + else if (varstr == "datadir") { /* ignore input value. */ val = ly_string2scm (lilypond_datadir); } - else if (var == ly_symbol2scm ("relative-includes")) + else if (varstr == "relative-includes") + { + relative_includes = valbool; + val = val_scm_bool; + } + else if (varstr == "warning-as-error") { - relative_includes = to_boolean (val); - val = scm_from_bool (to_boolean (val)); + /* warning_as_error is defined in flower/warn.cc */ + warning_as_error = valbool; + val = val_scm_bool; } - else if (var == ly_symbol2scm ("warning-as-error")) - val = scm_from_bool (to_boolean (val)); - else if (var == ly_symbol2scm ("music-strings-to-paths")) + else if (varstr == "music-strings-to-paths") { - music_strings_to_paths = to_boolean (val); - val = scm_from_bool (to_boolean (val)); + music_strings_to_paths = valbool; + val = val_scm_bool; } scm_hashq_set_x (option_hash, var, val); @@ -146,7 +138,6 @@ static string get_help_string () { SCM alist = ly_hash2alist (option_hash); - SCM converter = ly_lily_module_constant ("scm->string"); vector opts; @@ -157,7 +148,7 @@ get_help_string () string opt_spec = String_convert::char_string (' ', INDENT) + ly_symbol2string (sym) + " (" - + ly_scm2string (scm_call_1 (converter, val)) + + ly_scm2string (Lily::scm_to_string (val)) + ")"; if (opt_spec.length () + SEPARATION > HELP_INDENT) @@ -185,11 +176,12 @@ get_help_string () return help; } -LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (), - "Print @code{ly:set-option} usage.") +LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 1, 0, (SCM port), + "Print @code{ly:set-option} usage. Optional @var{port} argument" + "for the destination defaults to current output port.") { - string help = get_help_string (); - puts (help.c_str ()); + SCM str = scm_from_locale_string (get_help_string ().c_str ()); + scm_write_line (str, port); return SCM_UNSPECIFIED; } @@ -199,8 +191,8 @@ LY_DEFINE (ly_add_option, "ly:add-option", 3, 0, 0, "Add a program option @var{sym}. @var{val} is the default" " value and @var{description} is a string description.") { - if (!option_hash) - option_hash = scm_permanent_object (scm_c_make_hash_table (11)); + if (!option_hash.is_bound ()) + option_hash = scm_c_make_hash_table (11); LY_ASSERT_TYPE (ly_is_symbol, sym, 1); LY_ASSERT_TYPE (scm_is_string, description, 3); @@ -217,10 +209,10 @@ LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val), { LY_ASSERT_TYPE (ly_is_symbol, var, 1); - if (val == SCM_UNDEFINED) + if (SCM_UNBNDP (val)) val = SCM_BOOL_T; - string varstr = ly_scm2string (scm_symbol_to_string (var)); + string varstr = robust_symbol2string (var, ""); if (varstr.substr (0, 3) == string ("no-")) { var = ly_symbol2scm (varstr.substr (3, varstr.length () - 3).c_str ()); @@ -228,7 +220,7 @@ LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val), } SCM handle = scm_hashq_get_handle (option_hash, var); - if (handle == SCM_BOOL_F) + if (scm_is_false (handle)) warning (_f ("no such internal option: %s", varstr.c_str ())); internal_set_option (var, val); @@ -247,10 +239,10 @@ LY_DEFINE (ly_command_line_code, "ly:command-line-code", 0, 0, 0, (), return ly_string2scm (init_scheme_code_global); } -LY_DEFINE (ly_command_line_verbose_p, "ly:command-line-verbose?", 0, 0, 0, (), - "Was @code{be_verbose_global} set?") +LY_DEFINE (ly_verbose_output_p, "ly:verbose-output?", 0, 0, 0, (), + "Was verbose output requested, i.e. loglevel at least @code{DEBUG}?") { - return scm_from_bool (be_verbose_global); + return scm_from_bool (is_loglevel (LOG_DEBUG)); } LY_DEFINE (ly_all_options, "ly:all-options",