@ -21,6 +21,7 @@
# include "IndentHandler.h"
# include "IndentHandler.h"
# include <cstdlib>
# include <cstdlib>
# include <unistd.h>
# include "MainWindow.h"
# include "MainWindow.h"
# include "SettingsPaths.h"
# include "SettingsPaths.h"
@ -41,11 +42,11 @@
# include <tqlineedit.h>
# include <tqlineedit.h>
# include <tqmessagebox.h>
# include <tqmessagebox.h>
# include <tqpopupmenu.h>
# include <tqpopupmenu.h>
# include <tqprocess.h>
# include <tqspinbox.h>
# include <tqspinbox.h>
# include <tqtoolbox.h>
# include <tqtoolbox.h>
# include <tqtoolbutton.h>
# include <tqtoolbutton.h>
# include <tqtooltip.h>
# include <tqtooltip.h>
//--- #include <tqprocess.h>
//--- #include <tqsettings.h>
//--- #include <tqsettings.h>
//--- #include <tqstringlist.h>
//--- #include <tqstringlist.h>
//--- #include <tqbytearray.h>
//--- #include <tqbytearray.h>
@ -468,11 +469,11 @@ TQString IndentHandler::generateShellScript(const TQString &configFilename)
//---
//---
//--- // Set the directory where the indenter will be executed for the process' environment as PWD.
//--- // Set the directory where the indenter will be executed for the process' environment as PWD.
//--- TQStringList env = indentProcess.environment();
//--- TQStringList env = indentProcess.environment();
//--- env << "PWD=" + TQFileInfo(m_tempDirectoryStr).abs olute FilePath();
//--- env << "PWD=" + TQFileInfo(m_tempDirectoryStr).abs FilePath();
//--- indentProcess.setEnvironment(env);
//--- indentProcess.setEnvironment(env);
//---
//---
//--- // Set the directory for the indenter execution
//--- // Set the directory for the indenter execution
//--- indentProcess.setWorkingDirectory(TQFileInfo(m_tempDirectoryStr).abs olute FilePath());
//--- indentProcess.setWorkingDirectory(TQFileInfo(m_tempDirectoryStr).abs FilePath());
//---
//---
//--- tqDebug() << __LINE__ << " " << __FUNCTION__ << ": Will call the indenter in the directory " <<
//--- tqDebug() << __LINE__ << " " << __FUNCTION__ << ": Will call the indenter in the directory " <<
//--- indentProcess.workingDirectory() << " using this commandline call: " <<
//--- indentProcess.workingDirectory() << " using this commandline call: " <<
@ -921,6 +922,14 @@ void IndentHandler::resetToDefaultValues()
}
}
}
}
/*
\ brief Feedback when the inderter process has finished
*/
void IndentHandler : : indenterProcessFinished ( )
{
m_indenterProcessFinished = true ;
}
/*
/*
\ brief Opens and parses the indenter ini file that is declared by \ a iniFilePath .
\ brief Opens and parses the indenter ini file that is declared by \ a iniFilePath .
*/
*/
@ -1368,162 +1377,225 @@ TQString IndentHandler::getIndenterCfgFile()
*/
*/
bool IndentHandler : : createIndenterCallString ( )
bool IndentHandler : : createIndenterCallString ( )
{
{
//--- TQProcess indentProcess;
TQProcess indentProcess ( this ) ;
//---
TQObject : : connect ( & indentProcess , SIGNAL ( processExited ( ) ) , this , SLOT ( indenterProcessFinished ( ) ) ) ;
//--- if (m_indenterFileName.isEmpty())
//--- {
if ( m_indenterFileName . isEmpty ( ) )
//--- return false;
{
//--- }
return false ;
//---
}
//--- // First try to call the indenter inside of the data dir, using some suffix
//--- // ------------------------------------------------------------------------
// First try to call the indenter inside of the data dir, using some suffix
//---
// ------------------------------------------------------------------------
//--- // Set the directory for the indenter execution
//--- indentProcess.setWorkingDirectory(TQFileInfo(m_indenterDirectoryStr).absoluteFilePath());
// Set the directory for the indenter execution
//---
indentProcess . setWorkingDirectory ( TQFileInfo ( m_indenterDirectoryStr ) . absFilePath ( ) ) ;
//--- foreach(TQString suffix, TQStringList() << "" << ".exe" << ".bat" << ".com" << ".sh")
//--- {
TQStringList extentionList ;
//--- m_indenterExecutableSuffix = suffix;
extentionList < < " " < < " .exe " < < " .bat " < < " .com " < < " .sh " ;
//--- m_indenterExecutableCallString = TQFileInfo(m_indenterDirectoryStr).absoluteFilePath() + "/" +
for ( const TQString & suffix : extentionList )
//--- m_indenterFileName;
{
//--- m_indenterExecutableCallString += suffix;
m_indenterExecutableSuffix = suffix ;
//---
m_indenterExecutableCallString = TQFileInfo ( m_indenterDirectoryStr ) . absFilePath ( ) + " / " +
//--- // Only try to call the indenter, if the file exists.
m_indenterFileName ;
//--- if (TQFile::exists(m_indenterExecutableCallString))
m_indenterExecutableCallString + = suffix ;
//--- {
//--- // Only try to call the indenter directly if it is no php file
// Only try to call the indenter, if the file exists.
//--- if (TQFileInfo(m_indenterExecutableCallString).suffix().toLower() != "php")
if ( TQFile : : exists ( m_indenterExecutableCallString ) )
//--- {
{
//--- indentProcess.start(
// Only try to call the indenter directly if it is no php file
//--- "\"" + m_indenterExecutableCallString + +"\" " + m_indenterShowHelpParameter);
if ( TQFileInfo ( m_indenterExecutableCallString ) . extension ( false ) . lower ( ) ! = " php " )
//--- if (indentProcess.waitForFinished(2000))
{
//--- {
indentProcess . clearArguments ( ) ;
//--- m_indenterExecutableCallString = "\"" + m_indenterExecutableCallString + "\"";
indentProcess . addArgument ( m_indenterExecutableCallString ) ;
//--- return true;
indentProcess . addArgument ( m_indenterShowHelpParameter ) ;
//--- }
m_indenterProcessFinished = false ;
//--- else if (indentProcess.error() == TQProcess::Timedout)
indentProcess . start ( ) ;
//--- {
int counter = 20 ; // roughtly 2s at 100ms interval
//--- m_indenterExecutableCallString = "\"" + m_indenterExecutableCallString + "\"";
while ( ! m_indenterProcessFinished & & counter > 0 )
//--- return true;
{
//--- }
usleep ( 100 * 1000 ) ;
//--- }
tqApp - > processEvents ( ) ;
//---
- - counter ;
//--- // Test for needed interpreters
}
//--- // ----------------------------
if ( indentProcess . normalExit ( ) )
//--- // If the file could not be executed, try to find a shebang at its start or test if its a php
{
//--- // file.
m_indenterExecutableCallString = " \" " + m_indenterExecutableCallString + " \" " ;
//--- TQString interpreterName = "";
return true ;
//--- TQFile indenterExecutable(m_indenterExecutableCallString);
}
//---
else
//--- // If indenter executable file has .php as suffix, use php as default interpreter
{
//--- if (TQFileInfo(m_indenterExecutableCallString).suffix().toLower() == "php")
if ( indentProcess . isRunning ( ) )
//--- {
{
//--- interpreterName = "php -f";
indentProcess . kill ( ) ;
//--- }
}
//--- // Else try to open the file and read the shebang.
}
//--- else if (indenterExecutable.open(TQFile::ReadOnly))
}
//--- {
//--- // Read the first line of the file.
// Test for needed interpreters
//--- TQTextStream indenterExecutableContent(&indenterExecutable);
// ----------------------------
//--- TQString firstLineOfIndenterExe = indenterExecutableContent.readLine(75);
// If the file could not be executed, try to find a shebang at its start or test if its a php
//--- indenterExecutable.close();
// file.
//---
TQString interpreterName = " " ;
//--- // If the initial shebang is found, read the named intepreter. e.g. perl
TQFile indenterExecutable ( m_indenterExecutableCallString ) ;
//--- if (firstLineOfIndenterExe.startsWith("#!"))
//--- {
// If indenter executable file has .php as suffix, use php as default interpreter
//--- // Get the rightmost word. by splitting the string into only full words.
if ( TQFileInfo ( m_indenterExecutableCallString ) . extension ( false ) . lower ( ) = = " php " )
//--- interpreterName = firstLineOfIndenterExe.split("/").last();
{
//--- }
interpreterName = " php -f " ;
//--- }
}
//---
// Else try to open the file and read the shebang.
//--- // Try to call the interpreter, if it exists.
else if ( indenterExecutable . open ( IO_ReadOnly ) )
//--- if (!interpreterName.isEmpty())
{
//--- {
// Read the first line of the file.
//--- m_indenterExecutableCallString = interpreterName + " \"" + m_indenterExecutableCallString +
TQTextStream indenterExecutableContent ( & indenterExecutable ) ;
//--- "\"";
TQString firstLineOfIndenterExe = indenterExecutableContent . readLine ( ) ;
//--- indentProcess.start(interpreterName + " -h");
indenterExecutable . close ( ) ;
//--- if (indentProcess.waitForFinished(2000))
//--- {
// If the initial shebang is found, read the named intepreter. e.g. perl
//--- return true;
if ( firstLineOfIndenterExe . startsWith ( " #! " ) )
//--- }
{
//--- else if (indentProcess.error() == TQProcess::Timedout)
// Get the rightmost word. by splitting the string into only full words.
//--- {
TQStringList indenterFirstLineStrings = TQStringList : : split ( " / " , firstLineOfIndenterExe ) ;
//--- return true;
interpreterName = indenterFirstLineStrings . last ( ) ;
//--- }
}
//--- // now we know an interpreter is needed but it could not be called, so inform the user.
}
//--- else
//--- {
// Try to call the interpreter, if it exists.
//--- m_errorMessageDialog->showMessage(tr("Interpreter needed"), tr(
if ( ! interpreterName . isEmpty ( ) )
//--- "To use the selected indenter the program \"%1\" needs to be available in the global environment. You should add an entry to your path settings.").arg(
{
//--- interpreterName));
m_indenterExecutableCallString = interpreterName + " \" " +
//--- return true;
m_indenterExecutableCallString + " \" " ;
//--- }
indentProcess . clearArguments ( ) ;
//--- }
indentProcess . addArgument ( interpreterName ) ;
//--- }
indentProcess . addArgument ( " -h " ) ;
//--- }
m_indenterProcessFinished = false ;
//---
indentProcess . start ( ) ;
//--- // If unsuccessful try if the indenter executable is a JavaScript file
int counter = 20 ; // roughtly 2s at 100ms interval
//--- // -------------------------------------------------------------------
while ( ! m_indenterProcessFinished & & counter > 0 )
//--- m_indenterExecutableSuffix = ".js";
{
//--- m_indenterExecutableCallString = TQFileInfo(m_indenterDirectoryStr).absoluteFilePath() + "/" +
usleep ( 100 * 1000 ) ;
//--- m_indenterFileName;
tqApp - > processEvents ( ) ;
//--- m_indenterExecutableCallString += m_indenterExecutableSuffix;
- - counter ;
//--- if (TQFile::exists(m_indenterExecutableCallString))
}
//--- {
if ( indentProcess . normalExit ( ) )
//--- return true;
{
//--- }
return true ;
//---
}
//--- // If unsuccessful try to call the indenter global, using some suffix
// now we know an interpreter is needed but it could not be called, so inform the user.
//--- // ------------------------------------------------------------------
else
//--- foreach(TQString suffix, TQStringList() << "" << ".exe" << ".bat" << ".com" << ".sh")
{
//--- {
if ( indentProcess . isRunning ( ) )
//--- m_indenterExecutableSuffix = suffix;
{
//--- m_indenterExecutableCallString = m_indenterFileName + suffix;
indentProcess . kill ( ) ;
//--- indentProcess.start(m_indenterExecutableCallString + " " + m_indenterShowHelpParameter);
}
//--- if (indentProcess.waitForFinished(2000))
m_errorMessageDialog - > showMessage ( tr ( " Interpreter needed " ) ,
//--- {
tr ( " To use the selected indenter the program \" %1 \" needs to be available in the global environment. "
//--- return true;
" You should add an entry to your path settings. " ) . arg ( interpreterName ) ) ;
//--- }
return true ;
//--- else if (indentProcess.error() == TQProcess::Timedout)
}
//--- {
}
//--- return true;
}
//--- }
}
//--- }
//---
// If unsuccessful try if the indenter executable is a JavaScript file
//--- // If even globally calling the indenter fails, try calling .com and .exe via wine
// -------------------------------------------------------------------
//--- // -------------------------------------------------------------------------------
m_indenterExecutableSuffix = " .js " ;
//--- m_indenterExecutableCallString = "\"" + TQFileInfo(m_indenterDirectoryStr).absoluteFilePath() + "/" +
m_indenterExecutableCallString = TQFileInfo ( m_indenterDirectoryStr ) . absFilePath ( ) + " / " +
//--- m_indenterFileName;
m_indenterFileName ;
//---
m_indenterExecutableCallString + = m_indenterExecutableSuffix ;
//--- foreach(TQString suffix, TQStringList() << ".exe" << ".com")
if ( TQFile : : exists ( m_indenterExecutableCallString ) )
//--- {
{
//--- m_indenterExecutableSuffix = suffix;
return true ;
//--- if (TQFile::exists(m_indenterDirectoryStr + "/" + m_indenterFileName + suffix))
}
//--- {
//--- TQProcess wineTestProcess;
// If unsuccessful try to call the indenter global, using some suffix
//--- wineTestProcess.start("wine --version");
// ------------------------------------------------------------------
//--- // if the process of wine was not callable assume that wine is not installed
extentionList . clear ( ) ;
//--- if (!wineTestProcess.waitForFinished(2000))
extentionList < < " " < < " .exe " < < " .bat " < < " .com " < < " .sh " ;
//--- {
for ( const TQString & suffix : extentionList )
//--- m_errorMessageDialog->showMessage(tr("wine not installed"), tr(
{
//--- "There exists only a win32 executable of the indenter and wine does not seem to be installed. Please install wine to be able to run the indenter."));
m_indenterExecutableSuffix = suffix ;
//--- m_indenterExecutableCallString = "";
m_indenterExecutableCallString = m_indenterFileName + suffix ;
//--- return false;
indentProcess . clearArguments ( ) ;
//--- }
indentProcess . addArgument ( m_indenterExecutableCallString ) ;
//--- else
indentProcess . addArgument ( m_indenterShowHelpParameter ) ;
//--- {
m_indenterProcessFinished = false ;
//--- m_indenterExecutableCallString = "\"" +
indentProcess . start ( ) ;
//--- TQFileInfo(m_indenterDirectoryStr).absoluteFilePath() + "/";
int counter = 20 ; // roughtly 2s at 100ms interval
//--- m_indenterExecutableCallString += m_indenterFileName + suffix + "\"";
while ( ! m_indenterProcessFinished & & counter > 0 )
//--- m_indenterExecutableCallString = "wine " + m_indenterExecutableCallString;
{
//---
usleep ( 100 * 1000 ) ;
//--- return true;
tqApp - > processEvents ( ) ;
//--- }
- - counter ;
//--- }
}
//--- }
if ( indentProcess . normalExit ( ) )
//---
{
//--- m_indenterExecutableCallString = "";
return true ;
//--- m_indenterExecutableSuffix = "";
}
else
{
if ( indentProcess . isRunning ( ) )
{
indentProcess . kill ( ) ;
}
}
}
// If even globally calling the indenter fails, try calling .com and .exe via wine
// -------------------------------------------------------------------------------
m_indenterExecutableCallString = " \" " + TQFileInfo ( m_indenterDirectoryStr ) . absFilePath ( ) + " / " +
m_indenterFileName ;
extentionList . clear ( ) ;
extentionList < < " .exe " < < " .com " ;
for ( const TQString & suffix : extentionList )
{
m_indenterExecutableSuffix = suffix ;
if ( TQFile : : exists ( m_indenterDirectoryStr + " / " + m_indenterFileName + suffix ) )
{
indentProcess . clearArguments ( ) ;
indentProcess . addArgument ( " wine " ) ;
indentProcess . addArgument ( " --version " ) ;
m_indenterProcessFinished = false ;
indentProcess . start ( ) ;
int counter = 20 ; // roughtly 2s at 100ms interval
while ( ! m_indenterProcessFinished & & counter > 0 )
{
usleep ( 100 * 1000 ) ;
tqApp - > processEvents ( ) ;
- - counter ;
}
// if the process of wine was not callable assume that wine is not installed
if ( indentProcess . normalExit ( ) )
{
m_errorMessageDialog - > showMessage ( tr ( " wine not installed " ) , tr (
" There exists only a win32 executable of the indenter and wine does not seem to be installed. Please install wine to be able to run the indenter. " ) ) ;
m_indenterExecutableCallString = " " ;
return false ;
}
else
{
if ( indentProcess . isRunning ( ) )
{
indentProcess . kill ( ) ;
}
m_indenterExecutableCallString = " \" " +
TQFileInfo ( m_indenterDirectoryStr ) . absFilePath ( ) + " / " ;
m_indenterExecutableCallString + = m_indenterFileName + suffix + " \" " ;
m_indenterExecutableCallString = " wine " + m_indenterExecutableCallString ;
return true ;
}
}
}
m_indenterExecutableCallString = " " ;
m_indenterExecutableSuffix = " " ;
if ( indentProcess . isRunning ( ) )
{
indentProcess . kill ( ) ;
}
return false ;
return false ;
}
}