30 const char *argp_program_version =
32 const char *argp_program_bug_address =
33 "<bug-gnu-utils@prep.ai.mit.edu>";
37 "Argp example #4 -- a program with somewhat more complicated\
39 \vThis part of the documentation comes *after* the options;\
40 note that the text is automatically filled, but it's possible\
41 to force a line-break, e.g.\n<-- here.";
44 static char args_doc[] =
"ARG1 [STRING...]";
51 {
"verbose",
'v', 0, 0,
"Produce verbose output", 0},
52 {
"quiet",
'q', 0, 0,
"Don't produce any output", 0},
53 {
"silent",
's', 0, OPTION_ALIAS, 0, 0},
54 {
"output",
'o',
"FILE", 0,
55 "Output to FILE instead of standard output", 0},
57 {0,0,0,0,
"The following options should be grouped together:", 0},
58 {
"repeat",
'r',
"COUNT", OPTION_ARG_OPTIONAL,
59 "Repeat the output COUNT (default 10) times", 0},
60 {
"abort", OPT_ABORT, 0, 0,
"Abort before showing any output", 0},
70 int silent, verbose, abort;
77 parse_opt (
int key,
char *arg,
struct argp_state *state)
95 arguments->repeat_count = arg ? atoi (arg) : 10;
101 case ARGP_KEY_NO_ARGS:
120 arguments->strings = &state->argv[state->next];
121 state->next = state->argc;
126 return ARGP_ERR_UNKNOWN;
132 static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0};
134 int main (
int argc,
char **argv)
154 fprintf(stderr,
"ex4: ABORTED\n");
158 for (i = 0; i <
arguments.repeat_count; i++)
161 printf (
"STRINGS = ");
163 printf (j == 0 ?
"%s" :
", %s",
arguments.strings[j]);
165 printf (
"OUTPUT_FILE = %s\nVERBOSE = %s\nSILENT = %s\n",