FreeBSDのソースコードをSubverisonで取ってきて読んでいるんですけど、lib/libc/stdlib/getopt_long.cにある、getopt_internal()の対になって終わる、最後の"}"の括弧がないのですが、どうゆう意味があるんでしょうか?詳しい方誰か教えてください。よろしくお願い申し上げます。
versionは12.1です。
c
1static int 2getopt_internal(int nargc, char * const *nargv, const char *options, 3 const struct option *long_options, int *idx, int flags) 4{ 5 char *oli; /* option letter list index */ 6 int optchar, short_too; 7 static int posixly_correct = -1; 8 9 if (options == NULL) 10 return (-1); 11 12 /* 13 * XXX Some GNU programs (like cvs) set optind to 0 instead of 14 * XXX using optreset. Work around this braindamage. 15 */ 16 if (optind == 0) 17 optind = optreset = 1; 18 19 /* 20 * Disable GNU extensions if POSIXLY_CORRECT is set or options 21 * string begins with a '+'. 22 */ 23 if (posixly_correct == -1 || optreset) 24 posixly_correct = (getenv("POSIXLY_CORRECT") != NULL); 25 if (*options == '-') 26 flags |= FLAG_ALLARGS; 27 else if (posixly_correct || *options == '+') 28 flags &= ~FLAG_PERMUTE; 29 if (*options == '+' || *options == '-') 30 options++; 31 32 optarg = NULL; 33 if (optreset) 34 nonopt_start = nonopt_end = -1; 35start: 36 if (optreset || !*place) { /* update scanning pointer */ 37 optreset = 0; 38 if (optind >= nargc) { /* end of argument vector */ 39 place = EMSG; 40 if (nonopt_end != -1) { 41 /* do permutation, if we have to */ 42 permute_args(nonopt_start, nonopt_end, 43 optind, nargv); 44 optind -= nonopt_end - nonopt_start; 45 } 46 else if (nonopt_start != -1) { 47 /* 48 * If we skipped non-options, set optind 49 * to the first of them. 50 */ 51 optind = nonopt_start; 52 } 53 nonopt_start = nonopt_end = -1; 54 return (-1); 55 } 56 if (*(place = nargv[optind]) != '-' || 57#ifdef GNU_COMPATIBLE 58 place[1] == '\0') { 59#else 60 (place[1] == '\0' && strchr(options, '-') == NULL)) { 61#endif 62 place = EMSG; /* found non-option */ 63 if (flags & FLAG_ALLARGS) { 64 /* 65 * GNU extension: 66 * return non-option as argument to option 1 67 */ 68 optarg = nargv[optind++]; 69 return (INORDER); 70 } 71 if (!(flags & FLAG_PERMUTE)) { 72 /* 73 * If no permutation wanted, stop parsing 74 * at first non-option. 75 */ 76 return (-1); 77 } 78 /* do permutation */ 79 if (nonopt_start == -1) 80 nonopt_start = optind; 81 else if (nonopt_end != -1) { 82 permute_args(nonopt_start, nonopt_end, 83 optind, nargv); 84 nonopt_start = optind - 85 (nonopt_end - nonopt_start); 86 nonopt_end = -1; 87 } 88 optind++; 89 /* process next argument */ 90 goto start; 91 } 92 if (nonopt_start != -1 && nonopt_end == -1) 93 nonopt_end = optind; 94 95 /* 96 * If we have "-" do nothing, if "--" we are done. 97 */ 98 if (place[1] != '\0' && *++place == '-' && place[1] == '\0') { 99 optind++; 100 place = EMSG; 101 /* 102 * We found an option (--), so if we skipped 103 * non-options, we have to permute. 104 */ 105 if (nonopt_end != -1) { 106 permute_args(nonopt_start, nonopt_end, 107 optind, nargv); 108 optind -= nonopt_end - nonopt_start; 109 } 110 nonopt_start = nonopt_end = -1; 111 return (-1); 112 } 113 } 114 115 /* 116 * Check long options if: 117 * 1) we were passed some 118 * 2) the arg is not just "-" 119 * 3) either the arg starts with -- we are getopt_long_only() 120 */ 121 if (long_options != NULL && place != nargv[optind] && 122 (*place == '-' || (flags & FLAG_LONGONLY))) { 123 short_too = 0; 124#ifdef GNU_COMPATIBLE 125 dash_prefix = D_PREFIX; 126#endif 127 if (*place == '-') { 128 place++; /* --foo long option */ 129 if (*place == '\0') 130 return (BADARG); /* malformed option */ 131#ifdef GNU_COMPATIBLE 132 dash_prefix = DD_PREFIX; 133#endif 134 } else if (*place != ':' && strchr(options, *place) != NULL) 135 short_too = 1; /* could be short option too */ 136 137 optchar = parse_long_options(nargv, options, long_options, 138 idx, short_too, flags); 139 if (optchar != -1) { 140 place = EMSG; 141 return (optchar); 142 } 143 } 144 145 if ((optchar = (int)*place++) == (int)':' || 146 (optchar == (int)'-' && *place != '\0') || 147 (oli = strchr(options, optchar)) == NULL) { 148 /* 149 * If the user specified "-" and '-' isn't listed in 150 * options, return -1 (non-option) as per POSIX. 151 * Otherwise, it is an unknown option character (or ':'). 152 */ 153 if (optchar == (int)'-' && *place == '\0') 154 return (-1); 155 if (!*place) 156 ++optind; 157#ifdef GNU_COMPATIBLE 158 if (PRINT_ERROR) 159 warnx(posixly_correct ? illoptchar : gnuoptchar, 160 optchar); 161#else 162 if (PRINT_ERROR) 163 warnx(illoptchar, optchar); 164#endif 165 optopt = optchar; 166 return (BADCH); 167 } 168 if (long_options != NULL && optchar == 'W' && oli[1] == ';') { 169 /* -W long-option */ 170 if (*place) /* no space */ 171 /* NOTHING */; 172 else if (++optind >= nargc) { /* no arg */ 173 place = EMSG; 174 if (PRINT_ERROR) 175 warnx(recargchar, optchar); 176 optopt = optchar; 177 return (BADARG); 178 } else /* white space */ 179 place = nargv[optind]; 180#ifdef GNU_COMPATIBLE 181 dash_prefix = W_PREFIX; 182#endif 183 optchar = parse_long_options(nargv, options, long_options, 184 idx, 0, flags); 185 place = EMSG; 186 return (optchar); 187 } 188 if (*++oli != ':') { /* doesn't take argument */ 189 if (!*place) 190 ++optind; 191 } else { /* takes (optional) argument */ 192 optarg = NULL; 193 if (*place) /* no white space */ 194 optarg = place; 195 else if (oli[1] != ':') { /* arg not optional */ 196 if (++optind >= nargc) { /* no arg */ 197 place = EMSG; 198 if (PRINT_ERROR) 199 warnx(recargchar, optchar); 200 optopt = optchar; 201 return (BADARG); 202 } else 203 optarg = nargv[optind]; 204 } 205 place = EMSG; 206 ++optind; 207 } 208 /* dump back option letter */ 209 return (optchar); 210}
回答3件
あなたの回答
tips
プレビュー