From ad48f8038cf3aa6392912ba65fede7cf71250001 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Fri, 29 Jul 2011 07:52:29 +0300 Subject: options: commandline: print error type for parse failures If parsing an option fails, print a string corresponding to the parse function return value (M_OPT_MISSING_PARAM etc). The primary motivation is that the parsing code already outputs messages explaining most problems, but does not itself print anything in the missing parameter case. Before double-dash --options such errors were rare (or rather they resulted in the next commandline argument being silently misinterpreted as an argument to the previous option instead); but now an argument like "--ss" should give a better indication about the problem than just "Error parsing option". --- m_option.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'm_option.c') diff --git a/m_option.c b/m_option.c index 64a06d8971..34b7cd7a99 100644 --- a/m_option.c +++ b/m_option.c @@ -36,6 +36,24 @@ #include "stream/url.h" #include "libavutil/avstring.h" +char *m_option_strerror(int code) +{ + switch (code) { + case M_OPT_UNKNOWN: + return mp_gtext("Unrecognized option name"); + case M_OPT_MISSING_PARAM: + return mp_gtext("Required parameter for option missing"); + case M_OPT_INVALID: + return mp_gtext("Option parameter could not be parsed"); + case M_OPT_OUT_OF_RANGE: + return mp_gtext("Parameter is outside values allowed for option"); + case M_OPT_PARSER_ERR: + return mp_gtext("Parser error"); + default: + return NULL; + } +} + static const struct m_option *m_option_list_findb(const struct m_option *list, struct bstr name) { -- cgit v1.2.3