aboutsummaryrefslogtreecommitdiff
path: root/src/mail.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-10 15:03:43 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-10 17:21:54 +0300
commit8b04169265fb9762b2c1dfca3f43068f5b8233be (patch)
tree43049c1809b2b70b21ed9300ebdd286d18833c8b /src/mail.c
parentbb242e454d5cf8b0c6bb1ca5d009ec18e86c0c2b (diff)
downloadwydawca-8b04169265fb9762b2c1dfca3f43068f5b8233be.tar.gz
wydawca-8b04169265fb9762b2c1dfca3f43068f5b8233be.tar.bz2
Update grecs.
* Makefile.am (ChangeLog): Use git2chg.awk. * bootstrap.conf (gnulib_modules): Don't access grecs/gnulib.modules. * configure.ac (GRECS_SETUP): Add options. * gnulib.modules (getopt,gitlog-to-changelog) (hash,error,version-etc): Remove. * src/Makefile.am: Remove getopt.m4, use one from grecs. * src/getopt.m4: Remove. * src/cmdline.opt: Rewrite. * src/config.c: Update. * src/wydawca.h (spool) <aliases>: Change data type. (all_spool_aliases): Change data type. (config_finish): New proto. * src/wydawca.c: Use grecs functions. * src/dictionary.c: Likewise. * src/net.c: Likewise. * src/process.c: Likewise. * src/mail.c: Use grecs_symtab. * src/timer.c: Likewise. * src/triplet.c: Likewise.
Diffstat (limited to 'src/mail.c')
-rw-r--r--src/mail.c76
1 files changed, 19 insertions, 57 deletions
diff --git a/src/mail.c b/src/mail.c
index afcf29e..bac0381 100644
--- a/src/mail.c
+++ b/src/mail.c
@@ -16,7 +16,6 @@
#include "wydawca.h"
#include <mail.h>
-#include <hash.h>
#include <gpgme.h>
int mailer_opened;
@@ -365,66 +364,29 @@ struct message_template
/* int mime; for future use */
};
-static Hash_table *tmpl_table;
+static struct grecs_symtab *tmpl_table;
-/* Calculate the hash of a string. */
-static size_t
-tmpl_hasher (void const *data, unsigned n_buckets)
-{
- struct message_template const *tmpl = data;
- return hash_string (tmpl->name, n_buckets);
-}
-
-/* Compare two strings for equality. */
-static bool
-tmpl_compare (void const *data1, void const *data2)
-{
- struct message_template const *tmpl1 = data1;
- struct message_template const *tmpl2 = data2;
- return strcmp (tmpl1->name, tmpl2->name) == 0;
-}
-
-static void
-tmpl_free (void *data)
-{
- free (data);
-}
-
-struct message_template *
-alloc_message_template (const char *name, const char *text)
-{
- struct message_template *tmpl = xmalloc (sizeof (tmpl[0])
- + strlen (name) + 1
- + strlen (text) + 1);
- char *p = (char*) (tmpl + 1);
- tmpl->name = p;
- strcpy (tmpl->name, name);
-
- p += strlen (p) + 1;
- tmpl->text = p;
- strcpy (tmpl->text, text);
- return tmpl;
-}
-
-/* Register a template.
- FIXME: Issue a warning if it is already registered. */
+/* Register a template. */
void
register_message_template (const char *name, const char *text)
{
- struct message_template *tmpl, *s;
+ struct message_template key, *tmpl;
+ int install = 1;
- s = alloc_message_template (name, text);
+ key.name = (char*) text;
- if (!((tmpl_table
- || (tmpl_table = hash_initialize (0, 0,
- tmpl_hasher,
- tmpl_compare,
- tmpl_free)))
- && (tmpl = hash_insert (tmpl_table, s))))
- xalloc_die ();
+ if (!tmpl_table)
+ {
+ tmpl_table = grecs_symtab_create_default (sizeof (key));
+ if (!tmpl_table)
+ grecs_alloc_die ();
+ }
- if (s != tmpl)
- tmpl_free (s);
+ tmpl = grecs_symtab_lookup_or_install (tmpl_table, &key, &install);
+ if (!tmpl)
+ grecs_alloc_die();
+ if (!install)
+ grecs_warning (NULL, 0, "template %s already registered", text);
}
const char *
@@ -438,10 +400,10 @@ resolve_message_template (const char *name)
return NULL;
else
{
- struct message_template *p, tmpl;
+ struct message_template *p, key;
- tmpl.name = (char*) name + 1;
- p = hash_lookup (tmpl_table, &tmpl);
+ key.name = (char*) name + 1;
+ p = grecs_symtab_lookup_or_install (tmpl_table, &key, NULL);
return p ? p->text : NULL;
}
}

Return to:

Send suggestions and report system problems to the System administrator.