static void zak_gorg_parser_dispose (GObject *gobject);
static void zak_gorg_parser_finalize (GObject *gobject);
-#define ZAK_GORG_PARSER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_GORG_TYPE_PARSER, ZakGorgParserPrivate))
+static void zak_gorg_parser_parse (ZakGorgParser *zak_gorg_parser);
struct _ZakGorgParser
-{
- GObject parent_instance;
-};
-
-typedef struct _ZakGorgParserPrivate ZakGorgParserPrivate;
-struct _ZakGorgParserPrivate
{
+ GObject parent_instance;
+
+ GFile *gfile;
GNode *nodes;
};
-G_DEFINE_TYPE_WITH_PRIVATE (ZakGorgParser, zak_gorg_parser, ZAK_GORG_TYPE_PARSER)
+G_DEFINE_TYPE (ZakGorgParser, zak_gorg_parser, ZAK_GORG_TYPE_PARSER)
static void
zak_gorg_parser_class_init (ZakGorgParserClass *klass)
static void
zak_gorg_parser_init (ZakGorgParser *zak_gorg_parser)
{
- ZakGorgParserPrivate *priv = ZAK_GORG_PARSER_GET_PRIVATE (zak_gorg_parser);
-
- priv->nodes = NULL;
}
/**
{
ZakGorgParser *zak_gorg_parser;
- zak_gorg_parser = ZAK_GORG_PARSER (g_object_new (zak_gorg_parser_get_type (), NULL));
+ zak_gorg_parser = g_object_new (ZAK_GORG_TYPE_PARSER, NULL);
+ g_warning("gfile");
- return ZAK_GORG_PARSER (zak_gorg_parser);
+ zak_gorg_parser->nodes = NULL;
+ zak_gorg_parser->gfile = gfile;
+
+ zak_gorg_parser_parse (zak_gorg_parser);
+
+ return zak_gorg_parser;
}
/**
ZakGorgParser
*zak_gorg_parser_new (const gchar *filename)
{
+ GFile *gfile;
+
+ gfile = g_file_new_for_path (filename);
+
+ return zak_gorg_parser_new_gfile (gfile);
}
/* PRIVATE */
GParamSpec *pspec)
{
ZakGorgParser *zak_gorg_parser = (ZakGorgParser *)object;
- ZakGorgParserPrivate *priv = zak_gorg_parser_get_instance_private (zak_gorg_parser);
switch (property_id)
{
GParamSpec *pspec)
{
ZakGorgParser *zak_gorg_parser = (ZakGorgParser *)object;
- ZakGorgParserPrivate *priv = zak_gorg_parser_get_instance_private (zak_gorg_parser);
switch (property_id)
{
zak_gorg_parser_dispose (GObject *gobject)
{
ZakGorgParser *zak_gorg_parser = (ZakGorgParser *)gobject;
- ZakGorgParserPrivate *priv = zak_gorg_parser_get_instance_private (zak_gorg_parser);
zak_gorg_parser_finalize (GObject *gobject)
{
ZakGorgParser *zak_gorg_parser = (ZakGorgParser *)gobject;
- ZakGorgParserPrivate *priv = zak_gorg_parser_get_instance_private (zak_gorg_parser);
GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
parent_class->finalize (gobject);
}
+
+static void
+zak_gorg_parser_parse (ZakGorgParser *zak_gorg_parser)
+{
+ GError *error;
+ GFileInputStream *giostream;
+
+ GFileInfo *ginfo;
+ goffset size;
+
+ void *buffer;
+
+ error = NULL;
+ giostream = g_file_read (zak_gorg_parser->gfile, FALSE, &error);
+ if (giostream == NULL
+ || error != NULL)
+ {
+ g_warning ("Unable to open file. %s",
+ error != NULL && error->message != NULL ? error->message : "No details.");
+ return;
+ }
+ g_message ("GFileInputStream created.");
+
+ error = NULL;
+ ginfo = g_file_query_info (zak_gorg_parser->gfile, "standard::*", G_FILE_QUERY_INFO_NONE, NULL, &error);
+ if (ginfo == NULL
+ || error != NULL)
+ {
+ g_warning ("Unable to get file info. %s",
+ error != NULL && error->message != NULL ? error->message : "No details.");
+ return;
+ }
+ g_message ("GFileInfo created.");
+
+ size = g_file_info_get_size (ginfo);
+ g_message ("File size: %d.", size);
+
+ buffer = g_malloc (size);
+ if (!g_input_stream_read_all (G_INPUT_STREAM (giostream), buffer, size, NULL, NULL, &error)
+ || error != NULL)
+ {
+ g_warning ("Unable to read file. %s",
+ error != NULL && error->message != NULL ? error->message : "No details.");
+ return;
+ }
+
+ g_warning ("BUFFER %s", buffer);
+
+ g_free (buffer);
+ g_object_unref (ginfo);
+ g_object_unref (giostream);
+}
--- /dev/null
+/*
+ * Copyright (C) 2019 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "parser.h"
+
+int
+main (int argc, char *argv[])
+{
+ ZakGorgParser *parser;
+
+ g_message ("Parsing %s", argv[1]);
+ parser = zak_gorg_parser_new (argv[1]);
+
+ return 0;
+}