Lines Matching +full:permission +full:- +full:flags

7  * Permission to use, copy, modify, and distribute this software for any
9 * copyright notice and this permission notice appear in all copies.
21 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
61 #define PRINT_ERROR ((state->opterr) && (*options != ':'))
63 #define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */
64 #define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */
75 #define NO_PREFIX (-1)
90 #define RECARGCHAR "option requires an argument -- %c"
91 #define ILLOPTCHAR "illegal option -- %c" /* From P1003.2 */
94 #define GNUOPTCHAR "invalid option -- %c"
101 #define RECARGSTRING "option requires an argument -- %s"
102 #define AMBIG "ambiguous option -- %.*s"
103 #define NOARG "option doesn't take an argument -- %.*s"
104 #define ILLOPTSTRING "unknown option -- %s"
140 nnonopts = panonopt_end - panonopt_start; in permute_args()
141 nopts = opt_end - panonopt_end; in permute_args()
143 cyclelen = (opt_end - panonopt_start) / ncycle; in permute_args()
150 pos -= nnonopts; in permute_args()
164 * parse_long_options --
166 * Returns -1 if short_too is set and the option does not match long_options.
171 int *idx, int short_too, int flags) in parse_long_options() argument
180 current_argv = state->place; in parse_long_options()
185 current_dash = "-"; in parse_long_options()
188 current_dash = "--"; in parse_long_options()
191 current_dash = "-W "; in parse_long_options()
198 match = -1; in parse_long_options()
202 state->optind++; in parse_long_options()
206 /* argument found (--option=arg) */ in parse_long_options()
207 current_argv_len = has_equal - current_argv; in parse_long_options()
233 if (match == -1) { /* first partial match */ in parse_long_options()
235 } else if ((flags & FLAG_LONGONLY) || in parse_long_options()
252 state->optopt = 0; in parse_long_options()
255 if (match != -1) { /* option found */ in parse_long_options()
270 state->optopt = long_options[match].val; in parse_long_options()
272 state->optopt = 0; in parse_long_options()
283 state->optarg = has_equal; in parse_long_options()
288 state->optarg = nargv[state->optind++]; in parse_long_options()
292 && (state->optarg == NULL)) { in parse_long_options()
308 state->optopt = long_options[match].val; in parse_long_options()
310 state->optopt = 0; in parse_long_options()
312 --state->optind; in parse_long_options()
317 --state->optind; in parse_long_options()
318 return -1; in parse_long_options()
327 state->optopt = 0; in parse_long_options()
342 * getopt_internal --
348 int *idx, int flags) argument
354 return -1;
361 if (*options == '-') {
362 flags |= FLAG_ALLARGS;
364 flags &= ~FLAG_PERMUTE;
368 flags &= ~FLAG_PERMUTE;
369 } else if (*options == '-') {
370 flags |= FLAG_ALLARGS;
373 if (*options == '+' || *options == '-') {
381 if (state->optind == 0) {
382 state->optind = state->optreset = 1;
385 state->optarg = NULL;
386 if (state->optreset) {
387 state->nonopt_start = state->nonopt_end = -1;
390 if (state->optreset || !*(state->place)) {/* update scanning pointer */
391 state->optreset = 0;
392 if (state->optind >= nargc) { /* end of argument vector */
393 state->place = EMSG;
394 if (state->nonopt_end != -1) {
396 permute_args(state->nonopt_start,
397 state->nonopt_end,
398 state->optind, nargv);
399 state->optind -= state->nonopt_end -
400 state->nonopt_start;
401 } else if (state->nonopt_start != -1) {
403 * If we skipped non-options, set optind
406 state->optind = state->nonopt_start;
408 state->nonopt_start = state->nonopt_end = -1;
409 return -1;
411 state->place = nargv[state->optind];
412 if (*(state->place) != '-' ||
414 state->place[1] == '\0') {
416 (state->place[1] == '\0' && strchr(options, '-') == NULL)) {
418 state->place = EMSG; /* found non-option */
419 if (flags & FLAG_ALLARGS) {
422 * return non-option as argument to option 1
424 state->optarg = nargv[state->optind++];
427 if (!(flags & FLAG_PERMUTE)) {
430 * at first non-option.
432 return -1;
435 if (state->nonopt_start == -1) {
436 state->nonopt_start = state->optind;
437 } else if (state->nonopt_end != -1) {
438 permute_args(state->nonopt_start,
439 state->nonopt_end,
440 state->optind,
442 state->nonopt_start = state->optind -
443 (state->nonopt_end - state->nonopt_start);
444 state->nonopt_end = -1;
446 state->optind++;
450 if (state->nonopt_start != -1 && state->nonopt_end == -1) {
451 state->nonopt_end = state->optind;
455 * If we have "-" do nothing, if "--" we are done.
457 if (state->place[1] != '\0' && *++(state->place) == '-' &&
458 state->place[1] == '\0') {
459 state->optind++;
460 state->place = EMSG;
462 * We found an option (--), so if we skipped
463 * non-options, we have to permute.
465 if (state->nonopt_end != -1) {
466 permute_args(state->nonopt_start,
467 state->nonopt_end,
468 state->optind,
470 state->optind -= state->nonopt_end -
471 state->nonopt_start;
473 state->nonopt_start = state->nonopt_end = -1;
474 return -1;
481 * 2) the arg is not just "-"
482 * 3) either the arg starts with -- we are getopt_long_only()
484 if (long_options != NULL && state->place != nargv[state->optind] &&
485 (*(state->place) == '-' || (flags & FLAG_LONGONLY))) {
490 if (*(state->place) == '-') {
491 state->place++; /* --foo long option */
495 } else if (*(state->place) != ':' && strchr(options, *(state->place)) != NULL) {
501 flags);
502 if (optchar != -1) {
503 state->place = EMSG;
507 optchar = (int)*(state->place)++;
510 (optchar == (int)'-' && *(state->place) != '\0') ||
513 * If the user specified "-" and '-' isn't listed in
514 * options, return -1 (non-option) as per POSIX.
517 if (optchar == (int)'-' && *(state->place) == '\0') {
518 return -1;
520 if (!*(state->place)) {
521 ++state->optind;
532 state->optopt = optchar;
536 /* -W long-option */
537 if (*(state->place)) { /* no space */
539 } else if (++(state->optind) >= nargc) { /* no arg */
540 state->place = EMSG;
544 state->optopt = optchar;
546 } else if ((state->optind) < nargc) {
547 state->place = nargv[state->optind];
553 long_options, idx, 0, flags);
554 state->place = EMSG;
558 if (!*(state->place)) {
559 ++state->optind;
562 state->optarg = NULL;
563 if (*(state->place)) { /* no white space */
564 state->optarg = state->place;
566 if (++state->optind >= nargc) { /* no arg */
567 state->place = EMSG;
571 state->optopt = optchar;
574 state->optarg = nargv[state->optind];
576 state->place = EMSG;
577 ++state->optind;
584 * getopt_long --
607 * getopt_long_only --