msg_338.c revision 1.4 1 /* $NetBSD: msg_338.c,v 1.4 2021/08/22 22:09:57 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
55 void usage(void);
56
57 /* Seen in usr.bin/ftp/main.c 1.127 from 2020-07-18. */
58 int
59 question_option(int argc, char **argv)
60 {
61 int c;
62
63 /* FIXME */
64 /* expect+1: warning: option '?' should be handled in the switch [338] */
65 while ((c = getopt(argc, argv, "?x")) != -1) {
66 switch (c) {
67 case 'x':
68 break;
69 case '?':
70 usage();
71 return 0;
72 default:
73 usage();
74 return 1;
75 }
76 }
77 return 0;
78 }
79