1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 03:30:27 +02:00

* 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.
This commit is contained in:
Han-Wen Nienhuys 2007-01-19 19:35:36 +00:00
parent b0763985c4
commit 03347a975b
3 changed files with 22 additions and 3 deletions

View 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.

View 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;
}
}

View 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);