[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 00:48:02 CET 2003


On Thu, 27 Feb 2003, relson at users.sourceforge.net wrote:

>  int xatof(double *d, const char *in) {
>      char *end;
> +    double val;
> +
>      errno = 0;
> -    *d = strtod(in, &end);
> +    val = strtod(in, &end);
>      if (in == end || errno == EINVAL || errno == ERANGE) return 0;
> -    if (end < in + strlen(in)) return 0;
> -    return 1;
> +
> +    while (isspace(*end))

...isspace((unsigned char)*end)...

> +	end += 1;
> +
> +    if (*end == '#' || *end == '\0' || end == in + strlen(in)) 
> +    {
> +	*d = val;
> +	return 1;
> +    }
> +    else
> +	return 0;

I think this code belongs somewhere else. 1- code duplication. 2- it
will accept "all-blanks" when it expects a number, 3- xatof is not meant
to do string processing. It's a conversion function.

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

-- 
Matthias Andree




More information about the bogofilter-dev mailing list