X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-text-file.c;h=ea74fefee373ffb49dba8369440c3db404eb13db;hb=65d602ed236d685ffec00ad1552a193cf47b2e4d;hp=c105db786458cb52e1677d9b4c3770a433a6c8a4;hpb=bf62643ef9f4f991acd777b26aa747adc7886d8f;p=pspp diff --git a/src/ui/gui/psppire-text-file.c b/src/ui/gui/psppire-text-file.c index c105db7864..ea74fefee3 100644 --- a/src/ui/gui/psppire-text-file.c +++ b/src/ui/gui/psppire-text-file.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2017 Free Software Foundation + Copyright (C) 2017, 2020 Free Software Foundation This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -41,12 +41,13 @@ enum PROP_LINE_COUNT }; -enum {MAX_LINE_LEN = 16384}; /* Max length of an acceptable line. */ - static void read_lines (PsppireTextFile *tf) { + /* Max length of an acceptable line. */ + static const int MAX_LINE_LEN = 16384; + if (tf->file_name && 0 != g_strcmp0 ("unset", tf->encoding)) { struct line_reader *reader = line_reader_for_file (tf->encoding, tf->file_name, O_RDONLY); @@ -78,7 +79,7 @@ read_lines (PsppireTextFile *tf) tf->file_name, MAX_LINE_LEN); line_reader_close (reader); for (i = 0; i < tf->line_cnt; i++) - g_free (&tf->lines[i]); + g_free (tf->lines[i].string); tf->line_cnt = 0; ds_destroy (&input); return; @@ -88,7 +89,7 @@ read_lines (PsppireTextFile *tf) = recode_substring_pool ("UTF-8", line_reader_get_encoding (reader), input.ss, NULL); - } + } ds_destroy (&input); if (tf->line_cnt == 0) @@ -97,7 +98,7 @@ read_lines (PsppireTextFile *tf) msg (ME, _("`%s' is empty."), tf->file_name); line_reader_close (reader); for (i = 0; i < tf->line_cnt; i++) - g_free (&tf->lines[i]); + g_free (tf->lines[i].string); tf->line_cnt = 0; goto done; } @@ -185,10 +186,6 @@ psppire_text_file_get_property (GObject *object, }; } - -static void psppire_text_file_init (PsppireTextFile *text_file); -static void psppire_text_file_class_init (PsppireTextFileClass *class); - static void psppire_text_file_finalize (GObject *object); static void psppire_text_file_dispose (GObject *object); @@ -387,44 +384,9 @@ __tree_model_init (GtkTreeModelIface *iface) iface->iter_parent = __iter_parent; } - -GType -psppire_text_file_get_type (void) -{ - static GType text_file_type = 0; - - if (!text_file_type) - { - static const GTypeInfo text_file_info = - { - sizeof (PsppireTextFileClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) psppire_text_file_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (PsppireTextFile), - 0, - (GInstanceInitFunc) psppire_text_file_init, - }; - - static const GInterfaceInfo tree_model_info = { - (GInterfaceInitFunc) __tree_model_init, - NULL, - NULL - }; - - text_file_type = g_type_register_static (G_TYPE_OBJECT, - "PsppireTextFile", - &text_file_info, 0); - - g_type_add_interface_static (text_file_type, GTK_TYPE_TREE_MODEL, - &tree_model_info); - } - - return text_file_type; -} - +G_DEFINE_TYPE_WITH_CODE (PsppireTextFile, psppire_text_file, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL, + __tree_model_init)) static void psppire_text_file_class_init (PsppireTextFileClass *class) @@ -432,7 +394,7 @@ psppire_text_file_class_init (PsppireTextFileClass *class) GObjectClass *object_class; parent_class = g_type_class_peek_parent (class); - object_class = (GObjectClass*) class; + object_class = G_OBJECT_CLASS (class); GParamSpec *maximum_lines_spec = g_param_spec_int ("maximum-lines", @@ -513,6 +475,9 @@ psppire_text_file_finalize (GObject *object) { PsppireTextFile *tf = PSPPIRE_TEXT_FILE (object); + for (int i = 0; i < tf->line_cnt; i++) + g_free (tf->lines[i].string); + g_free (tf->encoding); g_free (tf->file_name);