2#include <config-kdoctools.h>
7#include <QCoreApplication>
8#include <QtCore/QString>
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") )
84int 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();
127 const QString checkFilename = args->
arg( 0 );
132 else if ( ckr ==
CheckFileIsNotFile ) kError() <<
"'" << checkFilename <<
"' is not a file.";
137 if ( args->
isSet(
"check" ) ) {
140 catalogs += KUrl::fromLocalFile(
KStandardDirs::locate(
"dtd",
"customization/catalog.xml" ) ).toEncoded();
143#if defined( XMLLINT )
160 QVector<const char *> params;
162 const QStringList paramList = args->
getOptionList(
"param" );
163 QStringList::ConstIterator it = paramList.begin();
164 QStringList::ConstIterator
end = paramList.end();
165 for ( ; it !=
end; ++it ) {
166 const QString tuple = *it;
167 const int ch = tuple.indexOf(
'=' );
169 kError() <<
"Key-Value tuple '" << tuple <<
"' lacks a '='!" << endl;
172 params.append( qstrdup( tuple.left( ch ).toUtf8() ) );
173 params.append( qstrdup( tuple.mid( ch + 1 ).toUtf8() ) );
176 params.append( NULL );
178 bool index = args->
isSet(
"htdig" );
179 QString tss = args->
getOption(
"stylesheet" );
181 tss =
"customization/kde-chunk.xsl";
183 tss =
"customization/htdig_index.xsl" ;
186 const QString cache = args->
getOption(
"cache" );
187 const bool usingStdOut = args->
isSet(
"stdout" );
188 const bool usingOutput = args->
isSet(
"output");
189 const QString outputOption = args->
getOption(
"output" );
192 xsltStylesheetPtr style_sheet =
193 xsltParseStylesheetFile((
const xmlChar *)tss.toLatin1().data());
195 if (style_sheet != NULL) {
197 xmlDocPtr doc = xmlReadFile( QFile::encodeName( checkFilename ).constData(),
198 NULL, XML_PARSE_NOENT|XML_PARSE_DTDLOAD|XML_PARSE_NONET );
199 xmlDocPtr res = xsltApplyStylesheet(style_sheet, doc, ¶ms[0]);
202 xsltFreeStylesheet(style_sheet);
204 xmlNodePtr cur = xmlDocGetRootElement(res);
205 if (!cur || xmlStrcmp(cur->name, (
const xmlChar *)
"entry")) {
206 fprintf(stderr,
"document of the wrong type, root node != entry");
213 for ( PairList::ConstIterator it =
list.constBegin(); it !=
list.constEnd();
215 fprintf( stdout,
"w\t%s\t%d\t%d\n", ( *it ).word.toUtf8().data(),
216 1000*wi/
list.count(), ( *it ).base );
220 kDebug() <<
"couldn't parse document " << checkFilename;
223 kDebug() <<
"couldn't parse style sheet " << tss;
229 fprintf(stderr,
"unable to parse %s\n", checkFilename.toLocal8Bit().data());
233 if ( !cache.isEmpty() ) {
235 kError() <<
i18n(
"Could not write to cache file %1." , cache ) << endl;
bool isSet(const QByteArray &option) const
QStringList getOptionList(const QByteArray &option) const
static void usage(const QByteArray &id=QByteArray())
static void init(const KAboutData *about)
static KCmdLineArgs * parsedArgs(const QByteArray &id=QByteArray())
static void addCmdLineOptions(const KCmdLineOptions &options, const KLocalizedString &name=KLocalizedString(), const QByteArray &id=QByteArray(), const QByteArray &afterId=QByteArray())
QString getOption(const QByteArray &option) const
KCmdLineOptions & add(const KCmdLineOptions &options)
static QString findExe(const QString &appname, const QString &pathstr=QString(), SearchOptions options=NoSearchOptions)
static QString locate(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
void output(QList< Action > actions, QHash< QString, QString > domain)
bool isExecutable(const QString &file)
KLocalizedString ki18n(const char *msg)
QString i18n(const char *text)
void parseEntry(PairList &list, xmlNodePtr cur, int base)
int main(int argc, char **argv)
int xmlLoadExtDtdDefaultValue
void doOutput(QString output, bool usingStdOut, bool usingOutput, const QString &outputOption, bool replaceCharset)
CheckFileResult checkFile(const QString &checkFilename)
CheckResult check(const QString &checkFilename, const QString &exe, const QByteArray &catalogs)
QStringList list(const QString &fileClass)
QString transform(const QString &pat, const QString &tss, const QVector< const char * > ¶ms)
bool saveToCache(const QString &contents, const QString &filename)
void fillInstance(KComponentData &ins, const QString &srcdir=QString())