diff options
Diffstat (limited to 'src/meta.c')
-rw-r--r-- | src/meta.c | 39 |
1 files changed, 31 insertions, 8 deletions
@@ -18,7 +18,7 @@ #include "sql.h" static const char * -meta_expand(struct metadef *def, void *data) +meta_expand(struct wy_metadef *def, void *data) { if (!def->value) { if (def->expand) @@ -29,7 +29,7 @@ meta_expand(struct metadef *def, void *data) } static const char * -find_expansion_char(int c, struct metadef *def, void *data) +find_expansion_char(int c, struct wy_metadef *def, void *data) { for (; def->kw; def++) if (def->kw[1] == 0 && def->kw[0] == c) @@ -38,7 +38,7 @@ find_expansion_char(int c, struct metadef *def, void *data) } static const char * -find_expansion_word(const char *kw, size_t len, struct metadef *def, +find_expansion_word(const char *kw, size_t len, struct wy_metadef *def, void *data) { for (; def->kw; def++) @@ -48,7 +48,7 @@ find_expansion_word(const char *kw, size_t len, struct metadef *def, } char * -meta_expand_string(const char *string, struct metadef *def, void *data, +meta_expand_string(const char *string, struct wy_metadef *def, void *data, struct dictionary *dict, void *handle) { const char *p, *s; @@ -135,7 +135,7 @@ meta_expand_string(const char *string, struct metadef *def, void *data, } void -meta_free(struct metadef *def) +meta_free(struct wy_metadef *def) { for (; def->kw; def++) { if (def->storage) { @@ -145,10 +145,10 @@ meta_free(struct metadef *def) } } -struct metadef * -metadef_join(struct metadef *a, struct metadef *b) +struct wy_metadef * +metadef_join(struct wy_metadef *a, struct wy_metadef *b) { - struct metadef *np; + struct wy_metadef *np; size_t i, j; for (i = 0; a[i].kw; i++); @@ -163,3 +163,26 @@ metadef_join(struct metadef *a, struct metadef *b) np[i + j].kw = NULL; return np; } + +char * +wy_expand_stats(const char *tmpl) +{ + struct wy_metadef *exp; + time_t t; + size_t tc; + char *text; + + tc = timer_get_count() * 3; + exp = make_stat_expansion(tc + 1); + time(&t); + exp[0].kw = "date"; + exp[0].value = exp[0].storage = grecs_strdup(ctime(&t)); + exp[0].value[strlen(exp[0].value) - 1] = 0; + timer_fill_meta(exp + 1, tc); + text = meta_expand_string(tmpl, exp, NULL, NULL, NULL); + meta_free(exp); + timer_free_meta(exp + 1, tc); + free(exp); + + return text; +} |