diff options
author | Michael Brown | 2013-07-18 17:11:39 +0200 |
---|---|---|
committer | Michael Brown | 2013-07-22 17:30:44 +0200 |
commit | 1625a8c05fe72b7c53cff049c646e913d6dab362 (patch) | |
tree | c937d5c72c1eb2b7a74c821165debc3bd5a50f25 /src/core/parseopt.c | |
parent | [parseopt] Move parse_settings() to parseopt.c (diff) | |
download | ipxe-1625a8c05fe72b7c53cff049c646e913d6dab362.tar.gz ipxe-1625a8c05fe72b7c53cff049c646e913d6dab362.tar.xz ipxe-1625a8c05fe72b7c53cff049c646e913d6dab362.zip |
[parseopt] Add parse_setting()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/parseopt.c')
-rw-r--r-- | src/core/parseopt.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/core/parseopt.c b/src/core/parseopt.c index 15cca085..65ad4ec5 100644 --- a/src/core/parseopt.c +++ b/src/core/parseopt.c @@ -196,6 +196,61 @@ int parse_settings ( char *text, struct settings **value ) { } /** + * 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 * * @v cmd Command descriptor |