src/languages/microbe.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2005 by David Saxton                                    *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "contexthelp.h"
00012 #include "docmanager.h"
00013 #include "logview.h"
00014 #include "microbe.h"
00015 #include "languagemanager.h"
00016 
00017 #include <kdebug.h>
00018 #include <klocale.h>
00019 #include <kmessagebox.h>
00020 #include <kstandarddirs.h>
00021 
00022 #include <qfile.h>
00023 #include <kprocess.h>
00024 
00025 Microbe::Microbe( ProcessChain *processChain, KTechlab *parent )
00026  : ExternalLanguage( processChain, parent, "Microbe" )
00027 {
00028         m_failedMessage = i18n("*** Compilation failed ***");
00029         m_successfulMessage = i18n("*** Compilation successful ***");
00030         
00031         // Setup error messages list
00032         QFile file( locate("appdata",i18n("error_messages_en_gb")) );
00033         if ( file.open( IO_ReadOnly ) ) 
00034         {
00035         QTextStream stream( &file );
00036         QString line;
00037         while ( !stream.atEnd() )
00038                 {
00039                         line = stream.readLine(); // line of text excluding '\n'
00040                         if ( !line.isEmpty() )
00041                         {
00042                                 bool ok;
00043                                 const int pos = line.left( line.find("#") ).toInt(&ok);
00044                                 if (ok) {
00045                                         m_errorMessages[pos] = line.right(line.length()-line.find("#"));
00046                                 } else {
00047                                         kdError() << k_funcinfo << "Error parsing Microbe error-message file"<<endl;
00048                                 }
00049                         }
00050         }
00051                 file.close();
00052         }
00053 }
00054 
00055 Microbe::~Microbe()
00056 {
00057 }
00058 
00059 
00060 void Microbe::processInput( ProcessOptions options )
00061 {
00062         resetLanguageProcess();
00063         m_processOptions = options;
00064         
00065         *m_languageProcess << ("microbe");
00066         
00067         // Input Asm file
00068         *m_languageProcess << ( options.inputFiles().first() );
00069         
00070         // Output filename
00071         *m_languageProcess << ( options.intermediaryOutput() );
00072         
00073         *m_languageProcess << ("--show-source");
00074         
00075         if ( !start() )
00076         {
00077                 KMessageBox::sorry( LanguageManager::self()->logView(), i18n("Assembly failed. Please check you have KTechlab installed properly (\"microbe\" could not be started).") );
00078                 processInitFailed();
00079                 return;
00080         }
00081 }
00082 
00083 
00084 bool Microbe::isError( const QString &message ) const
00085 {
00086          return message.contains( "Error", false );
00087 }
00088 
00089 bool Microbe::isWarning( const QString &message ) const
00090 {
00091         return message.contains( "Warning", false );
00092 }
00093 
00094 
00095 ProcessOptions::ProcessPath::Path Microbe::outputPath( ProcessOptions::ProcessPath::Path inputPath ) const
00096 {
00097         switch (inputPath)
00098         {
00099                 case ProcessOptions::ProcessPath::Microbe_AssemblyAbsolute:
00100                         return ProcessOptions::ProcessPath::None;
00101                         
00102                 case ProcessOptions::ProcessPath::Microbe_PIC:
00103                         return ProcessOptions::ProcessPath::AssemblyAbsolute_PIC;
00104                         
00105                 case ProcessOptions::ProcessPath::Microbe_Program:
00106                         return ProcessOptions::ProcessPath::AssemblyAbsolute_Program;
00107                         
00108                 case ProcessOptions::ProcessPath::AssemblyAbsolute_PIC:
00109                 case ProcessOptions::ProcessPath::AssemblyAbsolute_Program:
00110                 case ProcessOptions::ProcessPath::AssemblyRelocatable_Library:
00111                 case ProcessOptions::ProcessPath::AssemblyRelocatable_Object:
00112                 case ProcessOptions::ProcessPath::AssemblyRelocatable_PIC:
00113                 case ProcessOptions::ProcessPath::AssemblyRelocatable_Program:
00114                 case ProcessOptions::ProcessPath::C_AssemblyRelocatable:
00115                 case ProcessOptions::ProcessPath::C_Library:
00116                 case ProcessOptions::ProcessPath::C_Object:
00117                 case ProcessOptions::ProcessPath::C_PIC:
00118                 case ProcessOptions::ProcessPath::C_Program:
00119                 case ProcessOptions::ProcessPath::FlowCode_AssemblyAbsolute:
00120                 case ProcessOptions::ProcessPath::FlowCode_Microbe:
00121                 case ProcessOptions::ProcessPath::FlowCode_PIC:
00122                 case ProcessOptions::ProcessPath::FlowCode_Program:
00123                 case ProcessOptions::ProcessPath::Object_Disassembly:
00124                 case ProcessOptions::ProcessPath::Object_Library:
00125                 case ProcessOptions::ProcessPath::Object_PIC:
00126                 case ProcessOptions::ProcessPath::Object_Program:
00127                 case ProcessOptions::ProcessPath::PIC_AssemblyAbsolute:
00128                 case ProcessOptions::ProcessPath::Program_Disassembly:
00129                 case ProcessOptions::ProcessPath::Program_PIC:
00130                 case ProcessOptions::ProcessPath::Invalid:
00131                 case ProcessOptions::ProcessPath::None:
00132                         return ProcessOptions::ProcessPath::Invalid;
00133         }
00134         
00135         return ProcessOptions::ProcessPath::Invalid;
00136 }

Generated on Tue May 8 17:05:31 2007 for KTechLab by  doxygen 1.5.1