* options.c (scm_options_try): new function. This allows error
authorHan-Wen Nienhuys <hanwen@lilypond.org>
Fri, 19 Jan 2007 19:35:36 +0000 (19:35 +0000)
committerHan-Wen Nienhuys <hanwen@lilypond.org>
Fri, 19 Jan 2007 19:35:36 +0000 (19:35 +0000)
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.

libguile/ChangeLog
libguile/options.c
libguile/options.h

index c323294..58f662c 100644 (file)
@@ -1,5 +1,8 @@
 2007-01-19  Han-Wen Nienhuys  <hanwen@lilypond.org>
 
+       * options.c (scm_options_try): new function. This allows error
+       reporting before changing options in a critical section.
+
        * srcprop.c: use double cell for storing source-properties.  Put
        filename in the plist, and share between srcprops if possible.
        Remove specialized storage.
index 412192f..ae75e13 100644 (file)
@@ -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)
@@ -234,6 +242,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);
@@ -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;
     }
 }
index 7176124..5b96649 100644 (file)
@@ -40,6 +40,7 @@ typedef struct scm_t_option
 #define SCM_OPTION_SCM     2
 
 
+SCM_API SCM scm_options_try (SCM args, scm_t_option options[], const char *s, int dry_run);
 SCM_API SCM scm_options (SCM, scm_t_option [], const char*);
 SCM_API void scm_init_opts (SCM (*) (SCM), scm_t_option []);
 SCM_API void scm_init_options (void);