X-Git-Url: https://git.distorted.org.uk/~mdw/dvdrip/blobdiff_plain/4bd4876f5135f4dffd180d7e969dfd89151f4864..74f78bd74bf9db600cda6eabbf758e82a726b207:/lib.c diff --git a/lib.c b/lib.c index 521af8d..4f2950c 100644 --- a/lib.c +++ b/lib.c @@ -33,6 +33,40 @@ void bail_syserr(int err, const char *fmt, ...) exit(2); } +double parse_float(const char **p_inout, unsigned f, + double min, double max, const char *what) +{ + const char *p; + char *q; + double x; + int err; + + err = errno; errno = 0; + p = *p_inout; + x = strtod(p, &q); + if (errno || x < min || x > max || (!(f&PNF_JUNK) && *q)) + bail("bad %s `%s'", what, p); + *p_inout = q; errno = err; + return (x); +} + +long parse_int(const char **p_inout, unsigned f, + long min, long max, const char *what) +{ + const char *p; + char *q; + long x; + int err; + + err = errno; errno = 0; + p = *p_inout; + x = strtoul(p, &q, 0); + if (errno || x < min || x > max || (!(f&PNF_JUNK) && *q)) + bail("bad %s `%s'", what, p); + *p_inout = q; errno = err; + return (x); +} + void sit(double t) { struct timeval tv;