Re: cmdline_file_save accepts file handler instead

"Papp Gyozo (VBuster)" <[email protected]> Tue, 16 Oct 2007 11:02:48 +0200
Newsgroups gmane.comp.gnu.gengetopt.general
Message-ID <[email protected]>
> > of course it is, and help is always very very very very welcome :-)
> > 
> > I still haven't updated the public CVS with the version (refactoring of 
> > generated code) I'm working on, would you like to act on that one?  I 
> > can update the CVS by tomorrow.
> 
> It's OK for me.

well in the meanwhile to go further on this topic I attached the first draft about the new _dump function (Actually this patch includes my other request on garceful config file parsing ;)

_______________________________________________
Help-gengetopt mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gengetopt
option_dump.diff (text/x-patch, 2.5 KB)
? option_dump.diff
Index: c_source.h_skel
===================================================================
RCS file: /sources/gengetopt/gengetopt/src/skels/c_source.h_skel,v
retrieving revision 1.6
diff -u -d -r1.6 c_source.h_skel
--- c_source.h_skel	3 Aug 2007 15:58:23 -0000	1.6
+++ c_source.h_skel	16 Oct 2007 08:56:02 -0000
@@ -184,6 +184,25 @@
   clear_given (args_info);
 }
 
+
+int
+@parser_name@_dump(FILE *outfile, struct @args_info@ *args_info)
+{
+  int i = 0;
+
+  if (!outfile)
+    {
+	  /* FIXME: error message (do we really need it?  */
+      fprintf (stderr, "%s: cannot dump options to stream\n", @package_var_name@);
+      return EXIT_FAILURE;
+    }
+
+  @file_save_loop:method@
+
+  i = EXIT_SUCCESS;
+  return i;
+}
+
 int
 @parser_name@_file_save(const char *filename, struct @args_info@ *args_info)
 {
@@ -198,10 +217,9 @@
       return EXIT_FAILURE;
     }
 
-  @file_save_loop:method@
+  i = @parser_name@_dump(outfile, @args_info@);
   fclose (outfile);
 
-  i = EXIT_SUCCESS;
   return i;
 }
 
@@ -702,9 +720,11 @@
             }
         }
       else
-        { /* read up the remaining part up to a delimiter */
-          next_token = strcspn (farg, " \t\r\n#\'\"");
-          str_index += next_token;
+        { /* read up the remaining part up to end of line or comment sign */
+          char *ch = (str_index + (next_token = strcspn (farg, "\r\n#")));
+          /* remove trailing whitespaces */
+          for ( --ch; (*ch >= '\t' && *ch <= '\r') || *ch == ' '; --ch )
+            --next_token;
         }
 
       /* truncate farg at the delimiter and store it for further check */
Index: header.h_skel
===================================================================
RCS file: /sources/gengetopt/gengetopt/src/skels/header.h_skel,v
retrieving revision 1.4
diff -u -d -r1.4 header.h_skel
--- header.h_skel	3 Aug 2007 15:58:25 -0000	1.4
+++ header.h_skel	16 Oct 2007 08:56:02 -0000
@@ -93,6 +93,15 @@
   struct @parser_name@_params *params);
 
 /**
+ * Save the contents of the option struct into an already open FILE stream.
+ * @@param outfile the stream where to dump options
+ * @@param args_info the option struct to dump
+ * @@return 0 if everything went fine, NON 0 if an error took place
+ */
+int @parser_name@_dump(FILE *outfile,
+  struct @args_info@ *args_info);
+  
+/**
  * Save the contents of the option struct into a (text) file.
  * This file can be read by the config file parser (if generated by gengetopt)
  * @@param filename the file where to save