From 990fa191a6ce6bf8d21d5dc5e9ad8acd09765f06 Mon Sep 17 00:00:00 2001 From: Alexander Chernyakhovsky Date: Wed, 11 Sep 2013 17:06:59 -0400 Subject: [PATCH 3/3] Implement tokset --- src/hci/commands/nvo_cmd.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/hci/commands/nvo_cmd.c b/src/hci/commands/nvo_cmd.c index 3fd684d..e0853c3 100644 --- a/src/hci/commands/nvo_cmd.c +++ b/src/hci/commands/nvo_cmd.c @@ -323,6 +323,64 @@ static int inc_exec ( int argc, char **argv ) { return rc; } +static int tokset_exec ( int argc, char **argv ) { + struct set_core_options opts; + struct named_setting src_setting; + struct named_setting dst_setting; + char *value, *token, *rest; + char* sep; + unsigned int token_num, i; + int rc; + + /* Parse options */ + if ( ( rc = parse_options ( argc, argv, &set_cmd, &opts ) ) != 0 ) + goto err_parse_options; + + /* Parse src setting name */ + if ( ( rc = parse_existing_setting ( argv[optind], &src_setting ) ) != 0 ) + goto err_parse_setting; + + /* Parse dst setting name */ + if ( ( rc = parse_autovivified_setting ( argv[optind + 1], &dst_setting ) ) != 0 ) + goto err_parse_setting; + + sep = argv[optind + 2]; + if ( ( rc = parse_integer ( argv [ optind + 3 ], &token_num ) ) != 0) + goto err_parse_setting; + + if ( ( rc = fetchf_setting_copy ( src_setting.settings, &src_setting.setting, + &value ) ) < 0 ) { + printf ( "Could not find \"%s\": %s\n", + src_setting.setting.name, strerror ( rc ) ); + goto err_fetchf; + } + + token = rest = value; + for ( i = 0; ( i < token_num ); i++ ) { + token = rest; + strsep ( &rest, sep ); + } + + /* Apply default type if necessary */ + if ( ! dst_setting.setting.type ) + dst_setting.setting.type = &setting_type_string; + + /* Store setting */ + if ( ( rc = storef_setting ( dst_setting.settings, &dst_setting.setting, + token ) ) != 0 ) { + printf ( "Could not store \"%s\": %s\n", + dst_setting.setting.name, strerror ( rc ) ); + goto err_store; + } + +err_store: + free ( value ); + err_fetchf: + err_parse_setting: + err_parse_options: + return rc; +} + /** Non-volatile option commands */ struct command nvo_commands[] __command = { { @@ -334,6 +392,10 @@ struct command nvo_commands[] __command = { .exec = set_exec, }, { + .name = "tokset", + .exec = tokset_exec, + }, + { .name = "clear", .exec = clear_exec, }, -- 1.8.4