File indexing completed on 2025-04-20 08:13:37
0001 /*************************************************************************** 0002 * Copyright (C) 2005 by David Saxton * 0003 * david@bluehaze.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #include "microbe.h" 0012 #include "contexthelp.h" 0013 #include "docmanager.h" 0014 #include "languagemanager.h" 0015 #include "logview.h" 0016 0017 #include <KLocalizedString> 0018 #include <KMessageBox> 0019 #include <KProcess> 0020 0021 #include <QFile> 0022 0023 #include <ktechlab_debug.h> 0024 0025 Microbe::Microbe(ProcessChain *processChain) 0026 : ExternalLanguage(processChain, "Microbe") 0027 { 0028 m_failedMessage = i18n("*** Compilation failed ***"); 0029 m_successfulMessage = i18n("*** Compilation successful ***"); 0030 0031 #if 0 0032 // Setup error messages list 0033 QFile file( locate("appdata",i1 8n("error_messages_en_gb")) ); 0034 if ( file.open( QIODevice::ReadOnly ) ) 0035 { 0036 QTextStream stream( &file ); 0037 QString line; 0038 while ( !stream.atEnd() ) 0039 { 0040 line = stream.readLine(); // line of text excluding '\n' 0041 if ( !line.isEmpty() ) 0042 { 0043 bool ok; 0044 const int pos = line.left( line.indexOf("#") ).toInt(&ok); 0045 if (ok) { 0046 m_errorMessages[pos] = line.right(line.length()-line.indexOf("#")); 0047 } else { 0048 qCCritical(KTL_LOG) << "Error parsing Microbe error-message file"; 0049 } 0050 } 0051 } 0052 file.close(); 0053 } 0054 #endif 0055 } 0056 0057 Microbe::~Microbe() 0058 { 0059 } 0060 0061 void Microbe::processInput(ProcessOptions options) 0062 { 0063 resetLanguageProcess(); 0064 m_processOptions = options; 0065 0066 *m_languageProcess << ("microbe"); 0067 0068 // Input Asm file 0069 *m_languageProcess << (options.inputFiles().first()); 0070 0071 // Output filename 0072 *m_languageProcess << (options.intermediaryOutput()); 0073 0074 *m_languageProcess << ("--show-source"); 0075 0076 if (!start()) { 0077 KMessageBox::error(LanguageManager::self()->logView(), i18n("Assembly failed. Please check you have KTechlab installed properly (\"microbe\" could not be started).")); 0078 processInitFailed(); 0079 return; 0080 } 0081 } 0082 0083 bool Microbe::isError(const QString &message) const 0084 { 0085 return message.contains("Error", Qt::CaseInsensitive); 0086 } 0087 0088 bool Microbe::isWarning(const QString &message) const 0089 { 0090 return message.contains("Warning", Qt::CaseInsensitive); 0091 } 0092 0093 ProcessOptions::ProcessPath::Path Microbe::outputPath(ProcessOptions::ProcessPath::Path inputPath) const 0094 { 0095 switch (inputPath) { 0096 case ProcessOptions::ProcessPath::Microbe_AssemblyAbsolute: 0097 return ProcessOptions::ProcessPath::None; 0098 0099 case ProcessOptions::ProcessPath::Microbe_PIC: 0100 return ProcessOptions::ProcessPath::AssemblyAbsolute_PIC; 0101 0102 case ProcessOptions::ProcessPath::Microbe_Program: 0103 return ProcessOptions::ProcessPath::AssemblyAbsolute_Program; 0104 0105 case ProcessOptions::ProcessPath::AssemblyAbsolute_PIC: 0106 case ProcessOptions::ProcessPath::AssemblyAbsolute_Program: 0107 case ProcessOptions::ProcessPath::AssemblyRelocatable_Library: 0108 case ProcessOptions::ProcessPath::AssemblyRelocatable_Object: 0109 case ProcessOptions::ProcessPath::AssemblyRelocatable_PIC: 0110 case ProcessOptions::ProcessPath::AssemblyRelocatable_Program: 0111 case ProcessOptions::ProcessPath::C_AssemblyRelocatable: 0112 case ProcessOptions::ProcessPath::C_Library: 0113 case ProcessOptions::ProcessPath::C_Object: 0114 case ProcessOptions::ProcessPath::C_PIC: 0115 case ProcessOptions::ProcessPath::C_Program: 0116 case ProcessOptions::ProcessPath::FlowCode_AssemblyAbsolute: 0117 case ProcessOptions::ProcessPath::FlowCode_Microbe: 0118 case ProcessOptions::ProcessPath::FlowCode_PIC: 0119 case ProcessOptions::ProcessPath::FlowCode_Program: 0120 case ProcessOptions::ProcessPath::Object_Disassembly: 0121 case ProcessOptions::ProcessPath::Object_Library: 0122 case ProcessOptions::ProcessPath::Object_PIC: 0123 case ProcessOptions::ProcessPath::Object_Program: 0124 case ProcessOptions::ProcessPath::PIC_AssemblyAbsolute: 0125 case ProcessOptions::ProcessPath::Program_Disassembly: 0126 case ProcessOptions::ProcessPath::Program_PIC: 0127 case ProcessOptions::ProcessPath::Invalid: 0128 case ProcessOptions::ProcessPath::None: 0129 return ProcessOptions::ProcessPath::Invalid; 0130 } 0131 0132 return ProcessOptions::ProcessPath::Invalid; 0133 }