From kde-commits Mon Feb 14 11:11:40 2005 From: Frerich Raabe Date: Mon, 14 Feb 2005 11:11:40 +0000 To: kde-commits Subject: kdelibs/kdoctools Message-Id: <20050214111140.0C72C1D1A9 () office ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=110837958716109 CVS commit by raabe: - Make it possible to pass parameters to stylesheets. New feature, but coolo didn't complained, and this is necessary for a nice KDE_MANS fix. M +29 -6 meinproc.cpp 1.40 M +6 -5 xslt.cpp 1.70 M +3 -1 xslt.h 1.15 --- kdelibs/kdoctools/meinproc.cpp #1.39:1.40 @@ -27,4 +27,5 @@ #include #include +#include extern int xmlLoadExtDtdDefaultValue; @@ -79,4 +80,7 @@ static KCmdLineOptions options[] = { "cache ", I18N_NOOP( "Create a cache file for the document" ), 0}, { "srcdir ", I18N_NOOP( "Set the srcdir, for kdelibs" ), 0}, + + // XXX Un-comment after KDE 3.4 + { "param =", /*I18N_NOOP( "Parameters to pass to the stylesheet" )*/ 0, 0}, { "+xml", I18N_NOOP("The file to transform"), 0}, KCmdLineLastOption // End of options. @@ -181,4 +185,26 @@ int main(int argc, char **argv) { xmlLoadExtDtdDefaultValue = 1; + QValueVector params; + if (args->isSet( "output" ) ) { + params.append( qstrdup( "outputFile" ) ); + params.append( qstrdup( QFile::decodeName( args->getOption( "output" ) ).latin1() ) ); + } + { + const QCStringList paramList = args->getOptionList( "param" ); + QCStringList::ConstIterator it = paramList.begin(); + QCStringList::ConstIterator end = paramList.end(); + for ( ; it != end; ++it ) { + const QCString tuple = *it; + const int ch = tuple.find( '=' ); + if ( ch == -1 ) { + kdError() << "Key-Value tuple '" << tuple << "' lacks a '='!" << endl; + return( 2 ); + } + params.append( qstrdup( tuple.left( ch ) ) ); + params.append( qstrdup( tuple.mid( ch + 1 ) ) ); + } + } + params.append( NULL ); + bool index = args->isSet( "htdig" ); QString tss = args->getOption( "stylesheet" ); @@ -198,8 +224,5 @@ int main(int argc, char **argv) { xmlDocPtr doc = xmlParseFile( QFile::encodeName( args->arg( 0 ) ) ); - // the params can be used to customize it more flexible - const char *params[16 + 1]; - params[0] = NULL; - xmlDocPtr res = xsltApplyStylesheet(style_sheet, doc, params); + xmlDocPtr res = xsltApplyStylesheet(style_sheet, doc, ¶ms[0]); xmlFreeDoc(doc); @@ -229,5 +252,5 @@ int main(int argc, char **argv) { } else { - QString output = transform(args->arg( 0 ) , tss); + QString output = transform(args->arg( 0 ) , tss, params); if (output.isEmpty()) { fprintf(stderr, "unable to parse %s\n", args->arg( 0 )); --- kdelibs/kdoctools/xslt.cpp #1.69:1.70 @@ -26,4 +26,5 @@ #include #include +#include #if !defined( SIMPLE_XSLT ) @@ -47,5 +48,6 @@ int closeQString(void * context) { } -QString transform( const QString &pat, const QString& tss) +QString transform( const QString &pat, const QString& tss, + const QValueVector ¶ms ) { QString parsed; @@ -74,9 +76,8 @@ QString transform( const QString &pat, c return parsed; - // the params can be used to customize it more flexible - const char *params[16 + 1]; - params[0] = NULL; INFO(i18n("Applying stylesheet")); - xmlDocPtr res = xsltApplyStylesheet(style_sheet, doc, params); + QValueVector p = params; + p.append( NULL ); + xmlDocPtr res = xsltApplyStylesheet(style_sheet, doc, const_cast(&p[0])); xmlFreeDoc(doc); if (res != NULL) { --- kdelibs/kdoctools/xslt.h #1.14:1.15 @@ -3,6 +3,8 @@ #include +#include -QString transform(const QString &file, const QString& stylesheet); +QString transform(const QString &file, const QString& stylesheet, + const QValueVector ¶ms = QValueVector()); QString splitOut(const QString &parsed, int index); void fillInstance(KInstance &ins, const QString &srcdir = QString::null );