/*************************************************************************** * Copyright (C) 2005 by David Saxton * * david@bluehaze.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #include "asmparser.h" #include "ktechlab.h" #include "language.h" #include "logview.h" #include "outputmethoddlg.h" #include "processchain.h" #include "projectmanager.h" #include "languagemanager.h" #include "src/core/ktlconfig.h" #include #include #include #include #include #include //BEGIN class Language Language::Language( ProcessChain *processChain, KTechlab *parent, const TQString &name ) : TQObject(parent, name.utf8()) { p_ktechlab = parent; p_processChain = processChain; } Language::~Language() { } void Language::outputMessage( const TQString &message ) { LanguageManager::self()->slotMessage( message, extractMessageInfo(message) ); } void Language::outputWarning( const TQString &message ) { LanguageManager::self()->slotWarning( message, extractMessageInfo(message) ); } void Language::outputError( const TQString &message ) { LanguageManager::self()->slotError( message, extractMessageInfo(message) ); m_errorCount++; } void Language::finish( bool successful ) { if (successful) { outputMessage(m_successfulMessage + "\n"); p_ktechlab->slotChangeStatusbar(m_successfulMessage); ProcessOptions::ProcessPath::Path newPath = outputPath( m_processOptions.processPath() ); if ( newPath == ProcessOptions::ProcessPath::None ) emit processSucceeded(this); else if (p_processChain) { m_processOptions.setInputFiles( m_processOptions.intermediaryOutput() ); m_processOptions.setIntermediaryOutput( m_processOptions.targetFile() ); m_processOptions.setProcessPath(newPath); // p_processChain->compile(m_processOptions); p_processChain->setProcessOptions(m_processOptions); p_processChain->compile(); } } else { outputError(m_failedMessage + "\n"); p_ktechlab->slotChangeStatusbar(m_failedMessage); emit processFailed(this); return; } } void Language::reset() { m_errorCount = 0; } MessageInfo Language::extractMessageInfo( const TQString &text ) { if ( !text.startsWith("/") ) return MessageInfo(); const int index = text.find( ":", 0, false ); if ( index == -1 ) return MessageInfo(); const TQString fileName = text.left(index); // Extra line number const TQString message = text.right(text.length()-index); const int linePos = message.find( TQRegExp(":[\\d]+") ); int line = -1; if ( linePos != -1 ) { const int linePosEnd = message.find( ':', linePos+1 ); if ( linePosEnd != -1 ) { const TQString number = message.mid( linePos+1, linePosEnd-linePos-1 ).stripWhiteSpace(); bool ok; line = number.toInt(&ok)-1; if (!ok) line = -1; } } return MessageInfo( fileName, line ); } //END class Language //BEGIN class ProcessOptionsSpecial ProcessOptionsSpecial::ProcessOptionsSpecial() { m_bOutputMapFile = true; b_forceList = true; b_addToProject = ProjectManager::self()->currentProject(); p_flowCodeDocument = 0l; switch ( KTLConfig::hexFormat() ) { case KTLConfig::EnumHexFormat::inhx8m: m_hexFormat = "inhx8m"; break; case KTLConfig::EnumHexFormat::inhx8s: m_hexFormat = "inhx8s"; break; case KTLConfig::EnumHexFormat::inhx16: m_hexFormat = "inhx16"; break; case KTLConfig::EnumHexFormat::inhx32: default: m_hexFormat = "inhx32"; break; } } //END class ProcessOptionsSpecial //BEGIN class ProcessOptions ProcessOptions::ProcessOptions() { m_pHelper = new ProcessOptionsHelper; b_targetFileSet = false; m_pTextOutputTarget = 0l; } ProcessOptions::ProcessOptions( OutputMethodInfo info ) { m_pHelper = new ProcessOptionsHelper; b_addToProject = info.addToProject(); m_picID = info.picID(); b_targetFileSet = false; TQString target; if ( !TDEIO::NetAccess::download( info.outputFile(), target, 0l ) ) { // If the file could not be downloaded, for example does not // exist on disk, NetAccess will tell us what error to use KMessageBox::error( 0l, TDEIO::NetAccess::lastErrorString() ); return; } setTargetFile(target); switch ( info.method() ) { case OutputMethodInfo::Method::Direct: m_method = Method::LoadAsNew; break; case OutputMethodInfo::Method::SaveAndForget: m_method = Method::Forget; break; case OutputMethodInfo::Method::SaveAndLoad: m_method = Method::Load; break; } } void ProcessOptions::setTextOutputTarget( TextDocument * target, TQObject * receiver, const char * slot ) { m_pTextOutputTarget = target; TQObject::connect( m_pHelper, TQT_SIGNAL(textOutputtedTo( TextDocument* )), receiver, slot ); } void ProcessOptions::setTextOutputtedTo( TextDocument * outputtedTo ) { m_pTextOutputTarget = outputtedTo; emit m_pHelper->textOutputtedTo( m_pTextOutputTarget ); } void ProcessOptions::setTargetFile( const TQString &file ) { if (b_targetFileSet) { kdWarning() << "Trying to reset target file!"<