Mercurial > dovecot > original-hg > dovecot-1.2
changeset 5485:9b873c82bc88 HEAD
Added var_expand_table_build()
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 31 Mar 2007 17:04:28 +0300 |
parents | 40d3318b49d4 |
children | 61ef8b18a12c |
files | src/lib/var-expand.c src/lib/var-expand.h |
diffstat | 2 files changed, 31 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/var-expand.c Sat Mar 31 16:18:12 2007 +0300 +++ b/src/lib/var-expand.c Sat Mar 31 17:04:28 2007 +0300 @@ -1,6 +1,7 @@ /* Copyright (C) 2003-2004 Timo Sirainen */ #include "lib.h" +#include "array.h" #include "md5.h" #include "hash.h" #include "hex-binary.h" @@ -266,3 +267,30 @@ return *str; } + +const struct var_expand_table * +var_expand_table_build(char key, const char *value, char key2, ...) +{ + ARRAY_DEFINE(variables, struct var_expand_table); + struct var_expand_table *var; + va_list args; + + i_assert(key != '\0'); + + t_array_init(&variables, 16); + var = array_append_space(&variables); + var->key = key; + var->value = value; + + va_start(args, key2); + for (key = key2; key != '\0'; key = va_arg(args, int)) { + var = array_append_space(&variables); + var->key = key; + var->value = va_arg(args, const char *); + } + va_end(args); + + /* 0, NULL entry */ + (void)array_append_space(&variables); + return array_idx(&variables, 0); +}
--- a/src/lib/var-expand.h Sat Mar 31 16:18:12 2007 +0300 +++ b/src/lib/var-expand.h Sat Mar 31 17:04:28 2007 +0300 @@ -15,4 +15,7 @@ that are before it. The string should be the data after the '%' character. */ char var_get_key(const char *str); +const struct var_expand_table * +var_expand_table_build(char key, const char *value, char key2, ...); + #endif