tidying
This commit is contained in:
parent
5e133715cd
commit
62bf355ca3
Binary file not shown.
Before Width: | Height: | Size: 724 KiB After Width: | Height: | Size: 1.1 MiB |
|
@ -26,7 +26,7 @@ public class AppleBasicFormatter extends BasicFormatter
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
@Override
|
||||||
public void format (StringBuilder fullText)
|
public void append (StringBuilder fullText)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
int loadAddress = getLoadAddress ();
|
int loadAddress = getLoadAddress ();
|
||||||
|
@ -42,26 +42,22 @@ public class AppleBasicFormatter extends BasicFormatter
|
||||||
ptr += 4;
|
ptr += 4;
|
||||||
|
|
||||||
if (basicPreferences.appleLineWrap)
|
if (basicPreferences.appleLineWrap)
|
||||||
ptr = appendWithWrap (currentLine, ptr);
|
ptr = wrapLine (currentLine, ptr);
|
||||||
else
|
else
|
||||||
ptr = appendWithOutWrap (currentLine, ptr);
|
ptr = flatLine (currentLine, ptr);
|
||||||
|
|
||||||
if (ptr != (linkField - loadAddress))
|
if (ptr != (linkField - loadAddress))
|
||||||
{
|
|
||||||
System.out.printf ("%s: ptr: %04X, nextLine: %04X%n", program.name,
|
System.out.printf ("%s: ptr: %04X, nextLine: %04X%n", program.name,
|
||||||
ptr + loadAddress, linkField);
|
ptr + loadAddress, linkField);
|
||||||
// ptr = linkField - loadAddress; // use this when tested
|
|
||||||
}
|
|
||||||
|
|
||||||
currentLine.append (NEWLINE);
|
currentLine.append (NEWLINE);
|
||||||
|
|
||||||
fullText.append (currentLine);
|
fullText.append (currentLine);
|
||||||
currentLine.setLength (0);
|
currentLine.setLength (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
private int appendWithOutWrap (StringBuilder currentLine, int ptr)
|
private int flatLine (StringBuilder currentLine, int ptr)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
byte b;
|
byte b;
|
||||||
|
@ -99,11 +95,11 @@ public class AppleBasicFormatter extends BasicFormatter
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
private int appendWithWrap (StringBuilder currentLine, int ptr)
|
private int wrapLine (StringBuilder currentLine, int ptr)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
byte b;
|
byte b;
|
||||||
int cursor = currentLine.length (); // controls when to wrap
|
int cursor = currentLine.length ();
|
||||||
|
|
||||||
while ((b = buffer[ptr++]) != 0)
|
while ((b = buffer[ptr++]) != 0)
|
||||||
if (isHighBitSet (b))
|
if (isHighBitSet (b))
|
||||||
|
|
|
@ -46,11 +46,11 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
|
||||||
StringBuilder text = new StringBuilder ();
|
StringBuilder text = new StringBuilder ();
|
||||||
|
|
||||||
if (basicPreferences.showHeader)
|
if (basicPreferences.showHeader)
|
||||||
headerFormatter.format (text);
|
headerFormatter.append (text);
|
||||||
|
|
||||||
if (showDebugText)
|
if (showDebugText)
|
||||||
{
|
{
|
||||||
debugBasicFormatter.format (text);
|
debugBasicFormatter.append (text);
|
||||||
return Utility.rtrim (text);
|
return Utility.rtrim (text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,12 +61,12 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
|
||||||
}
|
}
|
||||||
|
|
||||||
if (basicPreferences.userFormat)
|
if (basicPreferences.userFormat)
|
||||||
userBasicFormatter.format (text);
|
userBasicFormatter.append (text);
|
||||||
else
|
else
|
||||||
appleBasicFormatter.format (text);
|
appleBasicFormatter.append (text);
|
||||||
|
|
||||||
if (basicPreferences.showAllXref)
|
if (basicPreferences.showAllXref)
|
||||||
xrefFormatter.format (text);
|
xrefFormatter.append (text);
|
||||||
|
|
||||||
return Utility.rtrim (text);
|
return Utility.rtrim (text);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ public abstract class BasicFormatter implements ApplesoftConstants
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
public abstract void format (StringBuilder fullText);
|
public abstract void append (StringBuilder fullText);
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class DebugBasicFormatter extends BasicFormatter
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
@Override
|
||||||
public void format (StringBuilder text)
|
public void append (StringBuilder text)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
int loadAddress = getLoadAddress ();
|
int loadAddress = getLoadAddress ();
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class HeaderFormatter extends BasicFormatter
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
@Override
|
||||||
public void format (StringBuilder fullText)
|
public void append (StringBuilder fullText)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
fullText.append ("Name : " + program.name + "\n");
|
fullText.append ("Name : " + program.name + "\n");
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.bytezone.diskbrowser.applefile;
|
package com.bytezone.diskbrowser.applefile;
|
||||||
|
|
||||||
|
import static com.bytezone.diskbrowser.utilities.Utility.ASCII_COLON;
|
||||||
|
import static com.bytezone.diskbrowser.utilities.Utility.ASCII_QUOTE;
|
||||||
import static com.bytezone.diskbrowser.utilities.Utility.unsignedShort;
|
import static com.bytezone.diskbrowser.utilities.Utility.unsignedShort;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -11,7 +13,7 @@ import com.bytezone.diskbrowser.utilities.Utility;
|
||||||
public class SourceLine implements ApplesoftConstants
|
public class SourceLine implements ApplesoftConstants
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
ApplesoftBasicProgram parent;
|
ApplesoftBasicProgram program;
|
||||||
int linkField;
|
int linkField;
|
||||||
int lineNumber;
|
int lineNumber;
|
||||||
int linePtr;
|
int linePtr;
|
||||||
|
@ -21,17 +23,17 @@ public class SourceLine implements ApplesoftConstants
|
||||||
List<SubLine> sublines = new ArrayList<> ();
|
List<SubLine> sublines = new ArrayList<> ();
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
SourceLine (ApplesoftBasicProgram parent, byte[] buffer, int ptr)
|
SourceLine (ApplesoftBasicProgram program, byte[] buffer, int ptr)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
this.parent = parent;
|
this.program = program;
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
|
|
||||||
linePtr = ptr;
|
linePtr = ptr;
|
||||||
linkField = unsignedShort (buffer, ptr);
|
linkField = unsignedShort (buffer, ptr);
|
||||||
lineNumber = unsignedShort (buffer, ptr + 2);
|
lineNumber = unsignedShort (buffer, ptr + 2);
|
||||||
|
|
||||||
int startPtr = ptr += 4; // skip link to next line and lineNumber
|
int startPtr = ptr += 4; // skip link field and lineNumber
|
||||||
boolean inString = false; // can toggle
|
boolean inString = false; // can toggle
|
||||||
boolean inRemark = false; // can only go false -> true
|
boolean inRemark = false; // can only go false -> true
|
||||||
byte b;
|
byte b;
|
||||||
|
@ -43,7 +45,7 @@ public class SourceLine implements ApplesoftConstants
|
||||||
|
|
||||||
if (inString)
|
if (inString)
|
||||||
{
|
{
|
||||||
if (b == Utility.ASCII_QUOTE) // terminate string
|
if (b == ASCII_QUOTE) // terminate string
|
||||||
inString = false;
|
inString = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -51,36 +53,28 @@ public class SourceLine implements ApplesoftConstants
|
||||||
switch (b)
|
switch (b)
|
||||||
{
|
{
|
||||||
// break IF statements into two sublines (allows for easier line indenting)
|
// break IF statements into two sublines (allows for easier line indenting)
|
||||||
case ApplesoftConstants.TOKEN_IF:
|
case TOKEN_IF:
|
||||||
// skip to THEN or GOTO - if not found then it's an error
|
|
||||||
while (buffer[ptr] != TOKEN_THEN && buffer[ptr] != TOKEN_GOTO
|
while (buffer[ptr] != TOKEN_THEN && buffer[ptr] != TOKEN_GOTO
|
||||||
&& buffer[ptr] != 0)
|
&& buffer[ptr] != 0)
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
// keep THEN with the IF
|
if (buffer[ptr] == TOKEN_THEN) // keep THEN with the IF
|
||||||
if (buffer[ptr] == TOKEN_THEN)
|
|
||||||
++ptr;
|
++ptr;
|
||||||
|
|
||||||
// create subline from the condition (plus THEN if it exists)
|
startPtr = addSubLine (startPtr, ptr); // create subline from the condition
|
||||||
sublines.add (new SubLine (this, startPtr, ptr - startPtr));
|
|
||||||
startPtr = ptr;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// end of subline, so add it, advance startPtr and continue
|
case ASCII_COLON: // end of subline
|
||||||
case Utility.ASCII_COLON:
|
startPtr = addSubLine (startPtr, ptr);
|
||||||
sublines.add (new SubLine (this, startPtr, ptr - startPtr));
|
|
||||||
startPtr = ptr;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOKEN_REM:
|
case TOKEN_REM:
|
||||||
if (ptr == startPtr + 1)
|
if (ptr == startPtr + 1) // at start of line
|
||||||
inRemark = true;
|
inRemark = true;
|
||||||
else
|
else // mid-line - should be illegal
|
||||||
{ // REM appears mid-line (should follow a colon)
|
{
|
||||||
System.out.printf ("%5d %s%n", lineNumber, "mid-line REM token");
|
System.out.printf ("%s : %5d mid-line REM token%n", program.name, lineNumber);
|
||||||
ptr--; // point back to this REM
|
startPtr = addSubLine (startPtr, --ptr); // point back to the REM
|
||||||
sublines.add (new SubLine (this, startPtr, ptr - startPtr));
|
|
||||||
startPtr = ptr;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -92,9 +86,14 @@ public class SourceLine implements ApplesoftConstants
|
||||||
|
|
||||||
length = ptr - linePtr;
|
length = ptr - linePtr;
|
||||||
|
|
||||||
// add whatever is left after the last colon
|
addSubLine (startPtr, ptr);
|
||||||
// if no colon was found this is the entire line
|
}
|
||||||
int bytesLeft = ptr - startPtr;
|
|
||||||
sublines.add (new SubLine (this, startPtr, bytesLeft));
|
// ---------------------------------------------------------------------------------//
|
||||||
|
private int addSubLine (int startPtr, int ptr)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
{
|
||||||
|
sublines.add (new SubLine (this, startPtr, ptr - startPtr));
|
||||||
|
return ptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;;
|
||||||
public class SubLine implements ApplesoftConstants
|
public class SubLine implements ApplesoftConstants
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
SourceLine parent;
|
SourceLine sourceLine;
|
||||||
|
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
int startPtr;
|
int startPtr;
|
||||||
|
@ -57,13 +57,13 @@ public class SubLine implements ApplesoftConstants
|
||||||
private final List<String> stringsText = new ArrayList<> ();
|
private final List<String> stringsText = new ArrayList<> ();
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
SubLine (SourceLine parent, int startPtr, int length)
|
SubLine (SourceLine sourceLine, int offset, int length)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
this.parent = parent;
|
this.sourceLine = sourceLine;
|
||||||
this.startPtr = startPtr;
|
this.startPtr = offset;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.buffer = parent.buffer;
|
this.buffer = sourceLine.buffer;
|
||||||
|
|
||||||
int ptr = startPtr;
|
int ptr = startPtr;
|
||||||
byte firstByte = buffer[startPtr];
|
byte firstByte = buffer[startPtr];
|
||||||
|
@ -91,8 +91,9 @@ public class SubLine implements ApplesoftConstants
|
||||||
else if (isEndOfLine (firstByte)) // empty subline
|
else if (isEndOfLine (firstByte)) // empty subline
|
||||||
return;
|
return;
|
||||||
else // probably Beagle Bros 0D or 0A
|
else // probably Beagle Bros 0D or 0A
|
||||||
System.out.printf ("%s unexpected bytes at line %5d:%n%s%n", parent.parent.name,
|
System.out.printf ("%s unexpected bytes at line %5d:%n%s%n",
|
||||||
parent.lineNumber, HexFormatter.formatNoHeader (buffer, startPtr, length));
|
sourceLine.program.name, sourceLine.lineNumber,
|
||||||
|
HexFormatter.formatNoHeader (buffer, startPtr, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
String var = "";
|
String var = "";
|
||||||
|
@ -102,11 +103,11 @@ public class SubLine implements ApplesoftConstants
|
||||||
boolean inDefine = false;
|
boolean inDefine = false;
|
||||||
int stringPtr = 0;
|
int stringPtr = 0;
|
||||||
|
|
||||||
int max = startPtr + length - 1;
|
int endOfLine = startPtr + length - 1;
|
||||||
while (isEndOfLine (buffer[max]))
|
while (isEndOfLine (buffer[endOfLine])) // zero or colon
|
||||||
--max;
|
--endOfLine;
|
||||||
|
|
||||||
while (ptr <= max)
|
while (ptr <= endOfLine)
|
||||||
{
|
{
|
||||||
byte b = buffer[ptr++];
|
byte b = buffer[ptr++];
|
||||||
|
|
||||||
|
@ -484,7 +485,7 @@ public class SubLine implements ApplesoftConstants
|
||||||
boolean isFirst ()
|
boolean isFirst ()
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
return (parent.linePtr + 4) == startPtr;
|
return (sourceLine.linePtr + 4) == startPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@ -564,7 +565,7 @@ public class SubLine implements ApplesoftConstants
|
||||||
{
|
{
|
||||||
// apple format uses left-justified line numbers so the length varies
|
// apple format uses left-justified line numbers so the length varies
|
||||||
text.setLength (0);
|
text.setLength (0);
|
||||||
text.append (String.format (" %d REM ", parent.lineNumber)); // mimic apple
|
text.append (String.format (" %d REM ", sourceLine.lineNumber)); // mimic apple
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
text.append (" REM ");
|
text.append (" REM ");
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class UserBasicFormatter extends BasicFormatter
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
@Override
|
||||||
public void format (StringBuilder fullText)
|
public void append (StringBuilder fullText)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
boolean insertBlankLine = false;
|
boolean insertBlankLine = false;
|
||||||
|
@ -254,7 +254,7 @@ public class UserBasicFormatter extends BasicFormatter
|
||||||
boolean started = false;
|
boolean started = false;
|
||||||
alignment.setFirst (startSubline);
|
alignment.setFirst (startSubline);
|
||||||
|
|
||||||
outerLoop: for (int i = sourceLines.indexOf (startSubline.parent); i < sourceLines
|
outerLoop: for (int i = sourceLines.indexOf (startSubline.sourceLine); i < sourceLines
|
||||||
.size (); i++)
|
.size (); i++)
|
||||||
{
|
{
|
||||||
boolean precededByIf = false;
|
boolean precededByIf = false;
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class XrefFormatter extends BasicFormatter
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
@Override
|
||||||
public void format (StringBuilder fullText)
|
public void append (StringBuilder fullText)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
if (basicPreferences.showSymbols)
|
if (basicPreferences.showSymbols)
|
||||||
|
|
Loading…
Reference in New Issue