X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fparser-conf.c;h=be19932c68c566dac92b9f915d3ec2680613dc4c;hp=e9f436c6c214b4d84328dc00558000fffce0e2c4;hb=01ed80939b8ed440390729c524ad875047dbd406;hpb=5472ed16df5642aedc124a1b49a35d99da98cc37 diff --git a/discover/parser-conf.c b/discover/parser-conf.c index e9f436c..be19932 100644 --- a/discover/parser-conf.c +++ b/discover/parser-conf.c @@ -58,11 +58,28 @@ char *conf_strip_str(char *s) } /** - * conf_get_param_pair - Get the next 'name=value' parameter pair. + * conf_replace_char - replace one char with another. + */ + +char *conf_replace_char(char *s, char from, char to) +{ + if (!s) + return NULL; + + for ( ; *s; s++) + if (*s == from) + *s = to; + + return s; +} + +/** + * conf_get_pair - Get the next 'name/value' parameter pair. * @str: The string to process. * @name_out: Returns a pointer to the name. * @value_out: Returns a pointer to the value. - * @terminator: The pair separator/terminator. + * @tdelimiter: The pair separator. + * @terminator: The pair terminator. * * Parses a name=value pair returning pointers in @name_out and @value_out. * The pair can be terminated by @terminator or a zero. @@ -75,18 +92,27 @@ char *conf_strip_str(char *s) * string. */ -char *conf_get_param_pair(char *str, char **name_out, char **value_out, - char terminator) +char *conf_get_pair(struct conf_context __attribute__((unused)) *conf, char *str, + char **name_out, char **value_out, char delimiter, char terminator) { char *sep, *end; + *name_out = *value_out = NULL; + /* terminate the value */ end = strchr(str, terminator); if (end) *end = 0; - sep = strchr(str, '='); + conf_replace_char(str, '\t', ' '); + + str = conf_strip_str(str); + + if (!str) + goto exit; + + sep = strchr(str, delimiter); if (!sep) { *name_out = NULL; @@ -97,6 +123,7 @@ char *conf_get_param_pair(char *str, char **name_out, char **value_out, *value_out = conf_strip_str(sep + 1); } +exit: pb_log("%s: @%s@%s@\n", __func__, *name_out, *value_out); return end ? end + 1 : NULL; @@ -120,6 +147,21 @@ int conf_param_in_list(const char *const *list, const char *param) return 0; } +/** + * conf_init_global_options - Zero the global option table. + */ + +void conf_init_global_options(struct conf_context *conf) +{ + int i; + + if (!conf->global_options) + return; + + for (i = 0; conf->global_options[i].name; i++) + conf->global_options[i].value = NULL; +} + /** * conf_set_global_option - Set a value in the global option table. * @@ -132,11 +174,13 @@ int conf_set_global_option(struct conf_context *conf, const char *name, { 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 = talloc_strdup(conf, value); - pb_log("%s: %s:%s\n", __func__, name, value); + pb_log("%s: @%s@%s@\n", __func__, name, value); return 1; } } @@ -157,9 +201,14 @@ const char *conf_get_global_option(struct conf_context *conf, { int i; + assert(conf->global_options); + for (i = 0; conf->global_options[i].name ;i++) - if (streq(name, conf->global_options[i].name)) + if (streq(name, conf->global_options[i].name)) { + pb_log("%s: @%s@%s@\n", __func__, name, + conf->global_options[i].value); return conf->global_options[i].value; + } assert(0 && "unknown global name"); return NULL; @@ -175,8 +224,11 @@ static void conf_parse_buf(struct conf_context *conf) { char *pos, *name, *value; + assert(conf->get_pair); + assert(conf->process_pair); + for (pos = conf->buf; pos;) { - pos = conf_get_param_pair(pos, &name, &value, '\n'); + pos = conf->get_pair(conf, pos, &name, &value, '\n'); if (!value) continue; @@ -187,11 +239,6 @@ static void conf_parse_buf(struct conf_context *conf) if (*value == '#') continue; - value = conf_strip_str(value); - - if (!value) - continue; - conf->process_pair(conf, name, value); }