[cvs] bogofilter/src xatof.c,1.1,1.2 xatoi.c,1.1,1.2 xatox.h,1.1,1.2

Matthias Andree matthias.andree at gmx.de
Fri Feb 28 01:25:55 CET 2003


On Fri, 28 Feb 2003, Matthias Andree wrote:

> Can we move killing comments and trailing whitespace to where it
> belongs, namely the configuration file reader? Do you mind if I change
> that?

More precisely, how about this patch -- the xato?.c patch just reverts
changes? (the entire set passes "make check"):

Index: configfile.c
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/src/configfile.c,v
retrieving revision 1.5
diff -u -r1.5 configfile.c
--- configfile.c	27 Feb 2003 03:37:37 -0000	1.5
+++ configfile.c	28 Feb 2003 00:24:37 -0000
@@ -64,7 +64,10 @@
 static bool process_config_parameter(const parm_desc *arg, const unsigned char *val)
 {
     bool ok = true;
+#if 0
+    /* strtok handles this */
     while (isspace(*val) || *val == '=') val += 1;
+#endif
     if (arg->addr.v == NULL)
 	return ok;
     switch (arg->type)
@@ -134,26 +137,20 @@
     return ok;
 }
 
-static bool process_config_line( const unsigned char *line, const parm_desc *parms )
+static bool process_config_line(const unsigned char *line,
+       const unsigned char *val,
+       const parm_desc *parms )
 {
-    size_t len;
-    const unsigned char *val;
     const parm_desc *arg;
 
     if (parms == NULL)
 	return false;
 
-    for (val=line; *val != '\0'; val += 1) {
-	if (isspace(*val) || *val == '=') {
-	    break;
-	}
-    }
-    len = val - line;
     for ( arg = parms; arg->name != NULL; arg += 1 )
     {
 	if (DEBUG_CONFIG(1))
 	    fprintf(dbgout, "Testing:  %s\n", arg->name);
-	if (strncmp(arg->name, (const char *)line, len) == 0)
+	if (strcasecmp(arg->name, (const char *)line) == 0)
 	{
 	    bool ok = process_config_parameter(arg, val);
 	    if (DEBUG_CONFIG(1) && ok )
@@ -170,6 +167,7 @@
     int lineno = 0;
     FILE *fp;
     char *filename;
+    char *arg = NULL, *val = NULL;
 
     if (tilde_expand) {
 	filename = tildeexpand(fname);
@@ -203,13 +201,21 @@
 	len = strlen((char *)buff);
 	if ( buff[0] == '#' || buff[0] == ';' || buff[0] == '\n' )
 	    continue;
-	while (iscntrl(buff[len-1]))
+	while (iscntrl(buff[len-1]) || isspace(buff[len-1]))
 	    buff[--len] = '\0';
 
-	if ( ! process_config_line( buff, usr_parms ) &&
-	     ! process_config_line( buff, sys_parms ) &&
-	     ! process_config_line( buff, format_parms ) &&
-	     fail_on_error)
+	arg = buff;
+	if (strcspn(arg, " \t=") < strlen(arg)) {
+	    val = arg + strcspn(arg, " \t=");
+	    *val++ = '\0';
+	    val += strspn(val, " \t=");
+	}
+
+	if (!arg || !val ||
+	       (! process_config_line(arg, val, usr_parms ) &&
+		! process_config_line(arg, val, sys_parms ) &&
+		! process_config_line(arg, val, format_parms ) &&
+		fail_on_error))
 	{
 	    error = true;
 	    if (!quiet)
Index: xatof.c
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/src/xatof.c,v
retrieving revision 1.3
diff -u -r1.3 xatof.c
--- xatof.c	27 Feb 2003 19:21:30 -0000	1.3
+++ xatof.c	28 Feb 2003 00:24:37 -0000
@@ -1,8 +1,5 @@
-/* $Id: xatof.c,v 1.3 2003/02/27 19:21:30 relson Exp $ */
-
 /** \file xatof.c
- * Implements xatof, an easy to use strtod() replacement with error
- * checking.
+ * Implements xatof, an easy to use strtod() wrapper.
  *
  * \author Matthias Andree
  * \date 2003
@@ -10,32 +7,17 @@
 
 #include "xatox.h"
 
-#include <ctype.h>
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
 
 int xatof(double *d, const char *in) {
     char *end;
-    double val;
-
     errno = 0;
-    val = strtod(in, &end);
+    *d = strtod(in, &end);
     if (in == end || errno == EINVAL || errno == ERANGE) return 0;
-
-    if (*end == 'f')		/* allow terminal 'f' */
-	end += 1;
-
-    while (isspace(*end))
-	end += 1;
-
-    if (*end == '#' || *end == '\0' || end == in + strlen(in)) 
-    {
-	*d = val;
-	return 1;
-    }
-    else
-	return 0;
+    if (end < in + strlen(in)) return 0;
+    return 1;
 }
 
 #if MAIN
Index: xatoi.c
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/src/xatoi.c,v
retrieving revision 1.2
diff -u -r1.2 xatoi.c
--- xatoi.c	27 Feb 2003 18:00:23 -0000	1.2
+++ xatoi.c	28 Feb 2003 00:24:37 -0000
@@ -1,5 +1,3 @@
-/* $Id: xatoi.c,v 1.2 2003/02/27 18:00:23 relson Exp $ */
-
 /** \file xatoi.c
  * Impl




More information about the bogofilter-dev mailing list