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

View File

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

View File

@ -330,7 +330,6 @@ int ReformatMerlin::Process(const ReformatHolder* pHolder,
{ {
const uint8_t* srcPtr = pHolder->GetSourceBuf(part); const uint8_t* srcPtr = pHolder->GetSourceBuf(part);
long srcLen = pHolder->GetSourceLen(part); long srcLen = pHolder->GetSourceLen(part);
long length = srcLen;
int retval = -1; int retval = -1;
enum { kStateLabel, kStateMnemonic, kStateOperand, kStateComment }; enum { kStateLabel, kStateMnemonic, kStateOperand, kStateComment };
int tabStop[] = { 0, 9, 15, 26 }; // 1:1 map with state enum int tabStop[] = { 0, 9, 15, 26 }; // 1:1 map with state enum
@ -343,12 +342,16 @@ int ReformatMerlin::Process(const ReformatHolder* pHolder,
bool isLineStart = true; bool isLineStart = true;
for ( ; srcLen > 0; srcLen--, srcPtr++) { for ( ; srcLen > 0; srcLen--, srcPtr++) {
bool wasLineStart = false;
if (isLineStart) { if (isLineStart) {
isLineStart = false; isLineStart = false;
wasLineStart = true;
OutputStart(); // begin new line in output buffer OutputStart(); // begin new line in output buffer
state = kStateLabel; state = kStateLabel;
if (*srcPtr == 0xaa) if (*srcPtr == 0xaa) {
// leading '*' makes entire line a comment
state = kStateComment; state = kStateComment;
}
} }
if (*srcPtr == 0x8d) { if (*srcPtr == 0x8d) {
OutputFinish(); // end of line OutputFinish(); // end of line
@ -358,6 +361,7 @@ int ReformatMerlin::Process(const ReformatHolder* pHolder,
isLineStart = true; isLineStart = true;
if (quoteChar != '\0') { if (quoteChar != '\0') {
// unterminated quote
DebugBreak(); DebugBreak();
quoteChar = '\0'; quoteChar = '\0';
} }
@ -383,7 +387,12 @@ int ReformatMerlin::Process(const ReformatHolder* pHolder,
// Merlin-16 v3.40 // Merlin-16 v3.40
state++; state++;
OutputTab(tabStop[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 // just comment, or comment on mnemonic w/o operand
// (shouldn't tab out if line started with label but // (shouldn't tab out if line started with label but
// contains 0x20s instead of 0xa0s between components; // contains 0x20s instead of 0xa0s between components;
@ -396,13 +405,10 @@ int ReformatMerlin::Process(const ReformatHolder* pHolder,
} }
} }
//done:
RTFEnd(); RTFEnd();
SetResultBuffer(pOutput); SetResultBuffer(pOutput);
retval = 0; retval = 0;
//bail:
return retval; return retval;
} }