Lines Matching +full:short +full:- +full:circuit
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2003-2008 Tim Kientzle
28 * Short options for bsdcat. Please keep this sorted.
35 * The symbolic names for options that lack a short equivalent are
44 int equivalent; /* Equivalent short option. */
61 * Old-style tar arguments: The original tar implementation treated
62 * the first argument word as a list of single-character option
67 * if the first command-line argument does not begin with '-'. We
68 * also allow regular short and long options to follow, e.g.,
69 * tar xbf 32 /dev/tape -P --format=pax
71 * -W long options: There's an obscure GNU convention (only rarely
72 * supported even there) that allows "-W option=argument" as an
77 * command-line parser from the beginning, I would have had normal
83 * options (such as -C) from the command line in write mode. That
87 * TODO: If we want to support arbitrary command-line options from -T
108 long_prefix = "--"; in bsdcat_getopt()
111 bsdcat->argument = NULL; in bsdcat_getopt()
114 if (bsdcat->getopt_state == state_start) { in bsdcat_getopt()
116 ++bsdcat->argv; in bsdcat_getopt()
117 --bsdcat->argc; in bsdcat_getopt()
118 if (*bsdcat->argv == NULL) in bsdcat_getopt()
119 return (-1); in bsdcat_getopt()
121 bsdcat->getopt_state = state_next_word; in bsdcat_getopt()
127 if (bsdcat->getopt_state == state_next_word) { in bsdcat_getopt()
129 if (bsdcat->argv[0] == NULL) in bsdcat_getopt()
130 return (-1); in bsdcat_getopt()
131 /* Doesn't start with '-', so no more options. */ in bsdcat_getopt()
132 if (bsdcat->argv[0][0] != '-') in bsdcat_getopt()
133 return (-1); in bsdcat_getopt()
134 /* "--" marks end of options; consume it and return. */ in bsdcat_getopt()
135 if (strcmp(bsdcat->argv[0], "--") == 0) { in bsdcat_getopt()
136 ++bsdcat->argv; in bsdcat_getopt()
137 --bsdcat->argc; in bsdcat_getopt()
138 return (-1); in bsdcat_getopt()
141 bsdcat->getopt_word = *bsdcat->argv++; in bsdcat_getopt()
142 --bsdcat->argc; in bsdcat_getopt()
143 if (bsdcat->getopt_word[1] == '-') { in bsdcat_getopt()
145 bsdcat->getopt_state = state_long; in bsdcat_getopt()
146 bsdcat->getopt_word += 2; /* Skip leading '--' */ in bsdcat_getopt()
148 /* Set up short option parser. */ in bsdcat_getopt()
149 bsdcat->getopt_state = state_short; in bsdcat_getopt()
150 ++bsdcat->getopt_word; /* Skip leading '-' */ in bsdcat_getopt()
155 * We're parsing a group of POSIX-style single-character options. in bsdcat_getopt()
157 if (bsdcat->getopt_state == state_short) { in bsdcat_getopt()
158 /* Peel next option off of a group of short options. */ in bsdcat_getopt()
159 opt = *bsdcat->getopt_word++; in bsdcat_getopt()
162 bsdcat->getopt_state = state_next_word; in bsdcat_getopt()
175 /* If arg is run-in, bsdcat->getopt_word already points to it. */ in bsdcat_getopt()
176 if (bsdcat->getopt_word[0] == '\0') { in bsdcat_getopt()
178 bsdcat->getopt_word = *bsdcat->argv; in bsdcat_getopt()
179 if (bsdcat->getopt_word == NULL) { in bsdcat_getopt()
181 "Option -%c requires an argument", in bsdcat_getopt()
185 ++bsdcat->argv; in bsdcat_getopt()
186 --bsdcat->argc; in bsdcat_getopt()
189 bsdcat->getopt_state = state_long; in bsdcat_getopt()
190 long_prefix = "-W "; /* For clearer errors. */ in bsdcat_getopt()
192 bsdcat->getopt_state = state_next_word; in bsdcat_getopt()
193 bsdcat->argument = bsdcat->getopt_word; in bsdcat_getopt()
198 /* We're reading a long option, including -W long=arg convention. */ in bsdcat_getopt()
199 if (bsdcat->getopt_state == state_long) { in bsdcat_getopt()
201 bsdcat->getopt_state = state_next_word; in bsdcat_getopt()
204 p = strchr(bsdcat->getopt_word, '='); in bsdcat_getopt()
206 optlength = (size_t)(p - bsdcat->getopt_word); in bsdcat_getopt()
207 bsdcat->argument = (char *)(uintptr_t)(p + 1); in bsdcat_getopt()
209 optlength = strlen(bsdcat->getopt_word); in bsdcat_getopt()
213 for (popt = bsdcat_longopts; popt->name != NULL; popt++) { in bsdcat_getopt()
214 /* Short-circuit if first chars don't match. */ in bsdcat_getopt()
215 if (popt->name[0] != bsdcat->getopt_word[0]) in bsdcat_getopt()
218 if (strncmp(bsdcat->getopt_word, popt->name, optlength) == 0) { in bsdcat_getopt()
222 if (strlen(popt->name) == optlength) { in bsdcat_getopt()
233 long_prefix, bsdcat->getopt_word); in bsdcat_getopt()
238 "Ambiguous option %s%s (matches --%s and --%s)", in bsdcat_getopt()
239 long_prefix, bsdcat->getopt_word, match->name, match2->name); in bsdcat_getopt()
244 if (match->required) { in bsdcat_getopt()
246 if (bsdcat->argument == NULL) { in bsdcat_getopt()
247 bsdcat->argument = *bsdcat->argv; in bsdcat_getopt()
248 if (bsdcat->argument == NULL) { in bsdcat_getopt()
251 long_prefix, match->name); in bsdcat_getopt()
254 ++bsdcat->argv; in bsdcat_getopt()
255 --bsdcat->argc; in bsdcat_getopt()
259 if (bsdcat->argument != NULL) { in bsdcat_getopt()
262 long_prefix, match->name); in bsdcat_getopt()
266 return (match->equivalent); in bsdcat_getopt()