Commit 21918238 219182387a823ae8113a5a14cf29f9263d00171c by Sergey Poznyakoff

Fix help output. Test it.

* include/mailutils/opt.h (MU_PARSEOPT_EXTRA_INFO)
(MU_PARSEOPT_EXIT_ERROR): New flags.
(struct mu_parseopt) <po_extra_info>: New member.
<po_exit_error>: New member.
* libmailutils/opt/help.c: Fix help output formatting.
Implement support for ARGP_HELP_FMT envvar.
* libmailutils/opt/opt.c (add_option_cache): Honor
MU_PARSEOPT_IMMEDIATE.
(parseopt_init): Initialize each member separately.

* libmailutils/tests/parseopt.c: Rewrite envvar handling.
* libmailutils/tests/Makefile.am: Add new tests.
* libmailutils/tests/testsuite.at (PARSEOPT_DEFAULT): New define.
* libmailutils/tests/parseopt00.at: Use PARSEOPT_DEFAULT.
* libmailutils/tests/parseopt01.at: Likewise.
* libmailutils/tests/parseopt02.at: Likewise.
* libmailutils/tests/parseopt03.at: Likewise.
* libmailutils/tests/parseopt04.at: Likewise.
* libmailutils/tests/parseopt05.at: Likewise.
* libmailutils/tests/parseopt06.at: Likewise.
* libmailutils/tests/parseopt07.at: Likewise.
* libmailutils/tests/parseopt08.at: Likewise.
* libmailutils/tests/parseopt09.at: Likewise.
* libmailutils/tests/parseopt10.at: Likewise.
* libmailutils/tests/parseopt11.at: Likewise.
* libmailutils/tests/parseopt12.at: Likewise.
* libmailutils/tests/parseopt13.at: Likewise.
* libmailutils/tests/parseopt14.at: Likewise.
* libmailutils/tests/parseopt15.at: Likewise.
* libmailutils/tests/parseopt16.at: Likewise.
* libmailutils/tests/parseopt17.at: Likewise.
* libmailutils/tests/parseopt18.at: Likewise.
* libmailutils/tests/parseopt19.at: Likewise.
* libmailutils/tests/parseopt20.at: Likewise.
* libmailutils/tests/parseopt21.at: Likewise.
* libmailutils/tests/parseopt22.at: Likewise.
* libmailutils/tests/parseopt23.at: New test.
* libmailutils/tests/parseopt24.at: New test.
* libmailutils/tests/parseopt25.at: New test.
* libmailutils/tests/parseopt_help00.at: New test.
* libmailutils/tests/parseopt_help01.at: New test.
* libmailutils/tests/parseopt_help02.at: New test.
* libmailutils/tests/parseopt_help03.at: New test.
* libmailutils/tests/parseopt_help04.at: New test.
* libmailutils/tests/parseopt_help05.at: New test.
* libmailutils/tests/parseopt_help06.at: New test.
* libmailutils/tests/parseopt_help07.at: New test.
* libmailutils/tests/parseopt_help08.at: New test.
* libmailutils/tests/parseopt_help09.at: New test.
* libmailutils/tests/parseopt_help10.at: New test.
* libmailutils/tests/parseopt_help11.at: New test.
1 parent 8905bb48
Showing 43 changed files with 1017 additions and 84 deletions
......@@ -61,7 +61,7 @@ struct mu_option
(!MU_OPTION_IS_OPTION(opt) && (opt)->opt_doc)
#define MU_OPTION_IS_VALID_SHORT_OPTION(opt) \
((opt)->opt_short > 0 && (opt)->opt_short < 127 && \
mu_isalnum ((opt)->opt_short))
(mu_isalnum ((opt)->opt_short) || ((opt)->opt_short == '?')))
#define MU_OPTION_IS_VALID_LONG_OPTION(opt) \
((opt)->opt_long != NULL)
......@@ -97,8 +97,11 @@ struct mu_option_cache
#define MU_PARSEOPT_BUG_ADDRESS 0x00010000
#define MU_PARSEOPT_PACKAGE_NAME 0x00020000
#define MU_PARSEOPT_PACKAGE_URL 0x00040000
#define MU_PARSEOPT_DATA 0x00080000
#define MU_PARSEOPT_HELP_HOOK 0x00100000
#define MU_PARSEOPT_EXTRA_INFO 0x00080000
#define MU_PARSEOPT_EXIT_ERROR 0x00100000
#define MU_PARSEOPT_HELP_HOOK 0x00200000
#define MU_PARSEOPT_DATA 0x00400000
#define MU_PARSEOPT_VERSION_HOOK 0x00800000
/* Reuse mu_parseopt struct initialized previously */
#define MU_PARSEOPT_REUSE 0x80000000
......@@ -116,6 +119,8 @@ struct mu_parseopt
int po_flags;
char *po_data; /* Call-specific data */
int po_exit_error; /* Exit on error with this code */
/* Informational: */
char const *po_prog_name;
......@@ -124,8 +129,10 @@ struct mu_parseopt
char const *po_bug_address;
char const *po_package_name;
char const *po_package_url;
void (*po_help_hook) (FILE *stream); /* FIXME: should take mu_Stream_t ?*/
char const *po_extra_info;
void (*po_help_hook) (FILE *stream); /* FIXME: should take mu_stream_t ?*/
void (*po_version_hook) (FILE *stream);
/* Output data */
int po_ind; /* Index of the next option */
......
......@@ -19,22 +19,161 @@
#endif
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <unistd.h>
#include <mailutils/alloc.h>
#include <mailutils/opt.h>
#include <mailutils/cctype.h>
#include <mailutils/nls.h>
#include <mailutils/wordsplit.h>
unsigned short_opt_col = 2;
unsigned long_opt_col = 6;
/*FIXME: doc_opt_col? */
unsigned header_col = 1;
unsigned opt_doc_col = 29;
unsigned usage_indent = 12;
unsigned rmargin = 79;
unsigned dup_args = 0;
unsigned dup_args_note = 1;
enum usage_var_type
{
usage_var_column,
usage_var_bool
};
static struct usage_var
{
char *name;
unsigned *valptr;
enum usage_var_type type;
} usage_var[] = {
{ "short-opt-col", &short_opt_col, usage_var_column },
{ "header-col", &header_col, usage_var_column },
{ "opt-doc-col", &opt_doc_col, usage_var_column },
{ "usage-indent", &usage_indent, usage_var_column },
{ "rmargin", &rmargin, usage_var_column },
{ "dup-args", &dup_args, usage_var_bool },
{ "dup-args-note", &dup_args_note, usage_var_bool },
{ "long-opt-col", &long_opt_col, usage_var_column },
{ "doc_opt_col", NULL, usage_var_column },
{ NULL }
};
#define LMARGIN 2
#define DESCRCOLUMN 30
#define RMARGIN 79
#define GROUPCOLUMN 2
#define USAGECOLUMN 13
static void
set_usage_var (struct mu_parseopt *po, char const *id)
{
struct usage_var *p;
size_t len;
int boolval = 1;
if (strlen (id) > 3 && memcmp (id, "no-", 3) == 0)
{
id += 3;
boolval = 0;
}
len = strcspn (id, "=");
for (p = usage_var; p->name; p++)
{
if (strlen (p->name) == len && memcmp (p->name, id, len) == 0)
{
if (!p->valptr)
return;
if (p->type == usage_var_bool)
{
if (id[len])
{
if (po->po_prog_name)
fprintf (stderr, "%s: ", po->po_prog_name);
fprintf (stderr,
"error in ARGP_HELP_FMT: improper usage of [no-]%s\n",
id);
return;
}
*p->valptr = boolval;
return;
}
if (id[len])
{
char *endp;
unsigned long val;
errno = 0;
val = strtoul (id + len + 1, &endp, 10);
if (errno || *endp)
{
if (po->po_prog_name)
fprintf (stderr, "%s: ", po->po_prog_name);
fprintf (stderr,
"error in ARGP_HELP_FMT: bad value for %s\n",
id);
}
else if (val > UINT_MAX)
{
if (po->po_prog_name)
fprintf (stderr, "%s: ", po->po_prog_name);
fprintf (stderr,
"error in ARGP_HELP_FMT: %s value is out of range\n",
id);
}
else
*p->valptr = val;
}
else
{
if (po->po_prog_name)
fprintf (stderr, "%s: ", po->po_prog_name);
fprintf (stderr,
"%s: ARGP_HELP_FMT parameter requires a value\n",
id);
return;
}
return;
}
}
if (po->po_prog_name)
fprintf (stderr, "%s: ", po->po_prog_name);
fprintf (stderr,
"%s: Unknown ARGP_HELP_FMT parameter\n",
id);
}
static void
indent (size_t start, size_t col)
init_usage_vars (struct mu_parseopt *po)
{
char *fmt;
struct mu_wordsplit ws;
size_t i;
fmt = getenv ("ARGP_HELP_FMT");
if (!fmt)
return;
ws.ws_delim=",";
if (mu_wordsplit (fmt, &ws,
MU_WRDSF_DELIM | MU_WRDSF_NOVAR | MU_WRDSF_NOCMD
| MU_WRDSF_WS | MU_WRDSF_SHOWERR))
return;
for (i = 0; i < ws.ws_wordc; i++)
{
set_usage_var (po, ws.ws_wordv[i]);
}
mu_wordsplit_free (&ws);
}
static int
indent (int start, int col)
{
for (; start < col; start++)
putchar (' ');
return start;
}
static void
......@@ -70,6 +209,22 @@ print_option_descr (const char *descr, size_t lmargin, size_t rmargin)
static size_t
print_opt_arg (struct mu_option *opt, int delim)
{
int w = 0;
if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL)
{
if (delim == '=')
w = printf ("[=%s]", gettext (opt->opt_arg));
else
w = printf ("[%s]", gettext (opt->opt_arg));
}
else
w = printf ("%c%s", delim, gettext (opt->opt_arg));
return w;
}
static size_t
print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
int *argsused)
{
......@@ -82,9 +237,11 @@ print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
{
if (num)
putchar ('\n');
indent (0, GROUPCOLUMN);
print_option_descr (gettext (opt->opt_doc), GROUPCOLUMN, RMARGIN);
putchar ('\n');
if (opt->opt_doc[0])
{
indent (0, header_col);
print_option_descr (gettext (opt->opt_doc), header_col, rmargin);
}
return num + 1;
}
......@@ -103,52 +260,51 @@ print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
{
if (w == 0)
{
indent (0, LMARGIN);
w = LMARGIN;
indent (0, short_opt_col);
w = short_opt_col;
}
else
w += printf (", ");
w += printf ("-%c", optbuf[i]->opt_short);
delim = ' ';
if (opt->opt_arg && dup_args)
w += print_opt_arg (opt, delim);
}
}
for (i = num; i < next; i++)
{
if (MU_OPTION_IS_VALID_LONG_OPTION (optbuf[i]))
{
if (w == 0)
{
indent (0, LMARGIN);
w = LMARGIN;
indent (0, short_opt_col);
w = short_opt_col;
}
else
w += printf (", ");
w += printf ("--%s", optbuf[i]->opt_long);
if (i == num)
w = indent (w, long_opt_col);
w += printf ("--%s", optbuf[i]->opt_long);
delim = '=';
if (opt->opt_arg && dup_args)
w += print_opt_arg (opt, delim);
}
}
if (opt->opt_arg)
{
*argsused = 1;
if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL)
{
if (delim == '=')
w += printf ("[=%s]", gettext (opt->opt_arg));
else
w += printf ("[%s]", gettext (opt->opt_arg));
}
else
w += printf ("%c%s", delim, gettext (opt->opt_arg));
if (!dup_args)
w += print_opt_arg (opt, delim);
}
if (w >= DESCRCOLUMN)
if (w >= opt_doc_col)
{
putchar ('\n');
w = 0;
}
indent (w, DESCRCOLUMN);
print_option_descr (gettext (opt->opt_doc), DESCRCOLUMN, RMARGIN);
indent (w, opt_doc_col);
print_option_descr (gettext (opt->opt_doc), opt_doc_col, rmargin);
return next;
}
......@@ -163,9 +319,9 @@ mu_option_describe_options (struct mu_option **optbuf, size_t optcnt)
i = print_option (optbuf, optcnt, i, &argsused);
putchar ('\n');
if (argsused)
if (argsused && dup_args_note)
{
print_option_descr (_("Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options."), 0, RMARGIN);
print_option_descr (_("Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options."), 0, rmargin);
putchar ('\n');
}
}
......@@ -173,6 +329,8 @@ mu_option_describe_options (struct mu_option **optbuf, size_t optcnt)
void
mu_program_help (struct mu_parseopt *po)
{
init_usage_vars (po);
printf ("%s", _("Usage:"));
if (po->po_prog_name)
printf (" %s", po->po_prog_name);
......@@ -182,7 +340,7 @@ mu_program_help (struct mu_parseopt *po)
putchar ('\n');
if (po->po_prog_doc)
print_option_descr (gettext (po->po_prog_doc), 0, RMARGIN);
print_option_descr (gettext (po->po_prog_doc), 0, rmargin);
putchar ('\n');
mu_option_describe_options (po->po_optv, po->po_optc);
......@@ -200,6 +358,8 @@ mu_program_help (struct mu_parseopt *po)
if (po->po_package_name && po->po_package_url)
printf (_("%s home page: <%s>\n"),
po->po_package_name, po->po_package_url);
if (po->po_flags & MU_PARSEOPT_EXTRA_INFO)
print_option_descr (po->po_extra_info, 0, rmargin);
}
static struct mu_option **option_tab;
......@@ -209,8 +369,22 @@ cmpidx_short (const void *a, const void *b)
{
unsigned const *ai = (unsigned const *)a;
unsigned const *bi = (unsigned const *)b;
int ac = option_tab[*ai]->opt_short;
int bc = option_tab[*bi]->opt_short;
int d;
if (mu_isalpha (ac))
{
if (!mu_isalpha (bc))
return -1;
}
else if (mu_isalpha (bc))
return 1;
return option_tab[*ai]->opt_short - option_tab[*bi]->opt_short;
d = mu_tolower (ac) - mu_tolower (bc);
if (d == 0)
d = mu_isupper (ac) ? 1 : -1;
return d;
}
static int
......@@ -228,7 +402,7 @@ mu_program_usage (struct mu_parseopt *po)
{
unsigned i;
unsigned n;
char buf[RMARGIN+1];
char buf[rmargin+1];
unsigned *idxbuf;
unsigned nidx;
......@@ -240,23 +414,25 @@ mu_program_usage (struct mu_parseopt *po)
{ \
buf[n] = 0; \
printf ("%s\n", buf); \
n = USAGECOLUMN; \
memset (buf, ' ', n); \
n = usage_indent; \
if (n) memset (buf, ' ', n); \
} \
while (0)
#define ADDC(c) \
do \
{ \
if (n == RMARGIN) FLUSH; \
if (n == rmargin) FLUSH; \
buf[n++] = c; \
} \
while (0)
init_usage_vars (po);
option_tab = optbuf;
idxbuf = mu_calloc (optcnt, sizeof (idxbuf[0]));
n = snprintf (buf, sizeof buf, "%s %s ", _("Usage:"), mu_progname);
n = snprintf (buf, sizeof buf, "%s %s ", _("Usage:"), po->po_prog_name);
/* Print a list of short options without arguments. */
for (i = nidx = 0; i < optcnt; i++)
......@@ -293,8 +469,10 @@ mu_program_usage (struct mu_parseopt *po)
const char *arg = gettext (opt->opt_arg);
size_t len = 5 + strlen (arg) + 1;
if (n + len > RMARGIN) FLUSH;
buf[n++] = ' ';
if (n + len >= rmargin)
FLUSH;
else
buf[n++] = ' ';
buf[n++] = '[';
buf[n++] = '-';
buf[n++] = opt->opt_short;
......@@ -320,10 +498,12 @@ mu_program_usage (struct mu_parseopt *po)
{
struct mu_option *opt = optbuf[idxbuf[i]];
const char *arg = opt->opt_arg ? gettext (opt->opt_arg) : NULL;
size_t len = 3 + strlen (opt->opt_long)
size_t len = 5 + strlen (opt->opt_long)
+ (arg ? 1 + strlen (arg) : 0);
if (n + len > RMARGIN) FLUSH;
buf[n++] = ' ';
if (n + len >= rmargin)
FLUSH;
else
buf[n++] = ' ';
buf[n++] = '[';
buf[n++] = '-';
buf[n++] = '-';
......@@ -339,6 +519,30 @@ mu_program_usage (struct mu_parseopt *po)
}
}
if (po->po_flags & MU_PARSEOPT_PROG_ARGS)
{
char const *p = po->po_prog_args;
if (n + 1 >= rmargin)
FLUSH;
buf[n++] = ' ';
while (*p)
{
size_t len = strcspn (p, " \t\n");
if (len == 0)
len = 1;
if (n + len >= rmargin)
FLUSH;
else
{
memcpy (buf + n, p, len);
p += len;
n += len;
}
}
}
FLUSH;
free (idxbuf);
}
......
......@@ -82,19 +82,30 @@ fn_usage (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
exit (EXIT_SUCCESS);
}
static void
fn_version (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
{
po->po_version_hook (stdout);
exit (EXIT_SUCCESS);
}
/* Default options */
struct mu_option mu_default_options[] = {
MU_OPTION_GROUP(""),
{ "help", 'h', NULL, MU_OPTION_IMMEDIATE, N_("give this help list"),
{ "help", '?', NULL, MU_OPTION_IMMEDIATE, N_("give this help list"),
mu_c_string, NULL, fn_help },
{ "version", 'V', NULL, MU_OPTION_IMMEDIATE, N_("print program version"),
mu_c_string, NULL, /* FIXME: fn_version */ },
{ "usage", 0, NULL, MU_OPTION_IMMEDIATE, N_("give a short usage message"),
mu_c_string, NULL, fn_usage
},
MU_OPTION_END
};
struct mu_option mu_version_options[] = {
{ "version", 'V', NULL, MU_OPTION_IMMEDIATE, N_("print program version"),
mu_c_string, NULL, fn_version },
MU_OPTION_END
};
/* Output error message */
static void
parse_error (struct mu_parseopt *po, char const *fmt, ...)
......@@ -132,7 +143,8 @@ add_option_cache (struct mu_parseopt *po, struct mu_option *opt,
cache->cache_opt = opt;
cache->cache_arg = arg ? mu_strdup (arg) : NULL;
if (opt->opt_flags & MU_OPTION_IMMEDIATE)
if ((po->po_flags & MU_PARSEOPT_IMMEDIATE)
|| (opt->opt_flags & MU_OPTION_IMMEDIATE))
{
parseopt_apply (cache, po);
mu_option_cache_destroy (cache);
......@@ -407,7 +419,7 @@ parse (struct mu_parseopt *po)
po->po_arg_count++;
continue;
}
exit (EXIT_ERROR);
exit (po->po_exit_error);
}
}
else
......@@ -426,7 +438,7 @@ parse (struct mu_parseopt *po)
po->po_arg_count++;
continue;
}
exit (EXIT_ERROR);
exit (po->po_exit_error);
}
arg = NULL;
}
......@@ -442,7 +454,7 @@ parse (struct mu_parseopt *po)
po->po_arg_count++;
continue;
}
exit (EXIT_ERROR);
exit (po->po_exit_error);
}
}
......@@ -459,7 +471,6 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
struct mu_option *opt;
size_t i, j;
memset (po, 0, sizeof *po);
po->po_argc = 0;
po->po_argv = NULL;
po->po_optc = 0;
......@@ -481,8 +492,14 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
po->po_package_url = NULL;
if (!(flags & MU_PARSEOPT_PACKAGE_URL))
po->po_data = NULL;
if (!(flags & MU_PARSEOPT_EXTRA_INFO))
po->po_extra_info = NULL;
if (!(flags & MU_PARSEOPT_HELP_HOOK))
po->po_help_hook = NULL;
if (!(flags & MU_PARSEOPT_EXIT_ERROR))
po->po_exit_error = EXIT_ERROR;
if (!(flags & MU_PARSEOPT_VERSION_HOOK))
po->po_version_hook = NULL;
/* Count the options */
po->po_optc = 0;
......@@ -493,6 +510,10 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
if (!(flags & MU_PARSEOPT_NO_STDOPT))
for (i = 0; !MU_OPTION_IS_END (&mu_default_options[i]); i++)
++po->po_optc;
if (flags & MU_PARSEOPT_VERSION_HOOK)
for (i = 0; !MU_OPTION_IS_END (&mu_version_options[i]); i++)
++po->po_optc;
/* Allocate the working buffer of option pointers */
po->po_optv = mu_calloc (po->po_optc + 1, sizeof (*po->po_optv));
......@@ -512,6 +533,10 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
if (!(flags & MU_PARSEOPT_NO_STDOPT))
for (i = 0; !MU_OPTION_IS_END (&mu_default_options[i]); i++, j++)
po->po_optv[j] = &mu_default_options[i];
if (flags & MU_PARSEOPT_VERSION_HOOK)
for (i = 0; !MU_OPTION_IS_END (&mu_version_options[i]); i++, j++)
po->po_optv[j] = &mu_version_options[i];
po->po_optv[j] = NULL;
......@@ -532,6 +557,16 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
start = sort_group (po->po_optv, start);
}
}
po->po_ind = 0;
po->po_opterr = 0;
po->po_optlist = NULL;
po->po_cur = NULL;
po->po_chr = 0;
po->po_arg_start = 0;
po->po_arg_count = 0;
po->po_permuted = 0;
return 0;
}
......
......@@ -127,6 +127,21 @@ TESTSUITE_AT = \
parseopt20.at\
parseopt21.at\
parseopt22.at\
parseopt23.at\
parseopt24.at\
parseopt25.at\
parseopt_help00.at\
parseopt_help01.at\
parseopt_help02.at\
parseopt_help03.at\
parseopt_help04.at\
parseopt_help05.at\
parseopt_help06.at\
parseopt_help07.at\
parseopt_help08.at\
parseopt_help09.at\
parseopt_help10.at\
parseopt_help11.at\
prop.at\
scantime.at\
strftime.at\
......
......@@ -63,8 +63,51 @@ struct mu_option group_b[] = {
struct mu_option *optv[] = { group_a, group_b, NULL };
static void
version_func (FILE *fp)
{
fputs ("version hook called\n", fp);
}
#define S(s) ((s)?(s):"(null)")
struct parseopt_param
{
char *name;
int flag;
mu_c_type_t type;
size_t off;
};
static struct parseopt_param parseopt_param[] = {
{ "MU_PARSEOPT_ARGV0", MU_PARSEOPT_ARGV0, mu_c_void },
{ "MU_PARSEOPT_IGNORE_ERRORS", MU_PARSEOPT_IGNORE_ERRORS, mu_c_void },
{ "MU_PARSEOPT_IN_ORDER", MU_PARSEOPT_IN_ORDER, mu_c_void },
{ "MU_PARSEOPT_NO_STDOPT", MU_PARSEOPT_NO_STDOPT, mu_c_void },
{ "MU_PARSEOPT_NO_ERREXIT", MU_PARSEOPT_NO_ERREXIT, mu_c_void },
{ "MU_PARSEOPT_IMMEDIATE", MU_PARSEOPT_IMMEDIATE, mu_c_void },
{ "MU_PARSEOPT_NO_SORT", MU_PARSEOPT_NO_SORT, mu_c_void },
{ "MU_PARSEOPT_PROG_NAME", MU_PARSEOPT_PROG_NAME,
mu_c_string, mu_offsetof(struct mu_parseopt, po_prog_name) },
{ "MU_PARSEOPT_PROG_DOC", MU_PARSEOPT_PROG_DOC,
mu_c_string, mu_offsetof(struct mu_parseopt, po_prog_doc) },
{ "MU_PARSEOPT_PROG_ARGS", MU_PARSEOPT_PROG_ARGS,
mu_c_string, mu_offsetof(struct mu_parseopt, po_prog_args) },
{ "MU_PARSEOPT_BUG_ADDRESS", MU_PARSEOPT_BUG_ADDRESS,
mu_c_string, mu_offsetof(struct mu_parseopt, po_bug_address) },
{ "MU_PARSEOPT_PACKAGE_NAME", MU_PARSEOPT_PACKAGE_NAME,
mu_c_string, mu_offsetof(struct mu_parseopt, po_package_name) },
{ "MU_PARSEOPT_PACKAGE_URL", MU_PARSEOPT_PACKAGE_URL,
mu_c_string, mu_offsetof(struct mu_parseopt, po_package_url) },
{ "MU_PARSEOPT_EXTRA_INFO", MU_PARSEOPT_EXTRA_INFO,
mu_c_string, mu_offsetof(struct mu_parseopt, po_extra_info) },
{ "MU_PARSEOPT_EXIT_ERROR", MU_PARSEOPT_EXIT_ERROR,
mu_c_int, mu_offsetof(struct mu_parseopt, po_exit_error) },
{ "MU_PARSEOPT_VERSION_HOOK", MU_PARSEOPT_VERSION_HOOK, mu_c_void },
{ NULL }
};
int
main (int argc, char *argv[])
{
......@@ -79,16 +122,29 @@ main (int argc, char *argv[])
flags = MU_PARSEOPT_DEFAULT;
else
{
if (getenv ("MU_PARSEOPT_IN_ORDER"))
flags |= MU_PARSEOPT_IN_ORDER;
if (getenv ("MU_PARSEOPT_IGNORE_ERRORS"))
flags |= MU_PARSEOPT_IGNORE_ERRORS;
if (getenv ("MU_PARSEOPT_IN_ORDER"))
flags |= MU_PARSEOPT_IN_ORDER;
if (getenv ("MU_PARSEOPT_NO_ERREXIT"))
flags |= MU_PARSEOPT_NO_ERREXIT;
if (getenv ("MU_PARSEOPT_NO_STDOPT"))
flags |= MU_PARSEOPT_NO_STDOPT;
struct parseopt_param *param;
for (param = parseopt_param; param->name; param++)
{
char *val = getenv (param->name);
if (val)
{
flags |= param->flag;
if (param->type != mu_c_void)
{
char *errmsg;
int rc = mu_str_to_c (val, param->type,
((char*)&po + param->off),
&errmsg);
if (rc)
{
fprintf (stderr, "envvar %s: %s\n",
param->name, errmsg ? errmsg : mu_strerror (rc));
}
}
}
}
if (flags & MU_PARSEOPT_VERSION_HOOK)
po.po_version_hook = version_func;
}
rc = mu_parseopt (&po, argc, argv, optv, flags);
......
......@@ -17,7 +17,7 @@
AT_SETUP([empty command line])
AT_KEYWORDS([parseopt parseopt00])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt
],
[0],
......
......@@ -17,7 +17,7 @@
AT_SETUP([command line without options])
AT_KEYWORDS([parseopt parseopt_noopt parseopt01])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt command line arguments
],
[0],
......
......@@ -17,7 +17,7 @@
AT_SETUP([short options])
AT_KEYWORDS([parseopt parseopt_short parseopt02])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt -f file -x -a -d command line arguments
],
[0],
......
......@@ -17,7 +17,7 @@
AT_SETUP([short option with argument])
AT_KEYWORDS([parseopt parseopt_short parseopt_short_arg parseopt03])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt -ffile -x -a -d command line arguments
],
[0],
......
......@@ -17,7 +17,7 @@
AT_SETUP([short option with optional argument])
AT_KEYWORDS([parseopt parseopt_short parseopt_short_opt_arg parseopt04])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt -ofile command line arguments
],
[0],
......
......@@ -17,7 +17,7 @@
AT_SETUP([short option without optional argument])
AT_KEYWORDS([parseopt parseopt_short parseopt_short_opt_noarg parseopt05])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt -o command line arguments
],
[0],
......
......@@ -17,7 +17,7 @@
AT_SETUP([incremental short option])
AT_KEYWORDS([parseopt parseopt_short parseopt_short_incr parseopt06])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt -d -d command line arguments
],
[0],
......
......@@ -17,7 +17,7 @@
AT_SETUP([short option clustering])
AT_KEYWORDS([parseopt parseopt_short parseopt_short_cluster parseopt07])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt -xffile -dado10 command line arguments
],
[0],
......
......@@ -17,7 +17,7 @@
AT_SETUP([long options])
AT_KEYWORDS([parseopt parseopt_long parseopt08])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt --file=file --all command line arguments
],
[0],
......
......@@ -17,7 +17,7 @@
AT_SETUP([long option with argument])
AT_KEYWORDS([parseopt parseopt_long parseopt_long_arg parseopt09])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt --file file command line arguments
],
[0],
......
......@@ -17,7 +17,7 @@
AT_SETUP([long option with optional argument])
AT_KEYWORDS([parseopt parseopt_long parseopt_long_opt_arg parseopt10])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt --optional=file command line arguments
],
[0],
......
......@@ -17,7 +17,7 @@
AT_SETUP([long option without optional argument])
AT_KEYWORDS([parseopt parseopt_long parseopt_long_opt_noarg parseopt11])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt --optional command line arguments
],
[0],
......
......@@ -17,7 +17,7 @@
AT_SETUP([incremental long option])
AT_KEYWORDS([parseopt parseopt_long parseopt_long_incr parseopt12])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt --debug --debug command line arguments
],
[0],
......
......@@ -17,7 +17,7 @@
AT_SETUP([abbreviated long options])
AT_KEYWORDS([parseopt parseopt_long parseopt_long_abbr parseopt13])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt --fil=file --fin=Word command line arguments
],
[0],
......
......@@ -17,7 +17,7 @@
AT_SETUP([ambiguous abbreviated long options])
AT_KEYWORDS([parseopt parseopt_long parseopt_long_abbr parseopt_long_ambig parseopt14])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt --fi=file --fi=Word command line arguments
],
[1],
......
......@@ -17,7 +17,7 @@
AT_SETUP([mixed long and short options])
AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt15.at])
AT_CHECK([
MU_PARSEOPT_DEFAULT=1
PARSEOPT_DEFAULT
parseopt --file=filename -o -xa --find word -j10 command line arguments
],
[0],
......
......@@ -15,8 +15,9 @@
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([option aliases])
AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt16.at])
AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_alias parseopt16.at])
AT_CHECK([
PARSEOPT_DEFAULT
parseopt -vvv
],
[0],
......
......@@ -17,6 +17,7 @@
AT_SETUP([argument permutation])
AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt17.at])
AT_CHECK([
PARSEOPT_DEFAULT
parseopt more --file=file arguments follow -x -o options
],
[0],
......
......@@ -17,6 +17,7 @@
AT_SETUP([double-dash])
AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt18.at])
AT_CHECK([
PARSEOPT_DEFAULT
parseopt -x --file=foobar -- -a --optional arg
],
[0],
......
......@@ -17,6 +17,7 @@
AT_SETUP([double-dash with permutation])
AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt19.at])
AT_CHECK([
PARSEOPT_DEFAULT
parseopt -x more --file=foobar -- -a --optional arg
],
[0],
......
......@@ -17,10 +17,11 @@
AT_SETUP([short option without required argument])
AT_KEYWORDS([parseopt parseopt_short parseopt_short_noarg parseopt20])
AT_CHECK([
PARSEOPT_DEFAULT
parseopt -f
],
[1],
[],
[parseopt: option '-f' requires an argument
])
AT_CLEANUP
\ No newline at end of file
AT_CLEANUP
......
......@@ -17,10 +17,11 @@
AT_SETUP([long option without required argument])
AT_KEYWORDS([parseopt parseopt_long parseopt_long_noarg parseopt21])
AT_CHECK([
PARSEOPT_DEFAULT
parseopt --file
],
[1],
[],
[parseopt: option '--file' requires an argument
])
AT_CLEANUP
\ No newline at end of file
AT_CLEANUP
......
......@@ -17,10 +17,11 @@
AT_SETUP([unrecognized option])
AT_KEYWORDS([parseopt parseopt_short parseopt_short_unrecognized parseopt22])
AT_CHECK([
PARSEOPT_DEFAULT
parseopt -X
],
[1],
[],
[parseopt: unrecognized option '-X'
])
AT_CLEANUP
\ No newline at end of file
AT_CLEANUP
......
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([in order parsing])
AT_KEYWORDS([parseopt parseopt_in_order parseopt23])
AT_CHECK([
PARSEOPT_DEFAULT
MU_PARSEOPT_IN_ORDER=1 parseopt --file=filename more -a -x arguments
],
[0],
[rc=0
file_name=filename
opt_value=initial
x_option=0
a_option=0
find_value=(null)
d_option=0
jobs=0
argv:
0: more
1: -a
2: -x
3: arguments
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([MU_PARSEOPT_VERSION_HOOK])
AT_KEYWORDS([parseopt MU_PARSEOPT_VERSION_HOOK parseopt25])
AT_CHECK([
PARSEOPT_DEFAULT
MU_PARSEOPT_VERSION_HOOK=1 parseopt -V
],
[0],
[version hook called
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([standard help output])
AT_KEYWORDS([parseopt parseopt_help parseopt_help00])
AT_CHECK([
PARSEOPT_DEFAULT
parseopt --help
],
[0],
[[Usage: parseopt [OPTION]...
Group A
-a, --all no arguments to this one
-f, --file=FILE set file name
-o, --optional[=FILE] optional argument
-x short-only option
Group B
-F, --find=VALUE find VALUE
-d, -v, --debug, --verbose another option
-j, --jobs=N sets numeric value
-?, --help give this help list
--usage give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
]])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([standard usage output])
AT_KEYWORDS([parseopt parseopt_help parseopt_help00])
AT_CHECK([
PARSEOPT_DEFAULT
parseopt --usage
],
[0],
[[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N] [-o FILE] [--all]
[--debug] [--file=FILE] [--find=VALUE] [--help] [--jobs=N]
[--optional=FILE] [--usage] [--verbose]
]])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([MU_PARSEOPT_PROG_NAME])
AT_KEYWORDS([parseopt parseopt_help parseopt_help02])
AT_CHECK([
PARSEOPT_DEFAULT
MU_PARSEOPT_PROG_NAME=newname parseopt --help
],
[0],
[[Usage: newname [OPTION]...
Group A
-a, --all no arguments to this one
-f, --file=FILE set file name
-o, --optional[=FILE] optional argument
-x short-only option
Group B
-F, --find=VALUE find VALUE
-d, -v, --debug, --verbose another option
-j, --jobs=N sets numeric value
-?, --help give this help list
--usage give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
]])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([MU_PARSEOPT_PROG_DOC])
AT_KEYWORDS([parseopt parseopt_help parseopt_help03])
AT_CHECK([
unset ARGP_HELP_FMT
MU_PARSEOPT_PROG_DOC="Tests option parsing" parseopt --help
],
[0],
[[Usage: parseopt [OPTION]...
Tests option parsing
Group A
-a, --all no arguments to this one
-f, --file=FILE set file name
-o, --optional[=FILE] optional argument
-x short-only option
Group B
-F, --find=VALUE find VALUE
-d, -v, --debug, --verbose another option
-j, --jobs=N sets numeric value
-?, --help give this help list
--usage give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
]])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([MU_PARSEOPT_PROG_ARGS])
AT_KEYWORDS([parseopt parseopt_help parseopt_help04])
AT_CHECK([
PARSEOPT_DEFAULT
MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS" parseopt --help
],
[0],
[Usage: parseopt [[OPTION]]... SOME MORE ARGS
Group A
-a, --all no arguments to this one
-f, --file=FILE set file name
-o, --optional[[=FILE]] optional argument
-x short-only option
Group B
-F, --find=VALUE find VALUE
-d, -v, --debug, --verbose another option
-j, --jobs=N sets numeric value
-?, --help give this help list
--usage give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([MU_PARSEOPT_BUG_ADDRESS])
AT_KEYWORDS([parseopt parseopt_help parseopt_help05])
AT_CHECK([
PARSEOPT_DEFAULT
MU_PARSEOPT_BUG_ADDRESS='<gray@gnu.org>' parseopt --help
],
[0],
[Usage: parseopt [[OPTION]]...
Group A
-a, --all no arguments to this one
-f, --file=FILE set file name
-o, --optional[[=FILE]] optional argument
-x short-only option
Group B
-F, --find=VALUE find VALUE
-d, -v, --debug, --verbose another option
-j, --jobs=N sets numeric value
-?, --help give this help list
--usage give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Report bugs to <gray@gnu.org>.
])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([MU_PARSEOPT_PACKAGE_NAME and MU_PARSEOPT_PACKAGE_URL])
AT_KEYWORDS([parseopt parseopt_help parseopt_help06])
AT_CHECK([
PARSEOPT_DEFAULT
MU_PARSEOPT_PACKAGE_NAME='GNU Mailutils' MU_PARSEOPT_PACKAGE_URL='http://mailutils.org' parseopt --help
],
[0],
[[Usage: parseopt [OPTION]...
Group A
-a, --all no arguments to this one
-f, --file=FILE set file name
-o, --optional[=FILE] optional argument
-x short-only option
Group B
-F, --find=VALUE find VALUE
-d, -v, --debug, --verbose another option
-j, --jobs=N sets numeric value
-?, --help give this help list
--usage give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
GNU Mailutils home page: <http://mailutils.org>
]])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([all data])
AT_KEYWORDS([parseopt parseopt_help parseopt_help07])
AT_CHECK([
PARSEOPT_DEFAULT
MU_PARSEOPT_PROG_DOC="Tests option parsing"\
MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS"\
MU_PARSEOPT_BUG_ADDRESS='<gray@gnu.org>'\
MU_PARSEOPT_PACKAGE_NAME='GNU Mailutils'\
MU_PARSEOPT_PACKAGE_URL='http://mailutils.org'\
MU_PARSEOPT_EXTRA_INFO='General help using GNU software: <http://www.gnu.org/gethelp/>'\
parseopt --help
],
[0],
[[Usage: parseopt [OPTION]... SOME MORE ARGS
Tests option parsing
Group A
-a, --all no arguments to this one
-f, --file=FILE set file name
-o, --optional[=FILE] optional argument
-x short-only option
Group B
-F, --find=VALUE find VALUE
-d, -v, --debug, --verbose another option
-j, --jobs=N sets numeric value
-?, --help give this help list
--usage give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Report bugs to <gray@gnu.org>.
GNU Mailutils home page: <http://mailutils.org>
General help using GNU software: <http://www.gnu.org/gethelp/>
]])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([ARGP_HELP_FMT compatibility])
AT_KEYWORDS([parseopt parseopt_help ARGP_HELP_FMT parseopt_help08])
AT_CHECK([
PARSEOPT_DEFAULT
ARGP_HELP_FMT=dup-args,no-dup-args-note,short-opt-col=1,opt-doc-col=32,header-col=10\
parseopt --help
],
[0],
[[Usage: parseopt [OPTION]...
Group A
-a, --all no arguments to this one
-f FILE, --file=FILE set file name
-o[FILE], --optional[=FILE] optional argument
-x short-only option
Group B
-F VALUE, --find=VALUE find VALUE
-d, -v, --debug, --verbose another option
-j N, --jobs=N sets numeric value
-?, --help give this help list
--usage give a short usage message
]])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([ARGP_HELP_FMT usage compatibility])
AT_KEYWORDS([parseopt parseopt_help ARGP_HELP_FMT parseopt_help09])
AT_CHECK([
PARSEOPT_DEFAULT
ARGP_HELP_FMT=rmargin=62,usage-indent=1\
parseopt --usage
],
[0],
[[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N]
[-o FILE] [--all] [--debug] [--file=FILE] [--find=VALUE]
[--help] [--jobs=N] [--optional=FILE] [--usage] [--verbose]
]])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([MU_PARSEOPT_VERSION_HOOK usage output])
AT_KEYWORDS([parseopt MU_PARSEOPT_VERSION_HOOK parseopt26])
AT_CHECK([
PARSEOPT_DEFAULT
MU_PARSEOPT_VERSION_HOOK=1 parseopt --usage
],
[0],
[[Usage: parseopt [-advVx?] [-f FILE] [-F VALUE] [-j N] [-o FILE] [--all]
[--debug] [--file=FILE] [--find=VALUE] [--help] [--jobs=N]
[--optional=FILE] [--usage] [--verbose] [--version]
]])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([MU_PARSEOPT_VERSION_HOOK help output])
AT_KEYWORDS([parseopt MU_PARSEOPT_VERSION_HOOK help])
AT_CHECK([
PARSEOPT_DEFAULT
MU_PARSEOPT_VERSION_HOOK=1 parseopt --help
],
[0],
[[Usage: parseopt [OPTION]...
Group A
-a, --all no arguments to this one
-f, --file=FILE set file name
-o, --optional[=FILE] optional argument
-x short-only option
Group B
-F, --find=VALUE find VALUE
-d, -v, --debug, --verbose another option
-j, --jobs=N sets numeric value
-?, --help give this help list
--usage give a short usage message
-V, --version print program version
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
]])
AT_CLEANUP
......@@ -57,6 +57,24 @@ AT_BANNER([Conversions])
m4_include([strtoc.at])
AT_BANNER([Command line parser])
m4_define([PARSEOPT_DEFAULT],[
unset ARGP_HELP_FMT
unset MU_PARSEOPT_ARGV0
unset MU_PARSEOPT_IGNORE_ERRORS
unset MU_PARSEOPT_IN_ORDER
unset MU_PARSEOPT_NO_STDOPT
unset MU_PARSEOPT_NO_ERREXIT
unset MU_PARSEOPT_IMMEDIATE
unset MU_PARSEOPT_NO_SORT
unset MU_PARSEOPT_PROG_NAME
unset MU_PARSEOPT_PROG_DOC
unset MU_PARSEOPT_PROG_ARGS
unset MU_PARSEOPT_BUG_ADDRESS
unset MU_PARSEOPT_PACKAGE_NAME
unset MU_PARSEOPT_PACKAGE_URL
])
m4_include([parseopt00.at])
m4_include([parseopt01.at])
m4_include([parseopt02.at])
......@@ -80,6 +98,23 @@ m4_include([parseopt19.at])
m4_include([parseopt20.at])
m4_include([parseopt21.at])
m4_include([parseopt22.at])
m4_include([parseopt23.at])
m4_include([parseopt24.at])
m4_include([parseopt25.at])
AT_BANNER([Command line help output])
m4_include([parseopt_help00.at])
m4_include([parseopt_help01.at])
m4_include([parseopt_help02.at])
m4_include([parseopt_help03.at])
m4_include([parseopt_help04.at])
m4_include([parseopt_help05.at])
m4_include([parseopt_help06.at])
m4_include([parseopt_help07.at])
m4_include([parseopt_help08.at])
m4_include([parseopt_help09.at])
m4_include([parseopt_help10.at])
m4_include([parseopt_help11.at])
AT_BANNER([Standard streams])
m4_include([strin.at])
......