2015-12-14 10:48:19 +00:00
|
|
|
#include "applesoftformatter.h"
|
2016-10-11 01:34:33 +00:00
|
|
|
#include "util.h"
|
2015-12-14 10:48:19 +00:00
|
|
|
|
|
|
|
ApplesoftFormatter::ApplesoftFormatter(QObject *parent) :
|
|
|
|
QObject(parent)
|
|
|
|
{
|
|
|
|
m_file = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApplesoftFormatter::setFile(ApplesoftFile *file)
|
|
|
|
{
|
|
|
|
m_file = file;
|
|
|
|
emit newFile(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ApplesoftFormatter::formatText()
|
|
|
|
{
|
|
|
|
if (!m_file) {
|
|
|
|
return ("No File");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString retval;
|
2016-10-11 01:34:33 +00:00
|
|
|
|
2015-12-14 10:48:19 +00:00
|
|
|
foreach (ApplesoftLine line, m_file->getLines()) {
|
|
|
|
QString linestring = QString("%1 ").arg(line.linenum,5,10,QChar(' '));
|
|
|
|
retval.append(linestring);
|
2016-10-11 01:34:33 +00:00
|
|
|
foreach (ApplesoftToken token, line.tokens)
|
|
|
|
{
|
2015-12-14 10:48:19 +00:00
|
|
|
QString tokenstr = token.getRawPrintableString();
|
|
|
|
|
2016-10-11 01:34:33 +00:00
|
|
|
if (m_format_options.testFlag(BreakAfterReturn)) {
|
|
|
|
if (token.getByteValue() == ApplesoftToken::ASReturn)
|
|
|
|
{
|
|
|
|
tokenstr += "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEBUGTOKENS
|
|
|
|
#ifdef DEBUGTOKENS
|
|
|
|
if (token.getTokenId() >= 0x80)
|
|
|
|
{
|
|
|
|
tokenstr = QString(" {%1} ").arg(uint16ToHex(token.getTokenId()));
|
|
|
|
// tokenstr = " __ ";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tokenstr = QString("%1").arg(QChar(token.getByteValue()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-12-14 10:48:19 +00:00
|
|
|
if (m_format_options.testFlag(ShowCtrlChars)) {
|
|
|
|
tokenstr.replace(QChar(0x7f),QChar(0x2401));
|
|
|
|
|
|
|
|
for (int idx = 1; idx <= 0x1f; idx++) {
|
2016-10-11 01:34:33 +00:00
|
|
|
if (idx == '\n') continue;
|
|
|
|
if (idx == '\t') continue;
|
2015-12-14 10:48:19 +00:00
|
|
|
tokenstr.replace(QChar(idx),QChar(idx+0x2400));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
retval.append(tokenstr);
|
|
|
|
}
|
|
|
|
retval.append("\n");
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|