From f3b32f8cb94bc83ded97bec478e666be6a07bf0d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 19 May 2011 16:47:08 +0200 Subject: dump_dir: fix loading of Unicode texts. Closes bz#622223 Signed-off-by: Denys Vlasenko --- src/gui-wizard-gtk/wizard.c | 6 +++++- src/lib/dump_dir.c | 30 +++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c index 414b501f..bd5d28c4 100644 --- a/src/gui-wizard-gtk/wizard.c +++ b/src/gui-wizard-gtk/wizard.c @@ -207,10 +207,14 @@ struct dump_dir *steal_if_needed(struct dump_dir *dd) dd_close(dd); char *HOME = getenv("HOME"); + if (!HOME || !HOME[0]) + { + struct passwd *pw = getpwuid(getuid()); + HOME = pw ? pw->pw_dir : NULL; + } if (HOME && HOME[0]) HOME = concat_path_file(HOME, ".abrt/spool"); else -//TODO: try to find homedir in password db? HOME = xstrdup("/tmp"); GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(g_assistant), diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c index 0c6467f4..03097ce1 100644 --- a/src/lib/dump_dir.c +++ b/src/lib/dump_dir.c @@ -651,21 +651,37 @@ static char *load_text_file(const char *path, unsigned flags) int ch; while ((ch = fgetc(fp)) != EOF) { +//TODO? \r -> \n? +//TODO? strip trailing spaces/tabs? if (ch == '\n') oneline = (oneline << 1) | 1; if (ch == '\0') ch = ' '; - if (isspace(ch) || (isascii(ch) && !iscntrl(ch))) + if (isspace(ch) || ch >= ' ') /* used !iscntrl, but it failed on unicode */ strbuf_append_char(buf_content, ch); } fclose(fp); - /* If file contains exactly one '\n' and it is at the end, remove it. - * This enables users to use simple "echo blah >file" in order to create - * short string items in dump dirs. - */ - if (oneline == 1 && buf_content->buf[buf_content->len - 1] == '\n') - buf_content->buf[--buf_content->len] = '\0'; + char last = oneline != 0 ? buf_content->buf[buf_content->len - 1] : 0; + if (last == '\n') + { + /* If file contains exactly one '\n' and it is at the end, remove it. + * This enables users to use simple "echo blah >file" in order to create + * short string items in dump dirs. + */ + if (oneline == 1) + buf_content->buf[--buf_content->len] = '\0'; + } + else /* last != '\n' */ + { + /* Last line is unterminated, fix it */ + /* Cases: */ + /* oneline=0: "qwe" - DONT fix this! */ + /* oneline=1: "qwe\nrty" - two lines in fact */ + /* oneline>1: "qwe\nrty\uio" */ + if (oneline >= 1) + strbuf_append_char(buf_content, '\n'); + } return strbuf_free_nobuf(buf_content); } -- cgit