aboutsummaryrefslogtreecommitdiff
path: root/src/meta.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-07-24 14:14:47 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-07-24 14:27:11 +0300
commitc047ed856d6d23137ef1df01c1297db36bad3f8c (patch)
tree1999db947cb5e38df8a85d314daa0eef7c7624d0 /src/meta.c
parent07ea006a31def46ba6ea936dbea366219152d9b6 (diff)
downloadwydawca-c047ed856d6d23137ef1df01c1297db36bad3f8c.tar.gz
wydawca-c047ed856d6d23137ef1df01c1297db36bad3f8c.tar.bz2
Use wordsplit to expand variables in strings.
* NEWS: Raise version number. * configure.ac: Link wydawca.h to include/wydawca Raise version number * doc/wydawca.texi: Document changes. * etc/wydawca.rc: Fix the syntax. * grecs: Upgrace. * include/wydawca/wydawca.h (wy_vlog): New proto. (wy_log, wy_dbg): Format is const char *. (wy_triplet_t): Change typedef. (wy_metadef): Remove struct. (wy_vardef): New struct. (wy_triplet_expand_param) (wy_expand_copy): New protos. * modules/logstat/mod_logstat.c: Update. * modules/mailutils/Makefile.am (AM_CPPFLAGS): Modify, * modules/mailutils/mod_mailutils.c: Update. * src/Makefile.am (wydawca_SOURCES): Remove meta.c * src/dictionary.c: Fix comment. * src/directive.c (directive_get_value): Triplet pointer is const. * src/meta.c: Remove. * src/timer.c: (timer_fill_meta) (timer_free_meta): Remove. * src/triplet.c: Use wordsplit for expansions. * src/wydawca.c (wy_vlog): New function. (wy_stat_expansion): New function. * src/wydawca.h: Remove metadef protos. * tests/etc/notify.rcin: Update variable reference syntax.
Diffstat (limited to 'src/meta.c')
-rw-r--r--src/meta.c191
1 files changed, 0 insertions, 191 deletions
diff --git a/src/meta.c b/src/meta.c
deleted file mode 100644
index 734be50..0000000
--- a/src/meta.c
+++ /dev/null
@@ -1,191 +0,0 @@
-/* wydawca - automatic release submission daemon
- Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2017, 2019
- Sergey Poznyakoff
-
- Wydawca is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 3 of the License, or (at your
- option) any later version.
-
- Wydawca is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with wydawca. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "wydawca.h"
-#include "sql.h"
-
-static const char *
-meta_expand(struct wy_metadef *def, void *data)
-{
- if (!def->value) {
- if (def->expand)
- return def->expand(def, data);
- def->value = "INTERNAL ERROR: NONEXPANDABLE DATA";
- }
- return def->value;
-}
-
-static const char *
-find_expansion_char(int c, struct wy_metadef *def, void *data)
-{
- for (; def->kw; def++)
- if (def->kw[1] == 0 && def->kw[0] == c)
- return meta_expand(def, data);
- return NULL;
-}
-
-static const char *
-find_expansion_word(const char *kw, size_t len, struct wy_metadef *def,
- void *data)
-{
- for (; def->kw; def++)
- if (strlen(def->kw) == len && memcmp(def->kw, kw, len) == 0)
- return meta_expand(def, data);
- return NULL;
-}
-
-char *
-meta_expand_string(const char *string, struct wy_metadef *def, void *data,
- struct dictionary *dict, void *handle)
-{
- const char *p, *s;
- char *res;
- struct grecs_txtacc *acc;
-
- if (!string)
- return NULL;
-
- acc = grecs_txtacc_create();
-
- for (p = string; *p;) {
- char *e;
- size_t len = strcspn(p, "$");
-
- grecs_txtacc_grow(acc, p, len);
- p += len;
- if (*p == '$') {
- switch (*++p) {
- case '$':
- grecs_txtacc_grow(acc, p, 1);
- p++;
- break;
-
- case '-':
- if (*++p)
- p++;
- break;
-
- case '{':
- e = strchr(p + 1, '}');
- if (e &&
- (s = find_expansion_word(p + 1, e - p - 1,
- def, data))) {
- if (dict) {
- char *newval;
- size_t len;
- /* FIXME: Return value? */
- dictionary_quote_string(dict,
- handle,
- s,
- &newval,
- &len);
- grecs_txtacc_grow(acc, newval,
- len);
- free(newval);
- } else
- grecs_txtacc_grow(acc, s,
- strlen(s));
- p = e + 1;
- } else {
- grecs_txtacc_grow(acc, p - 1, 2);
- p++;
- }
- break;
-
- default:
- if ((s = find_expansion_char(*p, def, data))
- != NULL)
- len = strlen(s);
- else {
- s = p - 1;
- len = 1;
- }
-
- if (dict) {
- char *newval;
- size_t len;
- /* FIXME: Return value? */
- dictionary_quote_string(dict,
- handle, s,
- &newval, &len);
- grecs_txtacc_grow(acc, newval, len);
- free(newval);
- } else
- grecs_txtacc_grow(acc, s, len);
- p++;
- }
- } else
- grecs_txtacc_grow(acc, p, 1);
- }
- grecs_txtacc_grow_char(acc, 0);
- res = grecs_txtacc_finish(acc, 1);
- grecs_txtacc_free(acc);
- return res;
-}
-
-void
-meta_free(struct wy_metadef *def)
-{
- for (; def->kw; def++) {
- if (def->storage) {
- free(def->storage);
- def->value = def->storage = NULL;
- }
- }
-}
-
-struct wy_metadef *
-metadef_join(struct wy_metadef *a, struct wy_metadef *b)
-{
- struct wy_metadef *np;
- size_t i, j;
-
- for (i = 0; a[i].kw; i++);
- if (b)
- for (j = 0; b[j].kw; j++);
- else
- j = 0;
- np = grecs_malloc((i + j + 1) * sizeof(a[0]));
- memcpy(np, a, i * sizeof(a[0]));
- if (j > 0)
- memcpy(np + i, b, j * sizeof(b[0]));
- 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;
-}

Return to:

Send suggestions and report system problems to the System administrator.