diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-01-01 13:25:55 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-01-01 13:33:04 +0200 |
commit | 24e6dfa7cffceea0cac0f3cc349192788f040939 (patch) | |
tree | c2bd53e9bc58873c8187e6bd622ae152b35d1d51 /src/meta.c | |
parent | 2bdd70d698c63d32f25b4f1142e09f5eaef4812a (diff) | |
download | wydawca-24e6dfa7cffceea0cac0f3cc349192788f040939.tar.gz wydawca-24e6dfa7cffceea0cac0f3cc349192788f040939.tar.bz2 |
Update copyright years. Switch to a familiar style.
Diffstat (limited to 'src/meta.c')
-rw-r--r-- | src/meta.c | 221 |
1 files changed, 107 insertions, 114 deletions
@@ -1,5 +1,5 @@ /* wydawca - automatic release submission daemon - Copyright (C) 2007-2011 Sergey Poznyakoff + Copyright (C) 2007-2013 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 @@ -18,136 +18,129 @@ #include "sql.h" static const char * -meta_expand (struct metadef *def, void *data) +meta_expand(struct metadef *def, void *data) { - if (!def->value) - { - if (def->expand) - return def->expand (def, data); - def->value = "INTERNAL ERROR: NONEXPANDABLE DATA"; - } - return def->value; + 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 metadef *def, void *data) +find_expansion_char(int c, struct metadef *def, void *data) { - for (; def->kw; def++) - if (def->kw[1] == 0 && def->kw[0] == c) - return meta_expand (def, data); - return NULL; + 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 metadef *def, void *data) +find_expansion_word(const char *kw, size_t len, struct 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; + 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 metadef *def, void *data, - struct dictionary *dict, void *handle) +meta_expand_string(const char *string, struct metadef *def, void *data, + struct dictionary *dict, void *handle) { - const char *p, *s; - char *res; - struct txtacc *acc; - - if (!string) - return NULL; - - acc = txtacc_create (); - - for (p = string; *p;) - { - char *e; - size_t len = strcspn (p, "$"); - - txtacc_grow (acc, p, len); - p += len; - if (*p == '$') - { - switch (*++p) - { - case '$': - 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); - txtacc_grow (acc, newval, len); - free (newval); - } - else - txtacc_grow (acc, s, strlen (s)); - p = e + 1; - } - else - { - 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); - txtacc_grow (acc, newval, len); - free (newval); - } - else - txtacc_grow (acc, s, len); - p++; - } + const char *p, *s; + char *res; + struct txtacc *acc; + + if (!string) + return NULL; + + acc = txtacc_create(); + + for (p = string; *p;) { + char *e; + size_t len = strcspn(p, "$"); + + txtacc_grow(acc, p, len); + p += len; + if (*p == '$') { + switch (*++p) { + case '$': + 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); + txtacc_grow(acc, newval, len); + free(newval); + } else + txtacc_grow(acc, s, strlen(s)); + p = e + 1; + } else { + 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); + txtacc_grow(acc, newval, len); + free(newval); + } else + txtacc_grow(acc, s, len); + p++; + } + } else + txtacc_grow(acc, p, 1); } - else - txtacc_grow (acc, p, 1); - } - txtacc_1grow (acc, 0); - res = txtacc_finish (acc, 1); - txtacc_free (acc); - return res; + txtacc_1grow(acc, 0); + res = txtacc_finish(acc, 1); + txtacc_free(acc); + return res; } void -meta_free (struct metadef *def) +meta_free(struct metadef *def) { - for (; def->kw; def++) - { - if (def->storage) - { - free (def->storage); - def->value = def->storage = NULL; + for (; def->kw; def++) { + if (def->storage) { + free(def->storage); + def->value = def->storage = NULL; + } } - } } - |