X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=ggo.h;h=81565e7c24b50d130afd36560c4f5973973f1090;hp=e81b10c6a3846f2b3c73bd14de56264216a2ba89;hb=820ae21f7a453408dca3faa9ff1d28ca94d60009;hpb=f652ce6afe7f6fd0e42814505234cbf4321a736e diff --git a/ggo.h b/ggo.h index e81b10c6..81565e7c 100644 --- a/ggo.h +++ b/ggo.h @@ -7,14 +7,64 @@ /** \file ggo.h Functions and structures for help text handling. */ /** - * Used by executables that can not use gengetopt's generated help function. + * Information extracted from the .cmdline.h header files. */ struct ggo_help { - /** The lines of the short help text. */ + /** Program or module (receiver, filter, writer) name. */ + const char *prefix; + /** Generated by gengetopt from the options in the .ggo file. */ const char **short_help; - /** The lines of the detailed help text. */ + /** Like \a short_help, plus the \a details section. */ const char **detailed_help; + /** The purpose text as specified in the ggo file. */ + const char *purpose; + /** Generated by gengetopt and exported via the *.cmdline.h file. */ + const char *usage; + /** The description text given in the .ggo file. */ + const char *description; }; -void ggo_print_help(struct ggo_help *help, int detailed_help); -__printf_1_2 void printf_or_die(const char *fmt, ...); +/** + * Control the output of \ref ggo_print_help(). + * + * Any combination of these flags may be passed to ggo_print_help(). + * Note that the list of supported options is always printed. + */ +enum ggo_print_help_flags { + /** Whether to print the short help or the detailed help. */ + GPH_DETAILED = 1 << 0, + /** Print the program or module name and the purpose text. */ + GPH_PRINT_NAME_PURPOSE = 1 << 1, + /** Print the synopsis. */ + GPH_PRINT_USAGE = 1 << 2, + /** Print the description text. */ + GPH_PRINT_DESCRIPTION = 1 << 3, +}; + +/** Used to print the normal help of programs (--help) */ +#define GPH_STANDARD_FLAGS \ + (GPH_PRINT_NAME_PURPOSE | GPH_PRINT_USAGE) + +/** Additional information for --detailed-help. */ +#define GPH_STANDARD_FLAGS_DETAILED \ + (GPH_STANDARD_FLAGS | GPH_DETAILED | GPH_PRINT_DESCRIPTION) + +/** For module help embedded in a program help. */ +#define GPH_MODULE_FLAGS 0 + +/** Modules help with detailed descriptions. */ +#define GPH_MODULE_FLAGS_DETAILED GPH_DETAILED | GPH_PRINT_DESCRIPTION + +/** Make a ggo_help structure using information from the .cmdline.h file. */ +#define DEFINE_GGO_HELP(_prefix) \ + { \ + .prefix = #_prefix, \ + .short_help = _prefix ## _args_info_help, \ + .detailed_help = _prefix ## _args_info_detailed_help, \ + .purpose = _prefix ## _args_info_purpose, \ + .usage = _prefix ## _args_info_usage, \ + .description = _prefix ## _args_info_description, \ + } + +void ggo_print_help(struct ggo_help *help, unsigned flags); +__printf_1_2 int printf_or_die(const char *fmt, ...);