changeset 86:ef8117b84a85

If output file parameter in uigui ini file is set to "stdout" use standard output of called process to receive the formatted code. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@259 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Mon, 05 Mar 2007 22:29:04 +0000
parents 7328bb113688
children c2a0a33f012d
files src/indenthandler.cpp
diffstat 1 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/indenthandler.cpp	Sun Mar 04 19:44:54 2007 +0000
+++ b/src/indenthandler.cpp	Mon Mar 05 22:29:04 2007 +0000
@@ -84,7 +84,7 @@
  */
 QString IndentHandler::callIndenter(QString sourceCode, QString inputFileExtension) {
     Q_ASSERT_X( !inputFileName.isEmpty(), "callIndenter", "inputFileName is empty" );
-    Q_ASSERT_X( !outputFileName.isEmpty(), "callIndenter", "outputFileName is empty" );
+//    Q_ASSERT_X( !outputFileName.isEmpty(), "callIndenter", "outputFileName is empty" );
     Q_ASSERT_X( !indenterFileName.isEmpty(), "callIndenter", "indenterFileName is empty" );
 
 	QString formattedSourceCode;
@@ -112,7 +112,7 @@
 	QFile outSrcFile(dataDirctoryStr + inputFileName + inputFileExtension);
 	parameterInputFile = " " + inputFileParameter + inputFileName + inputFileExtension;
 
-    if ( outputFileParameter != "none" ) {
+    if ( outputFileParameter != "none" && outputFileParameter != "stdout" ) {
         parameterOuputFile = " " + outputFileParameter + outputFileName + inputFileExtension;
     }
 
@@ -193,7 +193,7 @@
         processReturnString = "<html><body>";
         // test if there was an error during starting the process of the indenter, or in case of linux
         // there might also been an error starting wine
-        if ( !indentProcess.waitForFinished() ) {
+        if ( !indentProcess.waitForFinished(5000) ) {
             processReturnString += tr("<b>Returned error message:</b> ") + indentProcess.errorString() + "<br>";
 
             switch ( indentProcess.error() ) {
@@ -239,13 +239,19 @@
         }
     }
 
-    // read the output file generated by the indenter call
-    outSrcFile.setFileName(dataDirctoryStr + outputFileName + inputFileExtension);
-    outSrcFile.open(QFile::ReadOnly | QFile::Text);
-    QTextStream outSrcStrm(&outSrcFile);
-    outSrcStrm.setCodec( QTextCodec::codecForName("UTF-8") );
-    formattedSourceCode = outSrcStrm.readAll();
-    outSrcFile.close();
+
+	if ( indentProcess.exitCode() == 0 && outputFileParameter == "stdout"  ) {
+		formattedSourceCode = processReturnString;
+	}
+	else {
+		// read the output file generated by the indenter call
+		outSrcFile.setFileName(dataDirctoryStr + outputFileName + inputFileExtension);
+		outSrcFile.open(QFile::ReadOnly | QFile::Text);
+		QTextStream outSrcStrm(&outSrcFile);
+		outSrcStrm.setCodec( QTextCodec::codecForName("UTF-8") );
+		formattedSourceCode = outSrcStrm.readAll();
+		outSrcFile.close();
+	}
 
     // delete the temporary input and output files
     QFile::remove(dataDirctoryStr + outputFileName + inputFileExtension);