diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2008-02-21 12:24:37 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2008-02-21 12:24:37 +0000 |
commit | 086ab00158cb8e0d5f7b7bce00b5c5cbed3177ce (patch) | |
tree | 30fddbfd2e8df299adfbd8505551500d55ea8a77 /cmdutils.c | |
parent | 31304587da246672a240216d95298bb0ba9f9c64 (diff) | |
download | ffmpeg-086ab00158cb8e0d5f7b7bce00b5c5cbed3177ce.tar.gz |
parse_number_or_die()
Based on a patch by Stefano Sabatini.
Originally committed as revision 12167 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'cmdutils.c')
-rw-r--r-- | cmdutils.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/cmdutils.c b/cmdutils.c index abd10c50af..c01a6df247 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -32,6 +32,24 @@ #undef exit + +double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max) +{ + char *tail; + const char *error; + double d = strtod(numstr, &tail); + if (*tail) + error= "Expected number for %s but found: %s\n"; + else if (d < min || d > max) + error= "The value for %s was %s which is not within %f - %f\n"; + else if(type == OPT_INT64 && (int64_t)d != d) + error= "Expected int64 for %s but found %s\n"; + else + return d; + fprintf(stderr, error, context, numstr, min, max); + exit(1); +} + void show_help_options(const OptionDef *options, const char *msg, int mask, int value) { const OptionDef *po; |