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

KDocTools

  • sources
  • kde-4.12
  • kdelibs
  • 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 
11 CheckFileResult 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 
29 CheckResult 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 
60 void 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 }
meinproc_common.h
replaceCharsetHeader
void replaceCharsetHeader(QString &output)
Definition: xslt.cpp:321
CheckFileSuccess
Definition: meinproc_common.h:10
CheckFileIsNotFile
Definition: meinproc_common.h:12
checkFile
CheckFileResult checkFile(const QString &checkFilename)
Definition: meinproc_common.cpp:11
CheckFileDoesNotExist
Definition: meinproc_common.h:11
doOutput
void doOutput(QString output, bool usingStdOut, bool usingOutput, const QString &outputOption, bool replaceCharset)
Definition: meinproc_common.cpp:60
QString
splitOut
QString splitOut(const QString &parsed, int index)
Definition: xslt.cpp:222
CheckFileResult
CheckFileResult
Definition: meinproc_common.h:8
xslt.h
fromUnicode
QByteArray fromUnicode(const QString &data)
Definition: xslt.cpp:271
CheckResult
CheckResult
Definition: meinproc_common.h:18
check
CheckResult check(const QString &checkFilename, const QString &exe, const QByteArray &catalogs)
Definition: meinproc_common.cpp:29
CheckFileIsNotReadable
Definition: meinproc_common.h:13
CheckSuccess
Definition: meinproc_common.h:20
CheckNoOut
Definition: meinproc_common.h:21
CheckNoXmllint
Definition: meinproc_common.h:22
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:03 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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