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

KDocTools

  • kdoctools
meinproc_common.cpp
Go to the documentation of this file.
1
2#include "meinproc_common.h"
3
4#include "xslt.h"
5
6#include <QDir>
7#include <QFileInfo>
8
9#include <cstdlib>
10
11CheckFileResult checkFile( const QString &checkFilename )
12{
13 const QFileInfo checkFile(checkFilename);
14 if (!checkFile.exists())
15 {
16 return CheckFileDoesNotExist;
17 }
18 if (!checkFile.isFile())
19 {
20 return CheckFileIsNotFile;
21 }
22 if (!checkFile.isReadable())
23 {
24 return CheckFileIsNotReadable;
25 }
26 return CheckFileSuccess;
27}
28
29CheckResult check(const QString &checkFilename, const QString &exe, const QByteArray &catalogs)
30{
31 const QString pwd_buffer = QDir::currentPath();
32 const QFileInfo file( checkFilename );
33
34 setenv( "XML_CATALOG_FILES", catalogs.constData(), 1 );
35 if ( QFileInfo( exe ).isExecutable() ) {
36 QDir::setCurrent( file.absolutePath() );
37 QString cmd = exe;
38 cmd += " --valid --noout ";
39 cmd += file.fileName();
40 cmd += " 2>&1";
41 FILE *xmllint = popen( QFile::encodeName( cmd ).constData(), "r" );
42 char buf[ 512 ];
43 bool noout = true;
44 unsigned int n;
45 while ( ( n = fread(buf, 1, sizeof( buf ) - 1, xmllint ) ) ) {
46 noout = false;
47 buf[ n ] = '\0';
48 fputs( buf, stderr );
49 }
50 pclose( xmllint );
51 QDir::setCurrent( pwd_buffer );
52 if ( !noout )
53 return CheckNoOut;
54 } else {
55 return CheckNoXmllint;
56 }
57 return CheckSuccess;
58}
59
60void doOutput(QString output, bool usingStdOut, bool usingOutput, const QString &outputOption, bool replaceCharset)
61{
62 if (output.indexOf( "<FILENAME " ) == -1 || usingStdOut || usingOutput )
63 {
64 QFile file;
65 if ( usingStdOut ) {
66 file.open( stdout, QIODevice::WriteOnly );
67 } else {
68 if ( usingOutput )
69 file.setFileName( outputOption );
70 else
71 file.setFileName( "index.html" );
72 file.open(QIODevice::WriteOnly);
73 }
74 if (replaceCharset) replaceCharsetHeader( output );
75#ifdef Q_WS_WIN
76 QByteArray data = output.toUtf8();
77#else
78 QByteArray data = output.toLocal8Bit();
79#endif
80 file.write(data.data(), data.length());
81 file.close();
82 } else {
83 int index = 0;
84 while (true) {
85 index = output.indexOf("<FILENAME ", index);
86 if (index == -1)
87 break;
88 int filename_index = index + strlen("<FILENAME filename=\"");
89
90 const QString filename = output.mid(filename_index,
91 output.indexOf("\"", filename_index) -
92 filename_index);
93
94 QString filedata = splitOut(output, index);
95 QFile file(filename);
96 file.open(QIODevice::WriteOnly);
97 if (replaceCharset) replaceCharsetHeader( filedata );
98 const QByteArray data = fromUnicode( filedata );
99 file.write(data.data(), data.length());
100 file.close();
101
102 index += 8;
103 }
104 }
105}
output
void output(QList< Action > actions, QHash< QString, QString > domain)
isExecutable
bool isExecutable(const QString &file)
doOutput
void doOutput(QString output, bool usingStdOut, bool usingOutput, const QString &outputOption, bool replaceCharset)
Definition: meinproc_common.cpp:60
checkFile
CheckFileResult checkFile(const QString &checkFilename)
Definition: meinproc_common.cpp:11
check
CheckResult check(const QString &checkFilename, const QString &exe, const QByteArray &catalogs)
Definition: meinproc_common.cpp:29
meinproc_common.h
CheckFileResult
CheckFileResult
Definition: meinproc_common.h:9
CheckFileDoesNotExist
@ CheckFileDoesNotExist
Definition: meinproc_common.h:11
CheckFileIsNotReadable
@ CheckFileIsNotReadable
Definition: meinproc_common.h:13
CheckFileIsNotFile
@ CheckFileIsNotFile
Definition: meinproc_common.h:12
CheckFileSuccess
@ CheckFileSuccess
Definition: meinproc_common.h:10
CheckResult
CheckResult
Definition: meinproc_common.h:19
CheckNoXmllint
@ CheckNoXmllint
Definition: meinproc_common.h:22
CheckNoOut
@ CheckNoOut
Definition: meinproc_common.h:21
CheckSuccess
@ CheckSuccess
Definition: meinproc_common.h:20
replaceCharsetHeader
void replaceCharsetHeader(QString &output)
Definition: xslt.cpp:340
splitOut
QString splitOut(const QString &parsed, int index)
Definition: xslt.cpp:241
fromUnicode
QByteArray fromUnicode(const QString &data)
Definition: xslt.cpp:290
xslt.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDocTools

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal