From f573b414b482a01e87869a277cdb913d173fc925 Mon Sep 17 00:00:00 2001 From: albert-github Date: Wed, 16 Dec 2020 11:02:47 +0100 Subject: Improvements of reading the configuration file - 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"). --- addon/doxywizard/CMakeLists.txt | 1 + addon/doxywizard/config_doxyw.l | 62 ++++-------------------------- addon/doxywizard/config_msg.cpp | 83 ++++++++++++++++++++++++++++++++++++++++ addon/doxywizard/config_msg.h | 10 +++++ addon/doxywizard/doxywizard.cpp | 7 ++++ addon/doxywizard/doxywizard.h | 1 + addon/doxywizard/inputbool.cpp | 9 ++++- addon/doxywizard/inputint.cpp | 25 +++++++++--- addon/doxywizard/inputstring.cpp | 3 ++ 9 files changed, 138 insertions(+), 63 deletions(-) create mode 100644 addon/doxywizard/config_msg.cpp create mode 100644 addon/doxywizard/config_msg.h diff --git a/addon/doxywizard/CMakeLists.txt b/addon/doxywizard/CMakeLists.txt index 1ee8ed5..a6f65f8 100644 --- a/addon/doxywizard/CMakeLists.txt +++ b/addon/doxywizard/CMakeLists.txt @@ -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 diff --git a/addon/doxywizard/config_doxyw.l b/addon/doxywizard/config_doxyw.l index 71d48c9..38d9f38 100644 --- a/addon/doxywizard/config_doxyw.l +++ b/addon/doxywizard/config_doxyw.l @@ -24,7 +24,7 @@ #include "config.h" #include "input.h" #include "inputstring.h" -#include "doxywizard.h" +#include "config_msg.h" #include #include @@ -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); @@ -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; @@ -230,7 +187,6 @@ static void readIncludeFile(const QString &incName) else { config_err("@INCLUDE = %s: not found!\n",qPrintable(inc)); - exit(1); } } @@ -495,9 +451,11 @@ static void readIncludeFile(const QString &incName) } \n { BEGIN(Start); } \\[ \r\t]*\n { BEGIN(Start); } +. { } <*>\\[ \r\t]*\n { } +<*>[ \r\t] { } <*>\n -<*>. +<*>. { config_warn("ignoring unknown character '%c' at line %d, file %s\n",yytext[0],yylineno,qPrintable(g_yyFileName)); } %% @@ -607,10 +565,7 @@ bool parseConfig( ) { yylineno = 1; - if (DoxygenWizard::debugFlag) - { - MainWindow::instance().outputLogStart(); - } + config_open(); QHashIterator i(options); g_file = fopen(fileName.toLocal8Bit(),"r"); if (g_file==NULL) return false; @@ -651,10 +606,7 @@ bool parseConfig( } } fclose(g_file); - if (DoxygenWizard::debugFlag) - { - MainWindow::instance().outputLogFinish(); - } + config_finish(); return true; } diff --git a/addon/doxywizard/config_msg.cpp b/addon/doxywizard/config_msg.cpp new file mode 100644 index 0000000..f30e677 --- /dev/null +++ b/addon/doxywizard/config_msg.cpp @@ -0,0 +1,83 @@ +#include +#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(); + } +} diff --git a/addon/doxywizard/config_msg.h b/addon/doxywizard/config_msg.h new file mode 100644 index 0000000..c8f1070 --- /dev/null +++ b/addon/doxywizard/config_msg.h @@ -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 diff --git a/addon/doxywizard/doxywizard.cpp b/addon/doxywizard/doxywizard.cpp index eff99d6..c75279b 100755 --- a/addon/doxywizard/doxywizard.cpp +++ b/addon/doxywizard/doxywizard.cpp @@ -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); } diff --git a/addon/doxywizard/doxywizard.h b/addon/doxywizard/doxywizard.h index ff587aa..ccbd9b0 100755 --- a/addon/doxywizard/doxywizard.h +++ b/addon/doxywizard/doxywizard.h @@ -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; }; diff --git a/addon/doxywizard/inputbool.cpp b/addon/doxywizard/inputbool.cpp index 92d2929..132658d 100644 --- a/addon/doxywizard/inputbool.cpp +++ b/addon/doxywizard/inputbool.cpp @@ -12,6 +12,7 @@ #include "inputbool.h" #include "helplabel.h" +#include "config_msg.h" #include #include @@ -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 ); diff --git a/addon/doxywizard/inputint.cpp b/addon/doxywizard/inputint.cpp index de01862..ce3fa02 100644 --- a/addon/doxywizard/inputint.cpp +++ b/addon/doxywizard/inputint.cpp @@ -12,6 +12,7 @@ #include "inputint.h" #include "helplabel.h" +#include "config_msg.h" #include #include @@ -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(); } @@ -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); } diff --git a/addon/doxywizard/inputstring.cpp b/addon/doxywizard/inputstring.cpp index 5324085..ac76342 100644 --- a/addon/doxywizard/inputstring.cpp +++ b/addon/doxywizard/inputstring.cpp @@ -13,6 +13,7 @@ #include "inputstring.h" #include "helplabel.h" #include "doxywizard.h" +#include "config_msg.h" #include "config.h" #include @@ -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; } -- cgit v0.12