2004-02-26 Marcus Brinkmann <marcus@g10code.de>
authorMarcus Brinkmann <mb@g10code.com>
Thu, 26 Feb 2004 18:39:34 +0000 (18:39 +0000)
committerMarcus Brinkmann <mb@g10code.com>
Thu, 26 Feb 2004 18:39:34 +0000 (18:39 +0000)
* gpgconf-comp.c (change_options_program): Support all types of
options, including list types.

tools/ChangeLog
tools/README.gpgconf
tools/gpgconf-comp.c

index 154ec55..57c52f4 100644 (file)
@@ -1,9 +1,12 @@
 2004-02-26  Marcus Brinkmann  <marcus@g10code.de>
 
+       * 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.
index 0973939..03fd9da 100644 (file)
@@ -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?
+
+
index 524f217..3b9927f 100644 (file)
@@ -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;