Added support for checking files via commandline arguments.

This commit is contained in:
Vesa Pikki 2009-07-16 08:20:29 +03:00
parent cffa4772b0
commit 962757c257
5 changed files with 70 additions and 51 deletions

View File

@ -31,8 +31,6 @@ int main(int argc, char *argv[])
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
MainWindow window; MainWindow window;
window.show(); window.show();
return app.exec(); return app.exec();

View File

@ -91,7 +91,13 @@ MainWindow::MainWindow() :
QStringList args = QCoreApplication::arguments();
//Remove the application itself
args.removeFirst();
if (!args.isEmpty())
{
DoCheckFiles(args);
}
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -185,7 +191,53 @@ void MainWindow::SaveSettings()
mUI.mResults->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; QStringList selected;
@ -214,56 +266,17 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
} }
} }
if (selected.count() > 0) return selected;
{
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);
}
} }
void MainWindow::CheckFiles() void MainWindow::CheckFiles()
{ {
DoCheckFiles(QFileDialog::ExistingFiles); DoCheckFiles(SelectFilesToCheck(QFileDialog::ExistingFiles));
} }
void MainWindow::CheckDirectory() void MainWindow::CheckDirectory()
{ {
DoCheckFiles(QFileDialog::DirectoryOnly); DoCheckFiles(SelectFilesToCheck(QFileDialog::DirectoryOnly));
} }
Settings MainWindow::GetCppcheckSettings() Settings MainWindow::GetCppcheckSettings()

View File

@ -205,8 +205,16 @@ protected:
* directory to check. Use native dialogs instead of QT:s own dialogs. * directory to check. Use native dialogs instead of QT:s own dialogs.
* *
* @param mode Dialog open mode (files or directories) * @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 * @brief Get all files recursively from given path

View File

@ -38,14 +38,14 @@
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
Tokenizer::Tokenizer() Tokenizer::Tokenizer()
: _settings(0), _errorLogger(0) : _settings(0), _errorLogger(0)
{ {
_tokens = 0; _tokens = 0;
_tokensBack = 0; _tokensBack = 0;
} }
Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger)
: _settings(settings), _errorLogger(errorLogger) : _settings(settings), _errorLogger(errorLogger)
{ {
_tokens = 0; _tokens = 0;
_tokensBack = 0; _tokensBack = 0;
@ -1793,7 +1793,7 @@ bool Tokenizer::simplifyConditionOperator()
} }
else else
{ {
tok->insertToken(str.substr(pos1, pos2-pos1).c_str()); tok->insertToken(str.substr(pos1, pos2 - pos1).c_str());
pos1 = pos2 + 1; pos1 = pos2 + 1;
} }
tok = tok->next(); tok = tok->next();