Skip to content

Commit

Permalink
Make doxywizard compatible with Qt5
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri van Heesch committed Jul 14, 2015
1 parent c33e03f commit 333c7c4
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 186 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -23,6 +23,7 @@ option(use_sqlite3 "Add support for sqlite3 output [experimental]." OFF)
option(use_libclang "Add support for libclang parsing." OFF)
option(win_static "Link with /MT in stead of /MD on windows" OFF)
option(english_only "Only compile in support for the English language" OFF)
option(force_qt4 "Forces doxywizard to build using Qt4 even if Qt5 is installed" OFF)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(SOURCE "${CMAKE_SOURCE_DIR}")
Expand Down
46 changes: 41 additions & 5 deletions addon/doxywizard/CMakeLists.txt
@@ -1,5 +1,40 @@
if (build_wizard)

# search for Qt5
if (NOT force_qt4)
find_package(Qt5Core QUIET)
if (Qt5Core_FOUND)
message(STATUS "Using Qt5")
find_package(Qt5 COMPONENTS Widgets Gui Xml)
macro(qt_use_modules)
qt5_use_modules(${ARGN})
endmacro()
macro(qt_wrap_cpp)
qt5_wrap_cpp(${ARGN})
endmacro()
macro(qt_add_resources)
qt5_add_resources(${ARGN})
endmacro()
endif()
endif()
# fallback to Qt4
if (NOT Qt5Core_FOUND)
if (NOT force_qt4)
message(STATUS "Qt5 not found, searching for Qt4 instead...")
else()
message(STATUS "Using Qt4")
endif()
find_package(Qt4 REQUIRED COMPONENTS QtCore QtXml QtGui)
macro(qt_use_modules)
endmacro()
macro(qt_wrap_cpp)
qt4_wrap_cpp(${ARGN})
endmacro()
macro(qt_add_resources)
qt4_add_resources(${ARGN})
endmacro()
endif()

include_directories(
.
${CMAKE_SOURCE_DIR}/src
Expand All @@ -11,9 +46,9 @@ set(GENERATED_SRC_WIZARD ${GENERATED_SRC}/doxywizard)
file(MAKE_DIRECTORY ${GENERATED_SRC_WIZARD})

add_definitions(-DQT_ARCH_X86_64 -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DUNICODE)
set(QT_USE_QTXML TRUE)
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
if (NOT Qt5Core_FOUND)
include(${QT_USE_FILE})
endif()

# generate settings.h
file(GENERATE OUTPUT ${GENERATED_SRC_WIZARD}/settings.h
Expand Down Expand Up @@ -43,7 +78,7 @@ set_source_files_properties(${GENERATED_SRC_WIZARD}/configdoc.cpp PROPERTIES GEN

FLEX_TARGET(config_doxyw config_doxyw.l ${GENERATED_SRC_WIZARD}/config_doxyw.cpp COMPILE_FLAGS "-Pconfig_doxywYY")

QT4_WRAP_CPP(doxywizard_MOC
qt_wrap_cpp(doxywizard_MOC
doxywizard.h
expert.h
helplabel.h
Expand All @@ -54,7 +89,7 @@ inputstrlist.h
wizard.h
)

QT4_ADD_RESOURCES(doxywizard_RESOURCES_RCC doxywizard.qrc)
qt_add_resources(doxywizard_RESOURCES_RCC doxywizard.qrc)

add_executable(doxywizard WIN32
doxywizard.cpp
Expand All @@ -71,6 +106,7 @@ ${GENERATED_SRC_WIZARD}/configdoc.cpp
${doxywizard_MOC}
${doxywizard_RESOURCES_RCC}
)
qt_use_modules(doxywizard Core Gui Widgets Xml)
target_link_libraries(doxywizard
${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY}
)
Expand Down
71 changes: 40 additions & 31 deletions addon/doxywizard/config_doxyw.l
Expand Up @@ -20,7 +20,16 @@
*/
#include "config.h"
#include "input.h"
#include <QtCore>

#include <QString>
#include <QVariant>
#include <QStack>
#include <QTextCodec>
#include <QByteArray>
#include <QFileInfo>
#include <QStringList>
#include <QRegExp>
#include <QTextStream>

#define YY_NO_UNISTD_H 1

Expand Down Expand Up @@ -52,7 +61,7 @@ static QVariant *g_arg;
static Input *g_curOption=0;
static QString g_elemStr;
static QTextCodec *g_codec = QTextCodec::codecForName("UTF-8");
static QString g_codecName = QString::fromAscii("UTF-8");
static QString g_codecName = QString::fromLatin1("UTF-8");
static int g_lastState;
static QByteArray g_tmpString;

Expand All @@ -74,13 +83,13 @@ static int yyread(char *buf,int maxSize)
}
}

static QString warning_str = QString::fromAscii("warning: ");
static QString error_str = QString::fromAscii("error: ");
static QString warning_str = QString::fromLatin1("warning: ");
static QString error_str = QString::fromLatin1("error: ");

void config_err(const char *fmt, ...)
{
QString msg = error_str;
msg.append(QString::fromAscii(fmt));
msg.append(QString::fromLatin1(fmt));
va_list args;
va_start(args, fmt);
vfprintf(stderr, qPrintable(msg), args);
Expand All @@ -89,7 +98,7 @@ void config_err(const char *fmt, ...)
void config_warn(const char *fmt, ...)
{
QString msg = warning_str;
msg.append(QString::fromAscii(fmt));
msg.append(QString::fromLatin1(fmt));
va_list args;
va_start(args, fmt);
vfprintf(stderr, qPrintable(msg), args);
Expand All @@ -101,10 +110,10 @@ static void substEnvVarsInString(QString &s);

static void checkEncoding()
{
Input *option = g_options->value(QString::fromAscii("DOXYFILE_ENCODING"));
Input *option = g_options->value(QString::fromLatin1("DOXYFILE_ENCODING"));
if (option && option->value().toString()!=g_codecName)
{
QTextCodec *newCodec = QTextCodec::codecForName(option->value().toString().toAscii());
QTextCodec *newCodec = QTextCodec::codecForName(option->value().toString().toLatin1());
if (newCodec)
{
g_codec = newCodec;
Expand All @@ -115,7 +124,7 @@ static void checkEncoding()

static FILE *tryPath(const QString &path,const QString &fileName)
{
QString absName=!path.isEmpty() ? path+QString::fromAscii("/")+fileName : fileName;
QString absName=!path.isEmpty() ? path+QString::fromLatin1("/")+fileName : fileName;
QFileInfo fi(absName);
if (fi.exists() && fi.isFile())
{
Expand Down Expand Up @@ -144,7 +153,7 @@ static FILE *findFile(const QString &fileName)
if (f) return f;
}
// try cwd if g_includePathList fails
return tryPath(QString::fromAscii("."),fileName);
return tryPath(QString::fromLatin1("."),fileName);
}

static void readIncludeFile(const QString &incName)
Expand All @@ -160,8 +169,8 @@ static void readIncludeFile(const QString &incName)
substEnvVarsInString(inc);
inc = inc.trimmed();
uint incLen = inc.length();
if (inc.at(0)==QChar::fromAscii('"') &&
inc.at(incLen-1)==QChar::fromAscii('"')) // strip quotes
if (inc.at(0)==QChar::fromLatin1('"') &&
inc.at(incLen-1)==QChar::fromLatin1('"')) // strip quotes
{
inc=inc.mid(1,incLen-2);
}
Expand Down Expand Up @@ -383,7 +392,7 @@ static void readIncludeFile(const QString &incName)

static void substEnvVarsInString(QString &s)
{
static QRegExp re(QString::fromAscii("\\$\\([a-z_A-Z0-9]+\\)"));
static QRegExp re(QString::fromLatin1("\\$\\([a-z_A-Z0-9]+\\)"));
if (s.isEmpty()) return;
int p=0;
int i,l;
Expand All @@ -409,8 +418,8 @@ static void substEnvVarsInStrList(QStringList &sl)
foreach (QString result, sl)
{
// an argument with quotes will have an extra space at the end, so wasQuoted will be TRUE.
bool wasQuoted = (result.indexOf(QChar::fromAscii(' '))!=-1) ||
(result.indexOf(QChar::fromAscii('\t'))!=-1);
bool wasQuoted = (result.indexOf(QChar::fromLatin1(' '))!=-1) ||
(result.indexOf(QChar::fromLatin1('\t'))!=-1);
// here we strip the quote again
substEnvVarsInString(result);

Expand All @@ -430,33 +439,33 @@ static void substEnvVarsInStrList(QStringList &sl)
{
QChar c=0;
// skip until start of new word
while (i<l && ((c=result.at(i))==QChar::fromAscii(' ') || c==QChar::fromAscii('\t'))) i++;
while (i<l && ((c=result.at(i))==QChar::fromLatin1(' ') || c==QChar::fromLatin1('\t'))) i++;
p=i; // p marks the start index of the word
// skip until end of a word
while (i<l && ((c=result.at(i))!=QChar::fromAscii(' ') &&
c!=QChar::fromAscii('\t') &&
c!=QChar::fromAscii('"'))) i++;
while (i<l && ((c=result.at(i))!=QChar::fromLatin1(' ') &&
c!=QChar::fromLatin1('\t') &&
c!=QChar::fromLatin1('"'))) i++;
if (i<l) // not at the end of the string
{
if (c==QChar::fromAscii('"')) // word within quotes
if (c==QChar::fromLatin1('"')) // word within quotes
{
p=i+1;
for (i++;i<l;i++)
{
c=result.at(i);
if (c==QChar::fromAscii('"')) // end quote
if (c==QChar::fromLatin1('"')) // end quote
{
out += result.mid(p,i-p);
p=i+1;
break;
}
else if (c==QChar::fromAscii('\\')) // skip escaped stuff
else if (c==QChar::fromLatin1('\\')) // skip escaped stuff
{
i++;
}
}
}
else if (c==QChar::fromAscii(' ') || c==QChar::fromAscii('\t')) // separator
else if (c==QChar::fromLatin1(' ') || c==QChar::fromLatin1('\t')) // separator
{
out += result.mid(p,i-p);
p=i+1;
Expand Down Expand Up @@ -529,7 +538,7 @@ bool parseConfig(
void writeStringValue(QTextStream &t,QTextCodec *codec,const QString &s)
{
QChar c;
bool needsEscaping=FALSE;
bool needsEscaping=false;
// convert the string back to it original encoding
//QByteArray se = codec->fromUnicode(s);
t.setCodec(codec);
Expand All @@ -538,20 +547,20 @@ void writeStringValue(QTextStream &t,QTextCodec *codec,const QString &s)
{
while (!(c=*p++).isNull() && !needsEscaping)
{
needsEscaping = (c==QChar::fromAscii(' ') ||
c==QChar::fromAscii('\n') ||
c==QChar::fromAscii('\t') ||
c==QChar::fromAscii('"'));
needsEscaping = (c==QChar::fromLatin1(' ') ||
c==QChar::fromLatin1('\n') ||
c==QChar::fromLatin1('\t') ||
c==QChar::fromLatin1('"'));
}
if (needsEscaping)
{
t << "\"";
p=s.data();
while (!p->isNull())
{
if (*p ==QChar::fromAscii(' ') &&
*(p+1)==QChar::fromAscii('\0')) break; // skip inserted space at the end
if (*p ==QChar::fromAscii('"')) t << "\\"; // escape quotes
if (*p ==QChar::fromLatin1(' ') &&
*(p+1)==QChar::fromLatin1('\0')) break; // skip inserted space at the end
if (*p ==QChar::fromLatin1('"')) t << "\\"; // escape quotes
t << *p++;
}
t << "\"";
Expand Down

0 comments on commit 333c7c4

Please sign in to comment.