2
0
mirror of https://github.com/xcat2/xNBA.git synced 2024-11-22 09:31:51 +00:00

[parseopt] Add parse_setting()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2013-07-18 16:11:39 +01:00
parent 46433f9b5e
commit 1625a8c05f
2 changed files with 70 additions and 1 deletions

View File

@ -195,6 +195,61 @@ int parse_settings ( char *text, struct settings **value ) {
return 0;
}
/**
* Parse setting name
*
* @v text Text
* @v setting Named setting to fill in
* @v get_child Function to find or create child settings block
* @ret rc Return status code
*
* Note that this function modifies the original @c text.
*/
int parse_setting ( char *text, struct named_setting *setting,
get_child_settings_t get_child ) {
int rc;
/* Sanity check */
assert ( text != NULL );
/* Parse setting name */
if ( ( rc = parse_setting_name ( text, get_child, &setting->settings,
&setting->setting ) ) != 0 ) {
printf ( "\"%s\": invalid setting\n", text );
return rc;
}
return 0;
}
/**
* Parse existing setting name
*
* @v text Text
* @v setting Named setting to fill in
* @ret rc Return status code
*
* Note that this function modifies the original @c text.
*/
int parse_existing_setting ( char *text, struct named_setting *setting ) {
return parse_setting ( text, setting, find_child_settings );
}
/**
* Parse and autovivify setting name
*
* @v text Text
* @v setting Named setting to fill in
* @ret rc Return status code
*
* Note that this function modifies the original @c text.
*/
int parse_autovivified_setting ( char *text, struct named_setting *setting ) {
return parse_setting ( text, setting, autovivify_child_settings );
}
/**
* Print command usage message
*

View File

@ -11,10 +11,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <stddef.h>
#include <ipxe/settings.h>
struct net_device;
struct menu;
struct settings;
/** A command-line option descriptor */
struct option_descriptor {
@ -115,6 +115,14 @@ struct command_descriptor {
.usage = _usage, \
}
/** A parsed named setting */
struct named_setting {
/** Settings block */
struct settings *settings;
/** Setting */
struct setting setting;
};
extern int parse_string ( char *text, char **value );
extern int parse_integer ( char *text, unsigned int *value );
extern int parse_netdev ( char *text, struct net_device **netdev );
@ -122,6 +130,12 @@ extern int parse_menu ( char *text, struct menu **menu );
extern int parse_flag ( char *text __unused, int *flag );
extern int parse_key ( char *text, unsigned int *key );
extern int parse_settings ( char *text, struct settings **settings );
extern int parse_setting ( char *text, struct named_setting *setting,
get_child_settings_t get_child );
extern int parse_existing_setting ( char *text, struct named_setting *setting );
extern int parse_autovivified_setting ( char *text,
struct named_setting *setting );
extern void print_usage ( struct command_descriptor *cmd, char **argv );
extern int reparse_options ( int argc, char **argv,
struct command_descriptor *cmd, void *opts );
extern int parse_options ( int argc, char **argv,