39,21 → 39,6 |
#include <stdlib.h> |
#include <string.h> |
|
/* HelenOS Port: Something similar to warnx(), however we just print |
* to the console */ |
|
void warnx(const char *fmt, ...); |
|
void warnx(const char *fmt, ...) |
{ |
va_list vargs; |
va_start(vargs, fmt); |
vprintf(fmt, vargs); |
va_end(vargs); |
printf("\n"); |
return; |
} |
|
/* HelenOS Port : We're incorporating only the modern getopt_long with wrappers |
* to keep legacy getopt() usage from breaking. All references to REPLACE_GETOPT |
* are dropped, we just include the code */ |
93,14 → 78,19 |
static int nonopt_end = -1; /* first option after non options (for permute) */ |
|
/* Error messages */ |
static const char recargchar[] = "option requires an argument -- %c"; |
static const char recargstring[] = "option requires an argument -- %s"; |
static const char ambig[] = "ambiguous option -- %.*s"; |
static const char noarg[] = "option doesn't take an argument -- %.*s"; |
static const char illoptchar[] = "unknown option -- %c"; |
static const char illoptstring[] = "unknown option -- %s"; |
|
/* HelenOS Port: Calls to warnx() were eliminated (as we have no stderr that |
* may be redirected) and replaced with printf. As such, error messages now |
* end in a newline */ |
|
static const char recargchar[] = "option requires an argument -- %c\n"; |
static const char recargstring[] = "option requires an argument -- %s\n"; |
static const char ambig[] = "ambiguous option -- %.*s\n"; |
static const char noarg[] = "option doesn't take an argument -- %.*s\n"; |
static const char illoptchar[] = "unknown option -- %c\n"; |
static const char illoptstring[] = "unknown option -- %s\n"; |
|
|
/* |
* Compute the greatest common divisor of a and b. |
*/ |
256,7 → 246,7 |
if (!*place) |
++optind; |
if (PRINT_ERROR) |
warnx(illoptchar, optchar); |
printf(illoptchar, optchar); |
optopt = optchar; |
return BADCH; |
} |
268,7 → 258,7 |
if (++optind >= nargc) { /* no arg */ |
place = EMSG; |
if (PRINT_ERROR) |
warnx(recargchar, optchar); |
printf(recargchar, optchar); |
optopt = optchar; |
return BADARG; |
} else /* white space */ |
291,7 → 281,7 |
if (++optind >= nargc) { /* no arg */ |
place = EMSG; |
if (PRINT_ERROR) |
warnx(recargchar, optchar); |
printf(recargchar, optchar); |
optopt = optchar; |
return BADARG; |
} else |
415,7 → 405,7 |
if (ambiguous) { |
/* ambiguous abbreviation */ |
if (PRINT_ERROR) |
warnx(ambig, (int)current_argv_len, |
printf(ambig, (int)current_argv_len, |
current_argv); |
optopt = 0; |
return BADCH; |
424,7 → 414,7 |
if (long_options[match].has_arg == no_argument |
&& has_equal) { |
if (PRINT_ERROR) |
warnx(noarg, (int)current_argv_len, |
printf(noarg, (int)current_argv_len, |
current_argv); |
/* |
* XXX: GNU sets optopt to val regardless of |
456,7 → 446,7 |
* indicates no error should be generated |
*/ |
if (PRINT_ERROR) |
warnx(recargstring, current_argv); |
printf(recargstring, current_argv); |
/* |
* XXX: GNU sets optopt to val regardless |
* of flag |
470,7 → 460,7 |
} |
} else { /* unknown option */ |
if (PRINT_ERROR) |
warnx(illoptstring, current_argv); |
printf(illoptstring, current_argv); |
optopt = 0; |
return BADCH; |
} |