Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/util-linux/getopt.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/util-linux/getopt.c
r1765 r2725 4 4 * Copyright (c) 1997, 1998, 1999, 2000 Frodo Looijaard <frodol@dds.nl> 5 5 * 6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.6 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 7 7 */ 8 8 … … 23 23 * No important changes 24 24 * Version 1.1.0: Tue Jun 30 2000 25 * Added NLS support (partly written by Arkadiusz Mi <B6>kiewicz25 * Added NLS support (partly written by Arkadiusz Mickiewicz 26 26 * <misiek@misiek.eu.org>) 27 27 * Ported to Busybox - Alfred M. Szmidt <ams@trillian.itslinux.org> … … 39 39 enum { 40 40 NON_OPT = 1, 41 #if ENABLE_ GETOPT_LONG41 #if ENABLE_FEATURE_GETOPT_LONG 42 42 /* LONG_OPT is the code that is returned when a long option is found. */ 43 43 LONG_OPT = 2 … … 54 54 OPT_T = 0x20, // -T 55 55 OPT_u = 0x40, // -u 56 #if ENABLE_ GETOPT_LONG56 #if ENABLE_FEATURE_GETOPT_LONG 57 57 OPT_a = 0x80, // -a 58 58 OPT_l = 0x100, // -l … … 142 142 * Other settings are found in global variables. 143 143 */ 144 #if !ENABLE_GETOPT_LONG 145 #define generate_output(argv,argc,optstr,longopts) generate_output(argv,argc,optstr) 144 #if !ENABLE_FEATURE_GETOPT_LONG 145 #define generate_output(argv,argc,optstr,longopts) \ 146 generate_output(argv,argc,optstr) 146 147 #endif 147 148 static int generate_output(char **argv, int argc, const char *optstr, const struct option *longopts) 148 149 { 149 150 int exit_code = 0; /* We assume everything will be OK */ 150 unsignedopt;151 #if ENABLE_ GETOPT_LONG151 int opt; 152 #if ENABLE_FEATURE_GETOPT_LONG 152 153 int longindex; 153 154 #endif … … 156 157 if (quiet_errors) /* No error reporting from getopt(3) */ 157 158 opterr = 0; 158 optind = 0; /* Reset getopt(3) */ 159 160 /* We used it already in main() in getopt32(), 161 * we *must* reset getopt(3): */ 162 #ifdef __GLIBC__ 163 optind = 0; 164 #else /* BSD style */ 165 optind = 1; 166 /* optreset = 1; */ 167 #endif 159 168 160 169 while (1) { 161 170 opt = 162 #if ENABLE_ GETOPT_LONG171 #if ENABLE_FEATURE_GETOPT_LONG 163 172 alternative ? 164 173 getopt_long_only(argc, argv, optstr, longopts, &longindex) : … … 167 176 getopt(argc, argv, optstr); 168 177 #endif 169 if (opt == EOF)178 if (opt == -1) 170 179 break; 171 180 if (opt == '?' || opt == ':' ) 172 181 exit_code = 1; 173 182 else if (!quiet_output) { 174 #if ENABLE_ GETOPT_LONG183 #if ENABLE_FEATURE_GETOPT_LONG 175 184 if (opt == LONG_OPT) { 176 185 printf(" --%s", longopts[longindex].name); … … 184 193 else { 185 194 printf(" -%c", opt); 186 charptr = strchr(optstr, opt);195 charptr = strchr(optstr, opt); 187 196 if (charptr != NULL && *++charptr == ':') 188 197 printf(" %s", … … 196 205 while (optind < argc) 197 206 printf(" %s", normalize(argv[optind++])); 198 puts("");207 bb_putchar('\n'); 199 208 } 200 209 return exit_code; 201 210 } 202 211 203 #if ENABLE_ GETOPT_LONG212 #if ENABLE_FEATURE_GETOPT_LONG 204 213 /* 205 214 * Register several long options. options is a string of long options, … … 232 241 bb_error_msg_and_die("empty long option specified"); 233 242 } 234 long_options = xrealloc(long_options, 235 sizeof(long_options[0]) * (long_nr+2)); 243 long_options = xrealloc_vector(long_options, 4, long_nr); 236 244 long_options[long_nr].has_arg = arg_opt; 237 long_options[long_nr].flag = NULL;245 /*long_options[long_nr].flag = NULL; - xrealloc_vector did it */ 238 246 long_options[long_nr].val = LONG_OPT; 239 247 long_options[long_nr].name = xstrdup(tokptr); 240 248 long_nr++; 241 memset(&long_options[long_nr], 0, sizeof(long_options[0]));249 /*memset(&long_options[long_nr], 0, sizeof(long_options[0])); - xrealloc_vector did it */ 242 250 } 243 251 tokptr = strtok(NULL, ", \t\n"); … … 249 257 static void set_shell(const char *new_shell) 250 258 { 251 if (!strcmp(new_shell, "bash") || !strcmp(new_shell,"sh"))259 if (!strcmp(new_shell, "bash") || !strcmp(new_shell, "sh")) 252 260 return; 253 if (!strcmp(new_shell, "tcsh") || !strcmp(new_shell,"csh"))261 if (!strcmp(new_shell, "tcsh") || !strcmp(new_shell, "csh")) 254 262 option_mask32 |= SHELL_IS_TCSH; 255 263 else … … 266 274 */ 267 275 268 #if ENABLE_ GETOPT_LONG276 #if ENABLE_FEATURE_GETOPT_LONG 269 277 static const char getopt_longopts[] ALIGN1 = 270 278 "options\0" Required_argument "o" … … 280 288 #endif 281 289 282 int getopt_main(int argc, char * argv[]);283 int getopt_main(int argc, char * argv[])290 int getopt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 291 int getopt_main(int argc, char **argv) 284 292 { 285 293 char *optstr = NULL; … … 288 296 const char *compatible; 289 297 char *s_arg; 290 #if ENABLE_ GETOPT_LONG298 #if ENABLE_FEATURE_GETOPT_LONG 291 299 struct option *long_options = NULL; 292 300 llist_t *l_arg = NULL; … … 314 322 } 315 323 316 #if !ENABLE_ GETOPT_LONG324 #if !ENABLE_FEATURE_GETOPT_LONG 317 325 opt = getopt32(argv, "+o:n:qQs:Tu", &optstr, &name, &s_arg); 318 326 #else … … 323 331 /* Effectuate the read options for the applet itself */ 324 332 while (l_arg) { 325 long_options = add_long_options(long_options, l_arg->data); 326 l_arg = l_arg->link; 333 long_options = add_long_options(long_options, llist_pop(&l_arg)); 327 334 } 328 335 #endif
Note:
See TracChangeset
for help on using the changeset viewer.