From 6c09f661b83dd13a8403243c1441efa5c4900538 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Thu, 22 Aug 2019 13:47:41 +0200 Subject: In include, use content from editor if file is already open. This allows to assemble from modified include files without need to save their content the first. Signed-off-by: Pavel Pisa --- qtmips_asm/simpleasm.cpp | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'qtmips_asm/simpleasm.cpp') diff --git a/qtmips_asm/simpleasm.cpp b/qtmips_asm/simpleasm.cpp index ad720b9..223b34d 100644 --- a/qtmips_asm/simpleasm.cpp +++ b/qtmips_asm/simpleasm.cpp @@ -256,16 +256,9 @@ bool SimpleAsm::process_line(QString line, QString filename, error = QString("recursive include of file: \"%1\"").arg(incname); res = false; } else { - QFile incfile(incname); - if (!incfile.open(QFile::ReadOnly | QFile::Text)) { - error = QString("cannot open file: \"%1\"").arg(incname); + if (!process_file(incname, error_ptr)) { res = false; - } else for (int ln = 1; !incfile.atEnd(); ln++) { - QString line = incfile.readLine(); - if (!process_line(line, incname, ln, error_ptr)) { - res = false; - break; - } + error = QString("error in included file: \"%1\"").arg(incname); } } if (!res) { @@ -567,6 +560,29 @@ bool SimpleAsm::process_line(QString line, QString filename, return true; } +bool SimpleAsm::process_file(QString filename, QString *error_ptr) { + QString error; + bool res = true; + QFile srcfile(filename); + if (!srcfile.open(QFile::ReadOnly | QFile::Text)) { + error = QString("cannot open file: \"%1\"").arg(filename); + emit report_message(messagetype::MSG_ERROR, "", 0, 0, error, ""); + error_occured = true; + if (error_ptr != nullptr) + *error_ptr = error; + return false; + } + for (int ln = 1; !srcfile.atEnd(); ln++) { + QString line = srcfile.readLine(); + if ((line.count() > 0) && (line.at(line.count() - 1) == '\n')) + line.truncate(line.count() - 1); + if (!process_line(line, filename, ln, error_ptr)) + res = false; + } + srcfile.close(); + return res; +} + bool SimpleAsm::finish(QString *error_ptr) { bool error_reported = false; foreach(machine::RelocExpression *r, reloc) { -- cgit v1.2.3