summaryrefslogtreecommitdiff
path: root/include/mailutils
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-10-20 16:25:45 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2016-10-20 16:50:47 +0300
commit53eb68133eeede20c49445cd4ff58ad6e4becc07 (patch)
tree3750da378a9ce57404c0f8650c04d55f4ac9e58d /include/mailutils
parentfa7ac6058b528897684ec2eed9f396da159d856d (diff)
downloadmailutils-53eb68133eeede20c49445cd4ff58ad6e4becc07.tar.gz
mailutils-53eb68133eeede20c49445cd4ff58ad6e4becc07.tar.bz2
Support for single-dash long options (as in MH) and negation for boolean options.
* include/mailutils/opt.h (MU_PARSEOPT_SINGLE_DASH) (MU_PARSEOPT_NEGATION): New flags. (mu_parseopt) <po_negation, po_long_opt_start>: New fields. (mu_option_describe_options): Change signature. * libmailutils/opt/help.c (init_usage_vars): Initialize long_opt_col depending on the value of MU_PARSEOPT_SINGLE_DASH bit. (print_option): Handle single-dash long options and boolean options with negations. (option_summary): Likewise. (mu_option_describe_options): Take struct mu_parseopt * as its second parameter. * libmailutils/opt/opt.c (find_long_option): Handle boolean options with negations. Return also a pointer to the mu_option describing the originally used option (as opposed to the canonical one returned by the function). (parse): Handle single-dash long options. (parseopt_init): Initialize po_negation and po_long_opt_start. * libmailutils/tests/parseopt.c (parseopt_param): Handle MU_PARSEOPT_SINGLE_DASH and MU_PARSEOPT_NEGATION.
Diffstat (limited to 'include/mailutils')
-rw-r--r--include/mailutils/opt.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h
index fc4082497..972e3efb0 100644
--- a/include/mailutils/opt.h
+++ b/include/mailutils/opt.h
@@ -103,13 +103,17 @@ struct mu_option_cache
#define MU_PARSEOPT_DATA 0x00400000
#define MU_PARSEOPT_VERSION_HOOK 0x00800000
#define MU_PARSEOPT_PROG_DOC_HOOK 0x01000000
+/* Long options start with single dash. Disables recognition of traditional
+ short options */
+#define MU_PARSEOPT_SINGLE_DASH 0x02000000
+/* Negation prefix is set */
+#define MU_PARSEOPT_NEGATION 0x04000000
/* Reuse mu_parseopt struct initialized previously */
#define MU_PARSEOPT_REUSE 0x80000000
/* Mask for immutable flag bits */
#define MU_PARSEOPT_IMMUTABLE_MASK 0xFFFFF000
-
struct mu_parseopt
{
/* Input data: */
@@ -119,6 +123,7 @@ struct mu_parseopt
struct mu_option **po_optv; /* Array of ptrs to option structures */
int po_flags;
+ char *po_negation; /* Negation prefix for boolean options */
void *po_data; /* Call-specific data */
int po_exit_error; /* Exit on error with this code */
@@ -145,6 +150,9 @@ struct mu_parseopt
/* Auxiliary data */
char *po_cur; /* Points to the next character */
int po_chr; /* Single-char option */
+
+ char *po_long_opt_start; /* Character sequence that starts
+ long option */
/* The following two keep the position of the first non-optional argument
and the number of contiguous non-optional arguments after it.
@@ -161,6 +169,7 @@ struct mu_parseopt
unsigned po_permuted:1; /* Whether the arguments were permuted */
};
+
int mu_parseopt (struct mu_parseopt *p,
int argc, char **argv, struct mu_option **optv,
int flags);
@@ -171,8 +180,7 @@ void mu_parseopt_free (struct mu_parseopt *p);
unsigned mu_parseopt_getcolumn (const char *name);
-void mu_option_describe_options (mu_stream_t str,
- struct mu_option **optbuf, size_t optcnt);
+void mu_option_describe_options (mu_stream_t str, struct mu_parseopt *p);
void mu_program_help (struct mu_parseopt *p, mu_stream_t str);
void mu_program_usage (struct mu_parseopt *p, int optsummary, mu_stream_t str);
void mu_program_version (struct mu_parseopt *po, mu_stream_t str);
@@ -180,4 +188,6 @@ void mu_program_version (struct mu_parseopt *po, mu_stream_t str);
void mu_option_set_value (struct mu_parseopt *po, struct mu_option *opt,
char const *arg);
+int mu_option_possible_negation (struct mu_parseopt *po, struct mu_option *opt);
+
#endif

Return to:

Send suggestions and report system problems to the System administrator.