From 5de3dd4762ca33a0f92e79ffa4fe2ff67069d531 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 24 Feb 2010 01:49:02 +0000 Subject: Added KDE3 version of ktechlab git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/ktechlab@1095338 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/languages/language.cpp | 558 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 558 insertions(+) create mode 100644 src/languages/language.cpp (limited to 'src/languages/language.cpp') diff --git a/src/languages/language.cpp b/src/languages/language.cpp new file mode 100644 index 0000000..e7ce759 --- /dev/null +++ b/src/languages/language.cpp @@ -0,0 +1,558 @@ +/*************************************************************************** + * 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 QString &name ) + : QObject(parent,name) +{ + p_ktechlab = parent; + p_processChain = processChain; +} + + +Language::~Language() +{ +} + + +void Language::outputMessage( const QString &message ) +{ + LanguageManager::self()->slotMessage( message, extractMessageInfo(message) ); +} + + +void Language::outputWarning( const QString &message ) +{ + LanguageManager::self()->slotWarning( message, extractMessageInfo(message) ); +} + + +void Language::outputError( const QString &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 QString &text ) +{ + if ( !text.startsWith("/") ) + return MessageInfo(); + + const int index = text.find( ":", 0, false ); + if ( index == -1 ) + return MessageInfo(); + const QString fileName = text.left(index); + + // Extra line number + const QString message = text.right(text.length()-index); + const int linePos = message.find( QRegExp(":[\\d]+") ); + int line = -1; + if ( linePos != -1 ) + { + const int linePosEnd = message.find( ':', linePos+1 ); + if ( linePosEnd != -1 ) + { + const QString 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; + + QString target; + if ( !KIO::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, KIO::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, QObject * receiver, const char * slot ) +{ + m_pTextOutputTarget = target; + QObject::connect( m_pHelper, SIGNAL(textOutputtedTo( TextDocument* )), receiver, slot ); +} + + +void ProcessOptions::setTextOutputtedTo( TextDocument * outputtedTo ) +{ + m_pTextOutputTarget = outputtedTo; + emit m_pHelper->textOutputtedTo( m_pTextOutputTarget ); +} + + +void ProcessOptions::setTargetFile( const QString &file ) +{ + if (b_targetFileSet) + { + kdWarning() << "Trying to reset target file!"<