aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-07-13 23:47:29 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-07-13 23:47:29 +0200
commitf52fab94485d0056d25cbe74340626265472beee (patch)
tree912da022148f6e0be86e41f808287161a2fe9939 /src
parentaaedbf93f1a8e6da3fbd2ce7433888d45c9efe5f (diff)
downloadxK-f52fab94485d0056d25cbe74340626265472beee.tar.gz
xK-f52fab94485d0056d25cbe74340626265472beee.tar.xz
xK-f52fab94485d0056d25cbe74340626265472beee.zip
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. :)
Diffstat (limited to 'src')
-rw-r--r--src/kike.c27
1 files changed, 26 insertions, 1 deletions
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 <nl_types.h>
// --- 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 ------------------------------------------------------------
@@ -795,6 +801,24 @@ error_ssl_1:
}
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)
{
hard_assert (ctx->motd.len == 0);
@@ -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);