Giuseppe Bilotta <[email protected]> writes:

> I'm not a big fan of strtod because with it it's impossible to know if
> a conversion actually happened. xrandr --scale '  ' would actually be
> accepted (resulting in a scale value of 0), while the scanf catches
> it.

strtod takes an 'endptr' argument which can be used for precisely this
purpose, but I think your use of sscanf is easier to read as it does
both conversions in one call, and lets you pick the two different
versions easily (--scale 2 and --scale 2x1.5). One could imagine doing

        xscale = strtod(string, &endptr);
        if (*endptr) {
                if (endptr == string || *endptr != 'x')
                        syntax error;
                string = endptr + 1;
                yscale = strtod(string, &endptr);
                if (endptr == string || *endptr)
                        syntax error;
        } else {
                yscale = xscale;

That's a lot more code than two calls to sscanf...

> Of course there's also to be said that we could reject a scale factor
> of 0, regardless of whether it comes from a correct parsing of the
> string '0.0' or from the parse of an empty string (but of course then
> we couldn't customize the error message to differentiate between
> “incorrect parse” and “value out of range”).

Probably a good thing to catch.

-- 
-keith

Attachment: signature.asc
Description: PGP signature

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to