iPXE
Data Structures | Functions | Variables
param_cmd.c File Reference

Form parameter commands. More...

#include <stdlib.h>
#include <errno.h>
#include <getopt.h>
#include <ipxe/params.h>
#include <ipxe/parseopt.h>
#include <ipxe/command.h>

Go to the source code of this file.

Data Structures

struct  params_options
 "params" options More...
struct  param_options
 "param" options More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static int params_exec (int argc, char **argv)
 The "params" command.
static int param_exec (int argc, char **argv)
 The "param" command.

Variables

static struct option_descriptor params_opts []
 "params" option list
static struct command_descriptor params_cmd
 "params" command descriptor
static struct option_descriptor param_opts []
 "param" option list
static struct command_descriptor param_cmd
 "param" command descriptor
struct command param_commands[] __command
 Form parameter commands.

Detailed Description

Form parameter commands.

Definition in file param_cmd.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static int params_exec ( int  argc,
char **  argv 
) [static]

The "params" command.

Parameters:
argcArgument count
argvArgument list
Return values:
rcReturn status code

Definition at line 66 of file param_cmd.c.

References create_parameters(), params_options::delete, ENOMEM, params_options::name, params, parse_options(), and rc.

                                                 {
        struct params_options opts;
        struct parameters *params;
        int rc;

        /* Parse options */
        if ( ( rc = parse_options ( argc, argv, &params_cmd, &opts ) ) != 0)
                return rc;

        /* Create parameter list */
        params = create_parameters ( opts.name );
        if ( ! params )
                return -ENOMEM;

        /* Destroy parameter list, if applicable */
        if ( opts.delete ) {
                claim_parameters ( params );
                params_put ( params );
        }

        return 0;
}
static int param_exec ( int  argc,
char **  argv 
) [static]

The "param" command.

Parameters:
argcArgument count
argvArgument list
Return values:
rcReturn status code

Definition at line 113 of file param_cmd.c.

References add_parameter(), concat_args(), ENOMEM, free, key, optind, param, param_options::params, params, parse_options(), parse_parameters(), rc, and value.

                                                {
        struct param_options opts;
        char *key;
        char *value;
        struct parameters *params;
        struct parameter *param;
        int rc;

        /* Parse options */
        if ( ( rc = parse_options ( argc, argv, &param_cmd, &opts ) ) != 0 )
                goto err_parse_options;

        /* Parse key */
        key = argv[optind];

        /* Parse value */
        value = concat_args ( &argv[ optind + 1 ] );
        if ( ! value ) {
                rc = -ENOMEM;
                goto err_parse_value;
        }

        /* Identify parameter list */
        if ( ( rc = parse_parameters ( opts.params, &params ) ) != 0 )
                goto err_parse_parameters;

        /* Add parameter */
        param = add_parameter ( params, key, value );
        if ( ! param ) {
                rc = -ENOMEM;
                goto err_add_parameter;
        }

        /* Success */
        rc = 0;

 err_add_parameter:
 err_parse_parameters:
        free ( value );
 err_parse_value:
 err_parse_options:
        return rc;
}

Variable Documentation

struct option_descriptor params_opts[] [static]
Initial value:
 {
        OPTION_DESC ( "name", 'n', required_argument,
                      struct params_options, name, parse_string ),
        OPTION_DESC ( "delete", 'd', no_argument,
                      struct params_options, delete, parse_flag ),
}

"params" option list

Definition at line 48 of file param_cmd.c.

struct command_descriptor params_cmd [static]
Initial value:

"params" command descriptor

Definition at line 56 of file param_cmd.c.

struct option_descriptor param_opts[] [static]
Initial value:
 {
        OPTION_DESC ( "params", 'p', required_argument,
                      struct param_options, params, parse_string ),
}

"param" option list

Definition at line 96 of file param_cmd.c.

struct command_descriptor param_cmd [static]
Initial value:
        COMMAND_DESC ( struct param_options, param_opts, 1, MAX_ARGUMENTS,
                       "<key> [<value>]" )

"param" command descriptor

Definition at line 102 of file param_cmd.c.

struct command param_commands [] __command
Initial value:
 {
        {
                .name = "params",
                .exec = params_exec,
        },
        {
                .name = "param",
                .exec = param_exec,
        },
}

Form parameter commands.

Definition at line 158 of file param_cmd.c.