[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kdoctools [POSSIBLY UNSAFE]
From: Albert Astals Cid <tsdgeos () terra ! es>
Date: 2010-03-19 23:25:17
Message-ID: 20100319232517.8AF46AC860 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1105363 by aacid:
split files a bit to get a binary called meinproc4_simple that is simple and qt4 only \
dependant that i want to use in l10n.kde.org
M +22 -2 CMakeLists.txt
M +1 -0 kio_help.cpp
M +22 -90 meinproc.cpp
A meinproc_common.cpp [POSSIBLY UNSAFE: popen] [License: UNKNOWN]
A meinproc_common.h [License: UNKNOWN]
A meinproc_simple.cpp meinproc.cpp#1102726 [License: UNKNOWN]
M +0 -126 xslt.cpp
M +2 -6 xslt.h
A xslt_help.cpp xslt.cpp#1102726 [License: UNKNOWN]
A xslt_help.h xslt.h#1102726 [License: UNKNOWN]
A xslt_kde.cpp xslt.cpp#1102726 [License: UNKNOWN]
A xslt_kde.h xslt.h#1102726 [License: UNKNOWN]
--- trunk/KDE/kdelibs/kdoctools/CMakeLists.txt #1105362:1105363
@@ -22,6 +22,8 @@
kio_help.cpp
main.cpp
xslt.cpp
+ xslt_help.cpp
+ xslt_kde.cpp
)
@@ -34,7 +36,7 @@
########### next target ###############
-set(kio_ghelp_PART_SRCS kio_help.cpp main_ghelp.cpp xslt.cpp )
+set(kio_ghelp_PART_SRCS kio_help.cpp main_ghelp.cpp xslt.cpp xslt_help.cpp \
xslt_kde.cpp )
kde4_add_plugin(kio_ghelp ${kio_ghelp_PART_SRCS})
@@ -58,7 +60,7 @@
else (CMAKE_CROSSCOMPILING)
- set(meinproc_SRCS meinproc.cpp xslt.cpp )
+ set(meinproc_SRCS meinproc.cpp meinproc_common.cpp xslt.cpp xslt_kde.cpp )
kde4_add_executable(meinproc4 NOGUI ${meinproc_SRCS})
@@ -73,7 +75,25 @@
endif (CMAKE_CROSSCOMPILING)
+########### next target ###############
+if(KDE4_ENABLE_FINAL)
+ set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/meinproc4_simple_final_cpp.cpp \
PROPERTIES COMPILE_FLAGS -DSIMPLE_XSLT ) +else(KDE4_ENABLE_FINAL)
+ set_source_files_properties(xslt.cpp PROPERTIES COMPILE_FLAGS -DSIMPLE_XSLT )
+endif(KDE4_ENABLE_FINAL)
+
+if (NOT CMAKE_CROSSCOMPILING)
+ set(meinproc_qt_SRCS meinproc_simple.cpp meinproc_common.cpp xslt.cpp )
+
+ kde4_add_executable(meinproc4_simple NOGUI ${meinproc_qt_SRCS})
+
+ target_link_libraries(meinproc4_simple ${QT_QTCORE_LIBRARIES} \
${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES}) +
+ install(TARGETS meinproc4_simple ${INSTALL_TARGETS_DEFAULT_ARGS})
+
+endif (NOT CMAKE_CROSSCOMPILING)
+
########### next target ###############
set(genshortcutents_SRCS genshortcutents.cpp )
--- trunk/KDE/kdelibs/kdoctools/kio_help.cpp #1105362:1105363
@@ -24,6 +24,7 @@
#include "kio_help.h"
#include "xslt.h"
+#include "xslt_help.h"
#include <kdebug.h>
#include <kde_file.h>
--- trunk/KDE/kdelibs/kdoctools/meinproc.cpp #1105362:1105363
@@ -2,6 +2,7 @@
#include <config-kdoctools.h>
#include <config.h>
#include "xslt.h"
+#include "meinproc_common.h"
#include <QCoreApplication>
#include <QtCore/QString>
@@ -120,34 +121,23 @@
LIBXML_TEST_VERSION
- QString checkFilename = args->arg( 0 );
- QFileInfo checkFile(checkFilename);
- if (!checkFile.exists())
+ const QString checkFilename = args->arg( 0 );
+ CheckFileResult ckr = checkFile( checkFilename );
+ if ( ckr != CheckFileSuccess )
{
- kError() << "File '" << checkFilename << "' does not exist." << endl;
+ if ( ckr == CheckFileDoesNotExist ) kError() << "File '" << checkFilename << \
"' does not exist."; + else if ( ckr == CheckFileIsNotFile ) kError() << "'" \
<< checkFilename << "' is not a file."; + else if ( ckr == \
CheckFileIsNotReadable ) kError() << "File '" << checkFilename << "' is not \
readable."; return ( 2 );
}
- if (!checkFile.isFile())
- {
- kError() << "'" << checkFilename << "' is not a file." << endl;
- return ( 2 );
- }
- if (!checkFile.isReadable())
- {
- kError() << "File '" << checkFilename << "' is not readable." << endl;
- return ( 2 );
- }
if ( args->isSet( "check" ) ) {
- QString pwd_buffer = QDir::currentPath();
- QFileInfo file( args->arg( 0 ) );
QByteArray catalogs;
catalogs += KUrl::fromLocalFile( KStandardDirs::locate( "dtd", \
"customization/catalog.xml" ) ).toEncoded(); catalogs += ' ';
catalogs += KUrl::fromLocalFile( KStandardDirs::locate( "dtd", \
"docbook/xml-dtd-4.1.2/catalog.xml" ) ).toEncoded();
- setenv( "XML_CATALOG_FILES", catalogs.constData(), 1 );
QString exe;
#if defined( XMLLINT )
exe = XMLLINT;
@@ -157,31 +147,12 @@
if (exe.isEmpty())
exe = KStandardDirs::locate( "exe", "xmllint" );
}
- if ( QFileInfo( exe ).isExecutable() ) {
- QDir::setCurrent( file.absolutePath() );
- QString cmd = exe;
- cmd += " --valid --noout ";
-#ifdef Q_OS_WIN
- cmd += file.fileName();
-#else
- cmd += KShell::quoteArg(file.fileName());
-#endif
- cmd += " 2>&1";
- FILE *xmllint = popen( QFile::encodeName( cmd ).constData(), "r" );
- char buf[ 512 ];
- bool noout = true;
- unsigned int n;
- while ( ( n = fread(buf, 1, sizeof( buf ) - 1, xmllint ) ) ) {
- noout = false;
- buf[ n ] = '\0';
- fputs( buf, stderr );
- }
- pclose( xmllint );
- QDir::setCurrent( pwd_buffer );
- if ( !noout )
- return 1;
- } else {
- kWarning() << "couldn't find xmllint";
+
+ CheckResult cr = check( checkFilename, exe, catalogs );
+ if ( cr != CheckSuccess )
+ {
+ if ( cr == CheckNoXmllint ) kWarning() << "couldn't find xmllint";
+ return 1;
}
}
@@ -224,6 +195,10 @@
tss = "customization/htdig_index.xsl" ;
tss = KStandardDirs::locate( "dtd", tss );
+ const QString cache = args->getOption( "cache" );
+ const bool usingStdOut = args->isSet( "stdout" );
+ const bool usingOutput = args->isSet("output");
+ const QString outputOption = args->getOption( "output" );
if ( index ) {
xsltStylesheetPtr style_sheet =
@@ -231,7 +206,7 @@
if (style_sheet != NULL) {
- xmlDocPtr doc = xmlParseFile( QFile::encodeName( args->arg( 0 ) \
).constData() ); + xmlDocPtr doc = xmlParseFile( QFile::encodeName( \
checkFilename ).constData() );
xmlDocPtr res = xsltApplyStylesheet(style_sheet, doc, ¶ms[0]);
@@ -254,20 +229,19 @@
xmlFreeDoc(res);
} else {
- kDebug() << "couldn't parse document " << args->arg( 0 );
+ kDebug() << "couldn't parse document " << checkFilename;
}
} else {
kDebug() << "couldn't parse style sheet " << tss;
}
} else {
- QString output = transform(args->arg( 0 ) , tss, params);
+ QString output = transform(checkFilename , tss, params);
if (output.isEmpty()) {
- fprintf(stderr, "unable to parse %s\n", args->arg( 0 \
).toLocal8Bit().data()); + fprintf(stderr, "unable to parse %s\n", \
checkFilename.toLocal8Bit().data()); return(1);
}
- QString cache = args->getOption( "cache" );
if ( !cache.isEmpty() ) {
if ( !saveToCache( output, cache ) ) {
kError() << i18n( "Could not write to cache file %1." , cache ) << \
endl; @@ -275,49 +249,7 @@
goto end;
}
- if (output.indexOf( "<FILENAME " ) == -1 || args->isSet( "stdout" ) || \
args->isSet("output") )
- {
- QFile file;
- if (args->isSet( "stdout" ) ) {
- file.open( stdout, QIODevice::WriteOnly );
- } else {
- if (args->isSet( "output" ) )
- file.setFileName( args->getOption( "output" ));
- else
- file.setFileName( "index.html" );
- file.open(QIODevice::WriteOnly);
- }
- replaceCharsetHeader( output );
-#ifdef Q_WS_WIN
- QByteArray data = output.toUtf8();
-#else
- QByteArray data = output.toLocal8Bit();
-#endif
- file.write(data.data(), data.length());
- file.close();
- } else {
- int index = 0;
- while (true) {
- index = output.indexOf("<FILENAME ", index);
- if (index == -1)
- break;
- int filename_index = index + strlen("<FILENAME filename=\"");
-
- QString filename = output.mid(filename_index,
- output.indexOf("\"", filename_index) -
- filename_index);
-
- QString filedata = splitOut(output, index);
- QFile file(filename);
- file.open(QIODevice::WriteOnly);
- replaceCharsetHeader( filedata );
- QByteArray data = fromUnicode( filedata );
- file.write(data.data(), data.length());
- file.close();
-
- index += 8;
- }
- }
+ doOutput(output, usingStdOut, usingOutput, outputOption, true /* \
replaceCharset */); }
end:
xmlCleanupParser();
--- trunk/KDE/kdelibs/kdoctools/xslt.cpp #1105362:1105363
@@ -298,132 +298,6 @@
return filedata;
}
-void fillInstance(KComponentData &ins, const QString &srcdir)
-{
- QByteArray catalogs;
-
- if ( srcdir.isEmpty() ) {
- catalogs += KUrl::fromLocalFile( ins.dirs()->findResource("data", \
"ksgmltools2/customization/catalog.xml") ).toEncoded();
- catalogs += ' ';
- catalogs += KUrl::fromLocalFile( ins.dirs()->findResource("data", \
"ksgmltools2/docbook/xml-dtd-4.2/catalog.xml") ).toEncoded();
- ins.dirs()->addResourceType("dtd", "data", "ksgmltools2/");
- } else {
- catalogs += KUrl::fromLocalFile( srcdir +"/customization/catalog.xml" \
).toEncoded();
- catalogs += ' ';
- catalogs += KUrl::fromLocalFile( srcdir + "/docbook/xml-dtd-4.2/catalog.xml" \
).toEncoded();
- ins.dirs()->addResourceDir("dtd", srcdir);
- }
-
- setenv( "XML_CATALOG_FILES", catalogs.constData(), 1 );
- xmlInitializeCatalog();
-}
-
-static QIODevice *getBZip2device(const QString &fileName )
-{
- return KFilterDev::deviceForFile(fileName);
-}
-
-bool saveToCache( const QString &contents, const QString &filename )
-{
- QIODevice *fd = ::getBZip2device(filename);
- if ( !fd )
- return false;
-
- if (!fd->open(QIODevice::WriteOnly))
- {
- delete fd;
- return false;
- }
-
- fd->write( contents.toUtf8() );
- fd->close();
- delete fd;
- return true;
-}
-
-static bool readCache( const QString &filename,
- const QString &cache, QString &output)
-{
- kDebug( 7119 ) << filename << " " << cache;
- KGlobal::dirs()->addResourceType("dtd", "data", "ksgmltools2/");
- if ( !compareTimeStamps( filename, cache ) )
- return false;
- if ( !compareTimeStamps( KStandardDirs::locate( "dtd", \
"customization/kde-chunk.xsl"), cache ) )
- return false;
-
- kDebug( 7119 ) << "create filter";
- QIODevice *fd = ::getBZip2device(cache);
- if ( !fd )
- return false;
-
- if (!fd->open(QIODevice::ReadOnly))
- {
- delete fd;
- QFile::remove(cache);
- return false;
- }
-
- kDebug( 7119 ) << "reading";
-
- char buffer[32000];
- int n;
- QByteArray text;
- // Also end loop in case of error, when -1 is returned
- while ( ( n = fd->read(buffer, 31900) ) > 0)
- {
- buffer[n] = 0;
- text += buffer;
- }
- kDebug( 7119 ) << "read " << text.length();
- fd->close();
-
- output = QString::fromUtf8( text );
- delete fd;
-
- if (n == -1)
- return false;
-
- kDebug( 7119 ) << "finished ";
-
- return true;
-}
-
-QString lookForCache( const QString &filename )
-{
- kDebug() << "lookForCache " << filename;
- assert( filename.endsWith( QLatin1String(".docbook") ) );
- assert( QDir::isAbsolutePath(filename));
- QString cache = filename.left( filename.length() - 7 );
- QString output;
- if ( readCache( filename, cache + "cache.bz2", output) )
- return output;
-#ifdef Q_WS_WIN
- QFileInfo fi(filename);
- // make sure filenames do not contain the base path, otherwise
- // accessing user data from another location invalids cached files.
- // Accessing user data under a different path is possible
- // when using usb sticks - this may affect unix/mac systems also
- cache = '/' + fi.absolutePath().remove(KStandardDirs::installPath("html"),Qt::CaseInsensitive).replace('/','_') \
+ '_' + fi.baseName() + '.';
-#endif
- if ( readCache( filename,
- KStandardDirs::locateLocal( "cache",
- "kio_help" + cache +
- "cache.bz2" ), output ) )
- return output;
-
- return QString();
-}
-
-bool compareTimeStamps( const QString &older, const QString &newer )
-{
- QFileInfo _older( older );
- QFileInfo _newer( newer );
- assert( _older.exists() );
- if ( !_newer.exists() )
- return false;
- return ( _newer.lastModified() > _older.lastModified() );
-}
-
QByteArray fromUnicode( const QString &data )
{
#ifdef Q_WS_WIN
--- trunk/KDE/kdelibs/kdoctools/xslt.h #1105362:1105363
@@ -6,6 +6,7 @@
#include <QtCore/QVector>
class QByteArray;
+class QIODevice;
class KComponentData;
QString transform(const QString &file, const QString& stylesheet,
@@ -13,16 +14,11 @@
QString splitOut(const QString &parsed, int index);
void fillInstance(KComponentData &ins, const QString &srcdir = QString() );
bool saveToCache( const QString &contents, const QString &filename );
-QString lookForCache( const QString &filename );
QByteArray fromUnicode( const QString &data );
void replaceCharsetHeader( QString &output );
+QIODevice *getBZip2device(const QString &fileName );
extern bool warnings_exist;
extern QString *SRCDIR;
-/**
- * Compares two files and returns true if @param newer exists and is newer than
- * @param older
- **/
-bool compareTimeStamps( const QString &older, const QString &newer );
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic