Skip to content

Commit

Permalink
Improvements of reading the configuration file
Browse files Browse the repository at this point in the history
- making the parsing of the configuration consistent with the reading of the configuration file a doxygen run
- adding a number of warnings in case of problems in the configuration file
- making the configuration warnings better visible (popping up the "Output log Window").
  • Loading branch information
albert-github committed Dec 16, 2020
1 parent 7b2e841 commit f573b41
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 63 deletions.
1 change: 1 addition & 0 deletions addon/doxywizard/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ wizard.h
qt_add_resources(doxywizard_RESOURCES_RCC doxywizard.qrc)

add_executable(doxywizard WIN32
config_msg.cpp
doxywizard.cpp
expert.cpp
wizard.cpp
Expand Down
62 changes: 7 additions & 55 deletions addon/doxywizard/config_doxyw.l
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "config.h"
#include "input.h"
#include "inputstring.h"
#include "doxywizard.h"
#include "config_msg.h"

#include <QString>
#include <QVariant>
Expand Down Expand Up @@ -93,48 +93,6 @@ static yy_size_t yyread(char *buf,yy_size_t maxSize)
}
}

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::fromLatin1(fmt));
va_list args;
va_start(args, fmt);
if (DoxygenWizard::debugFlag)
{
char debugOut[1000]; // this size should be sufficient
vsnprintf(debugOut, 1000,qPrintable(msg), args);
MainWindow::instance().outputLogText(QString::fromLatin1(debugOut));
}
else
{
vfprintf(stderr, qPrintable(msg), args);
}
va_end(args);
}
void config_warn(const char *fmt, ...)
{
QString msg = warning_str;

msg.append(QString::fromLatin1(fmt));
va_list args;
va_start(args, fmt);
if (DoxygenWizard::debugFlag)
{
char debugOut[1000];
vsnprintf(debugOut, 1000,qPrintable(msg), args);
MainWindow::instance().outputLogText(QString::fromLatin1(debugOut));
}
else
{
vfprintf(stderr, qPrintable(msg), args);
}
va_end(args);
}

static void substEnvVarsInStrList(QStringList &sl);
static void substEnvVarsInString(QString &s);

Expand Down Expand Up @@ -190,9 +148,8 @@ static void readIncludeFile(const QString &incName)
{
if (g_includeDepth==MAX_INCLUDE_DEPTH)
{
config_err("maximum include depth (%d) reached, %s is not included. Aborting...\n",
config_err("maximum include depth (%d) reached, %s is not included.",
MAX_INCLUDE_DEPTH,qPrintable(incName));
exit(1);
}

QString inc = incName;
Expand Down Expand Up @@ -230,7 +187,6 @@ static void readIncludeFile(const QString &incName)
else
{
config_err("@INCLUDE = %s: not found!\n",qPrintable(inc));
exit(1);
}
}

Expand Down Expand Up @@ -495,9 +451,11 @@ static void readIncludeFile(const QString &incName)
}
<SkipComment>\n { BEGIN(Start); }
<SkipComment>\\[ \r\t]*\n { BEGIN(Start); }
<SkipComment,SkipInvalid>. { }
<*>\\[ \r\t]*\n { }
<*>[ \r\t] { }
<*>\n
<*>.
<*>. { config_warn("ignoring unknown character '%c' at line %d, file %s\n",yytext[0],yylineno,qPrintable(g_yyFileName)); }

%%

Expand Down Expand Up @@ -607,10 +565,7 @@ bool parseConfig(
)
{
yylineno = 1;
if (DoxygenWizard::debugFlag)
{
MainWindow::instance().outputLogStart();
}
config_open();
QHashIterator<QString, Input*> i(options);
g_file = fopen(fileName.toLocal8Bit(),"r");
if (g_file==NULL) return false;
Expand Down Expand Up @@ -651,10 +606,7 @@ bool parseConfig(
}
}
fclose(g_file);
if (DoxygenWizard::debugFlag)
{
MainWindow::instance().outputLogFinish();
}
config_finish();
return true;
}

Expand Down
83 changes: 83 additions & 0 deletions addon/doxywizard/config_msg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <QString>
#include "config_msg.h"
#include "doxywizard.h"

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::fromLatin1(fmt));
va_list args;
va_start(args, fmt);
if (DoxygenWizard::debugFlag)
{
char debugOut[1000]; // this size should be sufficient
vsnprintf(debugOut, 1000,qPrintable(msg), args);
MainWindow::instance().outputLogText(QString::fromLatin1(debugOut));
}
else
{
vfprintf(stderr, qPrintable(msg), args);
}
va_end(args);
}

void config_term(const char *fmt, ...)
{
QString msg = error_str;

msg.append(QString::fromLatin1(fmt));
va_list args;
va_start(args, fmt);
if (DoxygenWizard::debugFlag)
{
char debugOut[1000]; // this size should be sufficient
vsnprintf(debugOut, 1000,qPrintable(msg), args);
MainWindow::instance().outputLogText(QString::fromLatin1(debugOut));
}
else
{
vfprintf(stderr, qPrintable(msg), args);
}
va_end(args);
exit(1);
}

void config_warn(const char *fmt, ...)
{
QString msg = warning_str;

msg.append(QString::fromLatin1(fmt));
va_list args;
va_start(args, fmt);
if (DoxygenWizard::debugFlag)
{
char debugOut[1000];
vsnprintf(debugOut, 1000,qPrintable(msg), args);
MainWindow::instance().outputLogText(QString::fromLatin1(debugOut));
}
else
{
vfprintf(stderr, qPrintable(msg), args);
}
va_end(args);
}

void config_open()
{
if (DoxygenWizard::debugFlag)
{
MainWindow::instance().outputLogStart();
}
}

void config_finish()
{
if (DoxygenWizard::debugFlag)
{
MainWindow::instance().outputLogFinish();
}
}
10 changes: 10 additions & 0 deletions addon/doxywizard/config_msg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef DOXYW_MSG_H
#define DOXYW_MSG_H

void config_err(const char *fmt, ...);
void config_term(const char *fmt, ...);
void config_warn(const char *fmt, ...);
void config_open();
void config_finish();

#endif
7 changes: 7 additions & 0 deletions addon/doxywizard/doxywizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,14 +753,21 @@ bool MainWindow::discardUnsavedChanges(bool saveOption)

void MainWindow::outputLogStart()
{
m_outputLogTextCount = 0;
m_outputLog->clear();
}
void MainWindow::outputLogText(QString text)
{
m_outputLogTextCount++;
m_outputLog->append(APPQT(text));
}
void MainWindow::outputLogFinish()
{
if (m_outputLogTextCount > 0)
{
selectRunTab();
}

m_outputLog->ensureCursorVisible();
m_saveLog->setEnabled(true);
}
Expand Down
1 change: 1 addition & 0 deletions addon/doxywizard/doxywizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class MainWindow : public QMainWindow
QProcess *m_runProcess;
QTimer *m_timer;
QTabWidget *m_tabs;
int m_outputLogTextCount = 0;
bool m_running;
bool m_modified;
};
Expand Down
9 changes: 7 additions & 2 deletions addon/doxywizard/inputbool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "inputbool.h"
#include "helplabel.h"
#include "config_msg.h"

#include <QCheckBox>
#include <QTextStream>
Expand Down Expand Up @@ -91,16 +92,20 @@ QVariant &InputBool::value()
void InputBool::update()
{
QString v = m_value.toString().toLower();
if (v==QString::fromLatin1("yes") || v==QString::fromLatin1("true") || v==QString::fromLatin1("1"))
if (v==QString::fromLatin1("yes") || v==QString::fromLatin1("true") ||
v==QString::fromLatin1("1") || v==QString::fromLatin1("all"))
{
m_state = true;
}
else if (v==QString::fromLatin1("no") || v==QString::fromLatin1("false") || v==QString::fromLatin1("0"))
else if (v==QString::fromLatin1("no") || v==QString::fromLatin1("false") ||
v==QString::fromLatin1("0") || v==QString::fromLatin1("none"))
{
m_state = false;
}
else
{
config_warn("argument '%s' for option %s is not a valid boolean value."
" Using the default: %s!",qPrintable(m_value.toString()),qPrintable(m_id),m_default?"YES":"NO");
m_state = m_default;
}
m_cb->setChecked( m_state );
Expand Down
25 changes: 19 additions & 6 deletions addon/doxywizard/inputint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "inputint.h"
#include "helplabel.h"
#include "config_msg.h"

#include <QSpinBox>
#include <QGridLayout>
Expand Down Expand Up @@ -59,12 +60,19 @@ void InputInt::help()

void InputInt::setValue(int val)
{
val = qMax(m_minVal,val);
val = qMin(m_maxVal,val);
if (val!=m_val)
int newVal = val;
newVal = qMax(m_minVal,newVal);
newVal = qMin(m_maxVal,newVal);
if (val != newVal)
{
m_val = val;
m_sp->setValue(val);
config_warn("argument '%d' for option %s is not a valid number in the range [%d..%d]!"
" Using the default: %d!\n",val,qPrintable(m_id),m_minVal,m_maxVal,m_default);
newVal = m_default;
}
if (newVal!=m_val)
{
m_val = newVal;
m_sp->setValue(newVal);
m_value = m_val;
updateDefault();
}
Expand Down Expand Up @@ -101,7 +109,12 @@ void InputInt::update()
{
bool ok;
int newVal = m_value.toInt(&ok);
if (!ok) newVal = m_default;
if (!ok)
{
config_warn("argument '%s' for option %s is not a valid number in the range [%d..%d]!"
" Using the default: %d!\n",qPrintable(m_value.toString()),qPrintable(m_id),m_minVal,m_maxVal,m_default);
newVal = m_default;
}
setValue(newVal);
}

Expand Down
3 changes: 3 additions & 0 deletions addon/doxywizard/inputstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "inputstring.h"
#include "helplabel.h"
#include "doxywizard.h"
#include "config_msg.h"
#include "config.h"

#include <QComboBox>
Expand Down Expand Up @@ -268,5 +269,7 @@ QString InputString::checkEnumVal(const QString &value)
if (enumVal.toLower() == val) return enumVal;
}

config_warn("argument '%s' for option %s is not a valid enum value."
" Using the default: %s!",qPrintable(value),qPrintable(m_id),qPrintable(m_default));
return m_default;
}

0 comments on commit f573b41

Please sign in to comment.