Minor fix for the command line parser: we didn't previously
distinguish between unknown ''options'' (i.e., command line options that are registered and have some meaning) and unknown ''tokens'' (i.e., strings that do not begin with "-"). Hence, if you did: mpirun --fo my_mpi_program (when perhaps you meant to type "--foo", mpirun would complain that no such executable "--fo" existed. That is ''correct,'' but perhaps not completely useful. It is more accurate for mpirun to report that there is no such "--fo" option. This change to cmd_line.c makes it so that we will ''always'' report errors regarding tokens that begin with "-". This commit was SVN r26953.
Этот коммит содержится в:
родитель
fc712182db
Коммит
0b7b3feba9
@ -267,7 +267,8 @@ int opal_cmd_line_parse(opal_cmd_line_t *cmd, bool ignore_unknown,
|
||||
int i, j, orig, ret;
|
||||
cmd_line_option_t *option;
|
||||
cmd_line_param_t *param;
|
||||
bool is_unknown;
|
||||
bool is_unknown_option;
|
||||
bool is_unknown_token;
|
||||
bool is_option;
|
||||
bool has_unknowns;
|
||||
char **shortsv;
|
||||
@ -310,7 +311,8 @@ int opal_cmd_line_parse(opal_cmd_line_t *cmd, bool ignore_unknown,
|
||||
option = NULL;
|
||||
has_unknowns = false;
|
||||
for (i = 1; i < cmd->lcl_argc; ) {
|
||||
is_unknown = false;
|
||||
is_unknown_option = false;
|
||||
is_unknown_token = false;
|
||||
is_option = false;
|
||||
|
||||
/* Are we done? i.e., did we find the special "--" token? If
|
||||
@ -328,11 +330,12 @@ int opal_cmd_line_parse(opal_cmd_line_t *cmd, bool ignore_unknown,
|
||||
break;
|
||||
}
|
||||
|
||||
/* If it's not an option, then we've found an unrecognized
|
||||
token. */
|
||||
/* If it's not an option, then this is an error. Note that
|
||||
this is different than an unrecognized token; an
|
||||
unrecognized option is *always* an error. */
|
||||
|
||||
else if ('-' != cmd->lcl_argv[i][0]) {
|
||||
is_unknown = true;
|
||||
is_unknown_token = true;
|
||||
}
|
||||
|
||||
/* Nope, this is supposedly an option. Is it a long name? */
|
||||
@ -371,11 +374,11 @@ int opal_cmd_line_parse(opal_cmd_line_t *cmd, bool ignore_unknown,
|
||||
opal_argv_insert(&cmd->lcl_argv, i, shortsv);
|
||||
cmd->lcl_argc = opal_argv_count(cmd->lcl_argv);
|
||||
} else {
|
||||
is_unknown = true;
|
||||
is_unknown_option = true;
|
||||
}
|
||||
opal_argv_free(shortsv);
|
||||
} else {
|
||||
is_unknown = true;
|
||||
is_unknown_option = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -388,9 +391,9 @@ int opal_cmd_line_parse(opal_cmd_line_t *cmd, bool ignore_unknown,
|
||||
|
||||
if (is_option) {
|
||||
if (NULL == option) {
|
||||
is_unknown = true;
|
||||
is_unknown_option = true;
|
||||
} else {
|
||||
is_unknown = false;
|
||||
is_unknown_option = false;
|
||||
orig = i;
|
||||
++i;
|
||||
|
||||
@ -496,9 +499,9 @@ int opal_cmd_line_parse(opal_cmd_line_t *cmd, bool ignore_unknown,
|
||||
handle it. Copy everything (including the current token)
|
||||
into the tail. If we're not ignoring unknowns, then print
|
||||
an error and return. */
|
||||
if (is_unknown) {
|
||||
if (is_unknown_option || is_unknown_token) {
|
||||
has_unknowns = true;
|
||||
if (!ignore_unknown) {
|
||||
if (!ignore_unknown || is_unknown_option) {
|
||||
fprintf(stderr, "%s: Error: unknown option \"%s\"\n",
|
||||
cmd->lcl_argv[0], cmd->lcl_argv[i]);
|
||||
printed_error = true;
|
||||
|
@ -365,11 +365,19 @@ BEGIN_C_DECLS
|
||||
* is displayed. If ignore_unknown is true, the error message is
|
||||
* not displayed.
|
||||
*
|
||||
* Error messages are always displayed (to stderr, and
|
||||
* OPAL_ERR_SILENT is returned) if a token was encountered that
|
||||
* required N parameters, but <N parameters were found (e.g., "cmd
|
||||
* --param foo", but --param was registered to require 2 option
|
||||
* tokens).
|
||||
* Error messages are always displayed regardless of the value
|
||||
* of ignore_unknown (to stderr, and OPAL_ERR_SILENT is
|
||||
* returned) if:
|
||||
*
|
||||
* 1. A token was encountered that required N parameters, but <N
|
||||
* parameters were found (e.g., "cmd --param foo", but --param was
|
||||
* registered to require 2 option tokens).
|
||||
*
|
||||
* 2. An unknown token beginning with "-" is encountered. For
|
||||
* example, if "--fo" is specified, and no "fo" option is
|
||||
* registered (e.g., perhaps the user meant to type "--foo"), an
|
||||
* error message is always printed, UNLESS this unknown token
|
||||
* happens after a "--" token (see below).
|
||||
*
|
||||
* The contents of argc and argv are not changed during parsing.
|
||||
* argv[0] is assumed to be the executable name, and is ignored during
|
||||
@ -400,8 +408,23 @@ BEGIN_C_DECLS
|
||||
* third parameter to the first instance of "foo", and "other" will be
|
||||
* an unrecognized option.
|
||||
*
|
||||
* Invoking this function multiple times on different sets of argv
|
||||
* tokens is safe, but will erase any previous parsing results.
|
||||
* Note that -- can be used to allow unknown tokens that begin
|
||||
* with "-". For example, if a user wants to mpirun an executable
|
||||
* named "-my-mpi-program", the "usual" way:
|
||||
*
|
||||
* mpirun -my-mpi-program
|
||||
*
|
||||
* will cause an error, because mpirun won't find single-letter
|
||||
* options registered for some/all of those letters. But two
|
||||
* workarounds are possible:
|
||||
*
|
||||
* mpirun -- -my-mpi-program
|
||||
* or
|
||||
* mpirun ./-my-mpi-program
|
||||
*
|
||||
* Finally, note that invoking this function multiple times on
|
||||
* different sets of argv tokens is safe, but will erase any
|
||||
* previous parsing results.
|
||||
*/
|
||||
OPAL_DECLSPEC int opal_cmd_line_parse(opal_cmd_line_t *cmd,
|
||||
bool ignore_unknown,
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user