Lines Matching +full:short +full:- +full:circuit
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2003-2008 Tim Kientzle
27 * Short options for bsdunzip. Please keep this sorted.
35 * The symbolic names for options that lack a short equivalent are
44 int equivalent; /* Equivalent short option. */
75 long_prefix = "--"; in bsdunzip_getopt()
78 bsdunzip->argument = NULL; in bsdunzip_getopt()
81 if (bsdunzip->getopt_state == state_start) { in bsdunzip_getopt()
83 ++bsdunzip->argv; in bsdunzip_getopt()
84 --bsdunzip->argc; in bsdunzip_getopt()
85 if (*bsdunzip->argv == NULL) in bsdunzip_getopt()
86 return (-1); in bsdunzip_getopt()
87 bsdunzip->getopt_state = state_next_word; in bsdunzip_getopt()
93 if (bsdunzip->getopt_state == state_next_word) { in bsdunzip_getopt()
95 if (bsdunzip->argv[0] == NULL) in bsdunzip_getopt()
96 return (-1); in bsdunzip_getopt()
97 /* Doesn't start with '-', so no more options. */ in bsdunzip_getopt()
98 if (bsdunzip->argv[0][0] != '-') in bsdunzip_getopt()
99 return (-1); in bsdunzip_getopt()
100 /* "--" marks end of options; consume it and return. */ in bsdunzip_getopt()
101 if (strcmp(bsdunzip->argv[0], "--") == 0) { in bsdunzip_getopt()
102 ++bsdunzip->argv; in bsdunzip_getopt()
103 --bsdunzip->argc; in bsdunzip_getopt()
105 return (-1); in bsdunzip_getopt()
108 bsdunzip->getopt_word = *bsdunzip->argv++; in bsdunzip_getopt()
109 --bsdunzip->argc; in bsdunzip_getopt()
111 if (bsdunzip->getopt_word[1] == '-') { in bsdunzip_getopt()
113 bsdunzip->getopt_state = state_long; in bsdunzip_getopt()
114 bsdunzip->getopt_word += 2; /* Skip leading '--' */ in bsdunzip_getopt()
116 /* Set up short option parser. */ in bsdunzip_getopt()
117 bsdunzip->getopt_state = state_short; in bsdunzip_getopt()
118 ++bsdunzip->getopt_word; /* Skip leading '-' */ in bsdunzip_getopt()
123 * We're parsing a group of POSIX-style single-character options. in bsdunzip_getopt()
125 if (bsdunzip->getopt_state == state_short) { in bsdunzip_getopt()
126 /* Peel next option off of a group of short options. */ in bsdunzip_getopt()
127 opt = *bsdunzip->getopt_word++; in bsdunzip_getopt()
130 bsdunzip->getopt_state = state_next_word; in bsdunzip_getopt()
143 /* If arg is run-in, bsdunzip->getopt_word already points to it. */ in bsdunzip_getopt()
144 if (bsdunzip->getopt_word[0] == '\0') { in bsdunzip_getopt()
146 bsdunzip->getopt_word = *bsdunzip->argv; in bsdunzip_getopt()
147 if (bsdunzip->getopt_word == NULL) { in bsdunzip_getopt()
149 "Option -%c requires an argument", in bsdunzip_getopt()
153 ++bsdunzip->argv; in bsdunzip_getopt()
154 --bsdunzip->argc; in bsdunzip_getopt()
157 bsdunzip->getopt_state = state_next_word; in bsdunzip_getopt()
158 bsdunzip->argument = bsdunzip->getopt_word; in bsdunzip_getopt()
163 if (bsdunzip->getopt_state == state_long) { in bsdunzip_getopt()
165 bsdunzip->getopt_state = state_next_word; in bsdunzip_getopt()
168 p = strchr(bsdunzip->getopt_word, '='); in bsdunzip_getopt()
170 optlength = (size_t)(p - bsdunzip->getopt_word); in bsdunzip_getopt()
171 bsdunzip->argument = (char *)(uintptr_t)(p + 1); in bsdunzip_getopt()
173 optlength = strlen(bsdunzip->getopt_word); in bsdunzip_getopt()
177 for (popt = bsdunzip_longopts; popt->name != NULL; popt++) { in bsdunzip_getopt()
178 /* Short-circuit if first chars don't match. */ in bsdunzip_getopt()
179 if (popt->name[0] != bsdunzip->getopt_word[0]) in bsdunzip_getopt()
182 if (strncmp(bsdunzip->getopt_word, popt->name, optlength) == 0) { in bsdunzip_getopt()
186 if (strlen(popt->name) == optlength) { in bsdunzip_getopt()
197 long_prefix, bsdunzip->getopt_word); in bsdunzip_getopt()
202 "Ambiguous option %s%s (matches --%s and --%s)", in bsdunzip_getopt()
203 long_prefix, bsdunzip->getopt_word, match->name, match2->name); in bsdunzip_getopt()
208 if (match->required) { in bsdunzip_getopt()
210 if (bsdunzip->argument == NULL) { in bsdunzip_getopt()
211 bsdunzip->argument = *bsdunzip->argv; in bsdunzip_getopt()
212 if (bsdunzip->argument == NULL) { in bsdunzip_getopt()
215 long_prefix, match->name); in bsdunzip_getopt()
218 ++bsdunzip->argv; in bsdunzip_getopt()
219 --bsdunzip->argc; in bsdunzip_getopt()
224 if (bsdunzip->argument != NULL) { in bsdunzip_getopt()
227 long_prefix, match->name); in bsdunzip_getopt()
231 return (match->equivalent); in bsdunzip_getopt()