{"thread":{"id":"17498","subject":"[PATCH 3/4] parse-options: add new function \"usage_msg_opt\"","startedAt":"2009-02-02T05:12:58Z","lastAt":"2009-02-02T05:12:58Z","messageCount":1,"participants":["Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"102821","messageId":"20090202061258.e044e2b7.chriscool@tuxfamily.org","threadId":"17498","inReplyTo":null,"subject":"[PATCH 3/4] parse-options: add new function \"usage_msg_opt\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-02-02T05:12:58Z","receivedAt":"2009-02-02T05:12:58Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This function can be used instead of \"usage_with_options\" when you\nwant to print an error message before the usage string.\n\nIt may be useful because:\n\nif (condition)\n\tusage_msg_opt(\"condition is false\", usage, opts);\n\nis shorter than:\n\nif (condition) {\n\tfprintf(stderr, \"condition is false\\n\\n\");\n\tusage_with_options(usage, opts);\n}\n\nand may be more consistent.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n parse-options.c |    8 ++++++++\n parse-options.h |    4 ++++\n 2 files changed, 12 insertions(+), 0 deletions(-)\n\n\tThis patch may be generaly useful.\n\ndiff --git a/parse-options.c b/parse-options.c\nindex 4c5d09d..7a5fde8 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -449,6 +449,14 @@ void usage_with_options(const char * const *usagestr,\n \texit(129);\n }\n \n+void usage_msg_opt(const char *msg,\n+\t\t   const char * const *usagestr,\n+\t\t   const struct option *options)\n+{\n+\tfprintf(stderr, \"%s\\n\\n\", msg);\n+\tusage_with_options(usagestr, options);\n+}\n+\n int parse_options_usage(const char * const *usagestr,\n \t\t\tconst struct option *opts)\n {\ndiff --git a/parse-options.h b/parse-options.h\nindex 9122905..6061a19 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -113,6 +113,10 @@ extern int parse_options(int argc, const char **argv,\n extern NORETURN void usage_with_options(const char * const *usagestr,\n                                         const struct option *options);\n \n+extern NORETURN void usage_msg_opt(const char *msg,\n+\t\t\t\t   const char * const *usagestr,\n+\t\t\t\t   const struct option *options);\n+\n /*----- incremantal advanced APIs -----*/\n \n enum {\n-- \n1.6.1.2.353.g99fdd.dirty\n"}]}