Lines Matching +full:exact +full:- +full:len

1 /* flex - tool to generate fast lexical analyzers */
10 /* to contract no. DE-AC03-76SF00098 between the United States */
47 int namelen; /* Length of the actual option word, e.g., "--file[=foo]" is 4 */
48 int printlen; /* Length of entire string, e.g., "--file[=foo]" is 12 */
65 /* Accessor functions. These WOULD be one-liners, but portability calls. */
77 return s->options[i].opt_fmt + in NAME()
78 ((s->aux[i].flags & IS_LONG) ? 2 : 1); in NAME()
83 return s->aux[i].printlen; in PRINTLEN()
88 return s->options[i].r_val; in RVAL()
93 return s->aux[i].flags; in FLAGS()
98 return s->options[i].desc ? s->options[i].desc : ""; in DESC()
130 /* Macro to assure we reset subscript whenever we adjust s->index.*/
133 (s)->index += (n); \
134 (s)->subscript= 0; \
143 s->options = options; in scanopt_init()
144 s->optc = 0; in scanopt_init()
145 s->argc = argc; in scanopt_init()
146 s->argv = (char **) argv; in scanopt_init()
147 s->index = 1; in scanopt_init()
148 s->subscript = 0; in scanopt_init()
149 s->no_err_msg = (flags & SCANOPT_NO_ERR_MSG); in scanopt_init()
150 s->has_long = 0; in scanopt_init()
151 s->has_short = 0; in scanopt_init()
154 s->optc = 0; in scanopt_init()
155 while (options[s->optc].opt_fmt in scanopt_init()
156 || options[s->optc].r_val || options[s->optc].desc) in scanopt_init()
157 s->optc++; in scanopt_init()
160 s->aux = malloc((size_t) s->optc * sizeof (struct _aux)); in scanopt_init()
162 for (i = 0; i < s->optc; i++) { in scanopt_init()
167 opt = s->options + i; in scanopt_init()
168 aux = s->aux + i; in scanopt_init()
170 aux->flags = ARG_NONE; in scanopt_init()
172 if (opt->opt_fmt[0] == '-' && opt->opt_fmt[1] == '-') { in scanopt_init()
173 aux->flags |= IS_LONG; in scanopt_init()
174 pname = (const unsigned char *)(opt->opt_fmt + 2); in scanopt_init()
175 s->has_long = 1; in scanopt_init()
178 pname = (const unsigned char *)(opt->opt_fmt + 1); in scanopt_init()
179 s->has_short = 1; in scanopt_init()
181 aux->printlen = (int) strlen (opt->opt_fmt); in scanopt_init()
183 aux->namelen = 0; in scanopt_init()
187 || !(aux->flags & IS_LONG)) { in scanopt_init()
188 if (aux->namelen == 0) in scanopt_init()
189 aux->namelen = (int) (p - pname); in scanopt_init()
190 aux->flags |= ARG_REQ; in scanopt_init()
191 aux->flags &= ~ARG_NONE; in scanopt_init()
195 if (aux->namelen == 0) in scanopt_init()
196 aux->namelen = (int) (p - pname); in scanopt_init()
197 aux->flags &= ~(ARG_REQ | ARG_NONE); in scanopt_init()
198 aux->flags |= ARG_OPT; in scanopt_init()
202 if (aux->namelen == 0) in scanopt_init()
203 aux->namelen = (int) (p - pname); in scanopt_init()
220 * scanner - The scanner, already initialized with scanopt_init().
221 * fp - The file stream to write to.
222 * usage - Text to be prepended to option list.
253 p = s->argv[0] + strlen (s->argv[0]); in scanopt_usage()
254 while (p != s->argv[0] && *p != '/') in scanopt_usage()
255 --p; in scanopt_usage()
264 store = malloc((size_t) s->optc * sizeof (usg_elem)); in scanopt_usage()
265 for (i = 0; i < s->optc; i++) { in scanopt_usage()
269 ue->idx = i; in scanopt_usage()
270 ue->next = ue->alias = NULL; in scanopt_usage()
281 if (RVAL (s, (*ue_curr)->idx) == in scanopt_usage()
282 RVAL (s, ue->idx)) { in scanopt_usage()
284 ue_curr = &((*ue_curr)->alias); in scanopt_usage()
290 strcasecmp (NAME (s, (*ue_curr)->idx), in scanopt_usage()
291 NAME (s, ue->idx)) > 0) { in scanopt_usage()
294 ue_curr = &((*ue_curr)->next); in scanopt_usage()
298 ue->next = *ue_curr; in scanopt_usage()
306 for (i = 0; i < s->optc; i++) in scanopt_usage()
313 printf ("%2d: %s\n", ue->idx, NAME (s, ue->idx)); in scanopt_usage()
314 for (ue2 = ue->alias; ue2; ue2 = ue2->next) in scanopt_usage()
315 printf (" +---> %2d: %s\n", ue2->idx, in scanopt_usage()
316 NAME (s, ue2->idx)); in scanopt_usage()
317 ue = ue->next; in scanopt_usage()
325 for (ue = byr_val; ue; ue = ue->next) { in scanopt_usage()
327 int len = 0; in scanopt_usage() local
333 len += (nlong++||nshort) ? 2+PRINTLEN(s,i) : PRINTLEN(s,i);\ in scanopt_usage()
335 len += (nshort++||nlong)? 2+PRINTLEN(s,i) : PRINTLEN(s,i);\ in scanopt_usage()
338 if (!(FLAGS (s, ue->idx) & IS_LONG)) in scanopt_usage()
339 CALC_LEN (ue->idx); in scanopt_usage()
342 for (ap = ue->alias; ap; ap = ap->next) { in scanopt_usage()
343 if (FLAGS (s, ap->idx) & IS_LONG) in scanopt_usage()
345 CALC_LEN (ap->idx); in scanopt_usage()
348 if (FLAGS (s, ue->idx) & IS_LONG) in scanopt_usage()
349 CALC_LEN (ue->idx); in scanopt_usage()
352 for (ap = ue->alias; ap; ap = ap->next) { in scanopt_usage()
353 if (!(FLAGS (s, ap->idx) & IS_LONG)) in scanopt_usage()
355 CALC_LEN (ap->idx); in scanopt_usage()
358 if (len > maxlen[0]) in scanopt_usage()
359 maxlen[0] = len; in scanopt_usage()
362 len = (int) strlen (DESC (s, ue->idx)); in scanopt_usage()
363 if (len > maxlen[1]) in scanopt_usage()
364 maxlen[1] = len; in scanopt_usage()
369 columns = get_cols () - 1; in scanopt_usage()
372 maxlen[1] = columns - (maxlen[0] + indent * 2); in scanopt_usage()
382 while(_n-- > 0)\ in scanopt_usage()
391 for (ue = byr_val; ue; ue = ue->next) { in scanopt_usage()
396 has_short = !(FLAGS (s, ue->idx) & IS_LONG); in scanopt_usage()
397 for (ap = ue->alias; ap; ap = ap->next) { in scanopt_usage()
398 if (!(FLAGS (s, ap->idx) & IS_LONG)) { in scanopt_usage()
414 nchars+=fprintf(fp,"%s",s->options[i].opt_fmt);\ in scanopt_usage()
417 if (!(FLAGS (s, ue->idx) & IS_LONG)) in scanopt_usage()
418 PRINT_IT (ue->idx); in scanopt_usage()
421 for (ap = ue->alias; ap; ap = ap->next) { in scanopt_usage()
422 if (!(FLAGS (s, ap->idx) & IS_LONG)) in scanopt_usage()
423 PRINT_IT (ap->idx); in scanopt_usage()
427 if (FLAGS (s, ue->idx) & IS_LONG) in scanopt_usage()
428 PRINT_IT (ue->idx); in scanopt_usage()
431 for (ap = ue->alias; ap; ap = ap->next) { in scanopt_usage()
432 if (FLAGS (s, ap->idx) & IS_LONG) in scanopt_usage()
433 PRINT_IT (ap->idx); in scanopt_usage()
437 PRINT_SPACES (fp, desccol - nchars); in scanopt_usage()
443 pstart = DESC (s, ue->idx); in scanopt_usage()
453 || *p == '-') lastws = in scanopt_usage()
475 (int)(lastws - pstart), in scanopt_usage()
505 if (!s->no_err_msg) { in scanopt_err()
507 if (s->index > 0 && s->index < s->argc) { in scanopt_err()
510 s->argv[s->index][s->subscript]; in scanopt_err()
515 optname = s->argv[s->index]; in scanopt_err()
519 fprintf (stderr, "%s: ", s->argv[0]); in scanopt_err()
549 /* Internal. Match str against the regex ^--([^=]+)(=(.*))?
562 /* Match regex /--./ */ in matchlongopt()
564 if (p[0] != '-' || p[1] != '-' || !p[2]) in matchlongopt()
574 *optlen = (int) (p - *optname); in matchlongopt()
586 *arglen = (int) (p - *arg); in matchlongopt()
593 * Long options must match a non-ambiguous prefix, or exact match.
594 * Short options must be exact.
598 len, int *err_code, int *opt_offset) in find_opt()
603 *opt_offset = -1; in find_opt()
608 for (i = 0; i < s->optc; i++) { in find_opt()
611 optname = s->options[i].opt_fmt + (lookup_long ? 2 : 1); in find_opt()
613 if (lookup_long && (s->aux[i].flags & IS_LONG)) { in find_opt()
614 if (len > s->aux[i].namelen) in find_opt()
617 if (strncmp (optname, optstart, (size_t) len) == 0) { in find_opt()
621 /* exact match overrides all. */ in find_opt()
622 if (len == s->aux[i].namelen) { in find_opt()
630 s->options[i].r_val) nmatch--; in find_opt()
631 lastr_val = s->options[i].r_val; in find_opt()
634 else if (!lookup_long && !(s->aux[i].flags & IS_LONG)) { in find_opt()
644 *opt_offset = -1; in find_opt()
648 *opt_offset = -1; in find_opt()
664 int opt_offset = -1; in scanopt()
668 /* Normalize return-parameters. */ in scanopt()
670 SAFE_ASSIGN (optindex, s->index); in scanopt()
672 if (s->index >= s->argc) in scanopt()
676 pstart = s->argv[s->index] + s->subscript; in scanopt()
680 if (s->subscript == 0) { in scanopt()
682 /* test for exact match of "--" */ in scanopt()
683 if (pstart[0] == '-' && pstart[1] == '-' && !pstart[2]) { in scanopt()
684 SAFE_ASSIGN (optindex, s->index + 1); in scanopt()
705 else if (pstart[0] == '-' && pstart[1]) { in scanopt()
708 s->subscript++; in scanopt()
718 /* We have to re-check the subscript status because it in scanopt()
721 if (s->subscript != 0) { in scanopt()
724 * e.g., at the 'z' in `tar -xzf` */ in scanopt()
745 * the s->options array (and corresponding aux array). in scanopt()
751 has_next = s->index + 1 < s->argc in scanopt()
752 && strcmp ("--", s->argv[s->index + 1]) != 0; in scanopt()
754 optp = s->options + opt_offset; in scanopt()
755 auxp = s->aux + opt_offset; in scanopt()
758 if (auxp->flags & ARG_NONE) { in scanopt()
767 s->subscript++; in scanopt()
768 return optp->r_val; in scanopt()
772 if (auxp->flags & ARG_REQ) { in scanopt()
778 SAFE_ASSIGN (arg, s->argv[s->index + 1]); in scanopt()
785 return optp->r_val; in scanopt()
789 if (auxp->flags & ARG_OPT) { in scanopt()
792 return optp->r_val; in scanopt()
807 free(s->aux); in scanopt_destroy()