• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDocTools

meinproc_common.cpp

Go to the documentation of this file.
00001 
00002 #include "meinproc_common.h"
00003 
00004 #include "xslt.h"
00005 
00006 #include <QDir>
00007 #include <QFileInfo>
00008 
00009 #include <cstdlib>
00010 
00011 CheckFileResult checkFile( const QString &checkFilename )
00012 {
00013     const QFileInfo checkFile(checkFilename);
00014     if (!checkFile.exists())
00015     {
00016         return CheckFileDoesNotExist;
00017     }
00018     if (!checkFile.isFile())
00019     {
00020         return CheckFileIsNotFile;
00021     }
00022     if (!checkFile.isReadable())
00023     {
00024         return CheckFileIsNotReadable;
00025     }
00026     return CheckFileSuccess;
00027 }
00028 
00029 CheckResult check(const QString &checkFilename, const QString &exe, const QByteArray &catalogs)
00030 {
00031     const QString pwd_buffer = QDir::currentPath();
00032     const QFileInfo file( checkFilename );
00033 
00034     setenv( "XML_CATALOG_FILES", catalogs.constData(), 1 );
00035     if ( QFileInfo( exe ).isExecutable() ) {
00036         QDir::setCurrent( file.absolutePath() );
00037         QString cmd = exe;
00038         cmd += " --valid --noout ";
00039         cmd += file.fileName();
00040         cmd += " 2>&1";
00041         FILE *xmllint = popen( QFile::encodeName( cmd ).constData(), "r" );
00042         char buf[ 512 ];
00043         bool noout = true;
00044         unsigned int n;
00045         while ( ( n = fread(buf, 1, sizeof( buf ) - 1, xmllint ) ) ) {
00046             noout = false;
00047             buf[ n ] = '\0';
00048             fputs( buf, stderr );
00049         }
00050         pclose( xmllint );
00051         QDir::setCurrent( pwd_buffer );
00052         if ( !noout )
00053             return CheckNoOut;
00054     } else {
00055         return CheckNoXmllint;
00056     }
00057     return CheckSuccess;
00058 }
00059 
00060 void doOutput(QString output, bool usingStdOut, bool usingOutput, const QString &outputOption, bool replaceCharset)
00061 {
00062     if (output.indexOf( "<FILENAME " ) == -1 || usingStdOut || usingOutput )
00063     {
00064         QFile file;
00065         if ( usingStdOut ) {
00066             file.open( stdout, QIODevice::WriteOnly );
00067         } else {
00068             if ( usingOutput )
00069                 file.setFileName( outputOption );
00070             else
00071                 file.setFileName( "index.html" );
00072             file.open(QIODevice::WriteOnly);
00073         }
00074         if (replaceCharset) replaceCharsetHeader( output );
00075 #ifdef Q_WS_WIN
00076         QByteArray data = output.toUtf8();
00077 #else
00078         QByteArray data = output.toLocal8Bit();
00079 #endif
00080         file.write(data.data(), data.length());
00081         file.close();
00082     } else {
00083         int index = 0;
00084         while (true) {
00085             index = output.indexOf("<FILENAME ", index);
00086             if (index == -1)
00087                 break;
00088             int filename_index = index + strlen("<FILENAME filename=\"");
00089 
00090             const QString filename = output.mid(filename_index,
00091                                             output.indexOf("\"", filename_index) -
00092                                             filename_index);
00093 
00094             QString filedata = splitOut(output, index);
00095             QFile file(filename);
00096             file.open(QIODevice::WriteOnly);
00097             if (replaceCharset) replaceCharsetHeader( filedata );
00098             const QByteArray data = fromUnicode( filedata );
00099             file.write(data.data(), data.length());
00100             file.close();
00101 
00102             index += 8;
00103         }
00104     }
00105 }

KDocTools

Skip menu "KDocTools"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal