Add new member get_pair to conf parser context
authorGeoff Levand <geoff@infradead.org>
Sun, 18 Mar 2012 23:20:38 +0000 (16:20 -0700)
committerGeoff Levand <geoff@infradead.org>
Sun, 18 Mar 2012 23:27:55 +0000 (16:27 -0700)
To allow parsers more control over finding paramerter pairs
add a new member get_pair to the parser struct conf_context.
Initialize get_pair=conf_get_pair_equal for existing parsers.

Signed-off-by: Geoff Levand <geoff@infradead.org>
discover/kboot-parser.c
discover/parser-conf.c
discover/parser-conf.h
discover/yaboot-parser.c

index ab508ec8df5b253ca7617c670693e0dbb22e2e61..5fabc942c0da6492674fbbc8f453c4fe84b41fe2 100644 (file)
@@ -144,6 +144,7 @@ static int kboot_parse(struct discover_context *dc)
        conf->global_options = kboot_global_options,
        conf_init_global_options(conf);
        conf->conf_files = kboot_conf_files,
        conf->global_options = kboot_global_options,
        conf_init_global_options(conf);
        conf->conf_files = kboot_conf_files,
+       conf->get_pair = conf_get_pair_equal;
        conf->process_pair = kboot_process_pair;
        conf->parser_info = (void *)kboot_ignored_names,
 
        conf->process_pair = kboot_process_pair;
        conf->parser_info = (void *)kboot_ignored_names,
 
index a21efc4aced845e10fec38469e9abcc72bc85ed9..be19932c68c566dac92b9f915d3ec2680613dc4c 100644 (file)
@@ -155,6 +155,9 @@ void conf_init_global_options(struct conf_context *conf)
 {
        int i;
 
 {
        int i;
 
+       if (!conf->global_options)
+               return;
+
        for (i = 0; conf->global_options[i].name; i++)
                conf->global_options[i].value = NULL;
 }
        for (i = 0; conf->global_options[i].name; i++)
                conf->global_options[i].value = NULL;
 }
@@ -171,6 +174,8 @@ int conf_set_global_option(struct conf_context *conf, const char *name,
 {
        int i;
 
 {
        int i;
 
+       assert(conf->global_options);
+
        for (i = 0; conf->global_options[i].name; i++) {
                if (streq(name, conf->global_options[i].name)) {
                        conf->global_options[i].value
        for (i = 0; conf->global_options[i].name; i++) {
                if (streq(name, conf->global_options[i].name)) {
                        conf->global_options[i].value
@@ -196,6 +201,8 @@ const char *conf_get_global_option(struct conf_context *conf,
 {
        int i;
 
 {
        int i;
 
+       assert(conf->global_options);
+
        for (i = 0; conf->global_options[i].name ;i++)
                if (streq(name, conf->global_options[i].name)) {
                        pb_log("%s: @%s@%s@\n", __func__, name,
        for (i = 0; conf->global_options[i].name ;i++)
                if (streq(name, conf->global_options[i].name)) {
                        pb_log("%s: @%s@%s@\n", __func__, name,
@@ -217,8 +224,11 @@ static void conf_parse_buf(struct conf_context *conf)
 {
        char *pos, *name, *value;
 
 {
        char *pos, *name, *value;
 
+       assert(conf->get_pair);
+       assert(conf->process_pair);
+
        for (pos = conf->buf; pos;) {
        for (pos = conf->buf; pos;) {
-               pos = conf_get_pair_equal(conf, pos, &name, &value, '\n');
+               pos = conf->get_pair(conf, pos, &name, &value, '\n');
 
                if (!value)
                        continue;
 
                if (!value)
                        continue;
index 6aa0701bd6e72b50bb3b9232b5184062194fc3d6..efeb4f3d241c6a994db0fc225b1cc27b24455d6b 100644 (file)
@@ -33,6 +33,8 @@ struct conf_context {
        struct conf_global_option *global_options;
        const char *const *conf_files;
 
        struct conf_global_option *global_options;
        const char *const *conf_files;
 
+       char *(*get_pair)(struct conf_context *conf, char *str, char **name_out,
+               char **value_out, char terminator);
        void (*process_pair)(struct conf_context *conf, const char *name,
                char *value);
        void (*finish)(struct conf_context *conf);
        void (*process_pair)(struct conf_context *conf, const char *name,
                char *value);
        void (*finish)(struct conf_context *conf);
index ace994581311108d4e8231d2c0eff046e48639d9..430649266aa77bcf6f67f5a1ed89466e441cd129 100644 (file)
@@ -301,6 +301,7 @@ static int yaboot_parse(struct discover_context *dc)
        conf->global_options = yaboot_global_options,
        conf_init_global_options(conf);
        conf->conf_files = yaboot_conf_files,
        conf->global_options = yaboot_global_options,
        conf_init_global_options(conf);
        conf->conf_files = yaboot_conf_files,
+       conf->get_pair = conf_get_pair_equal;
        conf->process_pair = yaboot_process_pair;
        conf->finish = yaboot_finish;
        conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
        conf->process_pair = yaboot_process_pair;
        conf->finish = yaboot_finish;
        conf->parser_info = state = talloc_zero(conf, struct yaboot_state);