Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/util-linux/getopt.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/util-linux/getopt.c
r3232 r3621 36 36 //usage:#define getopt_full_usage "\n\n" 37 37 //usage: IF_LONG_OPTS( 38 //usage: " -a,--alternative Allow long options starting with single -" 39 //usage: "\n -l,--longoptions=LOPT[,...] Long options to be recognized" 40 //usage: "\n -n,--name=PROGNAME The name under which errors are reported" 41 //usage: "\n -o,--options=OPTSTRING Short options to be recognized" 42 //usage: "\n -q,--quiet Disable error reporting by getopt(3)" 38 //usage: IF_FEATURE_GETOPT_LONG( 39 //usage: " -a,--alternative Allow long options starting with single -\n" 40 //usage: " -l,--longoptions=LOPT[,...] Long options to recognize\n" 41 //usage: ) 42 //usage: " -n,--name=PROGNAME The name under which errors are reported" 43 //usage: "\n -o,--options=OPTSTRING Short options to recognize" 44 //usage: "\n -q,--quiet No error messages on unrecognized options" 43 45 //usage: "\n -Q,--quiet-output No normal output" 44 46 //usage: "\n -s,--shell=SHELL Set shell quoting conventions" 45 //usage: "\n -T,--test Test for getopt(1) version"46 //usage: "\n -u,--unquoted Don't quote theoutput"47 //usage: "\n -T,--test Version test (exits with 4)" 48 //usage: "\n -u,--unquoted Don't quote output" 47 49 //usage: ) 48 50 //usage: IF_NOT_LONG_OPTS( 49 //usage: " -a Allow long options starting with single -" 50 //usage: "\n -l LOPT[,...] Long options to be recognized" 51 //usage: "\n -n PROGNAME The name under which errors are reported" 52 //usage: "\n -o OPTSTRING Short options to be recognized" 53 //usage: "\n -q Disable error reporting by getopt(3)" 51 //usage: IF_FEATURE_GETOPT_LONG( 52 //usage: " -a Allow long options starting with single -\n" 53 //usage: " -l LOPT[,...] Long options to recognize\n" 54 //usage: ) 55 //usage: " -n PROGNAME The name under which errors are reported" 56 //usage: "\n -o OPTSTRING Short options to recognize" 57 //usage: "\n -q No error messages on unrecognized options" 54 58 //usage: "\n -Q No normal output" 55 59 //usage: "\n -s SHELL Set shell quoting conventions" 56 //usage: "\n -T Test for getopt(1) version"57 //usage: "\n -u Don't quote theoutput"60 //usage: "\n -T Version test (exits with 4)" 61 //usage: "\n -u Don't quote output" 58 62 //usage: ) 63 //usage: IF_FEATURE_GETOPT_LONG( /* example uses -l, needs FEATURE_GETOPT_LONG */ 59 64 //usage: "\n" 60 65 //usage: "\nExample:" … … 74 79 //usage: "\n esac" 75 80 //usage: "\ndone" 81 //usage: ) 76 82 //usage: 77 83 //usage:#define getopt_example_usage … … 215 221 { 216 222 int exit_code = 0; /* We assume everything will be OK */ 217 int opt;218 #if ENABLE_FEATURE_GETOPT_LONG219 int longindex;220 #endif221 const char *charptr;222 223 223 224 if (quiet_errors) /* No error reporting from getopt(3) */ … … 234 235 235 236 while (1) { 236 opt = 237 #if ENABLE_FEATURE_GETOPT_LONG 238 alternative ? 239 getopt_long_only(argc, argv, optstr, longopts, &longindex) : 240 getopt_long(argc, argv, optstr, longopts, &longindex); 237 #if ENABLE_FEATURE_GETOPT_LONG 238 int longindex; 239 int opt = alternative 240 ? getopt_long_only(argc, argv, optstr, longopts, &longindex) 241 : getopt_long(argc, argv, optstr, longopts, &longindex) 242 ; 241 243 #else 242 244 int opt = getopt(argc, argv, optstr); 243 245 #endif 244 246 if (opt == -1) … … 258 260 printf(" %s", normalize(optarg)); 259 261 else { 262 const char *charptr; 260 263 printf(" -%c", opt); 261 264 charptr = strchr(optstr, opt); 262 if (charptr != NULL&& *++charptr == ':')265 if (charptr && *++charptr == ':') 263 266 printf(" %s", 264 267 normalize(optarg ? optarg : "")); … … 268 271 269 272 if (!quiet_output) { 273 unsigned idx; 270 274 printf(" --"); 271 while (optind < argc) 272 printf(" %s", normalize(argv[optind++])); 275 idx = optind; 276 while (argv[idx]) 277 printf(" %s", normalize(argv[idx++])); 273 278 bb_putchar('\n'); 274 279 } … … 374 379 /* For some reason, the original getopt gave no error 375 380 * when there were no arguments. */ 376 p rintf(" --\n");381 puts(" --"); 377 382 return 0; 378 383 }
Note:
See TracChangeset
for help on using the changeset viewer.