removing options

This commit is contained in:
Denis Molony 2021-01-21 21:02:45 +10:00
parent 78350ac7ac
commit 6a1f7043cb
5 changed files with 87 additions and 105 deletions

View File

@ -68,7 +68,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
sourceLines.add (line);
checkXref (line);
ptr += line.length;
ptr += line.length; // assumes lines are contiguous
currentAddress = nextAddress;
}
@ -115,18 +115,19 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
}
// ---------------------------------------------------------------------------------//
private void getAppleFormat (StringBuilder text)
private void getAppleFormat (StringBuilder fullText)
// ---------------------------------------------------------------------------------//
{
int loadAddress = getLoadAddress ();
int ptr = 0;
int nextLine;
byte b;
StringBuilder text = new StringBuilder ();
while ((nextLine = Utility.unsignedShort (buffer, ptr)) != 0)
{
int lineNumber = Utility.unsignedShort (buffer, ptr + 2);
text.append (String.format (" %5d ", lineNumber));
text.append (String.format (" %d ", lineNumber));
ptr += 4;
while ((b = buffer[ptr++]) != 0)
@ -144,6 +145,13 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
text.deleteCharAt (text.length () - 1);
break;
case Utility.ASCII_LF:
int indent = Utility.getIndent (text);
text.append ("\n");
for (int i = 0; i < indent; i++)
text.append (" ");
break;
default:
text.append ((char) b);
}
@ -154,6 +162,14 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
// ptr = nextLine - loadAddress;
}
text.append (NEWLINE);
// List<String> lines = wrap (text, 29);
// fullText.append (String.format ("%d %s%n", lineNumber, lines.get (0)));
// for (int i = 1; i < lines.size (); i++)
// fullText.append (String.format (" %s%n", lines.get (i)));
fullText.append (text);
text.setLength (0);
}
}
@ -167,12 +183,11 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
Stack<String> loopVariables = new Stack<> ();
int alignEqualsPos = 0;
StringBuilder text;
int baseOffset = basicPreferences.showTargets ? 12 : 8;
int baseOffset = 7; // 5 digit line number + 2 spaces
for (SourceLine line : sourceLines)
{
text = new StringBuilder (getBase (line) + " ");
StringBuilder text = new StringBuilder (String.format ("%5d", (line.lineNumber)));
int indent = loopVariables.size (); // each full line starts at the loop indent
int ifIndent = 0; // IF statement(s) limit back indentation by NEXT
@ -219,17 +234,8 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
fullText.deleteCharAt (fullText.length () - 1); // remove newline
fullText.append (" ");
}
else // ... otherwise do all the indenting and showing of targets etc.
else // ... otherwise do all the indenting
{
// Prepare target indicators for subsequent sublines (ie no line number)
if (basicPreferences.showTargets && !subline.isFirst ())
if (subline.is (TOKEN_GOSUB)
|| (subline.is (TOKEN_ON) && subline.has (TOKEN_GOSUB)))
text.append ("<<--");
else if (subline.is (TOKEN_GOTO) || subline.isImpliedGoto ()
|| (subline.is (TOKEN_ON) && subline.has (TOKEN_GOTO)))
text.append (" <--");
// Align assign statements if required
if (basicPreferences.alignAssign)
alignEqualsPos = alignEqualsPosition (subline, alignEqualsPos);
@ -242,15 +248,15 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
// Add the current text, then reset it
String lineText = subline.getAlignedText (alignEqualsPos);
if (subline.is (TOKEN_REM) && basicPreferences.deleteExtraRemSpace)
lineText = lineText.replaceFirst ("REM ", "REM ");
// if (subline.is (TOKEN_REM) && basicPreferences.deleteExtraRemSpace)
// lineText = lineText.replaceFirst ("REM ", "REM ");
if (subline.is (TOKEN_DATA) && basicPreferences.deleteExtraDataSpace)
lineText = lineText.replaceFirst ("DATA ", "DATA ");
// Check for a wrappable REM/DATA/DIM statement
// (see SEA BATTLE on DISK283.DSK)
int inset = Math.max (text.length (), getIndent (fullText)) + 1;
int inset = Math.max (text.length (), Utility.getIndent (fullText)) + 1;
if (subline.is (TOKEN_REM) && lineText.length () > basicPreferences.wrapRemAt)
{
List<String> lines = splitLine (lineText, basicPreferences.wrapRemAt, ' ');
@ -706,20 +712,6 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
}
}
// ---------------------------------------------------------------------------------//
private int getIndent (StringBuilder fullText)
// ---------------------------------------------------------------------------------//
{
int ptr = fullText.length () - 1;
int indent = 0;
while (ptr >= 0 && fullText.charAt (ptr) != '\n')
{
--ptr;
++indent;
}
return indent;
}
// ---------------------------------------------------------------------------------//
private int countChars (StringBuilder text, byte ch)
// ---------------------------------------------------------------------------------//
@ -731,45 +723,6 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
return total;
}
// ---------------------------------------------------------------------------------//
private String getBase (SourceLine line)
// ---------------------------------------------------------------------------------//
{
boolean isTarget = gotoLines.containsKey (line.lineNumber)
|| gosubLines.containsKey (line.lineNumber);
if (!basicPreferences.showTargets)
{
if (!isTarget && basicPreferences.onlyShowTargetLineNumbers)
return " ";
return String.format (" %5d", line.lineNumber);
}
String lineNumberText = String.format ("%5d", line.lineNumber);
SubLine subline = line.sublines.get (0);
String c1 = " ", c2 = " ";
if (subline.is (TOKEN_GOSUB) || (subline.is (TOKEN_ON) && subline.has (TOKEN_GOSUB)))
c1 = "<<";
else if (subline.is (TOKEN_GOTO)
|| (subline.is (TOKEN_ON) && subline.has (TOKEN_GOTO)))
c1 = " <";
if (gotoLines.containsKey (line.lineNumber))
c2 = "> ";
if (gosubLines.containsKey (line.lineNumber))
c2 = ">>";
if (c1.equals (" ") && !c2.equals (" "))
c1 = "--";
if (!c1.equals (" ") && c2.equals (" "))
c2 = "--";
if (!isTarget && basicPreferences.onlyShowTargetLineNumbers)
lineNumberText = "";
return String.format ("%s%s %s", c1, c2, lineNumberText);
}
// Decide whether the current subline needs to be aligned on its equals sign. If so,
// and the column hasn't been calculated, read ahead to find the highest position.
// ---------------------------------------------------------------------------------//

View File

@ -571,7 +571,15 @@ public class SubLine implements ApplesoftConstants
{
int ptr = startPtr + 1;
int max = startPtr + length - 1;
text.append ("REM ");
// apple format uses left-justified line numbers so the length varies
if (isFirst ())
{
text.setLength (0);
text.append (String.format (" %d REM ", parent.lineNumber));
}
else
text.append ("REM ");
while (ptr < max)
{
@ -586,6 +594,13 @@ public class SubLine implements ApplesoftConstants
text.append ("\n");
break;
case Utility.ASCII_LF:
int indent = Utility.getIndent (text);
text.append ("\n");
for (int i = 0; i < indent; i++)
text.append (" ");
break;
default:
text.append ((char) buffer[ptr]); // do not mask with 0xFF
}

View File

@ -9,13 +9,13 @@ public class BasicPreferences
public boolean showAllXref = true;
public boolean splitRem = false;
public boolean alignAssign = true;
public boolean showTargets = true;
public boolean onlyShowTargetLineNumbers = true;
// public boolean showTargets = true;
// public boolean onlyShowTargetLineNumbers = true;
public boolean showCaret = false;
public boolean showThen = true;
public boolean blankAfterReturn = false;
public boolean formatRem = false;
public boolean deleteExtraRemSpace = false;
// public boolean deleteExtraRemSpace = false;
public boolean deleteExtraDataSpace = false;
public boolean showXref = false;
public boolean showCalls = false;
@ -38,9 +38,9 @@ public class BasicPreferences
text.append (String.format ("Split REM ................ %s%n", splitRem));
text.append (String.format ("Align assign ............. %s%n", alignAssign));
text.append (String.format ("Show targets ............. %s%n", showTargets));
text.append (
String.format ("Only target lines ........ %s%n", onlyShowTargetLineNumbers));
// text.append (String.format ("Show targets ............. %s%n", showTargets));
// text.append (
// String.format ("Only target lines ........ %s%n", onlyShowTargetLineNumbers));
text.append (String.format ("Show header .............. %s%n", showHeader));
text.append (String.format ("Format applesoft ......... %s%n", formatApplesoft));
text.append (String.format ("Show All Xref ............ %s%n", showAllXref));
@ -55,7 +55,7 @@ public class BasicPreferences
// text.append (String.format ("List strings ............. %s%n", listStrings));
text.append (String.format ("Blank after RETURN ....... %s%n", blankAfterReturn));
text.append (String.format ("Format REM ............... %s%n", formatRem));
text.append (String.format ("Delete extra REM space ... %s%n", deleteExtraRemSpace));
// text.append (String.format ("Delete extra REM space ... %s%n", deleteExtraRemSpace));
text.append (String.format ("Delete extra DATA space .. %s%n", deleteExtraDataSpace));
text.append (String.format ("Wrap PRINT at ............ %d%n", wrapPrintAt));
text.append (String.format ("Wrap REM at .............. %d%n", wrapRemAt));

View File

@ -51,8 +51,8 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
private static final String PREFS_SPLIT_REMARKS = "splitRemarks";
private static final String PREFS_SPLIT_DIM = "splitDim";
private static final String PREFS_ALIGN_ASSIGN = "alignAssign";
private static final String PREFS_SHOW_TARGETS = "showTargets";
private static final String PREFS_ONLY_SHOW_TARGETS = "onlyShowTargets";
// private static final String PREFS_SHOW_TARGETS = "showTargets";
// private static final String PREFS_ONLY_SHOW_TARGETS = "onlyShowTargets";
private static final String PREFS_SHOW_CARET = "showCaret";
private static final String PREFS_SHOW_THEN = "showThen";
private static final String PREFS_SHOW_XREF = "showXref";
@ -64,7 +64,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
// private static final String PREFS_LIST_STRINGS = "listStrings";
private static final String PREFS_BLANK_AFTER_RETURN = "blankAfterReturn";
private static final String PREFS_FORMAT_REM = "formatRem";
private static final String PREFS_DELETE_EXTRA_REM_SPACE = "deleteExtraRemSpace";
// private static final String PREFS_DELETE_EXTRA_REM_SPACE = "deleteExtraRemSpace";
private static final String PREFS_DELETE_EXTRA_DATA_SPACE = "deleteExtraDataSpace";
private static final String PREFS_SHOW_ASSEMBLER_TARGETS = "showAssemblerTargets";
@ -152,15 +152,15 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
final JMenuItem splitRemarkItem = new JCheckBoxMenuItem ("Split remarks");
final JMenuItem splitDimItem = new JCheckBoxMenuItem ("Split DIM");
final JMenuItem alignAssignItem = new JCheckBoxMenuItem ("Align consecutive assign");
final JMenuItem showBasicTargetsItem = new JCheckBoxMenuItem ("Show targets");
final JMenuItem onlyShowTargetLinesItem =
new JCheckBoxMenuItem ("Only show target line numbers");
// final JMenuItem showBasicTargetsItem = new JCheckBoxMenuItem ("Show targets");
// final JMenuItem onlyShowTargetLinesItem =
// new JCheckBoxMenuItem ("Only show target line numbers");
final JMenuItem showCaretItem = new JCheckBoxMenuItem ("Show caret");
final JMenuItem showThenItem = new JCheckBoxMenuItem ("Show THEN after IF");
final JMenuItem blankAfterReturnItem =
new JCheckBoxMenuItem ("Blank line after RETURN");
final JMenuItem formatRemItem = new JCheckBoxMenuItem ("Allow formatted REM");
final JMenuItem deleteExtraRemSpace = new JCheckBoxMenuItem ("Delete extra REM space");
// final JMenuItem deleteExtraRemSpace = new JCheckBoxMenuItem ("Delete extra REM space");
final JMenuItem deleteExtraDataSpace =
new JCheckBoxMenuItem ("Delete extra DATA space");
@ -267,13 +267,13 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
applesoftMenu.add (splitRemarkItem);
applesoftMenu.add (splitDimItem);
applesoftMenu.add (alignAssignItem);
applesoftMenu.add (showBasicTargetsItem);
applesoftMenu.add (onlyShowTargetLinesItem);
// applesoftMenu.add (showBasicTargetsItem);
// applesoftMenu.add (onlyShowTargetLinesItem);
applesoftMenu.add (showCaretItem);
applesoftMenu.add (showThenItem);
applesoftMenu.add (blankAfterReturnItem);
applesoftMenu.add (formatRemItem);
applesoftMenu.add (deleteExtraRemSpace);
// applesoftMenu.add (deleteExtraRemSpace);
applesoftMenu.add (deleteExtraDataSpace);
applesoftMenu.addSeparator ();
applesoftMenu.add (showXrefItem);
@ -293,10 +293,9 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
prodosMenu.add (prodosSortDirectoriesItem);
applesoftFormatItems = new ArrayList<> (Arrays.asList (splitRemarkItem, splitDimItem,
alignAssignItem, showBasicTargetsItem, onlyShowTargetLinesItem, showCaretItem,
showThenItem, blankAfterReturnItem, formatRemItem, deleteExtraRemSpace,
deleteExtraDataSpace));
applesoftFormatItems = new ArrayList<> (
Arrays.asList (splitRemarkItem, splitDimItem, alignAssignItem, showCaretItem,
showThenItem, blankAfterReturnItem, formatRemItem, deleteExtraDataSpace));
applesoftXrefItems = new ArrayList<> (Arrays.asList (showXrefItem, showCallsItem,
showSymbolsItem, showFunctionsItem, showConstantsItem, showDuplicateSymbolsItem));
@ -399,13 +398,13 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
basicPreferences.splitRem = splitRemarkItem.isSelected ();
basicPreferences.splitDim = splitDimItem.isSelected ();
basicPreferences.alignAssign = alignAssignItem.isSelected ();
basicPreferences.showTargets = showBasicTargetsItem.isSelected ();
basicPreferences.onlyShowTargetLineNumbers = onlyShowTargetLinesItem.isSelected ();
// basicPreferences.showTargets = showBasicTargetsItem.isSelected ();
// basicPreferences.onlyShowTargetLineNumbers = onlyShowTargetLinesItem.isSelected ();
basicPreferences.showCaret = showCaretItem.isSelected ();
basicPreferences.showThen = showThenItem.isSelected ();
basicPreferences.blankAfterReturn = blankAfterReturnItem.isSelected ();
basicPreferences.formatRem = formatRemItem.isSelected ();
basicPreferences.deleteExtraRemSpace = deleteExtraRemSpace.isSelected ();
// basicPreferences.deleteExtraRemSpace = deleteExtraRemSpace.isSelected ();
basicPreferences.deleteExtraDataSpace = deleteExtraDataSpace.isSelected ();
basicPreferences.showXref = showXrefItem.isSelected ();
@ -585,11 +584,11 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
prefs.putBoolean (PREFS_SHOW_DUPLICATE_SYMBOLS,
showDuplicateSymbolsItem.isSelected ());
// prefs.putBoolean (PREFS_LIST_STRINGS, listStringsItem.isSelected ());
prefs.putBoolean (PREFS_SHOW_TARGETS, showBasicTargetsItem.isSelected ());
prefs.putBoolean (PREFS_ONLY_SHOW_TARGETS, onlyShowTargetLinesItem.isSelected ());
// prefs.putBoolean (PREFS_SHOW_TARGETS, showBasicTargetsItem.isSelected ());
// prefs.putBoolean (PREFS_ONLY_SHOW_TARGETS, onlyShowTargetLinesItem.isSelected ());
prefs.putBoolean (PREFS_BLANK_AFTER_RETURN, blankAfterReturnItem.isSelected ());
prefs.putBoolean (PREFS_FORMAT_REM, formatRemItem.isSelected ());
prefs.putBoolean (PREFS_DELETE_EXTRA_REM_SPACE, deleteExtraRemSpace.isSelected ());
// prefs.putBoolean (PREFS_DELETE_EXTRA_REM_SPACE, deleteExtraRemSpace.isSelected ());
prefs.putBoolean (PREFS_DELETE_EXTRA_DATA_SPACE, deleteExtraDataSpace.isSelected ());
prefs.putBoolean (PREFS_SHOW_ASSEMBLER_TARGETS,
@ -647,13 +646,13 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
showDuplicateSymbolsItem
.setSelected (prefs.getBoolean (PREFS_SHOW_DUPLICATE_SYMBOLS, false));
// listStringsItem.setSelected (prefs.getBoolean (PREFS_LIST_STRINGS, false));
showBasicTargetsItem.setSelected (prefs.getBoolean (PREFS_SHOW_TARGETS, false));
onlyShowTargetLinesItem
.setSelected (prefs.getBoolean (PREFS_ONLY_SHOW_TARGETS, false));
// showBasicTargetsItem.setSelected (prefs.getBoolean (PREFS_SHOW_TARGETS, false));
// onlyShowTargetLinesItem
// .setSelected (prefs.getBoolean (PREFS_ONLY_SHOW_TARGETS, false));
blankAfterReturnItem.setSelected (prefs.getBoolean (PREFS_BLANK_AFTER_RETURN, false));
formatRemItem.setSelected (prefs.getBoolean (PREFS_FORMAT_REM, false));
deleteExtraRemSpace
.setSelected (prefs.getBoolean (PREFS_DELETE_EXTRA_REM_SPACE, false));
// deleteExtraRemSpace
// .setSelected (prefs.getBoolean (PREFS_DELETE_EXTRA_REM_SPACE, false));
deleteExtraDataSpace
.setSelected (prefs.getBoolean (PREFS_DELETE_EXTRA_DATA_SPACE, false));

View File

@ -18,6 +18,7 @@ public class Utility
// -----------------------------------------------------------------------------------//
{
public static final byte ASCII_BACKSPACE = 0x08;
public static final byte ASCII_LF = 0x0A;
public static final byte ASCII_CR = 0x0D;
public static final byte ASCII_QUOTE = 0x22;
public static final byte ASCII_DOLLAR = 0x24;
@ -59,6 +60,20 @@ public class Utility
return text.toString ();
}
// ---------------------------------------------------------------------------------//
public static int getIndent (StringBuilder fullText)
// ---------------------------------------------------------------------------------//
{
int ptr = fullText.length () - 1;
int indent = 0;
while (ptr >= 0 && fullText.charAt (ptr) != '\n')
{
--ptr;
++indent;
}
return indent;
}
// ---------------------------------------------------------------------------------//
public static int getLong (byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------//