diff --git a/gui/main.cpp b/gui/main.cpp index 45b8fd255..0c22730c4 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -31,8 +31,6 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); - - MainWindow window; window.show(); return app.exec(); diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 8af59f1a6..557a2c34c 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -91,7 +91,13 @@ MainWindow::MainWindow() : - + QStringList args = QCoreApplication::arguments(); + //Remove the application itself + args.removeFirst(); + if (!args.isEmpty()) + { + DoCheckFiles(args); + } } MainWindow::~MainWindow() @@ -185,7 +191,53 @@ void MainWindow::SaveSettings() mUI.mResults->SaveSettings(); } -void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) +void MainWindow::DoCheckFiles(const QStringList &files) +{ + if (files.isEmpty()) + { + return; + } + ClearResults(); + + QStringList fileNames; + QString selection; + + foreach(selection, files) + { + fileNames << RemoveUnacceptedFiles(GetFilesRecursively(selection)); + } + + mUI.mResults->Clear(); + mThread->ClearFiles(); + + if (fileNames.isEmpty()) + { + QMessageBox msg(QMessageBox::Warning, + tr("Cppcheck"), + tr("No suitable files found to check!"), + QMessageBox::Ok, + this); + msg.exec(); + return; + } + + mUI.mResults->CheckingStarted(); + + mThread->SetFiles(RemoveUnacceptedFiles(fileNames)); + QFileInfo inf(fileNames[0]); + QString absDirectory = inf.absoluteDir().path(); + mSettings->setValue(SETTINGS_CHECK_PATH, absDirectory); + EnableCheckButtons(false); + mUI.mActionSettings->setEnabled(false); + + mUI.mResults->SetCheckDirectory(absDirectory); + + Settings checkSettings = GetCppcheckSettings(); + mThread->Check(checkSettings, false); +} + + +QStringList MainWindow::SelectFilesToCheck(QFileDialog::FileMode mode) { QStringList selected; @@ -214,56 +266,17 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) } } - if (selected.count() > 0) - { - ClearResults(); - - QStringList fileNames; - QString selection; - - foreach(selection, selected) - { - fileNames << RemoveUnacceptedFiles(GetFilesRecursively(selection)); - } - - mUI.mResults->Clear(); - mThread->ClearFiles(); - - if (fileNames.isEmpty()) - { - QMessageBox msg(QMessageBox::Warning, - tr("Cppcheck"), - tr("No suitable files found to check!"), - QMessageBox::Ok, - this); - msg.exec(); - return; - } - - mUI.mResults->CheckingStarted(); - - mThread->SetFiles(RemoveUnacceptedFiles(fileNames)); - QFileInfo inf(fileNames[0]); - QString absDirectory = inf.absoluteDir().path(); - mSettings->setValue(SETTINGS_CHECK_PATH, absDirectory); - EnableCheckButtons(false); - mUI.mActionSettings->setEnabled(false); - - mUI.mResults->SetCheckDirectory(absDirectory); - - Settings checkSettings = GetCppcheckSettings(); - mThread->Check(checkSettings, false); - } + return selected; } void MainWindow::CheckFiles() { - DoCheckFiles(QFileDialog::ExistingFiles); + DoCheckFiles(SelectFilesToCheck(QFileDialog::ExistingFiles)); } void MainWindow::CheckDirectory() { - DoCheckFiles(QFileDialog::DirectoryOnly); + DoCheckFiles(SelectFilesToCheck(QFileDialog::DirectoryOnly)); } Settings MainWindow::GetCppcheckSettings() diff --git a/gui/mainwindow.h b/gui/mainwindow.h index b073dd184..bb75bb1f2 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -205,8 +205,16 @@ protected: * directory to check. Use native dialogs instead of QT:s own dialogs. * * @param mode Dialog open mode (files or directories) + * @return QStringList of files or directories that were selected to check */ - void DoCheckFiles(QFileDialog::FileMode mode); + QStringList SelectFilesToCheck(QFileDialog::FileMode mode); + + /** + * @brief Check all files specified in parameter files + * + * @param files List of files and/or directories to check + */ + void DoCheckFiles(const QStringList &files); /** * @brief Get all files recursively from given path diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp index b36e8d5bc..e2d2ee9ea 100644 --- a/src/preprocessor.cpp +++ b/src/preprocessor.cpp @@ -80,7 +80,7 @@ void Preprocessor::writeError(const std::string &fileName, const std::string &co * - remove characters that are redundant * - convert needed characters to standard ASCII */ - + // Not sure how to handle this character. Bailing out. if (ch < 0) continue; diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 0514a4583..7ba1652cd 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -38,14 +38,14 @@ //--------------------------------------------------------------------------- Tokenizer::Tokenizer() - : _settings(0), _errorLogger(0) + : _settings(0), _errorLogger(0) { _tokens = 0; _tokensBack = 0; } Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) - : _settings(settings), _errorLogger(errorLogger) + : _settings(settings), _errorLogger(errorLogger) { _tokens = 0; _tokensBack = 0; @@ -1793,7 +1793,7 @@ bool Tokenizer::simplifyConditionOperator() } else { - tok->insertToken(str.substr(pos1, pos2-pos1).c_str()); + tok->insertToken(str.substr(pos1, pos2 - pos1).c_str()); pos1 = pos2 + 1; } tok = tok->next();