diff options
author | Chad Versace <chad.versace@linux.intel.com> | 2013-09-16 17:44:49 -0700 |
---|---|---|
committer | Chad Versace <chad.versace@linux.intel.com> | 2013-09-16 18:12:13 -0700 |
commit | afef7f1b0a88aeb0e3c2008479bae21c8c7708dc (patch) | |
tree | abc8bef6337d8d5c8c3dd14b2e774972aa7cf4f2 /examples | |
parent | 73eed1160552a38a93987227ba91e6eff65d8eb6 (diff) |
gl_basic: Clean up usage errors
Add new function usage_error_printf() to simply emission of usage
errors.
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/gl_basic.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/examples/gl_basic.c b/examples/gl_basic.c index 79b1b64..a3a9793 100644 --- a/examples/gl_basic.c +++ b/examples/gl_basic.c @@ -92,14 +92,26 @@ gl_basic_error(const char *fmt, ...) exit(EXIT_FAILURE); } static void __attribute__((noreturn)) -error_usage(void) +usage_error_printf(const char *fmt, ...) { - fprintf(stderr, "usage error\n\n"); + fflush(stdout); + fprintf(stderr, "gl_basic: usage error"); + + if (fmt) { + va_list ap; + va_start(ap, fmt); + fprintf(stderr, ": "); + vfprintf(stderr, fmt, ap); + va_end(ap); + } + + fprintf(stderr, "\n"); + fprintf(stderr, "\n"); fprintf(stderr, "%s", usage_message); + exit(EXIT_FAILURE); } - static void error_waffle(void) { @@ -220,7 +232,7 @@ parse_args(int argc, char *argv[], struct options *opts) #endif if (argc < 3) - error_usage(); + usage_error_printf("not enough arguments"); // Set some context attrs to invalid values. opts->context_profile = -1; @@ -230,16 +242,14 @@ parse_args(int argc, char *argv[], struct options *opts) arg = argv[1]; ok = enum_map_translate_str(platform_map, arg, &opts->platform); if (!ok) { - fprintf(stderr, "error: '%s' is not a valid platform\n", arg); - error_usage(); + usage_error_printf("'%s' is not a valid platform", arg); } // Set context_api. arg = argv[2]; ok = enum_map_translate_str(context_api_map, arg, &opts->context_api); if (!ok) { - fprintf(stderr, "error: '%s' is not a valid API for a GL context\n", arg); - error_usage(); + usage_error_printf("'%s' is not a valid API for a GL context", arg); } // Set context_version. @@ -251,8 +261,7 @@ parse_args(int argc, char *argv[], struct options *opts) arg = argv[3]; match_count = sscanf(arg, "%d.%d", &major, &minor); if (match_count != 2) { - fprintf(stderr, "error: '%s' is not a valid GL version\n", arg); - error_usage(); + usage_error_printf("'%s' is not a valid GL version", arg); } opts->context_version = 10 * major + minor; } @@ -267,13 +276,12 @@ parse_args(int argc, char *argv[], struct options *opts) else if (strcmp(arg, "compat") == 0) opts->context_profile = WAFFLE_CONTEXT_COMPATIBILITY_PROFILE; else { - fprintf(stderr, "error: '%s' is not a valid GL profile\n", arg); - error_usage(); + usage_error_printf("'%s' is not a valid GL profile", arg); } } if (argc >= 6) - error_usage(); + usage_error_printf("too many arguments"); // Set dl. switch (opts->context_api) { |