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 1009 additions and 76 deletions
...@@ -61,7 +61,7 @@ struct mu_option ...@@ -61,7 +61,7 @@ struct mu_option
61 (!MU_OPTION_IS_OPTION(opt) && (opt)->opt_doc) 61 (!MU_OPTION_IS_OPTION(opt) && (opt)->opt_doc)
62 #define MU_OPTION_IS_VALID_SHORT_OPTION(opt) \ 62 #define MU_OPTION_IS_VALID_SHORT_OPTION(opt) \
63 ((opt)->opt_short > 0 && (opt)->opt_short < 127 && \ 63 ((opt)->opt_short > 0 && (opt)->opt_short < 127 && \
64 mu_isalnum ((opt)->opt_short)) 64 (mu_isalnum ((opt)->opt_short) || ((opt)->opt_short == '?')))
65 #define MU_OPTION_IS_VALID_LONG_OPTION(opt) \ 65 #define MU_OPTION_IS_VALID_LONG_OPTION(opt) \
66 ((opt)->opt_long != NULL) 66 ((opt)->opt_long != NULL)
67 67
...@@ -97,8 +97,11 @@ struct mu_option_cache ...@@ -97,8 +97,11 @@ struct mu_option_cache
97 #define MU_PARSEOPT_BUG_ADDRESS 0x00010000 97 #define MU_PARSEOPT_BUG_ADDRESS 0x00010000
98 #define MU_PARSEOPT_PACKAGE_NAME 0x00020000 98 #define MU_PARSEOPT_PACKAGE_NAME 0x00020000
99 #define MU_PARSEOPT_PACKAGE_URL 0x00040000 99 #define MU_PARSEOPT_PACKAGE_URL 0x00040000
100 #define MU_PARSEOPT_DATA 0x00080000 100 #define MU_PARSEOPT_EXTRA_INFO 0x00080000
101 #define MU_PARSEOPT_HELP_HOOK 0x00100000 101 #define MU_PARSEOPT_EXIT_ERROR 0x00100000
102 #define MU_PARSEOPT_HELP_HOOK 0x00200000
103 #define MU_PARSEOPT_DATA 0x00400000
104 #define MU_PARSEOPT_VERSION_HOOK 0x00800000
102 105
103 /* Reuse mu_parseopt struct initialized previously */ 106 /* Reuse mu_parseopt struct initialized previously */
104 #define MU_PARSEOPT_REUSE 0x80000000 107 #define MU_PARSEOPT_REUSE 0x80000000
...@@ -117,6 +120,8 @@ struct mu_parseopt ...@@ -117,6 +120,8 @@ struct mu_parseopt
117 120
118 char *po_data; /* Call-specific data */ 121 char *po_data; /* Call-specific data */
119 122
123 int po_exit_error; /* Exit on error with this code */
124
120 /* Informational: */ 125 /* Informational: */
121 char const *po_prog_name; 126 char const *po_prog_name;
122 char const *po_prog_doc; 127 char const *po_prog_doc;
...@@ -124,8 +129,10 @@ struct mu_parseopt ...@@ -124,8 +129,10 @@ struct mu_parseopt
124 char const *po_bug_address; 129 char const *po_bug_address;
125 char const *po_package_name; 130 char const *po_package_name;
126 char const *po_package_url; 131 char const *po_package_url;
132 char const *po_extra_info;
127 133
128 void (*po_help_hook) (FILE *stream); /* FIXME: should take mu_Stream_t ?*/ 134 void (*po_help_hook) (FILE *stream); /* FIXME: should take mu_stream_t ?*/
135 void (*po_version_hook) (FILE *stream);
129 136
130 /* Output data */ 137 /* Output data */
131 int po_ind; /* Index of the next option */ 138 int po_ind; /* Index of the next option */
......
...@@ -19,22 +19,161 @@ ...@@ -19,22 +19,161 @@
19 #endif 19 #endif
20 #include <stdlib.h> 20 #include <stdlib.h>
21 #include <string.h> 21 #include <string.h>
22 #include <limits.h>
23 #include <errno.h>
24 #include <unistd.h>
22 #include <mailutils/alloc.h> 25 #include <mailutils/alloc.h>
23 #include <mailutils/opt.h> 26 #include <mailutils/opt.h>
24 #include <mailutils/cctype.h> 27 #include <mailutils/cctype.h>
25 #include <mailutils/nls.h> 28 #include <mailutils/nls.h>
29 #include <mailutils/wordsplit.h>
26 30
27 #define LMARGIN 2 31 unsigned short_opt_col = 2;
28 #define DESCRCOLUMN 30 32 unsigned long_opt_col = 6;
29 #define RMARGIN 79 33 /*FIXME: doc_opt_col? */
30 #define GROUPCOLUMN 2 34 unsigned header_col = 1;
31 #define USAGECOLUMN 13 35 unsigned opt_doc_col = 29;
36 unsigned usage_indent = 12;
37 unsigned rmargin = 79;
38
39 unsigned dup_args = 0;
40 unsigned dup_args_note = 1;
41
42 enum usage_var_type
43 {
44 usage_var_column,
45 usage_var_bool
46 };
47
48 static struct usage_var
49 {
50 char *name;
51 unsigned *valptr;
52 enum usage_var_type type;
53 } usage_var[] = {
54 { "short-opt-col", &short_opt_col, usage_var_column },
55 { "header-col", &header_col, usage_var_column },
56 { "opt-doc-col", &opt_doc_col, usage_var_column },
57 { "usage-indent", &usage_indent, usage_var_column },
58 { "rmargin", &rmargin, usage_var_column },
59 { "dup-args", &dup_args, usage_var_bool },
60 { "dup-args-note", &dup_args_note, usage_var_bool },
61 { "long-opt-col", &long_opt_col, usage_var_column },
62 { "doc_opt_col", NULL, usage_var_column },
63 { NULL }
64 };
32 65
33 static void 66 static void
34 indent (size_t start, size_t col) 67 set_usage_var (struct mu_parseopt *po, char const *id)
68 {
69 struct usage_var *p;
70 size_t len;
71 int boolval = 1;
72
73 if (strlen (id) > 3 && memcmp (id, "no-", 3) == 0)
74 {
75 id += 3;
76 boolval = 0;
77 }
78 len = strcspn (id, "=");
79
80 for (p = usage_var; p->name; p++)
81 {
82 if (strlen (p->name) == len && memcmp (p->name, id, len) == 0)
83 {
84 if (!p->valptr)
85 return;
86
87 if (p->type == usage_var_bool)
88 {
89 if (id[len])
90 {
91 if (po->po_prog_name)
92 fprintf (stderr, "%s: ", po->po_prog_name);
93 fprintf (stderr,
94 "error in ARGP_HELP_FMT: improper usage of [no-]%s\n",
95 id);
96 return;
97 }
98 *p->valptr = boolval;
99 return;
100 }
101
102 if (id[len])
103 {
104 char *endp;
105 unsigned long val;
106
107 errno = 0;
108 val = strtoul (id + len + 1, &endp, 10);
109 if (errno || *endp)
110 {
111 if (po->po_prog_name)
112 fprintf (stderr, "%s: ", po->po_prog_name);
113 fprintf (stderr,
114 "error in ARGP_HELP_FMT: bad value for %s\n",
115 id);
116 }
117 else if (val > UINT_MAX)
118 {
119 if (po->po_prog_name)
120 fprintf (stderr, "%s: ", po->po_prog_name);
121 fprintf (stderr,
122 "error in ARGP_HELP_FMT: %s value is out of range\n",
123 id);
124 }
125 else
126 *p->valptr = val;
127 }
128 else
129 {
130 if (po->po_prog_name)
131 fprintf (stderr, "%s: ", po->po_prog_name);
132 fprintf (stderr,
133 "%s: ARGP_HELP_FMT parameter requires a value\n",
134 id);
135 return;
136 }
137 return;
138 }
139 }
140
141 if (po->po_prog_name)
142 fprintf (stderr, "%s: ", po->po_prog_name);
143 fprintf (stderr,
144 "%s: Unknown ARGP_HELP_FMT parameter\n",
145 id);
146 }
147
148 static void
149 init_usage_vars (struct mu_parseopt *po)
150 {
151 char *fmt;
152 struct mu_wordsplit ws;
153 size_t i;
154
155 fmt = getenv ("ARGP_HELP_FMT");
156 if (!fmt)
157 return;
158 ws.ws_delim=",";
159 if (mu_wordsplit (fmt, &ws,
160 MU_WRDSF_DELIM | MU_WRDSF_NOVAR | MU_WRDSF_NOCMD
161 | MU_WRDSF_WS | MU_WRDSF_SHOWERR))
162 return;
163 for (i = 0; i < ws.ws_wordc; i++)
164 {
165 set_usage_var (po, ws.ws_wordv[i]);
166 }
167
168 mu_wordsplit_free (&ws);
169 }
170
171 static int
172 indent (int start, int col)
35 { 173 {
36 for (; start < col; start++) 174 for (; start < col; start++)
37 putchar (' '); 175 putchar (' ');
176 return start;
38 } 177 }
39 178
40 static void 179 static void
...@@ -70,6 +209,22 @@ print_option_descr (const char *descr, size_t lmargin, size_t rmargin) ...@@ -70,6 +209,22 @@ print_option_descr (const char *descr, size_t lmargin, size_t rmargin)
70 209
71 210
72 static size_t 211 static size_t
212 print_opt_arg (struct mu_option *opt, int delim)
213 {
214 int w = 0;
215 if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL)
216 {
217 if (delim == '=')
218 w = printf ("[=%s]", gettext (opt->opt_arg));
219 else
220 w = printf ("[%s]", gettext (opt->opt_arg));
221 }
222 else
223 w = printf ("%c%s", delim, gettext (opt->opt_arg));
224 return w;
225 }
226
227 static size_t
73 print_option (struct mu_option **optbuf, size_t optcnt, size_t num, 228 print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
74 int *argsused) 229 int *argsused)
75 { 230 {
...@@ -82,9 +237,11 @@ print_option (struct mu_option **optbuf, size_t optcnt, size_t num, ...@@ -82,9 +237,11 @@ print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
82 { 237 {
83 if (num) 238 if (num)
84 putchar ('\n'); 239 putchar ('\n');
85 indent (0, GROUPCOLUMN); 240 if (opt->opt_doc[0])
86 print_option_descr (gettext (opt->opt_doc), GROUPCOLUMN, RMARGIN); 241 {
87 putchar ('\n'); 242 indent (0, header_col);
243 print_option_descr (gettext (opt->opt_doc), header_col, rmargin);
244 }
88 return num + 1; 245 return num + 1;
89 } 246 }
90 247
...@@ -103,13 +260,15 @@ print_option (struct mu_option **optbuf, size_t optcnt, size_t num, ...@@ -103,13 +260,15 @@ print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
103 { 260 {
104 if (w == 0) 261 if (w == 0)
105 { 262 {
106 indent (0, LMARGIN); 263 indent (0, short_opt_col);
107 w = LMARGIN; 264 w = short_opt_col;
108 } 265 }
109 else 266 else
110 w += printf (", "); 267 w += printf (", ");
111 w += printf ("-%c", optbuf[i]->opt_short); 268 w += printf ("-%c", optbuf[i]->opt_short);
112 delim = ' '; 269 delim = ' ';
270 if (opt->opt_arg && dup_args)
271 w += print_opt_arg (opt, delim);
113 } 272 }
114 } 273 }
115 274
...@@ -119,36 +278,33 @@ print_option (struct mu_option **optbuf, size_t optcnt, size_t num, ...@@ -119,36 +278,33 @@ print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
119 { 278 {
120 if (w == 0) 279 if (w == 0)
121 { 280 {
122 indent (0, LMARGIN); 281 indent (0, short_opt_col);
123 w = LMARGIN; 282 w = short_opt_col;
124 } 283 }
125 else 284 else
126 w += printf (", "); 285 w += printf (", ");
286 if (i == num)
287 w = indent (w, long_opt_col);
127 w += printf ("--%s", optbuf[i]->opt_long); 288 w += printf ("--%s", optbuf[i]->opt_long);
128 delim = '='; 289 delim = '=';
290 if (opt->opt_arg && dup_args)
291 w += print_opt_arg (opt, delim);
129 } 292 }
130 } 293 }
131 294
132 if (opt->opt_arg) 295 if (opt->opt_arg)
133 { 296 {
134 *argsused = 1; 297 *argsused = 1;
135 if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL) 298 if (!dup_args)
136 { 299 w += print_opt_arg (opt, delim);
137 if (delim == '=')
138 w += printf ("[=%s]", gettext (opt->opt_arg));
139 else
140 w += printf ("[%s]", gettext (opt->opt_arg));
141 }
142 else
143 w += printf ("%c%s", delim, gettext (opt->opt_arg));
144 } 300 }
145 if (w >= DESCRCOLUMN) 301 if (w >= opt_doc_col)
146 { 302 {
147 putchar ('\n'); 303 putchar ('\n');
148 w = 0; 304 w = 0;
149 } 305 }
150 indent (w, DESCRCOLUMN); 306 indent (w, opt_doc_col);
151 print_option_descr (gettext (opt->opt_doc), DESCRCOLUMN, RMARGIN); 307 print_option_descr (gettext (opt->opt_doc), opt_doc_col, rmargin);
152 308
153 return next; 309 return next;
154 } 310 }
...@@ -163,9 +319,9 @@ mu_option_describe_options (struct mu_option **optbuf, size_t optcnt) ...@@ -163,9 +319,9 @@ mu_option_describe_options (struct mu_option **optbuf, size_t optcnt)
163 i = print_option (optbuf, optcnt, i, &argsused); 319 i = print_option (optbuf, optcnt, i, &argsused);
164 putchar ('\n'); 320 putchar ('\n');
165 321
166 if (argsused) 322 if (argsused && dup_args_note)
167 { 323 {
168 print_option_descr (_("Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options."), 0, RMARGIN); 324 print_option_descr (_("Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options."), 0, rmargin);
169 putchar ('\n'); 325 putchar ('\n');
170 } 326 }
171 } 327 }
...@@ -173,6 +329,8 @@ mu_option_describe_options (struct mu_option **optbuf, size_t optcnt) ...@@ -173,6 +329,8 @@ mu_option_describe_options (struct mu_option **optbuf, size_t optcnt)
173 void 329 void
174 mu_program_help (struct mu_parseopt *po) 330 mu_program_help (struct mu_parseopt *po)
175 { 331 {
332 init_usage_vars (po);
333
176 printf ("%s", _("Usage:")); 334 printf ("%s", _("Usage:"));
177 if (po->po_prog_name) 335 if (po->po_prog_name)
178 printf (" %s", po->po_prog_name); 336 printf (" %s", po->po_prog_name);
...@@ -182,7 +340,7 @@ mu_program_help (struct mu_parseopt *po) ...@@ -182,7 +340,7 @@ mu_program_help (struct mu_parseopt *po)
182 putchar ('\n'); 340 putchar ('\n');
183 341
184 if (po->po_prog_doc) 342 if (po->po_prog_doc)
185 print_option_descr (gettext (po->po_prog_doc), 0, RMARGIN); 343 print_option_descr (gettext (po->po_prog_doc), 0, rmargin);
186 putchar ('\n'); 344 putchar ('\n');
187 345
188 mu_option_describe_options (po->po_optv, po->po_optc); 346 mu_option_describe_options (po->po_optv, po->po_optc);
...@@ -200,6 +358,8 @@ mu_program_help (struct mu_parseopt *po) ...@@ -200,6 +358,8 @@ mu_program_help (struct mu_parseopt *po)
200 if (po->po_package_name && po->po_package_url) 358 if (po->po_package_name && po->po_package_url)
201 printf (_("%s home page: <%s>\n"), 359 printf (_("%s home page: <%s>\n"),
202 po->po_package_name, po->po_package_url); 360 po->po_package_name, po->po_package_url);
361 if (po->po_flags & MU_PARSEOPT_EXTRA_INFO)
362 print_option_descr (po->po_extra_info, 0, rmargin);
203 } 363 }
204 364
205 static struct mu_option **option_tab; 365 static struct mu_option **option_tab;
...@@ -209,8 +369,22 @@ cmpidx_short (const void *a, const void *b) ...@@ -209,8 +369,22 @@ cmpidx_short (const void *a, const void *b)
209 { 369 {
210 unsigned const *ai = (unsigned const *)a; 370 unsigned const *ai = (unsigned const *)a;
211 unsigned const *bi = (unsigned const *)b; 371 unsigned const *bi = (unsigned const *)b;
372 int ac = option_tab[*ai]->opt_short;
373 int bc = option_tab[*bi]->opt_short;
374 int d;
375
376 if (mu_isalpha (ac))
377 {
378 if (!mu_isalpha (bc))
379 return -1;
380 }
381 else if (mu_isalpha (bc))
382 return 1;
212 383
213 return option_tab[*ai]->opt_short - option_tab[*bi]->opt_short; 384 d = mu_tolower (ac) - mu_tolower (bc);
385 if (d == 0)
386 d = mu_isupper (ac) ? 1 : -1;
387 return d;
214 } 388 }
215 389
216 static int 390 static int
...@@ -228,7 +402,7 @@ mu_program_usage (struct mu_parseopt *po) ...@@ -228,7 +402,7 @@ mu_program_usage (struct mu_parseopt *po)
228 { 402 {
229 unsigned i; 403 unsigned i;
230 unsigned n; 404 unsigned n;
231 char buf[RMARGIN+1]; 405 char buf[rmargin+1];
232 unsigned *idxbuf; 406 unsigned *idxbuf;
233 unsigned nidx; 407 unsigned nidx;
234 408
...@@ -240,23 +414,25 @@ mu_program_usage (struct mu_parseopt *po) ...@@ -240,23 +414,25 @@ mu_program_usage (struct mu_parseopt *po)
240 { \ 414 { \
241 buf[n] = 0; \ 415 buf[n] = 0; \
242 printf ("%s\n", buf); \ 416 printf ("%s\n", buf); \
243 n = USAGECOLUMN; \ 417 n = usage_indent; \
244 memset (buf, ' ', n); \ 418 if (n) memset (buf, ' ', n); \
245 } \ 419 } \
246 while (0) 420 while (0)
247 #define ADDC(c) \ 421 #define ADDC(c) \
248 do \ 422 do \
249 { \ 423 { \
250 if (n == RMARGIN) FLUSH; \ 424 if (n == rmargin) FLUSH; \
251 buf[n++] = c; \ 425 buf[n++] = c; \
252 } \ 426 } \
253 while (0) 427 while (0)
254 428
429 init_usage_vars (po);
430
255 option_tab = optbuf; 431 option_tab = optbuf;
256 432
257 idxbuf = mu_calloc (optcnt, sizeof (idxbuf[0])); 433 idxbuf = mu_calloc (optcnt, sizeof (idxbuf[0]));
258 434
259 n = snprintf (buf, sizeof buf, "%s %s ", _("Usage:"), mu_progname); 435 n = snprintf (buf, sizeof buf, "%s %s ", _("Usage:"), po->po_prog_name);
260 436
261 /* Print a list of short options without arguments. */ 437 /* Print a list of short options without arguments. */
262 for (i = nidx = 0; i < optcnt; i++) 438 for (i = nidx = 0; i < optcnt; i++)
...@@ -293,7 +469,9 @@ mu_program_usage (struct mu_parseopt *po) ...@@ -293,7 +469,9 @@ mu_program_usage (struct mu_parseopt *po)
293 const char *arg = gettext (opt->opt_arg); 469 const char *arg = gettext (opt->opt_arg);
294 size_t len = 5 + strlen (arg) + 1; 470 size_t len = 5 + strlen (arg) + 1;
295 471
296 if (n + len > RMARGIN) FLUSH; 472 if (n + len >= rmargin)
473 FLUSH;
474 else
297 buf[n++] = ' '; 475 buf[n++] = ' ';
298 buf[n++] = '['; 476 buf[n++] = '[';
299 buf[n++] = '-'; 477 buf[n++] = '-';
...@@ -320,9 +498,11 @@ mu_program_usage (struct mu_parseopt *po) ...@@ -320,9 +498,11 @@ mu_program_usage (struct mu_parseopt *po)
320 { 498 {
321 struct mu_option *opt = optbuf[idxbuf[i]]; 499 struct mu_option *opt = optbuf[idxbuf[i]];
322 const char *arg = opt->opt_arg ? gettext (opt->opt_arg) : NULL; 500 const char *arg = opt->opt_arg ? gettext (opt->opt_arg) : NULL;
323 size_t len = 3 + strlen (opt->opt_long) 501 size_t len = 5 + strlen (opt->opt_long)
324 + (arg ? 1 + strlen (arg) : 0); 502 + (arg ? 1 + strlen (arg) : 0);
325 if (n + len > RMARGIN) FLUSH; 503 if (n + len >= rmargin)
504 FLUSH;
505 else
326 buf[n++] = ' '; 506 buf[n++] = ' ';
327 buf[n++] = '['; 507 buf[n++] = '[';
328 buf[n++] = '-'; 508 buf[n++] = '-';
...@@ -339,6 +519,30 @@ mu_program_usage (struct mu_parseopt *po) ...@@ -339,6 +519,30 @@ mu_program_usage (struct mu_parseopt *po)
339 } 519 }
340 } 520 }
341 521
522 if (po->po_flags & MU_PARSEOPT_PROG_ARGS)
523 {
524 char const *p = po->po_prog_args;
525
526 if (n + 1 >= rmargin)
527 FLUSH;
528 buf[n++] = ' ';
529
530 while (*p)
531 {
532 size_t len = strcspn (p, " \t\n");
533 if (len == 0)
534 len = 1;
535 if (n + len >= rmargin)
536 FLUSH;
537 else
538 {
539 memcpy (buf + n, p, len);
540 p += len;
541 n += len;
542 }
543 }
544 }
545
342 FLUSH; 546 FLUSH;
343 free (idxbuf); 547 free (idxbuf);
344 } 548 }
......
...@@ -82,19 +82,30 @@ fn_usage (struct mu_parseopt *po, struct mu_option *opt, char const *unused) ...@@ -82,19 +82,30 @@ fn_usage (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
82 exit (EXIT_SUCCESS); 82 exit (EXIT_SUCCESS);
83 } 83 }
84 84
85 static void
86 fn_version (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
87 {
88 po->po_version_hook (stdout);
89 exit (EXIT_SUCCESS);
90 }
91
85 /* Default options */ 92 /* Default options */
86 struct mu_option mu_default_options[] = { 93 struct mu_option mu_default_options[] = {
87 MU_OPTION_GROUP(""), 94 MU_OPTION_GROUP(""),
88 { "help", 'h', NULL, MU_OPTION_IMMEDIATE, N_("give this help list"), 95 { "help", '?', NULL, MU_OPTION_IMMEDIATE, N_("give this help list"),
89 mu_c_string, NULL, fn_help }, 96 mu_c_string, NULL, fn_help },
90 { "version", 'V', NULL, MU_OPTION_IMMEDIATE, N_("print program version"),
91 mu_c_string, NULL, /* FIXME: fn_version */ },
92 { "usage", 0, NULL, MU_OPTION_IMMEDIATE, N_("give a short usage message"), 97 { "usage", 0, NULL, MU_OPTION_IMMEDIATE, N_("give a short usage message"),
93 mu_c_string, NULL, fn_usage 98 mu_c_string, NULL, fn_usage
94 }, 99 },
95 MU_OPTION_END 100 MU_OPTION_END
96 }; 101 };
97 102
103 struct mu_option mu_version_options[] = {
104 { "version", 'V', NULL, MU_OPTION_IMMEDIATE, N_("print program version"),
105 mu_c_string, NULL, fn_version },
106 MU_OPTION_END
107 };
108
98 /* Output error message */ 109 /* Output error message */
99 static void 110 static void
100 parse_error (struct mu_parseopt *po, char const *fmt, ...) 111 parse_error (struct mu_parseopt *po, char const *fmt, ...)
...@@ -132,7 +143,8 @@ add_option_cache (struct mu_parseopt *po, struct mu_option *opt, ...@@ -132,7 +143,8 @@ add_option_cache (struct mu_parseopt *po, struct mu_option *opt,
132 cache->cache_opt = opt; 143 cache->cache_opt = opt;
133 cache->cache_arg = arg ? mu_strdup (arg) : NULL; 144 cache->cache_arg = arg ? mu_strdup (arg) : NULL;
134 145
135 if (opt->opt_flags & MU_OPTION_IMMEDIATE) 146 if ((po->po_flags & MU_PARSEOPT_IMMEDIATE)
147 || (opt->opt_flags & MU_OPTION_IMMEDIATE))
136 { 148 {
137 parseopt_apply (cache, po); 149 parseopt_apply (cache, po);
138 mu_option_cache_destroy (cache); 150 mu_option_cache_destroy (cache);
...@@ -407,7 +419,7 @@ parse (struct mu_parseopt *po) ...@@ -407,7 +419,7 @@ parse (struct mu_parseopt *po)
407 po->po_arg_count++; 419 po->po_arg_count++;
408 continue; 420 continue;
409 } 421 }
410 exit (EXIT_ERROR); 422 exit (po->po_exit_error);
411 } 423 }
412 } 424 }
413 else 425 else
...@@ -426,7 +438,7 @@ parse (struct mu_parseopt *po) ...@@ -426,7 +438,7 @@ parse (struct mu_parseopt *po)
426 po->po_arg_count++; 438 po->po_arg_count++;
427 continue; 439 continue;
428 } 440 }
429 exit (EXIT_ERROR); 441 exit (po->po_exit_error);
430 } 442 }
431 arg = NULL; 443 arg = NULL;
432 } 444 }
...@@ -442,7 +454,7 @@ parse (struct mu_parseopt *po) ...@@ -442,7 +454,7 @@ parse (struct mu_parseopt *po)
442 po->po_arg_count++; 454 po->po_arg_count++;
443 continue; 455 continue;
444 } 456 }
445 exit (EXIT_ERROR); 457 exit (po->po_exit_error);
446 } 458 }
447 } 459 }
448 460
...@@ -459,7 +471,6 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options, ...@@ -459,7 +471,6 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
459 struct mu_option *opt; 471 struct mu_option *opt;
460 size_t i, j; 472 size_t i, j;
461 473
462 memset (po, 0, sizeof *po);
463 po->po_argc = 0; 474 po->po_argc = 0;
464 po->po_argv = NULL; 475 po->po_argv = NULL;
465 po->po_optc = 0; 476 po->po_optc = 0;
...@@ -481,8 +492,14 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options, ...@@ -481,8 +492,14 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
481 po->po_package_url = NULL; 492 po->po_package_url = NULL;
482 if (!(flags & MU_PARSEOPT_PACKAGE_URL)) 493 if (!(flags & MU_PARSEOPT_PACKAGE_URL))
483 po->po_data = NULL; 494 po->po_data = NULL;
495 if (!(flags & MU_PARSEOPT_EXTRA_INFO))
496 po->po_extra_info = NULL;
484 if (!(flags & MU_PARSEOPT_HELP_HOOK)) 497 if (!(flags & MU_PARSEOPT_HELP_HOOK))
485 po->po_help_hook = NULL; 498 po->po_help_hook = NULL;
499 if (!(flags & MU_PARSEOPT_EXIT_ERROR))
500 po->po_exit_error = EXIT_ERROR;
501 if (!(flags & MU_PARSEOPT_VERSION_HOOK))
502 po->po_version_hook = NULL;
486 503
487 /* Count the options */ 504 /* Count the options */
488 po->po_optc = 0; 505 po->po_optc = 0;
...@@ -494,6 +511,10 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options, ...@@ -494,6 +511,10 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
494 for (i = 0; !MU_OPTION_IS_END (&mu_default_options[i]); i++) 511 for (i = 0; !MU_OPTION_IS_END (&mu_default_options[i]); i++)
495 ++po->po_optc; 512 ++po->po_optc;
496 513
514 if (flags & MU_PARSEOPT_VERSION_HOOK)
515 for (i = 0; !MU_OPTION_IS_END (&mu_version_options[i]); i++)
516 ++po->po_optc;
517
497 /* Allocate the working buffer of option pointers */ 518 /* Allocate the working buffer of option pointers */
498 po->po_optv = mu_calloc (po->po_optc + 1, sizeof (*po->po_optv)); 519 po->po_optv = mu_calloc (po->po_optc + 1, sizeof (*po->po_optv));
499 if (!po->po_optv) 520 if (!po->po_optv)
...@@ -513,6 +534,10 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options, ...@@ -513,6 +534,10 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
513 for (i = 0; !MU_OPTION_IS_END (&mu_default_options[i]); i++, j++) 534 for (i = 0; !MU_OPTION_IS_END (&mu_default_options[i]); i++, j++)
514 po->po_optv[j] = &mu_default_options[i]; 535 po->po_optv[j] = &mu_default_options[i];
515 536
537 if (flags & MU_PARSEOPT_VERSION_HOOK)
538 for (i = 0; !MU_OPTION_IS_END (&mu_version_options[i]); i++, j++)
539 po->po_optv[j] = &mu_version_options[i];
540
516 po->po_optv[j] = NULL; 541 po->po_optv[j] = NULL;
517 542
518 /* Ensure sane start of options. This is necessary, in particular, 543 /* Ensure sane start of options. This is necessary, in particular,
...@@ -532,6 +557,16 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options, ...@@ -532,6 +557,16 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
532 start = sort_group (po->po_optv, start); 557 start = sort_group (po->po_optv, start);
533 } 558 }
534 } 559 }
560
561 po->po_ind = 0;
562 po->po_opterr = 0;
563 po->po_optlist = NULL;
564 po->po_cur = NULL;
565 po->po_chr = 0;
566 po->po_arg_start = 0;
567 po->po_arg_count = 0;
568 po->po_permuted = 0;
569
535 return 0; 570 return 0;
536 } 571 }
537 572
......
...@@ -127,6 +127,21 @@ TESTSUITE_AT = \ ...@@ -127,6 +127,21 @@ TESTSUITE_AT = \
127 parseopt20.at\ 127 parseopt20.at\
128 parseopt21.at\ 128 parseopt21.at\
129 parseopt22.at\ 129 parseopt22.at\
130 parseopt23.at\
131 parseopt24.at\
132 parseopt25.at\
133 parseopt_help00.at\
134 parseopt_help01.at\
135 parseopt_help02.at\
136 parseopt_help03.at\
137 parseopt_help04.at\
138 parseopt_help05.at\
139 parseopt_help06.at\
140 parseopt_help07.at\
141 parseopt_help08.at\
142 parseopt_help09.at\
143 parseopt_help10.at\
144 parseopt_help11.at\
130 prop.at\ 145 prop.at\
131 scantime.at\ 146 scantime.at\
132 strftime.at\ 147 strftime.at\
......
...@@ -63,8 +63,51 @@ struct mu_option group_b[] = { ...@@ -63,8 +63,51 @@ struct mu_option group_b[] = {
63 63
64 struct mu_option *optv[] = { group_a, group_b, NULL }; 64 struct mu_option *optv[] = { group_a, group_b, NULL };
65 65
66 static void
67 version_func (FILE *fp)
68 {
69 fputs ("version hook called\n", fp);
70 }
71
66 #define S(s) ((s)?(s):"(null)") 72 #define S(s) ((s)?(s):"(null)")
67 73
74 struct parseopt_param
75 {
76 char *name;
77 int flag;
78 mu_c_type_t type;
79 size_t off;
80 };
81
82 static struct parseopt_param parseopt_param[] = {
83 { "MU_PARSEOPT_ARGV0", MU_PARSEOPT_ARGV0, mu_c_void },
84 { "MU_PARSEOPT_IGNORE_ERRORS", MU_PARSEOPT_IGNORE_ERRORS, mu_c_void },
85 { "MU_PARSEOPT_IN_ORDER", MU_PARSEOPT_IN_ORDER, mu_c_void },
86 { "MU_PARSEOPT_NO_STDOPT", MU_PARSEOPT_NO_STDOPT, mu_c_void },
87 { "MU_PARSEOPT_NO_ERREXIT", MU_PARSEOPT_NO_ERREXIT, mu_c_void },
88 { "MU_PARSEOPT_IMMEDIATE", MU_PARSEOPT_IMMEDIATE, mu_c_void },
89 { "MU_PARSEOPT_NO_SORT", MU_PARSEOPT_NO_SORT, mu_c_void },
90
91 { "MU_PARSEOPT_PROG_NAME", MU_PARSEOPT_PROG_NAME,
92 mu_c_string, mu_offsetof(struct mu_parseopt, po_prog_name) },
93 { "MU_PARSEOPT_PROG_DOC", MU_PARSEOPT_PROG_DOC,
94 mu_c_string, mu_offsetof(struct mu_parseopt, po_prog_doc) },
95 { "MU_PARSEOPT_PROG_ARGS", MU_PARSEOPT_PROG_ARGS,
96 mu_c_string, mu_offsetof(struct mu_parseopt, po_prog_args) },
97 { "MU_PARSEOPT_BUG_ADDRESS", MU_PARSEOPT_BUG_ADDRESS,
98 mu_c_string, mu_offsetof(struct mu_parseopt, po_bug_address) },
99 { "MU_PARSEOPT_PACKAGE_NAME", MU_PARSEOPT_PACKAGE_NAME,
100 mu_c_string, mu_offsetof(struct mu_parseopt, po_package_name) },
101 { "MU_PARSEOPT_PACKAGE_URL", MU_PARSEOPT_PACKAGE_URL,
102 mu_c_string, mu_offsetof(struct mu_parseopt, po_package_url) },
103 { "MU_PARSEOPT_EXTRA_INFO", MU_PARSEOPT_EXTRA_INFO,
104 mu_c_string, mu_offsetof(struct mu_parseopt, po_extra_info) },
105 { "MU_PARSEOPT_EXIT_ERROR", MU_PARSEOPT_EXIT_ERROR,
106 mu_c_int, mu_offsetof(struct mu_parseopt, po_exit_error) },
107 { "MU_PARSEOPT_VERSION_HOOK", MU_PARSEOPT_VERSION_HOOK, mu_c_void },
108 { NULL }
109 };
110
68 int 111 int
69 main (int argc, char *argv[]) 112 main (int argc, char *argv[])
70 { 113 {
...@@ -79,16 +122,29 @@ main (int argc, char *argv[]) ...@@ -79,16 +122,29 @@ main (int argc, char *argv[])
79 flags = MU_PARSEOPT_DEFAULT; 122 flags = MU_PARSEOPT_DEFAULT;
80 else 123 else
81 { 124 {
82 if (getenv ("MU_PARSEOPT_IN_ORDER")) 125 struct parseopt_param *param;
83 flags |= MU_PARSEOPT_IN_ORDER; 126 for (param = parseopt_param; param->name; param++)
84 if (getenv ("MU_PARSEOPT_IGNORE_ERRORS")) 127 {
85 flags |= MU_PARSEOPT_IGNORE_ERRORS; 128 char *val = getenv (param->name);
86 if (getenv ("MU_PARSEOPT_IN_ORDER")) 129 if (val)
87 flags |= MU_PARSEOPT_IN_ORDER; 130 {
88 if (getenv ("MU_PARSEOPT_NO_ERREXIT")) 131 flags |= param->flag;
89 flags |= MU_PARSEOPT_NO_ERREXIT; 132 if (param->type != mu_c_void)
90 if (getenv ("MU_PARSEOPT_NO_STDOPT")) 133 {
91 flags |= MU_PARSEOPT_NO_STDOPT; 134 char *errmsg;
135 int rc = mu_str_to_c (val, param->type,
136 ((char*)&po + param->off),
137 &errmsg);
138 if (rc)
139 {
140 fprintf (stderr, "envvar %s: %s\n",
141 param->name, errmsg ? errmsg : mu_strerror (rc));
142 }
143 }
144 }
145 }
146 if (flags & MU_PARSEOPT_VERSION_HOOK)
147 po.po_version_hook = version_func;
92 } 148 }
93 149
94 rc = mu_parseopt (&po, argc, argv, optv, flags); 150 rc = mu_parseopt (&po, argc, argv, optv, flags);
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([empty command line]) 17 AT_SETUP([empty command line])
18 AT_KEYWORDS([parseopt parseopt00]) 18 AT_KEYWORDS([parseopt parseopt00])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt 21 parseopt
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([command line without options]) 17 AT_SETUP([command line without options])
18 AT_KEYWORDS([parseopt parseopt_noopt parseopt01]) 18 AT_KEYWORDS([parseopt parseopt_noopt parseopt01])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt command line arguments 21 parseopt command line arguments
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([short options]) 17 AT_SETUP([short options])
18 AT_KEYWORDS([parseopt parseopt_short parseopt02]) 18 AT_KEYWORDS([parseopt parseopt_short parseopt02])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt -f file -x -a -d command line arguments 21 parseopt -f file -x -a -d command line arguments
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([short option with argument]) 17 AT_SETUP([short option with argument])
18 AT_KEYWORDS([parseopt parseopt_short parseopt_short_arg parseopt03]) 18 AT_KEYWORDS([parseopt parseopt_short parseopt_short_arg parseopt03])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt -ffile -x -a -d command line arguments 21 parseopt -ffile -x -a -d command line arguments
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([short option with optional argument]) 17 AT_SETUP([short option with optional argument])
18 AT_KEYWORDS([parseopt parseopt_short parseopt_short_opt_arg parseopt04]) 18 AT_KEYWORDS([parseopt parseopt_short parseopt_short_opt_arg parseopt04])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt -ofile command line arguments 21 parseopt -ofile command line arguments
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([short option without optional argument]) 17 AT_SETUP([short option without optional argument])
18 AT_KEYWORDS([parseopt parseopt_short parseopt_short_opt_noarg parseopt05]) 18 AT_KEYWORDS([parseopt parseopt_short parseopt_short_opt_noarg parseopt05])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt -o command line arguments 21 parseopt -o command line arguments
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([incremental short option]) 17 AT_SETUP([incremental short option])
18 AT_KEYWORDS([parseopt parseopt_short parseopt_short_incr parseopt06]) 18 AT_KEYWORDS([parseopt parseopt_short parseopt_short_incr parseopt06])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt -d -d command line arguments 21 parseopt -d -d command line arguments
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([short option clustering]) 17 AT_SETUP([short option clustering])
18 AT_KEYWORDS([parseopt parseopt_short parseopt_short_cluster parseopt07]) 18 AT_KEYWORDS([parseopt parseopt_short parseopt_short_cluster parseopt07])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt -xffile -dado10 command line arguments 21 parseopt -xffile -dado10 command line arguments
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([long options]) 17 AT_SETUP([long options])
18 AT_KEYWORDS([parseopt parseopt_long parseopt08]) 18 AT_KEYWORDS([parseopt parseopt_long parseopt08])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt --file=file --all command line arguments 21 parseopt --file=file --all command line arguments
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([long option with argument]) 17 AT_SETUP([long option with argument])
18 AT_KEYWORDS([parseopt parseopt_long parseopt_long_arg parseopt09]) 18 AT_KEYWORDS([parseopt parseopt_long parseopt_long_arg parseopt09])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt --file file command line arguments 21 parseopt --file file command line arguments
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([long option with optional argument]) 17 AT_SETUP([long option with optional argument])
18 AT_KEYWORDS([parseopt parseopt_long parseopt_long_opt_arg parseopt10]) 18 AT_KEYWORDS([parseopt parseopt_long parseopt_long_opt_arg parseopt10])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt --optional=file command line arguments 21 parseopt --optional=file command line arguments
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([long option without optional argument]) 17 AT_SETUP([long option without optional argument])
18 AT_KEYWORDS([parseopt parseopt_long parseopt_long_opt_noarg parseopt11]) 18 AT_KEYWORDS([parseopt parseopt_long parseopt_long_opt_noarg parseopt11])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt --optional command line arguments 21 parseopt --optional command line arguments
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([incremental long option]) 17 AT_SETUP([incremental long option])
18 AT_KEYWORDS([parseopt parseopt_long parseopt_long_incr parseopt12]) 18 AT_KEYWORDS([parseopt parseopt_long parseopt_long_incr parseopt12])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt --debug --debug command line arguments 21 parseopt --debug --debug command line arguments
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([abbreviated long options]) 17 AT_SETUP([abbreviated long options])
18 AT_KEYWORDS([parseopt parseopt_long parseopt_long_abbr parseopt13]) 18 AT_KEYWORDS([parseopt parseopt_long parseopt_long_abbr parseopt13])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt --fil=file --fin=Word command line arguments 21 parseopt --fil=file --fin=Word command line arguments
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([ambiguous abbreviated long options]) 17 AT_SETUP([ambiguous abbreviated long options])
18 AT_KEYWORDS([parseopt parseopt_long parseopt_long_abbr parseopt_long_ambig parseopt14]) 18 AT_KEYWORDS([parseopt parseopt_long parseopt_long_abbr parseopt_long_ambig parseopt14])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt --fi=file --fi=Word command line arguments 21 parseopt --fi=file --fi=Word command line arguments
22 ], 22 ],
23 [1], 23 [1],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 AT_SETUP([mixed long and short options]) 17 AT_SETUP([mixed long and short options])
18 AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt15.at]) 18 AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt15.at])
19 AT_CHECK([ 19 AT_CHECK([
20 MU_PARSEOPT_DEFAULT=1 20 PARSEOPT_DEFAULT
21 parseopt --file=filename -o -xa --find word -j10 command line arguments 21 parseopt --file=filename -o -xa --find word -j10 command line arguments
22 ], 22 ],
23 [0], 23 [0],
......
...@@ -15,8 +15,9 @@ ...@@ -15,8 +15,9 @@
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. 15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16 16
17 AT_SETUP([option aliases]) 17 AT_SETUP([option aliases])
18 AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt16.at]) 18 AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_alias parseopt16.at])
19 AT_CHECK([ 19 AT_CHECK([
20 PARSEOPT_DEFAULT
20 parseopt -vvv 21 parseopt -vvv
21 ], 22 ],
22 [0], 23 [0],
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 AT_SETUP([argument permutation]) 17 AT_SETUP([argument permutation])
18 AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt17.at]) 18 AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt17.at])
19 AT_CHECK([ 19 AT_CHECK([
20 PARSEOPT_DEFAULT
20 parseopt more --file=file arguments follow -x -o options 21 parseopt more --file=file arguments follow -x -o options
21 ], 22 ],
22 [0], 23 [0],
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 AT_SETUP([double-dash]) 17 AT_SETUP([double-dash])
18 AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt18.at]) 18 AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt18.at])
19 AT_CHECK([ 19 AT_CHECK([
20 PARSEOPT_DEFAULT
20 parseopt -x --file=foobar -- -a --optional arg 21 parseopt -x --file=foobar -- -a --optional arg
21 ], 22 ],
22 [0], 23 [0],
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 AT_SETUP([double-dash with permutation]) 17 AT_SETUP([double-dash with permutation])
18 AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt19.at]) 18 AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt19.at])
19 AT_CHECK([ 19 AT_CHECK([
20 PARSEOPT_DEFAULT
20 parseopt -x more --file=foobar -- -a --optional arg 21 parseopt -x more --file=foobar -- -a --optional arg
21 ], 22 ],
22 [0], 23 [0],
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 AT_SETUP([short option without required argument]) 17 AT_SETUP([short option without required argument])
18 AT_KEYWORDS([parseopt parseopt_short parseopt_short_noarg parseopt20]) 18 AT_KEYWORDS([parseopt parseopt_short parseopt_short_noarg parseopt20])
19 AT_CHECK([ 19 AT_CHECK([
20 PARSEOPT_DEFAULT
20 parseopt -f 21 parseopt -f
21 ], 22 ],
22 [1], 23 [1],
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 AT_SETUP([long option without required argument]) 17 AT_SETUP([long option without required argument])
18 AT_KEYWORDS([parseopt parseopt_long parseopt_long_noarg parseopt21]) 18 AT_KEYWORDS([parseopt parseopt_long parseopt_long_noarg parseopt21])
19 AT_CHECK([ 19 AT_CHECK([
20 PARSEOPT_DEFAULT
20 parseopt --file 21 parseopt --file
21 ], 22 ],
22 [1], 23 [1],
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 AT_SETUP([unrecognized option]) 17 AT_SETUP([unrecognized option])
18 AT_KEYWORDS([parseopt parseopt_short parseopt_short_unrecognized parseopt22]) 18 AT_KEYWORDS([parseopt parseopt_short parseopt_short_unrecognized parseopt22])
19 AT_CHECK([ 19 AT_CHECK([
20 PARSEOPT_DEFAULT
20 parseopt -X 21 parseopt -X
21 ], 22 ],
22 [1], 23 [1],
......
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_SETUP([in order parsing])
18 AT_KEYWORDS([parseopt parseopt_in_order parseopt23])
19 AT_CHECK([
20 PARSEOPT_DEFAULT
21 MU_PARSEOPT_IN_ORDER=1 parseopt --file=filename more -a -x arguments
22 ],
23 [0],
24 [rc=0
25 file_name=filename
26 opt_value=initial
27 x_option=0
28 a_option=0
29 find_value=(null)
30 d_option=0
31 jobs=0
32 argv:
33 0: more
34 1: -a
35 2: -x
36 3: arguments
37 ])
38 AT_CLEANUP
39
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_SETUP([MU_PARSEOPT_VERSION_HOOK])
18 AT_KEYWORDS([parseopt MU_PARSEOPT_VERSION_HOOK parseopt25])
19 AT_CHECK([
20 PARSEOPT_DEFAULT
21 MU_PARSEOPT_VERSION_HOOK=1 parseopt -V
22 ],
23 [0],
24 [version hook called
25 ])
26 AT_CLEANUP
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_SETUP([standard help output])
18 AT_KEYWORDS([parseopt parseopt_help parseopt_help00])
19 AT_CHECK([
20 PARSEOPT_DEFAULT
21 parseopt --help
22 ],
23 [0],
24 [[Usage: parseopt [OPTION]...
25
26 Group A
27 -a, --all no arguments to this one
28 -f, --file=FILE set file name
29 -o, --optional[=FILE] optional argument
30 -x short-only option
31
32 Group B
33 -F, --find=VALUE find VALUE
34 -d, -v, --debug, --verbose another option
35 -j, --jobs=N sets numeric value
36
37 -?, --help give this help list
38 --usage give a short usage message
39
40 Mandatory or optional arguments to long options are also mandatory or optional
41 for any corresponding short options.
42
43 ]])
44 AT_CLEANUP
45
46
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_SETUP([standard usage output])
18 AT_KEYWORDS([parseopt parseopt_help parseopt_help00])
19 AT_CHECK([
20 PARSEOPT_DEFAULT
21 parseopt --usage
22 ],
23 [0],
24 [[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N] [-o FILE] [--all]
25 [--debug] [--file=FILE] [--find=VALUE] [--help] [--jobs=N]
26 [--optional=FILE] [--usage] [--verbose]
27 ]])
28 AT_CLEANUP
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_SETUP([MU_PARSEOPT_PROG_NAME])
18 AT_KEYWORDS([parseopt parseopt_help parseopt_help02])
19 AT_CHECK([
20 PARSEOPT_DEFAULT
21 MU_PARSEOPT_PROG_NAME=newname parseopt --help
22 ],
23 [0],
24 [[Usage: newname [OPTION]...
25
26 Group A
27 -a, --all no arguments to this one
28 -f, --file=FILE set file name
29 -o, --optional[=FILE] optional argument
30 -x short-only option
31
32 Group B
33 -F, --find=VALUE find VALUE
34 -d, -v, --debug, --verbose another option
35 -j, --jobs=N sets numeric value
36
37 -?, --help give this help list
38 --usage give a short usage message
39
40 Mandatory or optional arguments to long options are also mandatory or optional
41 for any corresponding short options.
42
43 ]])
44 AT_CLEANUP
45
46
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_SETUP([MU_PARSEOPT_PROG_DOC])
18 AT_KEYWORDS([parseopt parseopt_help parseopt_help03])
19 AT_CHECK([
20 unset ARGP_HELP_FMT
21 MU_PARSEOPT_PROG_DOC="Tests option parsing" parseopt --help
22 ],
23 [0],
24 [[Usage: parseopt [OPTION]...
25 Tests option parsing
26
27 Group A
28 -a, --all no arguments to this one
29 -f, --file=FILE set file name
30 -o, --optional[=FILE] optional argument
31 -x short-only option
32
33 Group B
34 -F, --find=VALUE find VALUE
35 -d, -v, --debug, --verbose another option
36 -j, --jobs=N sets numeric value
37
38 -?, --help give this help list
39 --usage give a short usage message
40
41 Mandatory or optional arguments to long options are also mandatory or optional
42 for any corresponding short options.
43
44 ]])
45 AT_CLEANUP
46
47
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_SETUP([MU_PARSEOPT_PROG_ARGS])
18 AT_KEYWORDS([parseopt parseopt_help parseopt_help04])
19 AT_CHECK([
20 PARSEOPT_DEFAULT
21 MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS" parseopt --help
22 ],
23 [0],
24 [Usage: parseopt [[OPTION]]... SOME MORE ARGS
25
26 Group A
27 -a, --all no arguments to this one
28 -f, --file=FILE set file name
29 -o, --optional[[=FILE]] optional argument
30 -x short-only option
31
32 Group B
33 -F, --find=VALUE find VALUE
34 -d, -v, --debug, --verbose another option
35 -j, --jobs=N sets numeric value
36
37 -?, --help give this help list
38 --usage give a short usage message
39
40 Mandatory or optional arguments to long options are also mandatory or optional
41 for any corresponding short options.
42
43 ])
44 AT_CLEANUP
45
46
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_SETUP([MU_PARSEOPT_BUG_ADDRESS])
18 AT_KEYWORDS([parseopt parseopt_help parseopt_help05])
19 AT_CHECK([
20 PARSEOPT_DEFAULT
21 MU_PARSEOPT_BUG_ADDRESS='<gray@gnu.org>' parseopt --help
22 ],
23 [0],
24 [Usage: parseopt [[OPTION]]...
25
26 Group A
27 -a, --all no arguments to this one
28 -f, --file=FILE set file name
29 -o, --optional[[=FILE]] optional argument
30 -x short-only option
31
32 Group B
33 -F, --find=VALUE find VALUE
34 -d, -v, --debug, --verbose another option
35 -j, --jobs=N sets numeric value
36
37 -?, --help give this help list
38 --usage give a short usage message
39
40 Mandatory or optional arguments to long options are also mandatory or optional
41 for any corresponding short options.
42
43 Report bugs to <gray@gnu.org>.
44 ])
45 AT_CLEANUP
46
47
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_SETUP([MU_PARSEOPT_PACKAGE_NAME and MU_PARSEOPT_PACKAGE_URL])
18 AT_KEYWORDS([parseopt parseopt_help parseopt_help06])
19 AT_CHECK([
20 PARSEOPT_DEFAULT
21 MU_PARSEOPT_PACKAGE_NAME='GNU Mailutils' MU_PARSEOPT_PACKAGE_URL='http://mailutils.org' parseopt --help
22 ],
23 [0],
24 [[Usage: parseopt [OPTION]...
25
26 Group A
27 -a, --all no arguments to this one
28 -f, --file=FILE set file name
29 -o, --optional[=FILE] optional argument
30 -x short-only option
31
32 Group B
33 -F, --find=VALUE find VALUE
34 -d, -v, --debug, --verbose another option
35 -j, --jobs=N sets numeric value
36
37 -?, --help give this help list
38 --usage give a short usage message
39
40 Mandatory or optional arguments to long options are also mandatory or optional
41 for any corresponding short options.
42
43 GNU Mailutils home page: <http://mailutils.org>
44 ]])
45 AT_CLEANUP
46
47
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_SETUP([all data])
18 AT_KEYWORDS([parseopt parseopt_help parseopt_help07])
19 AT_CHECK([
20 PARSEOPT_DEFAULT
21 MU_PARSEOPT_PROG_DOC="Tests option parsing"\
22 MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS"\
23 MU_PARSEOPT_BUG_ADDRESS='<gray@gnu.org>'\
24 MU_PARSEOPT_PACKAGE_NAME='GNU Mailutils'\
25 MU_PARSEOPT_PACKAGE_URL='http://mailutils.org'\
26 MU_PARSEOPT_EXTRA_INFO='General help using GNU software: <http://www.gnu.org/gethelp/>'\
27 parseopt --help
28 ],
29 [0],
30 [[Usage: parseopt [OPTION]... SOME MORE ARGS
31 Tests option parsing
32
33 Group A
34 -a, --all no arguments to this one
35 -f, --file=FILE set file name
36 -o, --optional[=FILE] optional argument
37 -x short-only option
38
39 Group B
40 -F, --find=VALUE find VALUE
41 -d, -v, --debug, --verbose another option
42 -j, --jobs=N sets numeric value
43
44 -?, --help give this help list
45 --usage give a short usage message
46
47 Mandatory or optional arguments to long options are also mandatory or optional
48 for any corresponding short options.
49
50 Report bugs to <gray@gnu.org>.
51 GNU Mailutils home page: <http://mailutils.org>
52 General help using GNU software: <http://www.gnu.org/gethelp/>
53 ]])
54 AT_CLEANUP
55
56
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_SETUP([ARGP_HELP_FMT compatibility])
18 AT_KEYWORDS([parseopt parseopt_help ARGP_HELP_FMT parseopt_help08])
19 AT_CHECK([
20 PARSEOPT_DEFAULT
21 ARGP_HELP_FMT=dup-args,no-dup-args-note,short-opt-col=1,opt-doc-col=32,header-col=10\
22 parseopt --help
23 ],
24 [0],
25 [[Usage: parseopt [OPTION]...
26
27 Group A
28 -a, --all no arguments to this one
29 -f FILE, --file=FILE set file name
30 -o[FILE], --optional[=FILE] optional argument
31 -x short-only option
32
33 Group B
34 -F VALUE, --find=VALUE find VALUE
35 -d, -v, --debug, --verbose another option
36 -j N, --jobs=N sets numeric value
37
38 -?, --help give this help list
39 --usage give a short usage message
40
41 ]])
42 AT_CLEANUP
43
44
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_SETUP([ARGP_HELP_FMT usage compatibility])
18 AT_KEYWORDS([parseopt parseopt_help ARGP_HELP_FMT parseopt_help09])
19 AT_CHECK([
20 PARSEOPT_DEFAULT
21 ARGP_HELP_FMT=rmargin=62,usage-indent=1\
22 parseopt --usage
23 ],
24 [0],
25 [[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N]
26 [-o FILE] [--all] [--debug] [--file=FILE] [--find=VALUE]
27 [--help] [--jobs=N] [--optional=FILE] [--usage] [--verbose]
28 ]])
29 AT_CLEANUP
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_SETUP([MU_PARSEOPT_VERSION_HOOK usage output])
18 AT_KEYWORDS([parseopt MU_PARSEOPT_VERSION_HOOK parseopt26])
19 AT_CHECK([
20 PARSEOPT_DEFAULT
21 MU_PARSEOPT_VERSION_HOOK=1 parseopt --usage
22 ],
23 [0],
24 [[Usage: parseopt [-advVx?] [-f FILE] [-F VALUE] [-j N] [-o FILE] [--all]
25 [--debug] [--file=FILE] [--find=VALUE] [--help] [--jobs=N]
26 [--optional=FILE] [--usage] [--verbose] [--version]
27 ]])
28 AT_CLEANUP
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2016 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_SETUP([MU_PARSEOPT_VERSION_HOOK help output])
18 AT_KEYWORDS([parseopt MU_PARSEOPT_VERSION_HOOK help])
19 AT_CHECK([
20 PARSEOPT_DEFAULT
21 MU_PARSEOPT_VERSION_HOOK=1 parseopt --help
22 ],
23 [0],
24 [[Usage: parseopt [OPTION]...
25
26 Group A
27 -a, --all no arguments to this one
28 -f, --file=FILE set file name
29 -o, --optional[=FILE] optional argument
30 -x short-only option
31
32 Group B
33 -F, --find=VALUE find VALUE
34 -d, -v, --debug, --verbose another option
35 -j, --jobs=N sets numeric value
36
37 -?, --help give this help list
38 --usage give a short usage message
39 -V, --version print program version
40
41 Mandatory or optional arguments to long options are also mandatory or optional
42 for any corresponding short options.
43
44 ]])
45 AT_CLEANUP
...@@ -57,6 +57,24 @@ AT_BANNER([Conversions]) ...@@ -57,6 +57,24 @@ AT_BANNER([Conversions])
57 m4_include([strtoc.at]) 57 m4_include([strtoc.at])
58 58
59 AT_BANNER([Command line parser]) 59 AT_BANNER([Command line parser])
60 m4_define([PARSEOPT_DEFAULT],[
61 unset ARGP_HELP_FMT
62 unset MU_PARSEOPT_ARGV0
63 unset MU_PARSEOPT_IGNORE_ERRORS
64 unset MU_PARSEOPT_IN_ORDER
65 unset MU_PARSEOPT_NO_STDOPT
66 unset MU_PARSEOPT_NO_ERREXIT
67 unset MU_PARSEOPT_IMMEDIATE
68 unset MU_PARSEOPT_NO_SORT
69
70 unset MU_PARSEOPT_PROG_NAME
71 unset MU_PARSEOPT_PROG_DOC
72 unset MU_PARSEOPT_PROG_ARGS
73 unset MU_PARSEOPT_BUG_ADDRESS
74 unset MU_PARSEOPT_PACKAGE_NAME
75 unset MU_PARSEOPT_PACKAGE_URL
76 ])
77
60 m4_include([parseopt00.at]) 78 m4_include([parseopt00.at])
61 m4_include([parseopt01.at]) 79 m4_include([parseopt01.at])
62 m4_include([parseopt02.at]) 80 m4_include([parseopt02.at])
...@@ -80,6 +98,23 @@ m4_include([parseopt19.at]) ...@@ -80,6 +98,23 @@ m4_include([parseopt19.at])
80 m4_include([parseopt20.at]) 98 m4_include([parseopt20.at])
81 m4_include([parseopt21.at]) 99 m4_include([parseopt21.at])
82 m4_include([parseopt22.at]) 100 m4_include([parseopt22.at])
101 m4_include([parseopt23.at])
102 m4_include([parseopt24.at])
103 m4_include([parseopt25.at])
104
105 AT_BANNER([Command line help output])
106 m4_include([parseopt_help00.at])
107 m4_include([parseopt_help01.at])
108 m4_include([parseopt_help02.at])
109 m4_include([parseopt_help03.at])
110 m4_include([parseopt_help04.at])
111 m4_include([parseopt_help05.at])
112 m4_include([parseopt_help06.at])
113 m4_include([parseopt_help07.at])
114 m4_include([parseopt_help08.at])
115 m4_include([parseopt_help09.at])
116 m4_include([parseopt_help10.at])
117 m4_include([parseopt_help11.at])
83 118
84 AT_BANNER([Standard streams]) 119 AT_BANNER([Standard streams])
85 m4_include([strin.at]) 120 m4_include([strin.at])
......