[gtksourceview] Add a versioning API



commit 628211ade71c2229df57afccc74eedf7e24cf77f
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Nov 1 16:46:01 2015 +0100

    Add a versioning API
    
    Add a header to check the version both at compile time and
    at runtime.

 configure.ac                                  |    8 ++
 docs/reference/gtksourceview-3.0-sections.txt |   15 +++
 gtksourceview/Makefile.am                     |    6 +-
 gtksourceview/gtksource.h                     |    1 +
 gtksourceview/gtksourceversion.c              |  118 +++++++++++++++++++++++++
 gtksourceview/gtksourceversion.h.in           |   98 ++++++++++++++++++++
 6 files changed, 245 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 7131c8e..f2269be 100644
--- a/configure.ac
+++ b/configure.ac
@@ -15,6 +15,13 @@ AC_INIT([gtksourceview],
 
 AX_IS_RELEASE([git-directory])
 
+GTK_SOURCE_MAJOR_VERSION=gtksourceview_major_version
+GTK_SOURCE_MINOR_VERSION=gtksourceview_minor_version
+GTK_SOURCE_MICRO_VERSION=gtksourceview_micro_version
+AC_SUBST(GTK_SOURCE_MAJOR_VERSION)
+AC_SUBST(GTK_SOURCE_MINOR_VERSION)
+AC_SUBST(GTK_SOURCE_MICRO_VERSION)
+
 # Libtool versioning
 #
 # For development releases, keep the same numbers.
@@ -193,6 +200,7 @@ data/styles/Makefile
 docs/Makefile
 docs/reference/Makefile
 gtksourceview/Makefile
+gtksourceview/gtksourceversion.h
 gtksourceview/completion-providers/Makefile
 gtksourceview/completion-providers/words/Makefile
 po/Makefile.in
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index 20a1dbc..ece5339 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -837,6 +837,21 @@ gtk_source_utils_escape_search_text
 </SECTION>
 
 <SECTION>
+<FILE>version</FILE>
+<TITLE>Version Information</TITLE>
+gtk_source_get_major_version
+gtk_source_get_minor_version
+gtk_source_get_micro_version
+gtk_source_check_version
+<SUBSECTION>
+GTK_SOURCE_MAJOR_VERSION
+GTK_SOURCE_MINOR_VERSION
+GTK_SOURCE_MICRO_VERSION
+GTK_SOURCE_CHECK_VERSION
+<SUBSECTION>
+</SECTION>
+
+<SECTION>
 <FILE>view</FILE>
 <TITLE>GtkSourceView</TITLE>
 GtkSourceView
diff --git a/gtksourceview/Makefile.am b/gtksourceview/Makefile.am
index bd2fffb..768e887 100644
--- a/gtksourceview/Makefile.am
+++ b/gtksourceview/Makefile.am
@@ -90,6 +90,7 @@ libgtksourceview_public_c_files =             \
        gtksourcetag.c                          \
        gtksourceundomanager.c                  \
        gtksourceutils.c                        \
+       gtksourceversion.c                      \
        gtksourceview.c
 
 libgtksourceview_private_headers =             \
@@ -188,7 +189,10 @@ libgtksourceview_3_0_la_LDFLAGS =          \
 libgtksourceview_3_0_includedir = $(includedir)/gtksourceview-3.0/gtksourceview
 
 libgtksourceview_3_0_include_HEADERS = $(libgtksourceview_public_headers)
-nodist_libgtksourceview_3_0_include_HEADERS = gtksourceview-typebuiltins.h
+
+nodist_libgtksourceview_3_0_include_HEADERS = \
+       gtksourceview-typebuiltins.h \
+       gtksourceversion.h
 
 gtksourceview-resources.c: gtksourceview.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) 
--sourcedir=$(srcdir) --generate-dependencies $(srcdir)/gtksourceview.gresource.xml)
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source 
$(srcdir)/gtksourceview.gresource.xml
diff --git a/gtksourceview/gtksource.h b/gtksourceview/gtksource.h
index f832274..44cca16 100644
--- a/gtksourceview/gtksource.h
+++ b/gtksourceview/gtksource.h
@@ -53,6 +53,7 @@
 #include <gtksourceview/gtksourcetag.h>
 #include <gtksourceview/gtksourceundomanager.h>
 #include <gtksourceview/gtksourceutils.h>
+#include <gtksourceview/gtksourceversion.h>
 #include <gtksourceview/gtksourceview.h>
 #include <gtksourceview/gtksourceview-typebuiltins.h>
 #include <gtksourceview/gtksourceautocleanups.h>
diff --git a/gtksourceview/gtksourceversion.c b/gtksourceview/gtksourceversion.c
new file mode 100644
index 0000000..e089044
--- /dev/null
+++ b/gtksourceview/gtksourceversion.c
@@ -0,0 +1,118 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ * gtksourceversion.c
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2015 - Paolo Borelli <pborelli gnome org>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView 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 Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gtksourceversion.h"
+
+/**
+ * SECTION:version
+ * @short_description: Variables and functions to check the GtkSourceView version
+ **/
+
+/**
+ * gtk_source_get_major_version:
+ *
+ * Returns the major version number of the GtkSourceView library.
+ * (e.g. in GtkSourceView version 3.20.0 this is 3.)
+ *
+ * This function is in the library, so it represents the GtkSourceView library
+ * your code is running against. Contrast with the #GTK_SOURCE_MAJOR_VERSION
+ * macro, which represents the major version of the GtkSourceView headers you
+ * have included when compiling your code.
+ *
+ * Returns: the major version number of the GtkSourceView library
+ *
+ * Since: 3.20
+ */
+guint
+gtk_source_get_major_version (void)
+{
+       return GTK_SOURCE_MAJOR_VERSION;
+}
+
+/**
+ * gtk_source_get_minor_version:
+ *
+ * Returns the minor version number of the GtkSourceView library.
+ * (e.g. in GtkSourceView version 3.20.0 this is 20.)
+ *
+ * This function is in the library, so it represents the GtkSourceView library
+ * your code is running against. Contrast with the #GTK_SOURCE_MINOR_VERSION
+ * macro, which represents the minor version of the GtkSourceView headers you
+ * have included when compiling your code.
+ *
+ * Returns: the minor version number of the GtkSourceView library
+ *
+ * Since: 3.20
+ */
+guint
+gtk_source_get_minor_version (void)
+{
+       return GTK_SOURCE_MINOR_VERSION;
+}
+
+/**
+ * gtk_source_get_micro_version:
+ *
+ * Returns the micro version number of the GtkSourceView library.
+ * (e.g. in GtkSourceView version 3.20.0 this is 0.)
+ *
+ * This function is in the library, so it represents the GtkSourceView library
+ * your code is running against. Contrast with the #GTK_SOURCE_MICRO_VERSION
+ * macro, which represents the micro version of the GtkSourceView headers you
+ * have included when compiling your code.
+ *
+ * Returns: the micro version number of the GtkSourceView library
+ *
+ * Since: 3.20
+ */
+guint
+gtk_source_get_micro_version (void)
+{
+       return GTK_SOURCE_MICRO_VERSION;
+}
+
+/**
+ * gtk_source_check_version:
+ * @major: the major version to check
+ * @minor: the minor version to check
+ * @micro: the micro version to check
+ *
+ * Like GTK_SOURCE_CHECK_VERSION, but the check for gtk_source_check_version is
+ * at runtime instead of compile time. This is useful for compiling
+ * against older versions of GtkSourceView, but using features from newer
+ * versions.
+ *
+ * Returns: %TRUE if the version of the GtkSourceView currently loaded
+ * is the same as or newer than the passed-in version.
+ *
+ * Since: 3.20
+ */
+gboolean
+gtk_source_check_version (guint major,
+                          guint minor,
+                          guint micro)
+{
+       return GTK_SOURCE_CHECK_VERSION (major, minor, micro);
+}
diff --git a/gtksourceview/gtksourceversion.h.in b/gtksourceview/gtksourceversion.h.in
new file mode 100644
index 0000000..ab82db5
--- /dev/null
+++ b/gtksourceview/gtksourceversion.h.in
@@ -0,0 +1,98 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ * gtksourceversion.h
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2015 - Paolo Borelli <pborelli gnome org>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView 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 Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __GTK_SOURCE_VERSION_H__
+#define __GTK_SOURCE_VERSION_H__
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+/**
+ * GTK_SOURCE_MAJOR_VERSION:
+ *
+ * Like gtk_source_get_major_version(), but from the headers used at
+ * application compile time, rather than from the library linked
+ * against at application run time.
+ *
+ * Since: 3.20
+ */
+#define GTK_SOURCE_MAJOR_VERSION (@GTK_SOURCE_MAJOR_VERSION@)
+
+/**
+ * GTK_SOURCE_MINOR_VERSION:
+ *
+ * Like gtk_source_get_minor_version(), but from the headers used at
+ * application compile time, rather than from the library linked
+ * against at application run time.
+ *
+ * Since: 3.20
+ */
+#define GTK_SOURCE_MINOR_VERSION (@GTK_SOURCE_MINOR_VERSION@)
+
+/**
+ * GTK_SOURCE_MICRO_VERSION:
+ *
+ * Like gtk_source_get_micro_version(), but from the headers used at
+ * application compile time, rather than from the library linked
+ * against at application run time.
+ *
+ * Since: 3.20
+ */
+#define GTK_SOURCE_MICRO_VERSION (@GTK_SOURCE_MICRO_VERSION@)
+
+
+/**
+ * GTK_SOURCE_CHECK_VERSION:
+ * @major: major version (e.g. 3 for version 3.20.0)
+ * @minor: minor version (e.g. 20 for version 3.20.0)
+ * @micro: micro version (e.g. 0 for version 3.20.0)
+ *
+ * Macro to test the version of GtkSourceView being compiled against.
+ *
+ * Returns: %TRUE if the version of the GtkSourceView header files
+ * is the same as or newer than the passed-in version.
+ *
+ * Since: 3.20
+ */
+#define GTK_SOURCE_CHECK_VERSION(major, minor, micro) \
+       (GTK_SOURCE_MAJOR_VERSION > (major) || \
+       (GTK_SOURCE_MAJOR_VERSION == (major) && GTK_SOURCE_MINOR_VERSION > (minor)) || \
+       (GTK_SOURCE_MAJOR_VERSION == (major) && GTK_SOURCE_MINOR_VERSION == (minor) && \
+        GTK_SOURCE_MICRO_VERSION >= (micro)))
+
+guint          gtk_source_get_major_version            (void);
+
+guint          gtk_source_get_minor_version            (void);
+
+guint          gtk_source_get_micro_version            (void);
+
+gboolean       gtk_source_check_version                (guint major,
+                                                        guint minor,
+                                                        guint micro);
+
+G_END_DECLS
+
+#endif /* __GTK_SOURCE_VERSION_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]