help-gengetopt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[help-gengetopt] config parser patch for more graceful parsing


From: Papp Gyozo (VBuster)
Subject: [help-gengetopt] config parser patch for more graceful parsing
Date: Fri, 28 Sep 2007 18:31:46 +0200

Hi,

some time ago I'd sent this patch but somehow it was silently forgotten without 
any notice. As the comment states this patch allows more freedom in the config 
file syntax; values will be read to the end of line or the comment sign (#).

This way one neither has to enclose nor escape string like these:

name = James Mc'Gregor
key  = MC JMS

I hope this patch could be in the next package.

--- gengetopt-2.18.orig/src/skels/c_source.h_skel       Fri Jul 14 20:07:31 2006
+++ gengetopt-2.18/src/skels/c_source.h_skel    Tue Nov 21 19:36:40 2006
@@ -653,8 +653,11 @@
             }
         }
       else
-        { /* read up the remaining part up to a delimiter */
-          next_token = strcspn (farg, " \t\r\n#\'\"");
+        { /* 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;
           str_index += next_token;
         }

The stop condition is a clumsy replacement of isspace() due to ASCII character 
table:

0x09: '\t' (horizontal tab)
0x0a: '\n' (newline)
0x0b: '\v' (vertical tab) 0x0b, 
0x0c: '\f' (formfeed), 
0x0d: '\r' (carriage return) 




--
Papp, Gyozo
Virusbuster Kft




reply via email to

[Prev in Thread] Current Thread [Next in Thread]