[FFmpeg-devel] [PATCH] Implement number parsing functions in cmdutils.c

Michael Niedermayer michaelni
Thu Feb 21 13:25:04 CET 2008


On Thu, Feb 21, 2008 at 09:34:51AM +0100, Stefano Sabatini wrote:
[...]
> +long long int parse_integer_or_die(const char *context, const char *numstr, long long int min, long long int max)
> +{
> +    long long int lli;
> +    char *tail;
> +
> +    /* errno could have been set by previous library calls, so reset it */
> +    errno = 0;
> +    lli = strtoll(numstr, &tail, 10);
> +    if (*tail) {
> +        fprintf(stderr, "Expected integer for %s but found: %s\n", context, numstr);
> +        exit(1);
> +    } else if (errno == ERANGE || lli < min || lli > max) {
> +        fprintf(stderr, "The value for %s must be >= %lld and <= %lld but you used: %s\n",
> +                context, min, max, numstr);
> +        exit(1);
> +    }
> +    return lli;
> +}
> +
> +double parse_double_or_die(const char *context, const char *numstr, double min, double max)
> +{
> +    double d;
> +    char *tail;
> +
> +    /* errno could have been set by previous library calls, so reset it */
> +    errno = 0;
> +    d = strtod(numstr, &tail);
> +    if (*tail) {
> +        fprintf(stderr, "Expected double for %s but found: %s\n", context, numstr);
> +        exit(1);
> +    } else if (errno == ERANGE || isnan(d) || d < min || d > max) {
> +        fprintf(stderr, "The value for %s must be >= %f and <= %f but you used: %s\n",
> +                context, min, max, numstr);
> +        exit(1);
> +    }
> +    return d;
> +}

commited something simpler

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080221/bc7e30a4/attachment.pgp>



More information about the ffmpeg-devel mailing list