msg_338.c revision 1.3 1 /* $NetBSD: msg_338.c,v 1.3 2021/04/05 01:35:34 rillig Exp $ */
2 # 3 "msg_338.c"
3
4 // Test for message: option '%c' should be handled in the switch [338]
5
6 int getopt(int, char *const *, const char *);
7 extern char *optarg;
8
9 int
10 main(int argc, char **argv)
11 {
12 int o;
13
14 while ((o = getopt(argc, argv, "a:bc:d")) != -1) { /* expect: 338 *//* expect: 338 */
15 switch (o) {
16 case 'a':
17 break;
18 case 'b':
19 /*
20 * The following while loop must not finish the check
21 * for the getopt options.
22 */
23 while (optarg[0] != '\0')
24 optarg++;
25 break;
26 case 'e': /* expect: option 'e' should be listed */
27 break;
28 case 'f': /* expect: option 'f' should be listed */
29 /*
30 * The case labels in nested switch statements are
31 * ignored by the check for getopt options.
32 */
33 switch (optarg[0]) {
34 case 'X':
35 break;
36 }
37 break;
38 case '?':
39 default:
40 break;
41 }
42 }
43
44 /* A while loop that is not related to getopt is simply skipped. */
45 while (o != 0) {
46 switch (o) {
47 case '?':
48 o = ':';
49 }
50 }
51
52 return 0;
53 }
54