From aa7a4c1aec98d5a730059ef956cd85867523a00d Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Thu, 26 Feb 2004 18:39:34 +0000 Subject: [PATCH] 2004-02-26 Marcus Brinkmann * gpgconf-comp.c (change_options_program): Support all types of options, including list types. --- tools/ChangeLog | 5 ++- tools/README.gpgconf | 8 +++++ tools/gpgconf-comp.c | 77 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 77 insertions(+), 13 deletions(-) diff --git a/tools/ChangeLog b/tools/ChangeLog index 154ec55e8..57c52f437 100644 --- a/tools/ChangeLog +++ b/tools/ChangeLog @@ -1,9 +1,12 @@ 2004-02-26 Marcus Brinkmann + * gpgconf-comp.c (change_options_program): Support all types of + options, including list types. + * README.gpgconf: Fix description of arguments. * gpgconf-comp.c (option_check_validity): Rewritten to properly support optional arguments in lists. - + * README.gpgconf: Add info about optional arg and arg type 0. * gpgconf-comp.c (gc_component_change_options): Parse list of arg type 0 options. diff --git a/tools/README.gpgconf b/tools/README.gpgconf index 0973939d0..03fd9daa7 100644 --- a/tools/README.gpgconf +++ b/tools/README.gpgconf @@ -412,3 +412,11 @@ TODO * Extend the backend interface to include gettext domain and description, if available, to avoid repeating this information in gpgconf. + +* Left out string arguments (optional) are written out exactly as +empty string arguments. Should we do quoting? + +* More string argument trouble: Special characters like newlines etc +cause trouble. Again, should we do quoting? + + diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c index 524f2170d..3b9927f61 100644 --- a/tools/gpgconf-comp.c +++ b/tools/gpgconf-comp.c @@ -1474,21 +1474,73 @@ change_options_program (gc_component_t component, gc_backend_t backend, option = gc_component[component].options; while (option->name) { - /* FIXME: Add support for lists and default arg (new_value eq ""). */ if (!(option->flags & GC_OPT_FLAG_GROUP) && option->backend == backend - && option->new_value - && *option->new_value) + && option->new_value) { - if (gc_arg_type[option->arg_type].fallback == GC_ARG_TYPE_STRING) - fprintf (src_file, "%s %s\n", option->name, - percent_deescape (&option->new_value[1])); - else if (option->arg_type == GC_ARG_TYPE_NONE) - fprintf (src_file, "%s\n", option->name); - else - fprintf (src_file, "%s %s\n", option->name, option->new_value); - if (ferror (src_file)) - goto change_one_err; + char *arg = option->new_value; + + do + { + if (*arg == '\0' || *arg == ',') + { + fprintf (src_file, "%s\n", option->name); + if (ferror (src_file)) + goto change_one_err; + } + else if (gc_arg_type[option->arg_type].fallback + == GC_ARG_TYPE_NONE) + { + assert (*arg == '1'); + fprintf (src_file, "%s\n", option->name); + if (ferror (src_file)) + goto change_one_err; + + arg++; + } + else if (gc_arg_type[option->arg_type].fallback + == GC_ARG_TYPE_STRING) + { + char *end; + + assert (*arg == '"'); + arg++; + + end = strchr (arg, ','); + if (end) + *end = '\0'; + + fprintf (src_file, "%s %s\n", option->name, + percent_deescape (arg)); + if (ferror (src_file)) + goto change_one_err; + + if (end) + *end = ','; + arg = end; + } + else + { + char *end; + + end = strchr (arg, ','); + if (end) + *end = '\0'; + + fprintf (src_file, "%s %s\n", option->name, arg); + if (ferror (src_file)) + goto change_one_err; + + if (end) + *end = ','; + arg = end; + } + + assert (arg == NULL || *arg == '\0' || *arg == ','); + if (arg && *arg == ',') + arg++; + } + while (arg && *arg); } option++; } @@ -1692,6 +1744,7 @@ gc_component_change_options (int component, FILE *in) option++; } + if (!err) { int i;