7 main (int argc
, char **argv
)
9 static const struct option options
[] =
11 {"required", required_argument
, NULL
, 'r'},
12 {"optional", optional_argument
, NULL
, 'o'},
13 {"none", no_argument
, NULL
, 'n'},
14 {"color", no_argument
, NULL
, 'C'},
15 {"colour", no_argument
, NULL
, 'C'},
28 while ((c
= getopt_long (argc
, argv
, "abc:", options
, NULL
)) >= 0)
44 fputs ("Unknown option.\n", stderr
);
47 fprintf (stderr
, "This should never happen!\n");
51 printf ("--required %s\n", optarg
);
52 result
|= strcmp (optarg
, "foobar") != 0;
55 printf ("--optional %s\n", optarg
);
56 result
|= optarg
== NULL
|| strcmp (optarg
, "bazbug") != 0;
64 printf ("aflag = %d, bflag = %d, cvalue = %s, Cflags = %d, nflag = %d\n",
65 aflag
, bflag
, cvalue
, Cflag
, nflag
);
67 result
|= (aflag
!= 1 || bflag
!= 1 || cvalue
== NULL
68 || strcmp (cvalue
, "foobar") != 0 || Cflag
!= 3 || nflag
!= 1);
70 for (index
= optind
; index
< argc
; index
++)
71 printf ("Non-option argument %s\n", argv
[index
]);
73 result
|= optind
+ 1 != argc
|| strcmp (argv
[optind
], "random") != 0;