2004-01-09 06:24:54 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-01-09 06:24:54 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-06-17 18:25:29 +04:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* General command line parsing facility for use throughout Open MPI.
|
2004-08-26 11:56:45 +04:00
|
|
|
*
|
|
|
|
* This scheme is inspired by the GNU getopt package. Command line
|
|
|
|
* options are registered. Each option can have up to three different
|
|
|
|
* matching tokens: a "short" name, a "single dash" name, and a "long"
|
|
|
|
* name. Each option can also take 0 or more arguments. Finally,
|
|
|
|
* each option can be repeated on the command line an arbitrary number
|
|
|
|
* of times.
|
|
|
|
*
|
|
|
|
* The "short" name can only be a single letter, and will be found
|
|
|
|
* after a single dash (e.g., "-a"). Multiple "short" names can be
|
|
|
|
* combined into a single command line argument (e.g., "-abc" can be
|
|
|
|
* equivalent to "-a -b -c").
|
|
|
|
*
|
|
|
|
* The "single dash" name is a multi-character name that only
|
|
|
|
* requires a single dash. This only exists to provide backwards
|
|
|
|
* compatability for some well-known command line options in prior
|
|
|
|
* MPI implementations (e.g., "mpirun -np 3"). It should be used
|
|
|
|
* sparingly.
|
|
|
|
*
|
|
|
|
* The "long" name is a multi-character name that is found after a
|
|
|
|
* pair of dashes. For example, "--some-option-name".
|
|
|
|
*
|
|
|
|
* A command line option is a combination of 1 or more of a short
|
|
|
|
* name, single dash name, and a long name. Any of the names may be
|
|
|
|
* used on the command line; they are treated as synonyms. For
|
|
|
|
* example, say the following was used in for an executable named
|
|
|
|
* "foo":
|
|
|
|
*
|
|
|
|
* \code
|
2005-07-04 04:13:44 +04:00
|
|
|
* opal_cmd_line_make_opt3(cmd, 'a', NULL, 'add', 1, "Add a user");
|
2004-08-26 11:56:45 +04:00
|
|
|
* \endcode
|
|
|
|
*
|
|
|
|
* In this case, the following command lines are exactly equivalent:
|
|
|
|
*
|
|
|
|
* \verbatim
|
|
|
|
* shell$ foo -a jsmith
|
|
|
|
* shell$ foo --add jsmith
|
|
|
|
* \endverbatim
|
|
|
|
*
|
|
|
|
* Note that this interface can also track multiple invocations of the
|
|
|
|
* same option. For example, the following is both legal and able to
|
|
|
|
* be retrieved through this interface:
|
|
|
|
*
|
|
|
|
* \verbatim
|
|
|
|
* shell$ foo -a jsmith -add bjones
|
|
|
|
* \endverbatim
|
|
|
|
*
|
|
|
|
* The caller to this interface creates a command line handle
|
2005-07-04 04:13:44 +04:00
|
|
|
* (opal_cmd_line_t) with OBJ_NEW() and then uses it to register the
|
|
|
|
* desired parameters via opal_cmd_line_make_opt3() (or the deprecated
|
|
|
|
* opal_cmd_line_make_opt()). Once all the parameters have been
|
|
|
|
* registered, the user invokes opal_cmd_line_parse() with the command
|
2004-08-26 11:56:45 +04:00
|
|
|
* line handle and the argv/argc pair to be parsed (typically the
|
|
|
|
* arguments from main()). The parser will examine the argv and find
|
|
|
|
* registered options and parameters. It will stop parsing when it
|
|
|
|
* runs into an recognized string token or the special "--" token.
|
|
|
|
*
|
|
|
|
* After the parse has occurred, various accessor functions can be
|
|
|
|
* used to determine which options were selected, what parameters were
|
|
|
|
* passed to them, etc.:
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* - opal_cmd_line_get_usage_msg() returns a string suitable for "help"
|
2004-08-26 11:56:45 +04:00
|
|
|
* kinds of messages.
|
2005-07-04 04:13:44 +04:00
|
|
|
* - opal_cmd_line_is_taken() returns a true or false indicating
|
2004-08-26 11:56:45 +04:00
|
|
|
* whether a given command line option was found on the command
|
|
|
|
* line.
|
2005-07-04 04:13:44 +04:00
|
|
|
* - opal_cmd_line_get_argc() returns the number of tokens parsed on
|
2004-08-26 11:56:45 +04:00
|
|
|
* the handle.
|
2005-07-04 04:13:44 +04:00
|
|
|
* - opal_cmd_line_get_argv() returns any particular string from the
|
2004-08-26 11:56:45 +04:00
|
|
|
* original argv.
|
2005-07-04 04:13:44 +04:00
|
|
|
* - opal_cmd_line_get_ninsts() returns the number of times a
|
2004-08-26 11:56:45 +04:00
|
|
|
* particular option was found on a command line.
|
2005-07-04 04:13:44 +04:00
|
|
|
* - opal_cmd_line_get_param() returns the Nth parameter in the Mth
|
2004-08-26 11:56:45 +04:00
|
|
|
* instance of a given parameter.
|
2005-07-04 04:13:44 +04:00
|
|
|
* - opal_cmd_line_get_tail() returns an array of tokens not parsed
|
2004-08-26 11:56:45 +04:00
|
|
|
* (i.e., if the parser ran into "--" or an unrecognized token).
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
|
|
|
* Note that a shortcut to creating a large number of options exists
|
2005-07-04 04:13:44 +04:00
|
|
|
* -- one can make a table of opal_cmd_line_init_t instances and the
|
|
|
|
* table to opal_cmd_line_create(). This creates an opal_cmd_line_t
|
2005-03-14 23:57:21 +03:00
|
|
|
* handle that is pre-seeded with all the options from the table
|
2005-07-04 04:13:44 +04:00
|
|
|
* without the need to repeatedly invoke opal_cmd_line_make_opt3() (or
|
|
|
|
* equivalent). This opal_cmd_line_t instance is just like any other;
|
2005-03-14 23:57:21 +03:00
|
|
|
* it is still possible to add more options via
|
2005-07-04 04:13:44 +04:00
|
|
|
* opal_cmd_line_make_opt3(), etc.
|
2004-06-17 18:25:29 +04:00
|
|
|
*/
|
2004-01-21 02:58:23 +03:00
|
|
|
|
2005-07-04 04:13:44 +04:00
|
|
|
#ifndef OPAL_CMD_LINE_H
|
|
|
|
#define OPAL_CMD_LINE_H
|
2004-01-09 06:24:54 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-08-26 11:56:45 +04:00
|
|
|
|
2005-07-03 20:06:07 +04:00
|
|
|
#include "opal/class/opal_object.h"
|
2005-07-03 20:22:16 +04:00
|
|
|
#include "opal/class/opal_list.h"
|
2005-07-04 02:45:48 +04:00
|
|
|
#include "opal/threads/mutex.h"
|
2004-01-10 21:19:55 +03:00
|
|
|
|
2004-10-21 02:31:03 +04:00
|
|
|
#if defined(c_plusplus) || defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
|
|
|
* \internal
|
|
|
|
*
|
|
|
|
* Main top-level handle. This interface should not be used by users!
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
struct opal_cmd_line_t {
|
2005-03-14 23:57:21 +03:00
|
|
|
/** Make this an OBJ handle */
|
2005-07-03 20:06:07 +04:00
|
|
|
opal_object_t super;
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
/** Thread safety */
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_mutex_t lcl_mutex;
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
/** List of cmd_line_option_t's (defined internally) */
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_t lcl_options;
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2005-07-04 04:13:44 +04:00
|
|
|
/** Duplicate of argc from opal_cmd_line_parse() */
|
2005-03-14 23:57:21 +03:00
|
|
|
int lcl_argc;
|
2005-07-04 04:13:44 +04:00
|
|
|
/** Duplicate of argv from opal_cmd_line_parse() */
|
2005-03-14 23:57:21 +03:00
|
|
|
char **lcl_argv;
|
|
|
|
|
|
|
|
/** Parsed output; list of cmd_line_param_t's (defined internally) */
|
2005-07-03 20:22:16 +04:00
|
|
|
opal_list_t lcl_params;
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
/** List of tail (unprocessed) arguments */
|
|
|
|
int lcl_tail_argc;
|
|
|
|
/** List of tail (unprocessed) arguments */
|
|
|
|
char **lcl_tail_argv;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* \internal
|
|
|
|
*
|
|
|
|
* Convenience typedef
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
typedef struct opal_cmd_line_t opal_cmd_line_t;
|
2004-01-10 20:21:33 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
|
|
|
* Data types supported by the parser
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
enum opal_cmd_line_type_t {
|
|
|
|
OPAL_CMD_LINE_TYPE_NULL,
|
|
|
|
OPAL_CMD_LINE_TYPE_STRING,
|
|
|
|
OPAL_CMD_LINE_TYPE_INT,
|
|
|
|
OPAL_CMD_LINE_TYPE_SIZE_T,
|
|
|
|
OPAL_CMD_LINE_TYPE_BOOL,
|
2004-01-10 20:21:33 +03:00
|
|
|
|
2005-07-04 04:13:44 +04:00
|
|
|
OPAL_CMD_LINE_TYPE_MAX
|
2005-03-14 23:57:21 +03:00
|
|
|
};
|
|
|
|
/**
|
|
|
|
* \internal
|
|
|
|
*
|
|
|
|
* Convenience typedef
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
typedef enum opal_cmd_line_type_t opal_cmd_line_type_t;
|
2004-01-10 20:21:33 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
|
|
|
* Datatype used to construct a command line handle; see
|
2005-07-04 04:13:44 +04:00
|
|
|
* opal_cmd_line_create().
|
2005-03-14 23:57:21 +03:00
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
struct opal_cmd_line_init_t {
|
2005-03-14 23:57:21 +03:00
|
|
|
/** If want to set an MCA parameter, set its type name here.
|
|
|
|
WARNING: This MCA tuple (type, component, param) will
|
|
|
|
eventually be replaced with a single name! */
|
|
|
|
const char *ocl_mca_type_name;
|
|
|
|
/** If want to set an MCA parameter, set its component name
|
|
|
|
here. WARNING: This MCA tuple (type, component, param)
|
|
|
|
will eventually be replaced with a single name! */
|
|
|
|
const char *ocl_mca_component_name;
|
|
|
|
/** If want to set an MCA parameter, set its parameter name
|
|
|
|
here. WARNING: This MCA tuple (type, component, param)
|
|
|
|
will eventually be replaced with a single name! */
|
|
|
|
const char *ocl_mca_param_name;
|
2004-01-10 20:21:33 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/** "Short" name (i.e., "-X", where "X" is a single letter) */
|
|
|
|
char ocl_cmd_short_name;
|
|
|
|
/** "Single dash" name (i.e., "-foo"). The use of these are
|
|
|
|
discouraged. */
|
|
|
|
const char *ocl_cmd_single_dash_name;
|
|
|
|
/** Long name (i.e., "--foo"). */
|
|
|
|
const char *ocl_cmd_long_name;
|
|
|
|
|
|
|
|
/** Number of parameters that this option takes */
|
|
|
|
int ocl_num_params;
|
|
|
|
|
|
|
|
/** If this parameter is encountered, its *first* parameter it
|
|
|
|
saved here. If the parameter is encountered again, the
|
|
|
|
value is overwritten. */
|
|
|
|
void *ocl_variable_dest;
|
|
|
|
/** If an ocl_variable_dest is given, its datatype must be
|
|
|
|
supplied as well. */
|
2005-07-04 04:13:44 +04:00
|
|
|
opal_cmd_line_type_t ocl_variable_type;
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
/** Description of the command line option, to be used with
|
2005-07-04 04:13:44 +04:00
|
|
|
opal_cmd_line_get_usage_msg(). */
|
2005-03-14 23:57:21 +03:00
|
|
|
const char *ocl_description;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* \internal
|
|
|
|
*
|
|
|
|
* Convenience typedef
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
typedef struct opal_cmd_line_init_t opal_cmd_line_init_t;
|
2004-08-26 11:56:45 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
|
|
|
* Top-level command line handle.
|
|
|
|
*
|
|
|
|
* This handle is used for accessing all command line functionality
|
2005-07-04 04:13:44 +04:00
|
|
|
* (i.e., all opal_cmd_line*() functions). Multiple handles can be
|
2005-03-14 23:57:21 +03:00
|
|
|
* created and simultaneously processed; each handle is independant
|
|
|
|
* from others.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* The opal_cmd_line_t handles are [simplisticly] thread safe;
|
2005-03-14 23:57:21 +03:00
|
|
|
* processing is guaranteed to be mutually exclusive if multiple
|
|
|
|
* threads invoke functions on the same handle at the same time --
|
|
|
|
* access will be serialized in an unspecified order.
|
|
|
|
*
|
|
|
|
* Once finished, handles should be released with OBJ_RELEASE(). The
|
2005-07-04 04:13:44 +04:00
|
|
|
* destructor for opal_cmd_line_t handles will free all memory
|
2005-03-14 23:57:21 +03:00
|
|
|
* associated with the handle.
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
OMPI_DECLSPEC OBJ_CLASS_DECLARATION(opal_cmd_line_t);
|
2004-01-09 06:24:54 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
|
|
|
* Make a command line handle from a table of initializers.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* @param cmd OPAL command line handle.
|
|
|
|
* @param table Table of opal_cmd_line_init_t instances for all
|
2005-03-14 23:57:21 +03:00
|
|
|
* the options to be included in the resulting command line
|
|
|
|
* handler.
|
|
|
|
*
|
|
|
|
* @retval OMPI_SUCCESS Upon success.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* This function takes a table of opal_cmd_line_init_t instances
|
|
|
|
* to pre-seed an OPAL command line handle. The last instance in
|
2005-03-14 23:57:21 +03:00
|
|
|
* the table must have '\0' for the short name and NULL for the
|
|
|
|
* single-dash and long names. The handle is expected to have
|
|
|
|
* been OBJ_NEW'ed or OBJ_CONSTRUCT'ed already.
|
|
|
|
*
|
|
|
|
* Upon return, the command line handle is just like any other. A
|
|
|
|
* sample using this syntax:
|
|
|
|
*
|
|
|
|
* \code
|
2005-07-04 04:13:44 +04:00
|
|
|
* opal_cmd_line_init_t cmd_line_init[] = {
|
2005-03-14 23:57:21 +03:00
|
|
|
* { NULL, NULL, NULL, 'h', NULL, "help", 0,
|
2005-07-04 04:13:44 +04:00
|
|
|
* &orterun_globals.help, OPAL_CMD_LINE_TYPE_BOOL,
|
2005-03-14 23:57:21 +03:00
|
|
|
* "This help message" },
|
|
|
|
*
|
|
|
|
* { NULL, NULL, NULL, '\0', NULL, "wd", 1,
|
2005-07-04 04:13:44 +04:00
|
|
|
* &orterun_globals.wd, OPAL_CMD_LINE_TYPE_STRING,
|
2005-03-14 23:57:21 +03:00
|
|
|
* "Set the working directory of the started processes" },
|
|
|
|
*
|
|
|
|
* { NULL, NULL, NULL, '\0', NULL, NULL, 0,
|
2005-07-04 04:13:44 +04:00
|
|
|
* NULL, OPAL_CMD_LINE_TYPE_NULL, NULL }
|
2005-03-14 23:57:21 +03:00
|
|
|
* };
|
|
|
|
* \endcode
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
OMPI_DECLSPEC int opal_cmd_line_create(opal_cmd_line_t *cmd,
|
|
|
|
opal_cmd_line_init_t *table);
|
2004-01-21 02:58:23 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
2005-10-08 02:27:27 +04:00
|
|
|
* \deprecated
|
|
|
|
*
|
2005-03-14 23:57:21 +03:00
|
|
|
* Create a command line option.
|
|
|
|
*
|
|
|
|
* This function is an older [deprecated] form of
|
2005-07-04 04:13:44 +04:00
|
|
|
* opal_cmd_line_make_opt3(). It is exactly equivalent to
|
|
|
|
* opal_cmd_line_make_opt3(cmd, short_name, NULL, long_name,
|
2005-03-14 23:57:21 +03:00
|
|
|
* num_params, desc).
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
OMPI_DECLSPEC int opal_cmd_line_make_opt(opal_cmd_line_t *cmd,
|
2005-03-14 23:57:21 +03:00
|
|
|
char short_name,
|
|
|
|
const char *long_name,
|
|
|
|
int num_params,
|
|
|
|
const char *desc);
|
2004-08-26 11:56:45 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
|
|
|
* Create a command line option.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* @param cmd OPAL command line handle.
|
2005-03-14 23:57:21 +03:00
|
|
|
* @param short_name "Short" name of the command line option.
|
|
|
|
* @param sd_name "Single dash" name of the command line option.
|
|
|
|
* @param long_name "Long" name of the command line option.
|
|
|
|
* @param num_params How many parameters this option takes.
|
|
|
|
* @param dest Short string description of this option.
|
|
|
|
*
|
|
|
|
* @retval OMPI_ERR_OUT_OF_RESOURCE If out of memory.
|
|
|
|
* @retval OMPI_ERR_BAD_PARAM If bad parameters passed.
|
|
|
|
* @retval OMPI_SUCCESS Upon success.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* Adds a command line option to the list of options that a a OPAL
|
2005-03-14 23:57:21 +03:00
|
|
|
* command line handle will accept. The short_name may take the
|
|
|
|
* special value '\0' to not have a short name. Likewise, the
|
|
|
|
* sd_name and long_name may take the special value NULL to not have
|
|
|
|
* a single dash or long name, respectively. However, one of the
|
|
|
|
* three must have a name.
|
|
|
|
*
|
|
|
|
* num_params indicates how many parameters this option takes. It
|
|
|
|
* must be greater than or equal to 0.
|
|
|
|
*
|
|
|
|
* Finally, desc is a short string description of this option. It is
|
2005-07-04 04:13:44 +04:00
|
|
|
* used to generate the output from opal_cmd_line_get_usage_msg().
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
OMPI_DECLSPEC int opal_cmd_line_make_opt3(opal_cmd_line_t *cmd,
|
2005-03-14 23:57:21 +03:00
|
|
|
char short_name,
|
|
|
|
const char *sd_name,
|
|
|
|
const char *long_name,
|
|
|
|
int num_params,
|
|
|
|
const char *desc);
|
2004-08-26 11:56:45 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
2005-07-04 04:13:44 +04:00
|
|
|
* Parse a command line according to a pre-built OPAL command line
|
2005-03-14 23:57:21 +03:00
|
|
|
* handle.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* @param cmd OPAL command line handle.
|
2005-03-14 23:57:21 +03:00
|
|
|
* @param ignore_unknown Whether to print an error message upon
|
|
|
|
* finding an unknown token or not
|
|
|
|
* @param argc Length of the argv array.
|
|
|
|
* @param argv Array of strings from the command line.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* @retval OPAL_SUCCESS Upon success.
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
|
|
|
* Parse a series of command line tokens according to the option
|
2005-07-04 04:13:44 +04:00
|
|
|
* descriptions from a OPAL command line handle. The OPAL command line
|
2005-03-14 23:57:21 +03:00
|
|
|
* handle can then be queried to see what options were used, what
|
|
|
|
* their parameters were, etc.
|
|
|
|
*
|
|
|
|
* If an unknown token is found in the command line (i.e., a token
|
|
|
|
* that is not a parameter or a registered option), the parsing will
|
|
|
|
* stop (see below). If ignore_unknown is false, an error message
|
|
|
|
* is displayed. If ignore_unknown is true, the error message is
|
|
|
|
* not displayed.
|
|
|
|
*
|
|
|
|
* The contents of argc and argv are not changed during parsing.
|
|
|
|
* argv[0] is assumed to be the executable name, and is ignored during
|
|
|
|
* parsing. It can later be retrieved with
|
|
|
|
*
|
|
|
|
* Parsing will stop in the following conditions:
|
|
|
|
*
|
|
|
|
* - all argv tokens are processed
|
|
|
|
* - the token "--" is found
|
|
|
|
* - an unrecognized token is found
|
|
|
|
*
|
|
|
|
* Upon any of these conditions, any remaining tokens will be placed
|
|
|
|
* in the "tail" (and therefore not examined by the parser),
|
|
|
|
* regardless of the value of ignore_unknown. The set of tail
|
2005-07-04 04:13:44 +04:00
|
|
|
* tokens is available from the opal_cmd_line_get_tail() function.
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
|
|
|
* Note that "--" is ignored if it is found in the middle an expected
|
|
|
|
* number of arguments. For example, if "--foo" is expected to have 3
|
|
|
|
* arguments, and the command line is:
|
|
|
|
*
|
|
|
|
* executable --foo a b -- other arguments
|
|
|
|
*
|
|
|
|
* This will result in an error, because "--" will be parsed as the
|
|
|
|
* 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.
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
OMPI_DECLSPEC int opal_cmd_line_parse(opal_cmd_line_t *cmd,
|
2005-03-14 23:57:21 +03:00
|
|
|
bool ignore_unknown,
|
|
|
|
int argc, char **argv);
|
2004-01-09 06:24:54 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
2005-07-04 04:13:44 +04:00
|
|
|
* Return a consolidated "usage" message for a OPAL command line handle.
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* @param cmd OPAL command line handle.
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
|
|
|
* @retval str Usage message.
|
|
|
|
*
|
|
|
|
* Returns a formatted string suitable for printing that lists the
|
|
|
|
* expected usage message and a short description of each option on
|
2005-07-04 04:13:44 +04:00
|
|
|
* the OPAL command line handle. Options that passed a NULL
|
|
|
|
* description to opal_cmd_line_make_opt() will not be included in the
|
2005-03-14 23:57:21 +03:00
|
|
|
* display (to allow for undocumented options).
|
|
|
|
*
|
|
|
|
* This function is typically only invoked internally by the
|
2005-07-04 06:38:44 +04:00
|
|
|
* opal_show_help() function.
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
|
|
|
* This function should probably be fixed up to produce prettier
|
|
|
|
* output.
|
|
|
|
*
|
|
|
|
* The returned string must be freed by the caller.
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
OMPI_DECLSPEC char *opal_cmd_line_get_usage_msg(opal_cmd_line_t *cmd);
|
2004-01-10 20:21:33 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
|
|
|
* Test if a given option was taken on the parsed command line.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* @param cmd OPAL command line handle.
|
2005-03-14 23:57:21 +03:00
|
|
|
* @param opt Short or long name of the option to check for.
|
|
|
|
*
|
|
|
|
* @retval true If the command line option was found during
|
2005-07-04 04:13:44 +04:00
|
|
|
* opal_cmd_line_parse().
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
|
|
|
* @retval false If the command line option was not found during
|
2005-07-04 04:13:44 +04:00
|
|
|
* opal_cmd_line_parse(), or opal_cmd_line_parse() was not invoked on
|
2005-03-14 23:57:21 +03:00
|
|
|
* this handle.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* This function should only be called after opal_cmd_line_parse().
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
|
|
|
* The function will return true if the option matching opt was found
|
|
|
|
* (either by its short or long name) during token parsing.
|
|
|
|
* Otherwise, it will return false.
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
OMPI_DECLSPEC bool opal_cmd_line_is_taken(opal_cmd_line_t *cmd,
|
2005-03-14 23:57:21 +03:00
|
|
|
const char *opt);
|
2004-01-10 20:21:33 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
2005-07-04 04:13:44 +04:00
|
|
|
* Return the number of arguments parsed on a OPAL command line handle.
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* @param cmd A pointer to the OPAL command line handle.
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
|
|
|
* @retval OMPI_ERROR If cmd is NULL.
|
|
|
|
* @retval argc Number of arguments previously added to the handle.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* Arguments are added to the handle via the opal_cmd_line_parse()
|
2005-03-14 23:57:21 +03:00
|
|
|
* function.
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
OMPI_DECLSPEC int opal_cmd_line_get_argc(opal_cmd_line_t *cmd);
|
2004-08-26 11:56:45 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
2005-07-04 04:13:44 +04:00
|
|
|
* Return a string argument parsed on a OPAL command line handle.
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* @param cmd A pointer to the OPAL command line handle.
|
2005-03-14 23:57:21 +03:00
|
|
|
* @param index The nth argument from the command line (0 is
|
|
|
|
* argv[0], etc.).
|
|
|
|
*
|
|
|
|
* @retval NULL If cmd is NULL or index is invalid
|
|
|
|
* @retval argument String of original argv[index]
|
|
|
|
*
|
|
|
|
* This function returns a single token from the arguments parsed
|
|
|
|
* on this handle. Arguments are added bia the
|
2005-07-04 04:13:44 +04:00
|
|
|
* opal_cmd_line_parse() function.
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
|
|
|
* What is returned is a pointer to the actual string that is on
|
|
|
|
* the handle; it should not be modified or freed.
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
OMPI_DECLSPEC char *opal_cmd_line_get_argv(opal_cmd_line_t *cmd,
|
2005-03-14 23:57:21 +03:00
|
|
|
int index);
|
2004-08-26 11:56:45 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
|
|
|
* Return the number of instances of an option found during parsing.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* @param cmd OPAL command line handle.
|
2005-03-14 23:57:21 +03:00
|
|
|
* @param opt Short or long name of the option to check for.
|
|
|
|
*
|
|
|
|
* @retval num Number of instances (to include 0) of a given potion
|
2005-07-04 04:13:44 +04:00
|
|
|
* found during opal_cmd_line_parse().
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
|
|
|
* @retval OMPI_ERR If the command line option was not found during
|
2005-07-04 04:13:44 +04:00
|
|
|
* opal_cmd_line_parse(), or opal_cmd_line_parse() was not invoked on
|
2005-03-14 23:57:21 +03:00
|
|
|
* this handle.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* This function should only be called after opal_cmd_line_parse().
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
|
|
|
* The function will return the number of instances of a given option
|
|
|
|
* (either by its short or long name) -- to include 0 -- or OMPI_ERR if
|
2005-07-04 04:13:44 +04:00
|
|
|
* either the option was not specified as part of the OPAL command line
|
|
|
|
* handle, or opal_cmd_line_parse() was not invoked on this handle.
|
2005-03-14 23:57:21 +03:00
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
OMPI_DECLSPEC int opal_cmd_line_get_ninsts(opal_cmd_line_t *cmd,
|
2005-03-14 23:57:21 +03:00
|
|
|
const char *opt);
|
2004-08-26 11:56:45 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
|
|
|
* Return a specific parameter for a specific instance of a option
|
|
|
|
* from the parsed command line.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* @param cmd OPAL command line handle.
|
2005-03-14 23:57:21 +03:00
|
|
|
* @param opt Short or long name of the option to check for.
|
|
|
|
* @param instance_num Instance number of the option to query.
|
|
|
|
* @param param_num Which parameter to return.
|
|
|
|
*
|
|
|
|
* @retval param String of the parameter.
|
|
|
|
* @retval NULL If any of the input values are invalid.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* This function should only be called after opal_cmd_line_parse().
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
|
|
|
* This function returns the Nth parameter for the Ith instance of a
|
|
|
|
* given option on the parsed command line (both N and I are
|
|
|
|
* zero-indexed). For example, on the command line:
|
|
|
|
*
|
|
|
|
* executable --foo bar1 bar2 --foo bar3 bar4
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* The call to opal_cmd_line_get_param(cmd, "foo", 1, 1) would return
|
|
|
|
* "bar4". opal_cmd_line_get_param(cmd, "bar", 0, 0) would return
|
|
|
|
* NULL, as would opal_cmd_line_get_param(cmd, "foo", 2, 2);
|
2005-03-14 23:57:21 +03:00
|
|
|
*
|
|
|
|
* The returned string should \em not be modified or freed by the
|
|
|
|
* caller.
|
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
OMPI_DECLSPEC char *opal_cmd_line_get_param(opal_cmd_line_t *cmd,
|
2005-03-14 23:57:21 +03:00
|
|
|
const char *opt,
|
|
|
|
int instance_num,
|
|
|
|
int param_num);
|
2004-06-17 18:25:29 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/**
|
2005-07-04 04:13:44 +04:00
|
|
|
* Return the entire "tail" of unprocessed argv from a OPAL
|
2005-03-14 23:57:21 +03:00
|
|
|
* command line handle.
|
|
|
|
*
|
2005-07-04 04:13:44 +04:00
|
|
|
* @param cmd A pointer to the OPAL command line handle.
|
2005-03-14 23:57:21 +03:00
|
|
|
* @param tailc Pointer to the output length of the null-terminated
|
|
|
|
* tail argv array.
|
|
|
|
* @param tailv Pointer to the output null-terminated argv of all
|
|
|
|
* unprocessed arguments from the command line.
|
|
|
|
*
|
|
|
|
* @retval OMPI_ERROR If cmd is NULL or otherwise invalid.
|
|
|
|
* @retval OMPI_SUCCESS Upon success.
|
|
|
|
*
|
|
|
|
* The "tail" is all the arguments on the command line that were
|
|
|
|
* not processed for some reason. Reasons for not processing
|
|
|
|
* arguments include:
|
|
|
|
*
|
|
|
|
* \sa The argument was not recognized
|
|
|
|
* \sa The argument "--" was seen, and therefore all arguments
|
|
|
|
* following it were not processed
|
|
|
|
*
|
|
|
|
* The output tailc parameter will be filled in with the integer
|
|
|
|
* length of the null-terminated tailv array (length including the
|
|
|
|
* final NULL entry). The output tailv parameter will be a copy
|
|
|
|
* of the tail parameters, and must be freed (likely with a call
|
2005-07-04 04:13:44 +04:00
|
|
|
* to opal_argv_free()) by the caller.
|
2005-03-14 23:57:21 +03:00
|
|
|
*/
|
2005-07-04 04:13:44 +04:00
|
|
|
OMPI_DECLSPEC int opal_cmd_line_get_tail(opal_cmd_line_t *cmd, int *tailc,
|
2005-03-14 23:57:21 +03:00
|
|
|
char ***tailv);
|
2004-08-26 11:56:45 +04:00
|
|
|
|
2004-10-21 02:31:03 +04:00
|
|
|
#if defined(c_plusplus) || defined(__cplusplus)
|
2004-01-09 06:24:54 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-07-04 04:13:44 +04:00
|
|
|
#endif /* OPAL_CMD_LINE_H */
|