From: Andrea Zagli Date: Sun, 7 Jul 2019 19:47:04 +0000 (+0200) Subject: First test. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=2f760ea338f3b7006d25bfea777db9b1e26c6d5b;p=libzakgorg First test. --- diff --git a/.gitignore b/.gitignore index 650b88c..e403dc9 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,5 @@ src/*marshal*.[ch] test-driver *.gir *.typelib -build \ No newline at end of file +build +dump \ No newline at end of file diff --git a/configure.ac b/configure.ac index 99ca02c..ee94627 100644 --- a/configure.ac +++ b/configure.ac @@ -52,6 +52,7 @@ AM_GLIB_GNU_GETTEXT # Checks for libraries. PKG_CHECK_MODULES(ZAKGORG, [glib-2.0 >= 2.36 gobject-2.0 >= 2.36 + gio-2.0 >= 2.36 gmodule-2.0 >= 2.0.0]) AC_SUBST(ZAKGORG_CFLAGS) diff --git a/libzakgorg.pc.in b/libzakgorg.pc.in index 1f0edc5..07299e5 100644 --- a/libzakgorg.pc.in +++ b/libzakgorg.pc.in @@ -6,6 +6,6 @@ includedir=@includedir@ Name: @PACKAGE_NAME@ Description: Class for magane org-mode files. Version: @PACKAGE_VERSION@ -Requires: glib-2.0 >= 2.36 gobject-2.0 +Requires: glib-2.0 >= 2.36 gobject-2.0 gio-2.0 Libs: -L${libdir} -lzakgorg Cflags: -I${includedir} diff --git a/src/parser.c b/src/parser.c index ce65493..8f8b428 100644 --- a/src/parser.c +++ b/src/parser.c @@ -39,20 +39,17 @@ static void zak_gorg_parser_get_property (GObject *object, 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) @@ -68,9 +65,6 @@ 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; } /** @@ -84,9 +78,15 @@ ZakGorgParser { 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; } /** @@ -98,6 +98,11 @@ ZakGorgParser 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 */ @@ -108,7 +113,6 @@ zak_gorg_parser_set_property (GObject *object, GParamSpec *pspec) { ZakGorgParser *zak_gorg_parser = (ZakGorgParser *)object; - ZakGorgParserPrivate *priv = zak_gorg_parser_get_instance_private (zak_gorg_parser); switch (property_id) { @@ -125,7 +129,6 @@ zak_gorg_parser_get_property (GObject *object, GParamSpec *pspec) { ZakGorgParser *zak_gorg_parser = (ZakGorgParser *)object; - ZakGorgParserPrivate *priv = zak_gorg_parser_get_instance_private (zak_gorg_parser); switch (property_id) { @@ -139,7 +142,6 @@ static void zak_gorg_parser_dispose (GObject *gobject) { ZakGorgParser *zak_gorg_parser = (ZakGorgParser *)gobject; - ZakGorgParserPrivate *priv = zak_gorg_parser_get_instance_private (zak_gorg_parser); @@ -151,10 +153,61 @@ static void 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); +} diff --git a/tests/Makefile.am b/tests/Makefile.am index 953f308..0537320 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,11 +1,12 @@ AM_CPPFLAGS = $(WARN_CFLAGS) \ $(DISABLE_DEPRECATED_CFLAGS) \ - $(ZAKFORM_CFLAGS) \ + $(ZAKGORG_CFLAGS) \ -I$(top_srcdir)/src -LIBS = $(ZAKFORM_LIBS) \ +LIBS = $(ZAKGORG_LIBS) \ -export-dynamic -LDADD = $(top_builddir)/src/libzakform.la +LDADD = $(top_builddir)/src/libzakgorg.la -noinst_PROGRAMS = +noinst_PROGRAMS = \ + dump diff --git a/tests/dump.c b/tests/dump.c new file mode 100644 index 0000000..f94085f --- /dev/null +++ b/tests/dump.c @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2019 Andrea Zagli + * + * 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; +} diff --git a/tests/simple.org b/tests/simple.org new file mode 100644 index 0000000..7d8f3b5 --- /dev/null +++ b/tests/simple.org @@ -0,0 +1,6 @@ +* first line +** sub 1 first line +** sub 2 first line +* second line +* third line +** sub 1 third line