1 | /* |
---|
2 | * gnome-db2html3 - by John Fleck - based on Daniel Veillard's |
---|
3 | * xsltproc: user program for the XSL Transformation engine |
---|
4 | * |
---|
5 | * Copyright (C) John Fleck, 2001 |
---|
6 | * Copyright (C) Mikael Hallendal, 2002 |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; either version 2 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Cambridge, MA 02139, USA. |
---|
21 | * |
---|
22 | */ |
---|
23 | |
---|
24 | #include <config.h> |
---|
25 | #include <glib.h> |
---|
26 | #include <string.h> |
---|
27 | #include <sys/time.h> |
---|
28 | #include <unistd.h> |
---|
29 | #include <stdlib.h> |
---|
30 | #include <libxml/xmlversion.h> |
---|
31 | #include <libxml/xmlmemory.h> |
---|
32 | #include <libxml/debugXML.h> |
---|
33 | #include <libxml/HTMLtree.h> |
---|
34 | #include <libxml/DOCBparser.h> |
---|
35 | #include <libxml/catalog.h> |
---|
36 | #ifdef LIBXML_XINCLUDE_ENABLED |
---|
37 | # include <libxml/xinclude.h> |
---|
38 | #endif |
---|
39 | #include <libxslt/xsltconfig.h> |
---|
40 | #include <libxslt/xslt.h> |
---|
41 | #include <libxslt/xsltInternals.h> |
---|
42 | #include <libxslt/transform.h> |
---|
43 | #include <libxslt/xsltutils.h> |
---|
44 | |
---|
45 | #include "yelp-error.h" |
---|
46 | |
---|
47 | /* stylesheet location based on Linux Standard Base * |
---|
48 | * http://www.linuxbase.org/spec/gLSB/gLSB/sgmlr002.html */ |
---|
49 | #define DB_STYLESHEET_PATH DATADIR"/sgml/docbook/yelp/docbook" |
---|
50 | #define STYLESHEET DATADIR"/sgml/docbook/yelp/yelp-customization.xsl" |
---|
51 | |
---|
52 | /* xmlParserInput * */ |
---|
53 | /* external_entity_loader (const char *URL, */ |
---|
54 | /* const char *ID, */ |
---|
55 | /* xmlParserCtxt *ctxt); */ |
---|
56 | |
---|
57 | gint |
---|
58 | main (gint argc, gchar **argv) |
---|
59 | { |
---|
60 | xsltStylesheet *stylesheet = NULL; |
---|
61 | /* YelpURI *uri; */ |
---|
62 | xmlDocPtr db_doc; |
---|
63 | xmlDocPtr final_doc; |
---|
64 | const gchar *params[16 + 1]; |
---|
65 | gchar *pathname; |
---|
66 | gchar *docpath; |
---|
67 | db_doc = NULL; |
---|
68 | |
---|
69 | putenv ("XML_CATALOG_FILES=" DATADIR "/yelp/catalog"); |
---|
70 | |
---|
71 | if (argc < 2) { |
---|
72 | g_print ("Usage 'yelp-db2html url'\n"); |
---|
73 | exit (1); |
---|
74 | } |
---|
75 | |
---|
76 | docpath = argv[1]; |
---|
77 | |
---|
78 | /* libxml housekeeping */ |
---|
79 | xmlSubstituteEntitiesDefault(1); |
---|
80 | xmlLoadExtDtdDefaultValue = 1; |
---|
81 | |
---|
82 | /* parse the stylesheet */ |
---|
83 | stylesheet = xsltParseStylesheetFile (STYLESHEET); |
---|
84 | |
---|
85 | if (!stylesheet) { |
---|
86 | g_error ("Error while parsing the stylesheet, make sure you have your docbook environment setup correctly."); |
---|
87 | exit (1); |
---|
88 | } |
---|
89 | |
---|
90 | if (strstr (docpath, ".sgml")) { |
---|
91 | db_doc = docbParseFile (docpath, "UTF-8"); |
---|
92 | } else { |
---|
93 | db_doc = xmlParseFile (docpath); |
---|
94 | #ifdef LIBXML_XINCLUDE_ENABLED |
---|
95 | xmlXIncludeProcess (db_doc); |
---|
96 | #endif |
---|
97 | } |
---|
98 | |
---|
99 | if (db_doc == NULL) { |
---|
100 | g_error ("Couldn't parse the document '%s'.", |
---|
101 | docpath); |
---|
102 | exit (1); |
---|
103 | } |
---|
104 | |
---|
105 | /* retrieve path component of filename passed in at |
---|
106 | command line */ |
---|
107 | pathname = g_path_get_dirname (docpath); |
---|
108 | |
---|
109 | /* set params to be passed to stylesheet */ |
---|
110 | params[0] = "gdb_docname"; |
---|
111 | params[1] = g_strconcat("\"", docpath, "\"", NULL) ; |
---|
112 | params[2] = "gdb_pathname"; |
---|
113 | params[3] = g_strconcat("\"", pathname, "\"", NULL) ; |
---|
114 | params[4] = "gdb_stylesheet_path"; |
---|
115 | params[5] = g_strconcat("\"", DB_STYLESHEET_PATH, "\"", NULL) ; |
---|
116 | params[6] = "gdb_multichunk"; |
---|
117 | params[7] = "1"; |
---|
118 | params[8] = NULL; |
---|
119 | |
---|
120 | g_free (pathname); |
---|
121 | |
---|
122 | final_doc = xsltApplyStylesheet (stylesheet, db_doc, params); |
---|
123 | |
---|
124 | xmlFree (db_doc); |
---|
125 | |
---|
126 | if (!final_doc) { |
---|
127 | g_error ("Error while applying the stylesheet."); |
---|
128 | exit (1); |
---|
129 | } |
---|
130 | |
---|
131 | xsltSaveResultToFile(stdout, final_doc, stylesheet); |
---|
132 | xsltFreeStylesheet(stylesheet); |
---|
133 | |
---|
134 | xmlFree (final_doc); |
---|
135 | xsltCleanupGlobals(); |
---|
136 | xmlCleanupParser(); |
---|
137 | |
---|
138 | return 0; |
---|
139 | } |
---|