X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Ftext-data-import-dialog.c;h=4badb6550dfe94b9ce026fd1a4871bce70312909;hb=refs%2Fbuilds%2F20130203032041%2Fpspp;hp=b5a50cbaba1f961f911e558402e32bd3e6af5885;hpb=d4ae90b2fe74d2d1427afad35d32c9e5584211ed;p=pspp diff --git a/src/ui/gui/text-data-import-dialog.c b/src/ui/gui/text-data-import-dialog.c index b5a50cbaba..4badb6550d 100644 --- a/src/ui/gui/text-data-import-dialog.c +++ b/src/ui/gui/text-data-import-dialog.c @@ -434,6 +434,7 @@ init_file (struct import_assistant *ia, GtkWindow *parent_window) enum { MAX_PREVIEW_LINES = 1000 }; /* Max number of lines to read. */ enum { MAX_LINE_LEN = 16384 }; /* Max length of an acceptable line. */ struct line_reader *reader; + struct string input; file->file_name = choose_file (parent_window, &file->encoding); if (file->file_name == NULL) @@ -447,14 +448,13 @@ init_file (struct import_assistant *ia, GtkWindow *parent_window) return false; } + ds_init_empty (&input); file->lines = xnmalloc (MAX_PREVIEW_LINES, sizeof *file->lines); for (; file->line_cnt < MAX_PREVIEW_LINES; file->line_cnt++) { - struct string *line = &file->lines[file->line_cnt]; - - ds_init_empty (line); - if (!line_reader_read (reader, line, MAX_LINE_LEN + 1) - || ds_length (line) > MAX_LINE_LEN) + ds_clear (&input); + if (!line_reader_read (reader, &input, MAX_LINE_LEN + 1) + || ds_length (&input) > MAX_LINE_LEN) { if (line_reader_eof (reader)) break; @@ -468,9 +468,15 @@ init_file (struct import_assistant *ia, GtkWindow *parent_window) file->file_name, MAX_LINE_LEN); line_reader_close (reader); destroy_file (ia); + ds_destroy (&input); return false; } + + ds_init_cstr (&file->lines[file->line_cnt], + recode_string ("UTF-8", line_reader_get_encoding (reader), + ds_cstr (&input), ds_length (&input))); } + ds_destroy (&input); if (file->line_cnt == 0) { @@ -1625,7 +1631,7 @@ destroy_formats_page (struct import_assistant *ia) if (p->psppire_dict != NULL) { - /* This destroys p->dict also. */ + dict_destroy (p->psppire_dict->dict); g_object_unref (p->psppire_dict); } clear_modified_vars (ia);