2 #include <config-kdoctools.h>
7 #include <QCoreApplication>
8 #include <QtCore/QString>
9 #include <QtCore/QFile>
10 #include <QtCore/QDir>
11 #include <QtCore/QTextCodec>
12 #include <QtCore/QFileInfo>
13 #include <QtCore/QList>
24 #include <libxml/xmlversion.h>
25 #include <libxml/xmlmemory.h>
26 #include <libxml/debugXML.h>
27 #include <libxml/HTMLtree.h>
28 #include <libxml/xmlIO.h>
29 #include <libxml/parserInternals.h>
30 #include <libxslt/xsltconfig.h>
31 #include <libxslt/xsltInternals.h>
32 #include <libxslt/transform.h>
33 #include <libxslt/xsltutils.h>
34 #include <libexslt/exslt.h>
57 base += atoi( (
const char* )xmlGetProp(cur, (
const xmlChar* )
"header") );
62 cur = cur->xmlChildrenNode;
65 if ( cur->type == XML_TEXT_NODE ) {
66 QString words = QString::fromUtf8( (
char* )cur->content );
67 const QStringList wlist = words.simplified().split(
' ',QString::SkipEmptyParts );
68 for ( QStringList::ConstIterator it = wlist.begin();
69 it != wlist.end(); ++it )
76 }
else if ( !xmlStrcmp( cur->name, (
const xmlChar *)
"entry") )
84 int main(
int argc,
char **argv) {
89 options.
add(
"stylesheet <xsl>",
ki18n(
"Stylesheet to use"));
90 options.
add(
"stdout",
ki18n(
"Output whole document to stdout"));
92 options.
add(
"output <file>",
ki18n(
"Output whole document to file"));
93 options.
add(
"htdig",
ki18n(
"Create a ht://dig compatible index"));
94 options.
add(
"check",
ki18n(
"Check the document for validity"));
95 options.
add(
"cache <file>",
ki18n(
"Create a cache file for the document"));
96 options.
add(
"srcdir <dir>",
ki18n(
"Set the srcdir, for kdelibs"));
97 options.
add(
"param <key>=<value>",
ki18n(
"Parameters to pass to the stylesheet"));
98 options.
add(
"+xml",
ki18n(
"The file to transform"));
100 KAboutData aboutData(
"meinproc4",
"kio_help4",
ki18n(
"XML-Translator" ),
102 ki18n(
"KDE Translator for XML"));
107 QCoreApplication app( argc, argv );
112 if ( args->
count() != 1 ) {
121 if ( args->
isSet(
"srcdir" ) )
122 srcdir = QDir( args->
getOption(
"srcdir" ) ).absolutePath();
137 if ( args->
isSet(
"check" ) ) {
140 catalogs += KUrl::fromLocalFile(
KStandardDirs::locate(
"dtd",
"customization/catalog.xml" ) ).toEncoded();
143 #if defined( XMLLINT )
160 xmlSubstituteEntitiesDefault(1);
163 QVector<const char *> params;
169 if (args->
isSet(
"output" ) ) {
170 params.append( qstrdup(
"outputFile" ) );
171 params.append( qstrdup( args->
getOption(
"output" ).toLocal8Bit() ) );
176 QStringList::ConstIterator it = paramList.begin();
177 QStringList::ConstIterator
end = paramList.end();
178 for ( ; it != end; ++it ) {
180 const int ch = tuple.indexOf(
'=' );
182 kError() <<
"Key-Value tuple '" << tuple <<
"' lacks a '='!" << endl;
185 params.append( qstrdup( tuple.left( ch ).toUtf8() ) );
186 params.append( qstrdup( tuple.mid( ch + 1 ).toUtf8() ) );
189 params.append( NULL );
191 bool index = args->
isSet(
"htdig" );
194 tss =
"customization/kde-chunk.xsl";
196 tss =
"customization/htdig_index.xsl" ;
200 const bool usingStdOut = args->
isSet(
"stdout" );
201 const bool usingOutput = args->
isSet(
"output");
205 xsltStylesheetPtr style_sheet =
206 xsltParseStylesheetFile((
const xmlChar *)tss.toLatin1().data());
208 if (style_sheet != NULL) {
210 xmlDocPtr doc = xmlParseFile( QFile::encodeName( checkFilename ).constData() );
212 xmlDocPtr res = xsltApplyStylesheet(style_sheet, doc, ¶ms[0]);
215 xsltFreeStylesheet(style_sheet);
217 xmlNodePtr cur = xmlDocGetRootElement(res);
218 if (!cur || xmlStrcmp(cur->name, (
const xmlChar *)
"entry")) {
219 fprintf(stderr,
"document of the wrong type, root node != entry");
226 for ( PairList::ConstIterator it = list.constBegin(); it != list.constEnd();
228 fprintf( stdout,
"w\t%s\t%d\t%d\n", ( *it ).word.toUtf8().data(),
229 1000*wi/list.count(), ( *it ).base );
233 kDebug() <<
"couldn't parse document " << checkFilename;
236 kDebug() <<
"couldn't parse style sheet " << tss;
241 if (output.isEmpty()) {
242 fprintf(stderr,
"unable to parse %s\n", checkFilename.toLocal8Bit().data());
246 if ( !cache.isEmpty() ) {
248 kError() <<
i18n(
"Could not write to cache file %1." , cache ) << endl;
253 doOutput(output, usingStdOut, usingOutput, outputOption,
true );