No issues found
1 /*
2 * Copyright (C) 2009, Nokia <ivan.frade@nokia.com>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 */
19
20 #include <glib.h>
21 #include <gio/gio.h>
22 #include <string.h>
23 #include <stdio.h>
24 #include "ttl_loader.h"
25 #include "ttl_model.h"
26 #include "ttl_sgml.h"
27
28 static gchar *desc_file = NULL;
29 static gchar *output_file = NULL;
30 static gchar *fts_properties_file = NULL;
31 static gchar *explanation_file = NULL;
32
33 static GOptionEntry entries[] = {
34 { "desc", 'd', 0, G_OPTION_ARG_FILENAME, &desc_file,
35 "TTL file with the ontology description and documentation",
36 NULL
37 },
38 { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output_file,
39 "File to write the output (default stdout)",
40 NULL
41 },
42 { "fts", 'f', 0, G_OPTION_ARG_FILENAME, &fts_properties_file,
43 "Output file listing the full text indexed properties",
44 NULL
45 },
46 { "explanation", 'e', 0, G_OPTION_ARG_FILENAME, &explanation_file,
47 "Verbosy explanation file in HTML format to include in the webpage",
48 NULL
49 },
50 { NULL }
51 };
52
53 gint
54 main (gint argc, gchar **argv)
55 {
56 GOptionContext *context;
57 Ontology *ontology = NULL;
58 OntologyDescription *description = NULL;
59 gchar *ttl_file = NULL;
60 gchar *dirname = NULL;
61 FILE *f = NULL;
62 FILE *fts = NULL;
63
64 /* Translators: this messagge will apper immediately after the */
65 /* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE> */
66 context = g_option_context_new ("- Generates HTML doc for a TTL file");
67
68 /* Translators: this message will appear after the usage string */
69 /* and before the list of options. */
70 g_option_context_add_main_entries (context, entries, NULL);
71 g_option_context_parse (context, &argc, &argv, NULL);
72
73 if (!desc_file) {
74 gchar *help;
75
76 g_printerr ("%s\n\n",
77 "Description file is mandatory");
78
79 help = g_option_context_get_help (context, TRUE, NULL);
80 g_option_context_free (context);
81 g_printerr ("%s", help);
82 g_free (help);
83
84 return -1;
85 }
86
87 if (output_file) {
88 f = fopen (output_file, "w");
89 } else {
90 f = stdout;
91 }
92 g_assert (f != NULL);
93
94 if (fts_properties_file) {
95 fts = fopen (fts_properties_file, "a");
96 }
97
98 description = ttl_loader_load_description (desc_file);
99
100 dirname = g_path_get_dirname (desc_file);
101 ttl_file = g_build_filename (dirname,
102 description->relativePath,
103 NULL);
104
105 ontology = ttl_loader_load_ontology (ttl_file);
106 g_free (ttl_file);
107 g_free (dirname);
108
109 ttl_sgml_print (description, ontology, f, fts, explanation_file);
110
111 ttl_loader_free_ontology (ontology);
112 ttl_loader_free_description (description);
113
114 g_option_context_free (context);
115
116 fclose (f);
117
118 if (fts) {
119 fclose (fts);
120 }
121
122 return 0;
123 }