Mercurial > hg > forks > UniversalIndentGUI
changeset 449:9295d568a84e
- fixed a bug where the string "<html><body>" was prepended to the output code. Occurred for example when using the shell indenter.
- Added the possibility to directly setting php files as indenter. The suffix .php is recognized and php used as default interpreter.
git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@684 59b1889a-e5ac-428c-b0c7-476e01d41282
author | thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282> |
---|---|
date | Thu, 22 May 2008 14:55:35 +0000 |
parents | 4728ebaecd3a |
children | f15116853ab2 |
files | src/indenthandler.cpp |
diffstat | 1 files changed, 29 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/src/indenthandler.cpp Tue May 20 17:55:55 2008 +0000 +++ b/src/indenthandler.cpp Thu May 22 14:55:35 2008 +0000 @@ -342,9 +342,10 @@ indentProcess.start(indenterCompleteCallString); - processReturnString = "<html><body>"; + processReturnString = ""; // test if there was an error during starting the process of the indenter if ( !indentProcess.waitForFinished(10000) ) { + processReturnString = "<html><body>"; processReturnString += tr("<b>Returned error message:</b> ") + indentProcess.errorString() + "<br>"; switch ( indentProcess.error() ) { @@ -1073,11 +1074,17 @@ indenterExecutableCallString = "\"" + indenterExecutableCallString + "\""; return true; } - // If the file could not be executed, try to find a shebang at its start. + // If the file could not be executed, try to find a shebang at its start or test if its a php file. else { - // Try to open the file. + QString interpreterName = ""; QFile indenterExecutable( indenterExecutableCallString ); - if ( indenterExecutable.open(QFile::ReadOnly) ) { + + // If indenter executable file has .php as suffix, use php as default interpreter + if ( QFileInfo(indenterExecutableCallString).suffix().toLower() == "php" ) { + interpreterName = "php -f"; + } + // Else try to open the file and read the shebang. + else if ( indenterExecutable.open(QFile::ReadOnly) ) { // Read the first line of the file. QTextStream indenterExecutableContent(&indenterExecutable); QString firstLineOfIndenterExe = indenterExecutableContent.readLine(75); @@ -1086,25 +1093,25 @@ // If the initial shebang is found, read the named intepreter. e.g. perl if ( firstLineOfIndenterExe.startsWith("#!") ) { // Get the rightmost word. by splitting the string into only full words. - QString interpreterName = firstLineOfIndenterExe.split( "/" ).last(); + interpreterName = firstLineOfIndenterExe.split( "/" ).last(); + } + } - // Try to call the interpreter, if it exists. - if ( !interpreterName.isEmpty() ) { - indenterExecutableCallString = interpreterName + " \"" + indenterExecutableCallString + "\""; - indentProcess.start( interpreterName + " -h"); - if ( indentProcess.waitForFinished(2000) ) { - return true; - } - else if ( indentProcess.error() == QProcess::Timedout ) { - return true; - } - // now we know an interpreter is needed but it could not be called, so inform the user. - else { - errorMessageDialog->showMessage( tr("Interpreter needed"), - tr("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) ); - return true; - } - } + // Try to call the interpreter, if it exists. + if ( !interpreterName.isEmpty() ) { + indenterExecutableCallString = interpreterName + " \"" + indenterExecutableCallString + "\""; + indentProcess.start( interpreterName + " -h"); + if ( indentProcess.waitForFinished(2000) ) { + return true; + } + else if ( indentProcess.error() == QProcess::Timedout ) { + return true; + } + // now we know an interpreter is needed but it could not be called, so inform the user. + else { + errorMessageDialog->showMessage( tr("Interpreter needed"), + tr("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) ); + return true; } } }