diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-10 15:03:43 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-10 17:21:54 +0300 |
commit | 8b04169265fb9762b2c1dfca3f43068f5b8233be (patch) | |
tree | 43049c1809b2b70b21ed9300ebdd286d18833c8b /src/mail.c | |
parent | bb242e454d5cf8b0c6bb1ca5d009ec18e86c0c2b (diff) | |
download | wydawca-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.c | 78 |
1 files changed, 20 insertions, 58 deletions
@@ -16,7 +16,6 @@ | |||
16 | 16 | ||
17 | #include "wydawca.h" | 17 | #include "wydawca.h" |
18 | #include <mail.h> | 18 | #include <mail.h> |
19 | #include <hash.h> | ||
20 | #include <gpgme.h> | 19 | #include <gpgme.h> |
21 | 20 | ||
22 | int mailer_opened; | 21 | int mailer_opened; |
@@ -365,66 +364,29 @@ struct message_template | |||
365 | /* int mime; for future use */ | 364 | /* int mime; for future use */ |
366 | }; | 365 | }; |
367 | 366 | ||
368 | static Hash_table *tmpl_table; | 367 | static struct grecs_symtab *tmpl_table; |
369 | 368 | ||
370 | /* Calculate the hash of a string. */ | 369 | /* Register a template. */ |
371 | static size_t | ||
372 | tmpl_hasher (void const *data, unsigned n_buckets) | ||
373 | { | ||
374 | struct message_template const *tmpl = data; | ||
375 | return hash_string (tmpl->name, n_buckets); | ||
376 | } | ||
377 | |||
378 | /* Compare two strings for equality. */ | ||
379 | static bool | ||
380 | tmpl_compare (void const *data1, void const *data2) | ||
381 | { | ||
382 | struct message_template const *tmpl1 = data1; | ||
383 | struct message_template const *tmpl2 = data2; | ||
384 | return strcmp (tmpl1->name, tmpl2->name) == 0; | ||
385 | } | ||
386 | |||
387 | static void | ||
388 | tmpl_free (void *data) | ||
389 | { | ||
390 | free (data); | ||
391 | } | ||
392 | |||
393 | struct message_template * | ||
394 | alloc_message_template (const char *name, const char *text) | ||
395 | { | ||
396 | struct message_template *tmpl = xmalloc (sizeof (tmpl[0]) | ||
397 | + strlen (name) + 1 | ||
398 | + strlen (text) + 1); | ||
399 | char *p = (char*) (tmpl + 1); | ||
400 | tmpl->name = p; | ||
401 | strcpy (tmpl->name, name); | ||
402 | |||
403 | p += strlen (p) + 1; | ||
404 | tmpl->text = p; | ||
405 | strcpy (tmpl->text, text); | ||
406 | return tmpl; | ||
407 | } | ||
408 | |||
409 | /* Register a template. | ||
410 | FIXME: Issue a warning if it is already registered. */ | ||
411 | void | 370 | void |
412 | register_message_template (const char *name, const char *text) | 371 | register_message_template (const char *name, const char *text) |
413 | { | 372 | { |
414 | struct message_template *tmpl, *s; | 373 | struct message_template key, *tmpl; |
415 | 374 | int install = 1; | |
416 | s = alloc_message_template (name, text); | 375 | |
376 | key.name = (char*) text; | ||
417 | 377 | ||
418 | if (!((tmpl_table | 378 | if (!tmpl_table) |
419 | || (tmpl_table = hash_initialize (0, 0, | 379 | { |
420 | tmpl_hasher, | 380 | tmpl_table = grecs_symtab_create_default (sizeof (key)); |
421 | tmpl_compare, | 381 | if (!tmpl_table) |
422 | tmpl_free))) | 382 | grecs_alloc_die (); |
423 | && (tmpl = hash_insert (tmpl_table, s)))) | 383 | } |
424 | xalloc_die (); | ||
425 | 384 | ||
426 | if (s != tmpl) | 385 | tmpl = grecs_symtab_lookup_or_install (tmpl_table, &key, &install); |
427 | tmpl_free (s); | 386 | if (!tmpl) |
387 | grecs_alloc_die(); | ||
388 | if (!install) | ||
389 | grecs_warning (NULL, 0, "template %s already registered", text); | ||
428 | } | 390 | } |
429 | 391 | ||
430 | const char * | 392 | const char * |
@@ -438,10 +400,10 @@ resolve_message_template (const char *name) | |||
438 | return NULL; | 400 | return NULL; |
439 | else | 401 | else |
440 | { | 402 | { |
441 | struct message_template *p, tmpl; | 403 | struct message_template *p, key; |
442 | 404 | ||
443 | tmpl.name = (char*) name + 1; | 405 | key.name = (char*) name + 1; |
444 | p = hash_lookup (tmpl_table, &tmpl); | 406 | p = grecs_symtab_lookup_or_install (tmpl_table, &key, NULL); |
445 | return p ? p->text : NULL; | 407 | return p ? p->text : NULL; |
446 | } | 408 | } |
447 | } | 409 | } |