From b7dd384048c9c8fa916cd4651b0341f037a16f02 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Fri, 25 Dec 2015 21:22:59 +0100 Subject: degesch: little step towards localisation We don't use LC_MESSAGES, though, so it doesn't really matter as of now. liberty currently isn't prepared for non-ASCII errors or filenames, and just silently expects everything to be in the same all-compatible encoding. degesch further expects the encoding to be UTF-8. All strings should ideally be converted to UTF-8 as soon as possible. --- degesch.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/degesch.c b/degesch.c index 09f5d69..12c1345 100644 --- a/degesch.c +++ b/degesch.c @@ -2548,6 +2548,7 @@ irc_to_term (struct app_context *ctx, const char *text) // Format strings use a #-quoted notation, to differentiate from printf: // #s inserts a string (expected to be in UTF-8) // #d inserts a signed integer +// #l inserts a locale-encoded string // // #S inserts a string from the server with unknown encoding // #m inserts a mIRC-formatted string (auto-resets at boundaries) @@ -2767,6 +2768,14 @@ restart: case 's': str_append (buf, (s = va_arg (*ap, char *))); break; + case 'l': + if (!(tmp = iconv_xstrdup (self->ctx->term_to_utf8, + (s = va_arg (*ap, char *)), -1, NULL))) + print_error ("character conversion failed for: %s", "output"); + else + str_append (buf, tmp); + free (tmp); + break; case 'S': tmp = irc_to_utf8 (self->ctx, (s = va_arg (*ap, char *))); @@ -3228,7 +3237,7 @@ buffer_open_log_file (struct app_context *ctx, struct buffer *buffer) char *path = buffer_get_log_path (buffer); if (!(buffer->log_file = fopen (path, "ab"))) - log_global_error (ctx, "Couldn't open log file `#s': #s", + log_global_error (ctx, "Couldn't open log file `#s': #l", path, strerror (errno)); else set_cloexec (fileno (buffer->log_file)); @@ -9664,7 +9673,7 @@ process_input (struct app_context *ctx, char *user_input) { char *input; if (!(input = iconv_xstrdup (ctx->term_to_utf8, user_input, -1, NULL))) - print_error ("character conversion failed for `%s'", "user input"); + print_error ("character conversion failed for: %s", "user input"); else { struct str_vector lines; @@ -10173,7 +10182,7 @@ launch_backlog_helper (struct app_context *ctx, FILE *backlog) "Failed to launch backlog helper", strerror (errno)); _exit (EXIT_FAILURE); case -1: - log_global_error (ctx, "#s: #s", + log_global_error (ctx, "#s: #l", "Failed to launch backlog helper", strerror (errno)); break; default: @@ -10187,7 +10196,7 @@ display_backlog (struct app_context *ctx) FILE *backlog = tmpfile (); if (!backlog) { - log_global_error (ctx, "#s: #s", + log_global_error (ctx, "#s: #l", "Failed to create a temporary file", strerror (errno)); return; } @@ -10211,7 +10220,7 @@ display_full_log (struct app_context *ctx) if (!full_log) { - log_global_error (ctx, "Failed to open log file for #s: #s", + log_global_error (ctx, "Failed to open log file for #s: #l", ctx->current_buffer->name, strerror (errno)); return; } @@ -10280,7 +10289,7 @@ launch_input_editor (struct app_context *ctx) "Failed to launch editor", strerror (errno)); _exit (EXIT_FAILURE); case -1: - log_global_error (ctx, "#s: #s", + log_global_error (ctx, "#s: #l", "Failed to launch editor", strerror (errno)); free (filename); break; @@ -10310,7 +10319,7 @@ process_edited_input (struct app_context *ctx) "could not re-insert the modified text"); if (unlink (ctx->editor_filename)) - log_global_error (ctx, "Could not unlink `#s': #s", + log_global_error (ctx, "Could not unlink `#s': #l", ctx->editor_filename, strerror (errno)); free (ctx->editor_filename); -- cgit v1.2.3-70-g09d2