3 /* Flag set by @samp{--verbose}. */
4 static int verbose_flag
;
15 static struct option long_options
[] =
17 /* These options set a flag. */
18 {"verbose", 0, &verbose_flag
, 1},
19 {"brief", 0, &verbose_flag
, 0},
20 /* These options don't set a flag.
21 We distinguish them by their indices. */
29 /* @code{getopt_long} stores the option index here. */
32 c
= getopt_long (argc
, argv
, "abc:d:",
33 long_options
, &option_index
);
35 /* Detect the end of the options. */
42 /* If this option set a flag, do nothing else now. */
43 if (long_options
[option_index
].flag
!= 0)
45 printf ("option %s", long_options
[option_index
].name
);
47 printf (" with arg %s", optarg
);
60 printf ("option -c with value `%s'\n", optarg
);
64 printf ("option -d with value `%s'\n", optarg
);
68 /* @code{getopt_long} already printed an error message. */
76 /* Instead of reporting @samp{--verbose}
77 and @samp{--brief} as they are encountered,
78 we report the final status resulting from them. */
80 puts ("verbose flag is set");
82 /* Print any remaining command line arguments (not options). */
85 printf ("non-option ARGV-elements: ");
87 printf ("%s ", argv
[optind
++]);