summaryrefslogtreecommitdiff
path: root/libguile/options.c
diff options
context:
space:
mode:
authorHan-Wen Nienhuys <hanwen@lilypond.org>2007-01-19 19:35:36 +0000
committerHan-Wen Nienhuys <hanwen@lilypond.org>2007-01-19 19:35:36 +0000
commit03347a975b726f4b645339660156f62aba1f27ec (patch)
tree540449204d6516103eae2037f7b7f7c8e3847694 /libguile/options.c
parentb0763985c406ea86dde87854cfaabc175c293eb1 (diff)
downloadguile-03347a975b726f4b645339660156f62aba1f27ec.tar.gz
* options.c (scm_options_try): new function. This allows error
reporting before changing options in a critical section. * options.c: remove n (for length) from scm_option_X functions. Detect option list length by looking for NULL name.
Diffstat (limited to 'libguile/options.c')
-rw-r--r--libguile/options.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/libguile/options.c b/libguile/options.c
index 412192fb9..ae75e1318 100644
--- a/libguile/options.c
+++ b/libguile/options.c
@@ -164,9 +164,14 @@ options_length (scm_t_option options[])
* formed option setting, i. e. if for every non-boolean option a value is
* given. For this reason, the function applies all changes to a copy of the
* original setting in memory. Only if 'args' was successfully processed,
- * the new setting will overwrite the old one. */
+ * the new setting will overwrite the old one.
+ *
+ * If DRY_RUN is set, don't change anything. This is useful for trying out an option
+ * before entering a critical section.
+ */
static void
-change_option_setting (SCM args, scm_t_option options[], const char *s)
+change_option_setting (SCM args, scm_t_option options[], const char *s,
+ int dry_run)
{
unsigned int i;
SCM locally_protected_args = args;
@@ -214,6 +219,9 @@ change_option_setting (SCM args, scm_t_option options[], const char *s)
args = SCM_CDR (args);
}
+ if (dry_run)
+ return;
+
for (i = 0; options[i].name; ++i)
{
if (options[i].type == SCM_OPTION_SCM)
@@ -235,6 +243,13 @@ change_option_setting (SCM args, scm_t_option options[], const char *s)
SCM
scm_options (SCM args, scm_t_option options[], const char *s)
{
+ return scm_options_try (args, options, s, 0);
+}
+
+SCM
+scm_options_try (SCM args, scm_t_option options[], const char *s,
+ int dry_run)
+{
if (SCM_UNBNDP (args))
return get_option_setting (options);
else if (!SCM_NULL_OR_NIL_P (args) && !scm_is_pair (args))
@@ -247,7 +262,7 @@ scm_options (SCM args, scm_t_option options[], const char *s)
SCM old_setting;
SCM_ASSERT (scm_is_true (scm_list_p (args)), args, 1, s);
old_setting = get_option_setting (options);
- change_option_setting (args, options, s);
+ change_option_setting (args, options, s, dry_run);
return old_setting;
}
}