From f52fab94485d0056d25cbe74340626265472beee Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sun, 13 Jul 2014 23:47:29 +0200 Subject: Load X/Open message catalogs This is going to enable making changes to ERR and RPL messages without modifying the source code. Localized messages could be interesting. :) --- src/kike.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/kike.c b/src/kike.c index 60774cf..faea7b9 100644 --- a/src/kike.c +++ b/src/kike.c @@ -22,6 +22,7 @@ #define PROGRAM_VERSION "alpha" #include "common.c" +#include // --- Configuration (application-specific) ------------------------------------ @@ -29,6 +30,7 @@ static struct config_item g_config_table[] = { { "server_name", NULL, "Server name" }, { "motd", NULL, "MOTD filename" }, + { "catalog", NULL, "catgets localization catalog" }, { "bind_host", NULL, "Address of the IRC server" }, { "bind_port", "6667", "Port of the IRC server" }, @@ -325,6 +327,7 @@ struct server_context bool polling; ///< The event loop is running struct str_vector motd; ///< MOTD (none if empty) + nl_catd catalog; ///< Message catalog for server msgs }; static void @@ -347,6 +350,7 @@ server_context_init (struct server_context *self) self->polling = false; str_vector_init (&self->motd); + self->catalog = (nl_catd) -1; } static void @@ -374,6 +378,8 @@ server_context_free (struct server_context *self) poller_free (&self->poller); str_vector_free (&self->motd); + if (self->catalog != (nl_catd) -1) + catclose (self->catalog); } // --- Main program ------------------------------------------------------------ @@ -794,6 +800,24 @@ error_ssl_1: return false; } +static bool +irc_initialize_catalog (struct server_context *ctx, struct error **e) +{ + hard_assert (ctx->catalog == (nl_catd) -1); + const char *catalog = str_map_find (&ctx->config, "catalog"); + if (!catalog) + return true; + + ctx->catalog = catopen (catalog, NL_CAT_LOCALE); + if (ctx->catalog == (nl_catd) -1) + { + error_set (e, IO_ERROR, IO_ERROR_FAILED, "%s: %s", + "failed reading the message catalog file", strerror (errno)); + return false; + } + return true; +} + static bool irc_initialize_motd (struct server_context *ctx, struct error **e) { @@ -1046,7 +1070,8 @@ main (int argc, char *argv[]) if (!irc_initialize_ssl (&ctx)) exit (EXIT_FAILURE); - if (!irc_listen (&ctx, &e)) + if (!irc_initialize_catalog (&ctx, &e) + || !irc_listen (&ctx, &e)) { print_error ("%s", e->message); error_free (e); -- cgit v1.2.3-70-g09d2