mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-12-28 19:32:42 +00:00
List applesoft strings
This commit is contained in:
parent
14888c22e8
commit
1e27aafde0
@ -31,6 +31,8 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
private final int endPtr;
|
||||
private final Map<Integer, List<Integer>> gotoLines = new TreeMap<> ();
|
||||
private final Map<Integer, List<Integer>> gosubLines = new TreeMap<> ();
|
||||
private final List<Integer> stringsLine = new ArrayList<> ();
|
||||
private final List<String> stringsText = new ArrayList<> ();
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public ApplesoftBasicProgram (String name, byte[] buffer)
|
||||
@ -70,7 +72,6 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
{
|
||||
int indentSize = 2;
|
||||
boolean insertBlankLine = false;
|
||||
boolean showGosubs = true;
|
||||
|
||||
StringBuilder fullText = new StringBuilder ();
|
||||
Stack<String> loopVariables = new Stack<> ();
|
||||
@ -253,13 +254,14 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
fullText.append ("\nExtra data:\n\n");
|
||||
fullText.append (HexFormatter.formatNoHeader (buffer, ptr, buffer.length - ptr,
|
||||
programLoadAddress + ptr));
|
||||
fullText.append ("\n");
|
||||
}
|
||||
|
||||
if (basicPreferences.showXref && !gosubLines.isEmpty ())
|
||||
{
|
||||
if (fullText.charAt (fullText.length () - 2) != '\n')
|
||||
fullText.append ("\n");
|
||||
fullText.append ("Subroutine:\n");
|
||||
fullText.append ("GOSUB:\n");
|
||||
for (Integer line : gosubLines.keySet ())
|
||||
fullText.append (String.format (" %5s %s%n", line, gosubLines.get (line)));
|
||||
}
|
||||
@ -268,11 +270,23 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
{
|
||||
if (fullText.charAt (fullText.length () - 2) != '\n')
|
||||
fullText.append ("\n");
|
||||
fullText.append ("GoTo:\n");
|
||||
fullText.append ("GOTO:\n");
|
||||
for (Integer line : gotoLines.keySet ())
|
||||
fullText.append (String.format (" %5s %s%n", line, gotoLines.get (line)));
|
||||
}
|
||||
|
||||
if (basicPreferences.listStrings && stringsLine.size () > 0)
|
||||
{
|
||||
if (fullText.charAt (fullText.length () - 2) != '\n')
|
||||
fullText.append ("\n");
|
||||
fullText.append ("Strings:\n");
|
||||
for (int i = 0; i < stringsLine.size (); i++)
|
||||
{
|
||||
fullText.append (
|
||||
String.format (" %5s %s%n", stringsLine.get (i), stringsText.get (i)));
|
||||
}
|
||||
}
|
||||
|
||||
if (fullText.length () > 0)
|
||||
while (fullText.charAt (fullText.length () - 1) == '\n')
|
||||
fullText.deleteCharAt (fullText.length () - 1); // remove trailing newlines
|
||||
@ -595,6 +609,7 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
boolean inString = false; // can toggle
|
||||
boolean inRemark = false; // can only go false -> true
|
||||
byte b;
|
||||
int stringPtr = 0;
|
||||
|
||||
while (ptr < buffer.length && (b = buffer[ptr++]) != 0)
|
||||
{
|
||||
@ -604,7 +619,12 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
if (inString)
|
||||
{
|
||||
if (b == ASCII_QUOTE) // terminate string
|
||||
{
|
||||
inString = false;
|
||||
String s = new String (buffer, stringPtr - 1, ptr - stringPtr + 1);
|
||||
stringsText.add (s);
|
||||
stringsLine.add (lineNumber);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -648,6 +668,7 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
|
||||
case ASCII_QUOTE:
|
||||
inString = true;
|
||||
stringPtr = ptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -667,10 +688,7 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
int length;
|
||||
String[] nextVariables;
|
||||
String forVariable = "";
|
||||
int targetLine = -1;
|
||||
|
||||
// used for aligning the equals sign
|
||||
int assignEqualPos;
|
||||
int assignEqualPos; // used for aligning the equals sign
|
||||
|
||||
SubLine (SourceLine parent, int startPtr, int length)
|
||||
{
|
||||
@ -704,13 +722,13 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
break;
|
||||
|
||||
case TOKEN_GOTO:
|
||||
String target = new String (buffer, startPtr + 1, length - 2);
|
||||
addXref (target, gotoLines);
|
||||
int targetLine = getLineNumber (buffer, startPtr + 1);
|
||||
addXref (targetLine, gotoLines);
|
||||
break;
|
||||
|
||||
case TOKEN_GOSUB:
|
||||
target = new String (buffer, startPtr + 1, length - 2);
|
||||
addXref (target, gosubLines);
|
||||
targetLine = getLineNumber (buffer, startPtr + 1);
|
||||
addXref (targetLine, gosubLines);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -718,38 +736,36 @@ public class ApplesoftBasicProgram extends BasicProgram
|
||||
{
|
||||
if (isDigit (b)) // numeric, so must be a line number
|
||||
{
|
||||
String target = new String (buffer, startPtr, length - 1);
|
||||
addXref (target, gotoLines);
|
||||
int targetLine = getLineNumber (buffer, startPtr);
|
||||
addXref (targetLine, gotoLines);
|
||||
}
|
||||
else
|
||||
recordEqualsPosition ();
|
||||
}
|
||||
}
|
||||
|
||||
private void addXref (String target, Map<Integer, List<Integer>> map)
|
||||
private int getLineNumber (byte[] buffer, int offset)
|
||||
{
|
||||
try
|
||||
int lineNumber = 0;
|
||||
while (offset < buffer.length)
|
||||
{
|
||||
targetLine = Integer.parseInt (target);
|
||||
if (map.containsKey (targetLine))
|
||||
int b = (buffer[offset++] & 0xFF) - 0x30;
|
||||
if (b < 0 || b > 9)
|
||||
break;
|
||||
lineNumber = lineNumber * 10 + b;
|
||||
}
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
private void addXref (int targetLine, Map<Integer, List<Integer>> map)
|
||||
{
|
||||
List<Integer> lines = map.get (targetLine);
|
||||
lines.add (parent.lineNumber);
|
||||
}
|
||||
else
|
||||
if (lines == null)
|
||||
{
|
||||
List<Integer> lines = new ArrayList<> ();
|
||||
lines.add (parent.lineNumber);
|
||||
lines = new ArrayList<> ();
|
||||
map.put (targetLine, lines);
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
// System.out.printf ("b: %d, start: %d, length: %d%n", b, startPtr, (length - 1));
|
||||
System.out.println (target);
|
||||
System.out.println (HexFormatter.format (buffer, startPtr, length - 1));
|
||||
System.out.println (e);
|
||||
}
|
||||
lines.add (parent.lineNumber);
|
||||
}
|
||||
|
||||
private boolean isImpliedGoto ()
|
||||
|
@ -11,6 +11,7 @@ public class BasicPreferences
|
||||
public boolean onlyShowTargetLineNumbers = true;
|
||||
public boolean showCaret = false;
|
||||
public boolean showThen = true;
|
||||
public boolean listStrings = false;
|
||||
public boolean blankAfterReturn = false;
|
||||
public boolean deleteExtraRemSpace = false;
|
||||
public boolean deleteExtraDataSpace = false;
|
||||
@ -35,6 +36,7 @@ public class BasicPreferences
|
||||
text.append (String.format ("Show caret ............... %s%n", showCaret));
|
||||
text.append (String.format ("Show THEN ................ %s%n", showThen));
|
||||
text.append (String.format ("Show Xref ................ %s%n", showXref));
|
||||
text.append (String.format ("List strings ............. %s%n", listStrings));
|
||||
text.append (String.format ("Blank after RETURN ....... %s%n", blankAfterReturn));
|
||||
text.append (String.format ("Delete extra REM space ... %s%n", deleteExtraRemSpace));
|
||||
text.append (String.format ("Delete extra DATA space .. %s%n", deleteExtraDataSpace));
|
||||
|
@ -25,8 +25,8 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AppleFileSource;
|
||||
import com.bytezone.diskbrowser.disk.HybridDisk;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.disk.HybridDisk;
|
||||
import com.bytezone.diskbrowser.duplicates.DiskDetails;
|
||||
import com.bytezone.diskbrowser.gui.DuplicateAction.DiskTableSelectionListener;
|
||||
import com.bytezone.diskbrowser.gui.FontAction.FontChangeEvent;
|
||||
|
@ -50,6 +50,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
private static final String PREFS_SHOW_CARET = "showCaret";
|
||||
private static final String PREFS_SHOW_THEN = "showThen";
|
||||
private static final String PREFS_SHOW_XREF = "showXref";
|
||||
private static final String PREFS_LIST_STRINGS = "listStrings";
|
||||
private static final String PREFS_BLANK_AFTER_RETURN = "blankAfterReturn";
|
||||
private static final String PREFS_DELETE_EXTRA_REM_SPACE = "deleteExtraRemSpace";
|
||||
private static final String PREFS_DELETE_EXTRA_DATA_SPACE = "deleteExtraDataSpace";
|
||||
@ -138,6 +139,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
final JMenuItem showCaretItem = new JCheckBoxMenuItem ("Show caret");
|
||||
final JMenuItem showThenItem = new JCheckBoxMenuItem ("Show THEN after IF");
|
||||
final JMenuItem showXrefItem = new JCheckBoxMenuItem ("Show Xref");
|
||||
final JMenuItem listStringsItem = new JCheckBoxMenuItem ("List strings");
|
||||
final JMenuItem blankAfterReturn = new JCheckBoxMenuItem ("Blank line after RETURN");
|
||||
final JMenuItem deleteExtraRemSpace = new JCheckBoxMenuItem ("Delete extra REM space");
|
||||
final JMenuItem deleteExtraDataSpace =
|
||||
@ -145,7 +147,8 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
|
||||
// Assembler menu items
|
||||
final JMenuItem showAssemblerTargetsItem = new JCheckBoxMenuItem ("Show targets");
|
||||
final JMenuItem showAssemblerStringsItem = new JCheckBoxMenuItem ("Show strings");
|
||||
final JMenuItem showAssemblerStringsItem =
|
||||
new JCheckBoxMenuItem ("List possible strings");
|
||||
final JMenuItem showAssemblerHeaderItem = new JCheckBoxMenuItem ("Show header");
|
||||
|
||||
// Prodos menu items
|
||||
@ -237,6 +240,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
applesoftMenu.add (showCaretItem);
|
||||
applesoftMenu.add (showThenItem);
|
||||
applesoftMenu.add (showXrefItem);
|
||||
applesoftMenu.add (listStringsItem);
|
||||
applesoftMenu.add (blankAfterReturn);
|
||||
applesoftMenu.add (deleteExtraRemSpace);
|
||||
applesoftMenu.add (deleteExtraDataSpace);
|
||||
@ -298,6 +302,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
showCaretItem.addActionListener (basicPreferencesAction);
|
||||
showThenItem.addActionListener (basicPreferencesAction);
|
||||
showXrefItem.addActionListener (basicPreferencesAction);
|
||||
listStringsItem.addActionListener (basicPreferencesAction);
|
||||
blankAfterReturn.addActionListener (basicPreferencesAction);
|
||||
deleteExtraRemSpace.addActionListener (basicPreferencesAction);
|
||||
deleteExtraDataSpace.addActionListener (basicPreferencesAction);
|
||||
@ -345,6 +350,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
basicPreferences.showCaret = showCaretItem.isSelected ();
|
||||
basicPreferences.showThen = showThenItem.isSelected ();
|
||||
basicPreferences.showXref = showXrefItem.isSelected ();
|
||||
basicPreferences.listStrings = listStringsItem.isSelected ();
|
||||
basicPreferences.blankAfterReturn = blankAfterReturn.isSelected ();
|
||||
basicPreferences.deleteExtraRemSpace = deleteExtraRemSpace.isSelected ();
|
||||
basicPreferences.deleteExtraDataSpace = deleteExtraDataSpace.isSelected ();
|
||||
@ -502,6 +508,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
prefs.putBoolean (PREFS_SHOW_CARET, showCaretItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_THEN, showThenItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_XREF, showXrefItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_LIST_STRINGS, listStringsItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_HEADER, showHeaderItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_TARGETS, showBasicTargetsItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_ONLY_SHOW_TARGETS, onlyShowTargetLinesItem.isSelected ());
|
||||
@ -552,6 +559,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
|
||||
showCaretItem.setSelected (prefs.getBoolean (PREFS_SHOW_CARET, false));
|
||||
showThenItem.setSelected (prefs.getBoolean (PREFS_SHOW_THEN, true));
|
||||
showXrefItem.setSelected (prefs.getBoolean (PREFS_SHOW_XREF, false));
|
||||
listStringsItem.setSelected (prefs.getBoolean (PREFS_LIST_STRINGS, false));
|
||||
showHeaderItem.setSelected (prefs.getBoolean (PREFS_SHOW_HEADER, true));
|
||||
showBasicTargetsItem.setSelected (prefs.getBoolean (PREFS_SHOW_TARGETS, false));
|
||||
onlyShowTargetLinesItem
|
||||
|
Loading…
Reference in New Issue
Block a user