Added support for checking files via commandline arguments.
This commit is contained in:
parent
cffa4772b0
commit
962757c257
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue