[tracker/wip/carlosg/domain-ontologies: 16/76] docs: Unify ontology documentation tools



commit a579751b433757dbaa1663f24ded78756ef5766a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jun 15 17:46:34 2017 +0200

    docs: Unify ontology documentation tools
    
    Now we have a single tool for the general ontology documentation
    and the per-class/property one.

 docs/reference/ontology/Makefile.am        |    2 +-
 docs/reference/ontology/meson.build        |   10 +-
 docs/reference/ontology/ontology-docs.sgml |    2 +-
 docs/tools/Makefile.am                     |    9 +-
 docs/tools/gen-doc.sh                      |   49 ----------
 docs/tools/meson.build                     |    7 +-
 docs/tools/ttl2sgml.c                      |  122 +++++++++++++++++++------
 docs/tools/ttl_loader.c                    |  137 +++++----------------------
 docs/tools/ttl_loader.h                    |   13 ++-
 docs/tools/ttl_sgml.c                      |   14 ++-
 docs/tools/ttl_sgml.h                      |    4 +-
 docs/tools/ttlresource2sgml.c              |   95 +++++++------------
 docs/tools/ttlresource2sgml.h              |   35 +++++++
 13 files changed, 220 insertions(+), 279 deletions(-)
---
diff --git a/docs/reference/ontology/Makefile.am b/docs/reference/ontology/Makefile.am
index 6414e51..42fe722 100644
--- a/docs/reference/ontology/Makefile.am
+++ b/docs/reference/ontology/Makefile.am
@@ -13,7 +13,7 @@ ONTOLOGY_INTRODUCTIONS =     \
 # Generation of the ontology XML files.
 gen-doc.stamp: $(ONTOLOGY_INTRODUCTIONS)
        $(MKDIR_P) xml
-       $(top_srcdir)/docs/tools/gen-doc.sh $(top_builddir)/docs/tools/ttl2sgml 
$(top_builddir)/docs/tools/ttlresource2sgml $(top_srcdir)/src/ontologies/nepomuk xml/
+       $(top_builddir)/docs/tools/ttl2sgml -d $(top_srcdir)/src/ontologies/nepomuk -o xml/
        $(AM_V_GEN) touch $@
 
 version.xml: gen-doc.stamp
diff --git a/docs/reference/ontology/meson.build b/docs/reference/ontology/meson.build
index 6c1b9d3..3767fea 100644
--- a/docs/reference/ontology/meson.build
+++ b/docs/reference/ontology/meson.build
@@ -13,14 +13,12 @@ version_xml = configure_file(input: 'version.xml.in',
 #        -e $ONTOLOGIES_INFO_DIR/$PREFIX/explanation.xml
 
 
-gen_doc = meson.source_root() + '/docs/tools/gen-doc.sh'
 generated = custom_target('ontology-doc-generated',
     output: 'gen-doc.stamp',
-    command: [gen_doc, ttl2sgml, ttlresource2sgml,
-              meson.source_root() + '/src/ontologies',
-              meson.source_root() + '/docs/ontologies',
-              join_paths(meson.current_build_dir(), 'xml/')],
-    depends: [ttl2sgml, ttlresource2sgml],
+    command: [ttl2sgml,
+              '-d', meson.source_root() + '/src/ontologies/nepomuk',
+              '-o', join_paths(meson.current_build_dir(), 'xml/')],
+    depends: ttl2sgml,
     # FIXME: this shouldn't be necessary, but currently the 'dependencies'
     # parameter to gnome.gtkdoc() doesn't actually trigger building of custom
     # targets.
diff --git a/docs/reference/ontology/ontology-docs.sgml b/docs/reference/ontology/ontology-docs.sgml
index 440e65c..b878f2f 100644
--- a/docs/reference/ontology/ontology-docs.sgml
+++ b/docs/reference/ontology/ontology-docs.sgml
@@ -53,6 +53,6 @@
     <xi:include href="xml/slo-ontology.xml" />
     <xi:include href="xml/tracker-ontology.xml" />
     <xi:include href="xml/maemo-ontology.xml" />
-    <xi:include href="xml/libosinfo-ontology.xml" />
+    <xi:include href="xml/osinfo-ontology.xml" />
   </part>
 </book>
diff --git a/docs/tools/Makefile.am b/docs/tools/Makefile.am
index b067d2f..3f77f17 100644
--- a/docs/tools/Makefile.am
+++ b/docs/tools/Makefile.am
@@ -1,4 +1,4 @@
-noinst_PROGRAMS = ttl2sgml ttlresource2sgml
+noinst_PROGRAMS = ttl2sgml
 
 AM_CPPFLAGS =                                          \
        $(BUILD_CFLAGS)                                \
@@ -24,12 +24,9 @@ TTL_LOADER_FILES =                                     \
 
 ttl2sgml_SOURCES =                                     \
        $(TTL_LOADER_FILES)                            \
+       ttlresource2sgml.c                             \
+       ttlresource2sgml.h                             \
        ttl2sgml.c
 
-ttlresource2sgml_SOURCES =                             \
-       $(TTL_LOADER_FILES)                            \
-       ttlresource2sgml.c
-
 EXTRA_DIST = \
-       gen-doc.sh \
        meson.build
diff --git a/docs/tools/meson.build b/docs/tools/meson.build
index 4092ae2..bb4076c 100644
--- a/docs/tools/meson.build
+++ b/docs/tools/meson.build
@@ -7,11 +7,6 @@ ttl_loader_files = [
 ]
 
 ttl2sgml = executable('ttl2sgml',
-    ttl_loader_files, 'ttl2sgml.c',
-    dependencies: [tracker_data_dep, tracker_sparql_dep],
-    c_args: ['-DTRACKER_COMPILATION'])
-
-ttlresource2sgml = executable('ttlresource2sgml',
-    ttl_loader_files, 'ttlresource2sgml.c',
+    ttl_loader_files, 'ttl2sgml.c', 'ttlresource2sgml.c',
     dependencies: [tracker_data_dep, tracker_sparql_dep],
     c_args: ['-DTRACKER_COMPILATION'])
diff --git a/docs/tools/ttl2sgml.c b/docs/tools/ttl2sgml.c
index 065d445..f3b46bc 100644
--- a/docs/tools/ttl2sgml.c
+++ b/docs/tools/ttl2sgml.c
@@ -24,31 +24,85 @@
 #include "ttl_loader.h"
 #include "ttl_model.h"
 #include "ttl_sgml.h"
+#include "ttlresource2sgml.h"
 
-static gchar *desc_file = NULL;
-static gchar *output_file = NULL;
+static gchar *ontology_dir = NULL;
+static gchar *output_dir = NULL;
 
 static GOptionEntry   entries[] = {
-       { "desc", 'd', 0, G_OPTION_ARG_FILENAME, &desc_file,
-         "TTL file with the ontology description and documentation",
+       { "ontology-dir", 'd', 0, G_OPTION_ARG_FILENAME, &ontology_dir,
+         "Ontology directory",
          NULL
        },
-       { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output_file,
+       { "output-dir", 'o', 0, G_OPTION_ARG_FILENAME, &output_dir,
          "File to write the output (default stdout)",
          NULL
        },
        { NULL }
 };
 
+static gint
+compare_files (gconstpointer a,
+              gconstpointer b)
+{
+       const GFile *file_a = a, *file_b = b;
+       gchar *basename_a, *basename_b;
+       gint res;
+
+       basename_a = g_file_get_basename ((GFile*) file_a);
+       basename_b = g_file_get_basename ((GFile*) file_b);
+       res = strcmp (basename_a, basename_b);
+
+       g_free (basename_a);
+       g_free (basename_b);
+
+       return res;
+}
+
+static GList *
+get_description_files (GFile *dir)
+{
+       GFileEnumerator *enumerator;
+       GFileInfo *info;
+       GFile *desc_file;
+       GList *files;
+       const gchar *name;
+
+       enumerator = g_file_enumerate_children (dir,
+                                               G_FILE_ATTRIBUTE_STANDARD_NAME,
+                                               G_FILE_QUERY_INFO_NONE,
+                                               NULL, NULL);
+
+       if (!enumerator) {
+               return NULL;
+       }
+
+       files = NULL;
+
+       while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) {
+               name = g_file_info_get_name (info);
+
+               if (g_str_has_suffix (name, ".description")) {
+                       desc_file = g_file_enumerator_get_child (enumerator, info);
+                       files = g_list_insert_sorted (files, desc_file, compare_files);
+               }
+
+               g_object_unref (info);
+       }
+
+       g_object_unref (enumerator);
+
+       return files;
+}
+
 gint
 main (gint argc, gchar **argv)
 {
        GOptionContext *context;
        Ontology *ontology = NULL;
        OntologyDescription *description = NULL;
-       gchar *ttl_file = NULL;
-       gchar *dirname = NULL;
-       FILE *f = NULL;
+       GList *description_files, *l;
+       GFile *ontology_file, *output_file;
 
        /* Translators: this messagge will apper immediately after the  */
        /* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE>     */
@@ -59,11 +113,11 @@ main (gint argc, gchar **argv)
        g_option_context_add_main_entries (context, entries, NULL);
        g_option_context_parse (context, &argc, &argv, NULL);
 
-       if (!desc_file) {
+       if (!ontology_dir || !output_dir) {
                gchar *help;
 
                g_printerr ("%s\n\n",
-                           "Description file is mandatory");
+                           "Ontology and output dirs are mandatory");
 
                help = g_option_context_get_help (context, TRUE, NULL);
                g_option_context_free (context);
@@ -73,32 +127,44 @@ main (gint argc, gchar **argv)
                return -1;
        }
 
-       if (output_file) {
-               f = fopen (output_file, "w");
-       } else {
-               f = stdout;
+       ontology_file = g_file_new_for_path (ontology_dir);
+       output_file = g_file_new_for_path (output_dir);
+       description_files = get_description_files (ontology_file);
+
+       if (!description_files) {
+               g_printerr ("Ontology description files not found in dir\n");
+               return -1;
        }
-       g_assert (f != NULL);
 
-       description = ttl_loader_load_description (desc_file);
+       ontology = ttl_loader_new_ontology ();
 
-       dirname = g_path_get_dirname (desc_file);
-       ttl_file = g_build_filename (dirname,
-                                    description->relativePath,
-                                    NULL);
+       for (l = description_files; l; l = l->next) {
+               Ontology *file_ontology = NULL;
+               GFile *ttl_file, *ttl_output_file;
+               gchar *filename;
 
-       ontology = ttl_loader_load_ontology (ttl_file);
-       g_free (ttl_file);
-       g_free (dirname);
+               description = ttl_loader_load_description (l->data);
+               ttl_file = g_file_get_child (ontology_file, description->relativePath);
 
-       ttl_sgml_print (description, ontology, f);
+               filename = g_strdup_printf ("%s-ontology.xml", description->localPrefix);
+               ttl_output_file = g_file_get_child (output_file, filename);
+               g_free (filename);
 
-       ttl_loader_free_ontology (ontology);
-       ttl_loader_free_description (description);
+               file_ontology = ttl_loader_new_ontology ();
 
-       g_option_context_free (context);
+               ttl_loader_load_ontology (ontology, ttl_file);
+               ttl_loader_load_ontology (file_ontology, ttl_file);
+               ttl_loader_load_prefix_from_description (ontology, description);
+
+               ttl_sgml_print (description, file_ontology, ttl_output_file);
+
+               ttl_loader_free_ontology (file_ontology);
+               ttl_loader_free_description (description);
+       }
+
+       generate_ontology_class_docs (ontology, output_file);
 
-       fclose (f);
+       g_option_context_free (context);
 
        return 0;
 }
diff --git a/docs/tools/ttl_loader.c b/docs/tools/ttl_loader.c
index 92a518b..4f882d0 100644
--- a/docs/tools/ttl_loader.c
+++ b/docs/tools/ttl_loader.c
@@ -336,13 +336,11 @@ load_description (OntologyDescription *desc,
        }
 }
 
-
 Ontology *
-ttl_loader_load_ontology (const gchar *ttl_file)
+ttl_loader_new_ontology (void)
 {
        Ontology *ontology;
 
-       g_debug ("Loading ontology... %s\n", ttl_file);
        ontology = g_new0 (Ontology, 1);
        ontology->classes = g_hash_table_new_full (g_str_hash,
                                                   g_str_equal,
@@ -356,138 +354,55 @@ ttl_loader_load_ontology (const gchar *ttl_file)
        ontology->prefixes = g_hash_table_new_full (g_str_hash,
                                                    g_str_equal,
                                                    g_free, g_free);
-
-       if (ttl_file) {
-               TrackerTurtleReader *reader;
-               GError *error = NULL;
-               GFile *file = g_file_new_for_path (ttl_file);
-
-               reader = tracker_turtle_reader_new (file, NULL);
-               g_object_unref (file);
-
-               while (error == NULL && tracker_turtle_reader_next (reader, &error)) {
-                       load_in_memory (ontology,
-                                       tracker_turtle_reader_get_subject (reader),
-                                       tracker_turtle_reader_get_predicate (reader),
-                                       tracker_turtle_reader_get_object (reader));
-               }
-
-               g_object_unref (reader);
-
-               if (error) {
-                       g_message ("Turtle parse error: %s", error->message);
-                       g_error_free (error);
-               }
-       } else {
-               g_warning ("Unable to open '%s'", ttl_file);
-       }
-
        return ontology;
 }
 
-static GList *
-get_ontology_files (GFile *dir)
+void
+ttl_loader_load_ontology (Ontology    *ontology,
+                          GFile       *ttl_file)
 {
-       GFileEnumerator *enumerator;
-       GFileInfo *info;
-       GList *files;
-       const gchar *name;
-
-       enumerator = g_file_enumerate_children (dir,
-                                               G_FILE_ATTRIBUTE_STANDARD_NAME,
-                                               G_FILE_QUERY_INFO_NONE,
-                                               NULL, NULL);
-
-       if (!enumerator) {
-               return NULL;
-       }
-
-       files = NULL;
+       TrackerTurtleReader *reader;
+       GError *error = NULL;
 
-       while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) {
-               name = g_file_info_get_name (info);
+       g_return_if_fail (G_IS_FILE (ttl_file));
 
-               if (g_str_has_suffix (name, ".ontology")) {
-                       files = g_list_insert_sorted (files, g_strdup (name),
-                                                     (GCompareFunc) g_strcmp0);
-               }
+       reader = tracker_turtle_reader_new (ttl_file, NULL);
 
-               g_object_unref (info);
+       while (error == NULL && tracker_turtle_reader_next (reader, &error)) {
+               load_in_memory (ontology,
+                               tracker_turtle_reader_get_subject (reader),
+                               tracker_turtle_reader_get_predicate (reader),
+                               tracker_turtle_reader_get_object (reader));
        }
 
-       g_object_unref (enumerator);
+       g_object_unref (reader);
 
-       return files;
+       if (error) {
+               g_message ("Turtle parse error: %s", error->message);
+               g_error_free (error);
+       }
 }
 
-Ontology *
-ttl_loader_load_ontology_dir (const gchar *ttl_dir)
+void
+ttl_loader_load_prefix_from_description (Ontology            *ontology,
+                                         OntologyDescription *description)
 {
-       GFile *dir = g_file_new_for_path (ttl_dir);
-       Ontology *ontology;
-       GList *files, *f;
-
-       ontology = g_new0 (Ontology, 1);
-       ontology->classes = g_hash_table_new_full (g_str_hash,
-                                                  g_str_equal,
-                                                  g_free,
-                                                  (GDestroyNotify)ttl_model_class_free);
-
-       ontology->properties = g_hash_table_new_full (g_str_hash,
-                                                     g_str_equal,
-                                                     g_free,
-                                                     (GDestroyNotify)ttl_model_property_free);
-       ontology->prefixes = g_hash_table_new_full (g_str_hash,
-                                                   g_str_equal,
-                                                   g_free, g_free);
-
-       files = get_ontology_files (dir);
-       g_object_unref (dir);
-
-       for (f = files; f; f = f->next) {
-               TrackerTurtleReader *reader;
-               GError *error = NULL;
-               gchar *ttl_file;
-               GFile *file;
-
-               ttl_file = g_build_filename (ttl_dir, f->data, NULL);
-               file = g_file_new_for_path (ttl_file);
-               reader = tracker_turtle_reader_new (file, NULL);
-               g_object_unref (file);
-               g_free (ttl_file);
-
-               while (error == NULL && tracker_turtle_reader_next (reader, &error)) {
-                       load_in_memory (ontology,
-                                       tracker_turtle_reader_get_subject (reader),
-                                       tracker_turtle_reader_get_predicate (reader),
-                                       tracker_turtle_reader_get_object (reader));
-               }
-
-               g_object_unref (reader);
-
-               if (error) {
-                       g_message ("Turtle parser error: %s", error->message);
-                       g_error_free (error);
-                       break;
-               }
+       if (!g_hash_table_lookup (ontology->prefixes, description->baseUrl)) {
+               g_hash_table_insert (ontology->prefixes,
+                                    g_strdup (description->baseUrl),
+                                    g_strdup (description->localPrefix));
        }
-
-       return ontology;
 }
 
 OntologyDescription *
-ttl_loader_load_description (const gchar *filename)
+ttl_loader_load_description (GFile *file)
 {
        OntologyDescription *desc;
        TrackerTurtleReader *reader;
        GError *error = NULL;
-       GFile *file;
 
        desc = ttl_model_description_new ();
-
-       file = g_file_new_for_path (filename);
        reader = tracker_turtle_reader_new (file, NULL);
-       g_object_unref (file);
 
        while (error == NULL && tracker_turtle_reader_next (reader, &error)) {
                load_description (desc,
diff --git a/docs/tools/ttl_loader.h b/docs/tools/ttl_loader.h
index 0edeb02..1f4fc50 100644
--- a/docs/tools/ttl_loader.h
+++ b/docs/tools/ttl_loader.h
@@ -21,16 +21,19 @@
 #define __TTL_LOADER_H__
 
 #include <glib.h>
+#include <gio/gio.h>
 #include "ttl_model.h"
 
 G_BEGIN_DECLS
 
-void                  ttl_loader_init             (void);
-void                  ttl_loader_shutdown         (void);
+Ontology            * ttl_loader_new_ontology     (void);
 
-Ontology            * ttl_loader_load_ontology    (const gchar *filename);
-Ontology            * ttl_loader_load_ontology_dir(const gchar *dir);
-OntologyDescription * ttl_loader_load_description (const gchar *filename);
+void                  ttl_loader_load_ontology    (Ontology    *ontology,
+                                                  GFile       *filename);
+OntologyDescription * ttl_loader_load_description (GFile       *filename);
+
+void                  ttl_loader_load_prefix_from_description (Ontology            *ontology,
+                                                               OntologyDescription *description);
 
 void                  ttl_loader_free_ontology    (Ontology *ontology);
 void                  ttl_loader_free_description (OntologyDescription *desc);
diff --git a/docs/tools/ttl_sgml.c b/docs/tools/ttl_sgml.c
index b041def..3526e9d 100644
--- a/docs/tools/ttl_sgml.c
+++ b/docs/tools/ttl_sgml.c
@@ -196,12 +196,17 @@ print_ontology_class (Ontology      *ontology,
 
 void
 ttl_sgml_print (OntologyDescription *description,
-                Ontology *ontology,
-                FILE *f)
+                Ontology            *ontology,
+                GFile               *file)
 {
        GHashTableIter iter;
-        gchar *upper_name;
+       gchar *upper_name, *path;
        OntologyClass *def;
+       FILE *f;
+
+       path = g_file_get_path (file);
+       f = fopen (path, "w");
+       g_assert (f != NULL);
 
         upper_name = g_ascii_strup (description->localPrefix, -1);
        print_sgml_header (f, description);
@@ -220,5 +225,6 @@ ttl_sgml_print (OntologyDescription *description,
         g_fprintf (f, "</section>\n");
        print_sgml_footer (f);
 
-        g_free (upper_name);
+       g_free (upper_name);
+       fclose (f);
 }
diff --git a/docs/tools/ttl_sgml.h b/docs/tools/ttl_sgml.h
index b2d9f23..ece602e 100644
--- a/docs/tools/ttl_sgml.h
+++ b/docs/tools/ttl_sgml.h
@@ -27,8 +27,8 @@
 G_BEGIN_DECLS
 
 void ttl_sgml_print (OntologyDescription *description,
-                     Ontology *ontology,
-                     FILE *output);
+                     Ontology            *ontology,
+                     GFile               *file);
 
 G_END_DECLS
 
diff --git a/docs/tools/ttlresource2sgml.c b/docs/tools/ttlresource2sgml.c
index 9a24b57..1ab85c2 100644
--- a/docs/tools/ttlresource2sgml.c
+++ b/docs/tools/ttlresource2sgml.c
@@ -26,24 +26,10 @@
 #include "ttl_loader.h"
 #include "ttl_model.h"
 #include "ttl_sgml.h"
-
-static gchar *ontology_dir = NULL;
-static gchar *output_dir = NULL;
+#include "ttlresource2sgml.h"
 
 #define TRACKER_ONTOLOGY_CLASS "http://www.tracker-project.org/ontologies/tracker#Ontology";
 
-static GOptionEntry   entries[] = {
-       { "ontology-dir", 'd', 0, G_OPTION_ARG_FILENAME, &ontology_dir,
-         "Ontology directory",
-         NULL
-       },
-       { "output-dir", 'o', 0, G_OPTION_ARG_FILENAME, &output_dir,
-         "File to write the output (default stdout)",
-         NULL
-       },
-       { NULL }
-};
-
 static gchar *
 name_get_prefix (Ontology    *ontology,
                  const gchar *name)
@@ -94,20 +80,25 @@ name_to_shortname (Ontology    *ontology,
 
 static void
 class_get_parent_hierarchy (Ontology       *ontology,
-                            OntologyClass  *klass,
+                            const gchar    *class_name,
                             GList         **list)
 {
+       OntologyClass *klass;
        GList *l;
 
        /* Ensure we only got the same class there once */
-       *list = g_list_remove (*list, klass->classname);
-       *list = g_list_prepend (*list, klass->classname);
+       *list = g_list_remove (*list, (gpointer) class_name);
+       *list = g_list_prepend (*list, (gpointer) class_name);
 
-       for (l = klass->superclasses; l; l = l->next) {
-               OntologyClass *parent_class;
+       klass = g_hash_table_lookup (ontology->classes, class_name);
+       if (!klass) {
+               klass = ttl_model_class_new (class_name);
+               g_hash_table_insert (ontology->classes, klass->classname, klass);
+               return;
+       }
 
-               parent_class = g_hash_table_lookup (ontology->classes, l->data);
-               class_get_parent_hierarchy (ontology, parent_class, list);
+       for (l = klass->superclasses; l; l = l->next) {
+               class_get_parent_hierarchy (ontology, l->data, list);
        }
 }
 
@@ -126,7 +117,7 @@ class_get_hierarchy (Ontology      *ontology,
                hierarchy = g_list_prepend (hierarchy, l->data);
        }
 
-       class_get_parent_hierarchy (ontology, klass, &hierarchy);
+       class_get_parent_hierarchy (ontology, klass->classname, &hierarchy);
 
        return hierarchy;
 }
@@ -676,6 +667,15 @@ print_properties (FILE          *f,
                                OntologyClass *cl;
 
                                superprop = g_hash_table_lookup (ontology->properties, l->data);
+
+                               if (!superprop) {
+                                       superprop = ttl_model_property_new (l->data);
+                                       g_hash_table_insert (ontology->properties, superprop->propertyname, 
superprop);
+                               }
+
+                               if (!superprop->domain)
+                                       continue;
+
                                cl = g_hash_table_lookup (ontology->classes, superprop->domain->data);
 
                                shortname = name_to_shortname (ontology, superprop->propertyname, NULL);
@@ -763,22 +763,26 @@ generate_class_docs (OntologyClass *klass,
        print_sgml_footer (f);
 }
 
-static void
-generate_ontology_class_docs (Ontology    *ontology,
-                              const gchar *output_dir)
+void
+generate_ontology_class_docs (Ontology *ontology,
+                              GFile    *output_dir)
 {
-       GHashTableIter iter;
        OntologyClass *klass;
+       GList *classes, *l;
        FILE *f;
 
-       g_hash_table_iter_init (&iter, ontology->classes);
+       classes = g_hash_table_get_values (ontology->classes);
 
-       while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &klass)) {
+       for (l = classes; l; l = l->next) {
                gchar *shortname, *class_filename, *output_file;
+               GFile *child;
 
+               klass = l->data;
                shortname = name_to_shortname (ontology, klass->classname, "-");
                class_filename = g_strdup_printf ("%s.xml", shortname);
-               output_file = g_build_filename (output_dir, class_filename, NULL);
+               child = g_file_get_child (output_dir, class_filename);
+
+               output_file = g_file_get_path (child);
 
                f = fopen (output_file, "w");
 
@@ -793,35 +797,6 @@ generate_ontology_class_docs (Ontology    *ontology,
                generate_class_docs (klass, ontology, f);
                fclose (f);
        }
-}
-
-int
-main (int argc, char *argv[])
-{
-       GOptionContext *context;
-       Ontology *ontology;
-
-       context = g_option_context_new ("- Generates ontology docs");
-
-       g_option_context_add_main_entries (context, entries, NULL);
-       g_option_context_parse (context, &argc, &argv, NULL);
-
-       if (!ontology_dir || !output_dir) {
-               gchar *help;
-
-               g_printerr ("%s\n\n",
-                           "Ontology and output dirs are mandatory");
-
-               help = g_option_context_get_help (context, TRUE, NULL);
-               g_option_context_free (context);
-               g_printerr ("%s", help);
-               g_free (help);
-
-               return -1;
-       }
-
-       ontology = ttl_loader_load_ontology_dir (ontology_dir);
-       generate_ontology_class_docs (ontology, output_dir);
 
-       return 0;
+       g_list_free (classes);
 }
diff --git a/docs/tools/ttlresource2sgml.h b/docs/tools/ttlresource2sgml.h
new file mode 100644
index 0000000..2a7dfc5
--- /dev/null
+++ b/docs/tools/ttlresource2sgml.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2017, Red Hat, Inc
+ *
+ * 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 the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Author: Carlos Garnacho <carlosg gnome org>
+ */
+
+#ifndef __TTLRESOURCE2SGML_H__
+#define __TTLRESOURCE2SGML_H__
+
+#include <glib.h>
+#include "ttl_model.h"
+
+G_BEGIN_DECLS
+
+void generate_ontology_class_docs (Ontology *ontology,
+                                   GFile    *output_dir);
+
+G_END_DECLS
+
+#endif /* __TTLRESOURCE2SGML__ */


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