Fix Merlin file formatting

The code was mis-handling semicolons embedded in macros, treating
them as the start of a comment.  It now checks to see if they're
at the start of a line or preceded by a space.
This commit is contained in:
Andy McFadden 2015-07-01 09:05:07 -07:00
parent 8c1707e28b
commit adb65c5e9d
3 changed files with 16 additions and 10 deletions

View File

@ -4,8 +4,8 @@ faddenSoft
http://www.faddensoft.com/
CiderPress
http://a2ciderpress.com/
4.0.1-a1
42052
4.0.1-a2
42186
C:\DATA\faddenSoft\fs.ico
Copyright © 2015 CiderPress project authors. All rights reserved.
C:\Src\CiderPress\DIST\ReadMe.txt
@ -355,7 +355,7 @@ FALSE
4095
Setup401a1.exe
Setup401a2.exe
FALSE

View File

@ -15,7 +15,7 @@
#define kAppMajorVersion 4
#define kAppMinorVersion 0
#define kAppBugVersion 1
#define kAppDevString L"-a1"
#define kAppDevString L"-a2"
/*
* Windows application object.

View File

@ -330,7 +330,6 @@ int ReformatMerlin::Process(const ReformatHolder* pHolder,
{
const uint8_t* srcPtr = pHolder->GetSourceBuf(part);
long srcLen = pHolder->GetSourceLen(part);
long length = srcLen;
int retval = -1;
enum { kStateLabel, kStateMnemonic, kStateOperand, kStateComment };
int tabStop[] = { 0, 9, 15, 26 }; // 1:1 map with state enum
@ -343,13 +342,17 @@ int ReformatMerlin::Process(const ReformatHolder* pHolder,
bool isLineStart = true;
for ( ; srcLen > 0; srcLen--, srcPtr++) {
bool wasLineStart = false;
if (isLineStart) {
isLineStart = false;
wasLineStart = true;
OutputStart(); // begin new line in output buffer
state = kStateLabel;
if (*srcPtr == 0xaa)
if (*srcPtr == 0xaa) {
// leading '*' makes entire line a comment
state = kStateComment;
}
}
if (*srcPtr == 0x8d) {
OutputFinish(); // end of line
@ -358,6 +361,7 @@ int ReformatMerlin::Process(const ReformatHolder* pHolder,
isLineStart = true;
if (quoteChar != '\0') {
// unterminated quote
DebugBreak();
quoteChar = '\0';
}
@ -383,7 +387,12 @@ int ReformatMerlin::Process(const ReformatHolder* pHolder,
// Merlin-16 v3.40
state++;
OutputTab(tabStop[state]);
} else if (*srcPtr == 0xbb) { // high-ASCII ';'
} else if (*srcPtr == 0xbb &&
(wasLineStart || *(srcPtr-1) == 0xa0)) {
// Found a high-ASCII ';' at the start of the line or right after
// a space. Semicolons can appear in the middle of macros, so
// we need the extra test to avoid introducing a column break.
//
// just comment, or comment on mnemonic w/o operand
// (shouldn't tab out if line started with label but
// contains 0x20s instead of 0xa0s between components;
@ -396,13 +405,10 @@ int ReformatMerlin::Process(const ReformatHolder* pHolder,
}
}
//done:
RTFEnd();
SetResultBuffer(pOutput);
retval = 0;
//bail:
return retval;
}