From 20ad92fbd5c031ff9d80365abbbff83b02383307 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Sun, 21 Feb 2021 07:42:40 +1000 Subject: [PATCH] tidying --- .../applefile/ApplesoftBasicProgram.java | 2 +- .../diskbrowser/applefile/SubLine.java | 143 +++++++++--------- 2 files changed, 74 insertions(+), 71 deletions(-) diff --git a/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java b/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java index 290e435..692f69c 100644 --- a/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java +++ b/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java @@ -933,7 +933,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons { for (SubLine subline : line.sublines) { - for (String symbol : subline.getSymbols ()) + for (String symbol : subline.getVariables ()) checkVar (symbol, line.lineNumber, symbolLines, uniqueSymbols); for (String symbol : subline.getArrays ()) checkVar (symbol, line.lineNumber, arrayLines, uniqueArrays); diff --git a/src/com/bytezone/diskbrowser/applefile/SubLine.java b/src/com/bytezone/diskbrowser/applefile/SubLine.java index ca34bab..9050fc1 100644 --- a/src/com/bytezone/diskbrowser/applefile/SubLine.java +++ b/src/com/bytezone/diskbrowser/applefile/SubLine.java @@ -29,7 +29,7 @@ public class SubLine implements ApplesoftConstants private final List gotoLines = new ArrayList<> (); private final List gosubLines = new ArrayList<> (); - private final List symbols = new ArrayList<> (); + private final List variables = new ArrayList<> (); private final List functions = new ArrayList<> (); private final List arrays = new ArrayList<> (); @@ -213,64 +213,8 @@ public class SubLine implements ApplesoftConstants if (!arrays.contains (var)) arrays.add (var); } - else if (!symbols.contains (var)) - symbols.add (var); - } - - // ---------------------------------------------------------------------------------// - List getSymbols () - // ---------------------------------------------------------------------------------// - { - return symbols; - } - - // ---------------------------------------------------------------------------------// - List getFunctions () - // ---------------------------------------------------------------------------------// - { - return functions; - } - - // ---------------------------------------------------------------------------------// - List getArrays () - // ---------------------------------------------------------------------------------// - { - return arrays; - } - - // ---------------------------------------------------------------------------------// - List getGotoLines () - // ---------------------------------------------------------------------------------// - { - return gotoLines; - } - - // ---------------------------------------------------------------------------------// - List getGosubLines () - // ---------------------------------------------------------------------------------// - { - return gosubLines; - } - - // ---------------------------------------------------------------------------------// - List getConstantsInt () - // ---------------------------------------------------------------------------------// - { - return constantsInt; - } - - // ---------------------------------------------------------------------------------// - List getConstantsFloat () - // ---------------------------------------------------------------------------------// - { - return constantsFloat; - } - - // ---------------------------------------------------------------------------------// - List getStringsText () - // ---------------------------------------------------------------------------------// - { - return stringsText; + else if (!variables.contains (var)) + variables.add (var); } // ---------------------------------------------------------------------------------// @@ -386,8 +330,7 @@ public class SubLine implements ApplesoftConstants { try { - int decimalPos = var.indexOf ('.'); - if (decimalPos < 0) + if (var.indexOf ('.') < 0) // no decimal point { int varInt = Integer.parseInt (var); if (!constantsInt.contains (varInt)) @@ -402,7 +345,6 @@ public class SubLine implements ApplesoftConstants } catch (NumberFormatException nfe) { - // System.out.printf ("NFE1: %s%n", var); return false; } return true; @@ -416,6 +358,7 @@ public class SubLine implements ApplesoftConstants int ptr = startPtr + 1; int max = startPtr + length - 1; + while (ptr < max) { byte b = buffer[ptr++]; @@ -437,6 +380,7 @@ public class SubLine implements ApplesoftConstants for (int i = start; i < buffer.length; i++) if (buffer[i] == value) return i; + return -1; } @@ -500,8 +444,10 @@ public class SubLine implements ApplesoftConstants { int p = startPtr + 1; int max = startPtr + length; + while (buffer[p] != TOKEN_EQUALS && p < max) p++; + if (buffer[p] == TOKEN_EQUALS) equalsPosition = toString ().indexOf ('='); // use expanded line } @@ -645,15 +591,8 @@ public class SubLine implements ApplesoftConstants len--; byte[] buffer2 = new byte[len]; System.arraycopy (buffer, startPtr + 1, buffer2, 0, buffer2.length); - return buffer2; - } - // ---------------------------------------------------------------------------------// - @Override - public String toString () - // ---------------------------------------------------------------------------------// - { - return toStringBuilder ().toString (); + return buffer2; } // ---------------------------------------------------------------------------------// @@ -663,6 +602,62 @@ public class SubLine implements ApplesoftConstants return Utility.isHighBitSet (b); } + // ---------------------------------------------------------------------------------// + List getVariables () + // ---------------------------------------------------------------------------------// + { + return variables; + } + + // ---------------------------------------------------------------------------------// + List getFunctions () + // ---------------------------------------------------------------------------------// + { + return functions; + } + + // ---------------------------------------------------------------------------------// + List getArrays () + // ---------------------------------------------------------------------------------// + { + return arrays; + } + + // ---------------------------------------------------------------------------------// + List getGotoLines () + // ---------------------------------------------------------------------------------// + { + return gotoLines; + } + + // ---------------------------------------------------------------------------------// + List getGosubLines () + // ---------------------------------------------------------------------------------// + { + return gosubLines; + } + + // ---------------------------------------------------------------------------------// + List getConstantsInt () + // ---------------------------------------------------------------------------------// + { + return constantsInt; + } + + // ---------------------------------------------------------------------------------// + List getConstantsFloat () + // ---------------------------------------------------------------------------------// + { + return constantsFloat; + } + + // ---------------------------------------------------------------------------------// + List getStringsText () + // ---------------------------------------------------------------------------------// + { + return stringsText; + } + // ---------------------------------------------------------------------------------// public StringBuilder toStringBuilder () // ---------------------------------------------------------------------------------// @@ -697,4 +692,12 @@ public class SubLine implements ApplesoftConstants return line; } + + // ---------------------------------------------------------------------------------// + @Override + public String toString () + // ---------------------------------------------------------------------------------// + { + return toStringBuilder ().toString (); + } }