38 |
mode */ |
mode */ |
39 |
enum { |
enum { |
40 |
NON_OPT = 1, |
NON_OPT = 1, |
41 |
#if ENABLE_GETOPT_LONG |
#if ENABLE_FEATURE_GETOPT_LONG |
42 |
/* LONG_OPT is the code that is returned when a long option is found. */ |
/* LONG_OPT is the code that is returned when a long option is found. */ |
43 |
LONG_OPT = 2 |
LONG_OPT = 2 |
44 |
#endif |
#endif |
53 |
OPT_s = 0x10, // -s |
OPT_s = 0x10, // -s |
54 |
OPT_T = 0x20, // -T |
OPT_T = 0x20, // -T |
55 |
OPT_u = 0x40, // -u |
OPT_u = 0x40, // -u |
56 |
#if ENABLE_GETOPT_LONG |
#if ENABLE_FEATURE_GETOPT_LONG |
57 |
OPT_a = 0x80, // -a |
OPT_a = 0x80, // -a |
58 |
OPT_l = 0x100, // -l |
OPT_l = 0x100, // -l |
59 |
#endif |
#endif |
141 |
* optstr must contain the short options, and longopts the long options. |
* optstr must contain the short options, and longopts the long options. |
142 |
* Other settings are found in global variables. |
* Other settings are found in global variables. |
143 |
*/ |
*/ |
144 |
#if !ENABLE_GETOPT_LONG |
#if !ENABLE_FEATURE_GETOPT_LONG |
145 |
#define generate_output(argv,argc,optstr,longopts) \ |
#define generate_output(argv,argc,optstr,longopts) \ |
146 |
generate_output(argv,argc,optstr) |
generate_output(argv,argc,optstr) |
147 |
#endif |
#endif |
149 |
{ |
{ |
150 |
int exit_code = 0; /* We assume everything will be OK */ |
int exit_code = 0; /* We assume everything will be OK */ |
151 |
int opt; |
int opt; |
152 |
#if ENABLE_GETOPT_LONG |
#if ENABLE_FEATURE_GETOPT_LONG |
153 |
int longindex; |
int longindex; |
154 |
#endif |
#endif |
155 |
const char *charptr; |
const char *charptr; |
168 |
|
|
169 |
while (1) { |
while (1) { |
170 |
opt = |
opt = |
171 |
#if ENABLE_GETOPT_LONG |
#if ENABLE_FEATURE_GETOPT_LONG |
172 |
alternative ? |
alternative ? |
173 |
getopt_long_only(argc, argv, optstr, longopts, &longindex) : |
getopt_long_only(argc, argv, optstr, longopts, &longindex) : |
174 |
getopt_long(argc, argv, optstr, longopts, &longindex); |
getopt_long(argc, argv, optstr, longopts, &longindex); |
180 |
if (opt == '?' || opt == ':' ) |
if (opt == '?' || opt == ':' ) |
181 |
exit_code = 1; |
exit_code = 1; |
182 |
else if (!quiet_output) { |
else if (!quiet_output) { |
183 |
#if ENABLE_GETOPT_LONG |
#if ENABLE_FEATURE_GETOPT_LONG |
184 |
if (opt == LONG_OPT) { |
if (opt == LONG_OPT) { |
185 |
printf(" --%s", longopts[longindex].name); |
printf(" --%s", longopts[longindex].name); |
186 |
if (longopts[longindex].has_arg) |
if (longopts[longindex].has_arg) |
209 |
return exit_code; |
return exit_code; |
210 |
} |
} |
211 |
|
|
212 |
#if ENABLE_GETOPT_LONG |
#if ENABLE_FEATURE_GETOPT_LONG |
213 |
/* |
/* |
214 |
* Register several long options. options is a string of long options, |
* Register several long options. options is a string of long options, |
215 |
* separated by commas or whitespace. |
* separated by commas or whitespace. |
273 |
* 4) Returned for -T |
* 4) Returned for -T |
274 |
*/ |
*/ |
275 |
|
|
276 |
#if ENABLE_GETOPT_LONG |
#if ENABLE_FEATURE_GETOPT_LONG |
277 |
static const char getopt_longopts[] ALIGN1 = |
static const char getopt_longopts[] ALIGN1 = |
278 |
"options\0" Required_argument "o" |
"options\0" Required_argument "o" |
279 |
"longoptions\0" Required_argument "l" |
"longoptions\0" Required_argument "l" |
295 |
unsigned opt; |
unsigned opt; |
296 |
const char *compatible; |
const char *compatible; |
297 |
char *s_arg; |
char *s_arg; |
298 |
#if ENABLE_GETOPT_LONG |
#if ENABLE_FEATURE_GETOPT_LONG |
299 |
struct option *long_options = NULL; |
struct option *long_options = NULL; |
300 |
llist_t *l_arg = NULL; |
llist_t *l_arg = NULL; |
301 |
#endif |
#endif |
321 |
return generate_output(argv+1, argc-1, s, long_options); |
return generate_output(argv+1, argc-1, s, long_options); |
322 |
} |
} |
323 |
|
|
324 |
#if !ENABLE_GETOPT_LONG |
#if !ENABLE_FEATURE_GETOPT_LONG |
325 |
opt = getopt32(argv, "+o:n:qQs:Tu", &optstr, &name, &s_arg); |
opt = getopt32(argv, "+o:n:qQs:Tu", &optstr, &name, &s_arg); |
326 |
#else |
#else |
327 |
applet_long_options = getopt_longopts; |
applet_long_options = getopt_longopts; |