static bool
settings_find_key_nth(struct setting_parser_context *ctx, const char *key,
- unsigned int n, const struct setting_define **def_r,
+ unsigned int *n, const struct setting_define **def_r,
struct setting_link **link_r)
{
const struct setting_define *def;
unsigned int i;
/* try to find from roots */
- for (i = 0; i < ctx->root_count; i++) {
+ for (i = *n; i < ctx->root_count; i++) {
def = setting_define_find(ctx->roots[i].info, key);
- if (def != NULL && n-- == 0) {
+ if (def != NULL) {
+ *n = i + 1;
*def_r = def;
*link_r = &ctx->roots[i];
return TRUE;
}
}
- if (n > 0)
+ if (*n > ctx->root_count)
return FALSE;
+ *n += 1;
/* try to find from links */
end = strrchr(key, SETTINGS_SEPARATOR);
const struct setting_define **def_r,
struct setting_link **link_r)
{
- return settings_find_key_nth(ctx, key, 0, def_r, link_r);
+ unsigned int n = 0;
+
+ return settings_find_key_nth(ctx, key, &n, def_r, link_r);
}
static void
struct setting_link *link;
unsigned int n = 0;
- if (!settings_find_key(ctx, key, &def, &link)) {
+ if (!settings_find_key_nth(ctx, key, &n, &def, &link)) {
ctx->error = p_strconcat(ctx->parser_pool,
"Unknown setting: ", key, NULL);
return 0;
if (settings_parse(ctx, link, def, key, value) < 0)
return -1;
/* there may be more instances of the setting */
- } while (settings_find_key_nth(ctx, key, ++n, &def, &link));
+ } while (settings_find_key_nth(ctx, key, &n, &def, &link));
return 1;
}