visicalc lookup

This commit is contained in:
Denis Molony 2017-02-18 20:54:24 +11:00
parent d5d10b4e6a
commit 176a03a786
12 changed files with 110 additions and 85 deletions

View File

@ -11,6 +11,7 @@ import java.util.Map;
import com.bytezone.diskbrowser.prodos.ProdosConstants;
import com.bytezone.diskbrowser.utilities.HexFormatter;
// see big red computer club folder
public class QuickDrawFont extends AbstractFile
{
Map<Integer, Character> characters = new HashMap<Integer, Character> ();
@ -58,6 +59,9 @@ public class QuickDrawFont extends AbstractFile
this.fileType = fileType;
this.auxType = auxType;
if (auxType != 0)
System.out.printf ("Font aux: %04X%n", auxType);
fontName = HexFormatter.getPascalString (buffer, 0);
int nameLength = (buffer[0] & 0xFF);
@ -134,23 +138,25 @@ public class QuickDrawFont extends AbstractFile
private void createCharacters ()
{
// System.out.printf ("Total chars: %d%n", totalCharacters);
for (int i = 0, max = totalCharacters + 1; i < max; i++)
{
// index into the strike
int location = HexFormatter.unsignedShort (buffer, locationTableOffset + i * 2);
// System.out.printf ("%3d %04X %n", i, location);
int j = i + 1; // next character
if (j < max)
{
int nextLocation =
HexFormatter.unsignedShort (buffer, locationTableOffset + j * 2);
int pixelWidth = nextLocation - location;
if (pixelWidth < 0)
{
System.out.println ("*********** Bad pixelWidth");
corrupt = true;
return;
}
// if (pixelWidth < 0)
// {
// System.out.println ("*********** Bad pixelWidth");
// corrupt = true;
// return;
// }
if (pixelWidth > 0)
characters.put (i, new Character (location, pixelWidth));

View File

@ -133,7 +133,7 @@ public class AppleworksWPFile extends AbstractFile
break;
default:
System.out.printf ("Unknown value : %02X %02X%n", b1, b2);
System.out.printf ("Unknown value in %s: %02X %02X%n", name, b1, b2);
}
ptr += 2;
}

View File

@ -1,5 +1,7 @@
package com.bytezone.diskbrowser.visicalc;
import java.util.Arrays;
class Address implements Comparable<Address>
{
private static final int MAX_ROWS = 255;
@ -57,7 +59,9 @@ class Address implements Comparable<Address>
}
catch (NumberFormatException e)
{
System.out.printf ("sCol:%s,sRow:%s%n", sCol, sRow);
System.out.printf ("NFE: %s%n", sRow);
System.out.println (Arrays.toString (Thread.currentThread ().getStackTrace ()));
}
}

View File

@ -1,10 +1,13 @@
package com.bytezone.diskbrowser.visicalc;
class Count extends RangeFunction
class Count extends Function
{
private final Range range;
public Count (Sheet parent, String text)
{
super (parent, text);
range = new Range (text);
}
@Override

View File

@ -1,7 +1,8 @@
package com.bytezone.diskbrowser.visicalc;
class Lookup extends RangeFunction
class Lookup extends Function
{
protected final Range range;
String sourceText;
String rangeText;
Expression source;
@ -13,6 +14,7 @@ class Lookup extends RangeFunction
int pos = text.indexOf (',');
sourceText = text.substring (8, pos);
rangeText = text.substring (pos + 1, text.length () - 1);
range = new Range (rangeText);
}
@Override
@ -34,7 +36,7 @@ class Lookup extends RangeFunction
for (Address address : range)
{
Cell cell = parent.getCell (address);
if (cell != null && cell.getValue () > sourceValue)
if (cell != null && cell.getValue () > sourceValue) // past the value
break;
target = address;
}
@ -52,4 +54,7 @@ class Lookup extends RangeFunction
return this;
}
// @LOOKUP(B8,F3...F16)
// @LOOKUP(.2*K8+K7,F3...F16)
}

View File

@ -1,10 +1,13 @@
package com.bytezone.diskbrowser.visicalc;
class Max extends RangeFunction
class Max extends Function
{
private final Range range;
public Max (Sheet parent, String text)
{
super (parent, text);
range = new Range (text);
}
@Override

View File

@ -1,10 +1,13 @@
package com.bytezone.diskbrowser.visicalc;
class Min extends RangeFunction
class Min extends Function
{
private final Range range;
public Min (Sheet parent, String text)
{
super (parent, text);
range = new Range (text);
}
@Override

View File

@ -1,15 +1,17 @@
package com.bytezone.diskbrowser.visicalc;
public class Npv extends RangeFunction
public class Npv extends Function
{
// private final String valueText;
// private final String rangeText;
//
// private final Expression valueExp;
private final Range range;
Npv (Sheet parent, String text)
{
super (parent, text);
range = new Range (text);
// int pos = text.indexOf (',');
// valueText = text.substring (8, pos);

View File

@ -4,18 +4,41 @@ import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Range implements Iterable<Address>
{
private static final Pattern rangePattern =
Pattern.compile ("([A-B]?[A-Z])([0-9]{1,3})\\.\\.\\.([A-B]?[A-Z])([0-9]{1,3})");
private static final Pattern addressList = Pattern.compile ("\\(([^,]+(,[^,]+)*)\\)");
Address from, to;
List<Address> range = new ArrayList<Address> ();
public Range (String rangeText)
{
setRange (rangeText);
}
public Range (Address from, Address to)
{
this.from = from;
this.to = to;
addRange ();
}
public Range (String[] cells)
{
for (String s : cells)
range.add (new Address (s));
}
private void addRange ()
{
range.add (from);
Address tempFrom = from;
if (from.row == to.row)
while (from.compareTo (to) < 0)
@ -31,12 +54,7 @@ class Range implements Iterable<Address>
}
else
throw new InvalidParameterException ();
}
public Range (String[] cells)
{
for (String s : cells)
range.add (new Address (s));
from = tempFrom;
}
boolean isHorizontal ()
@ -53,6 +71,47 @@ class Range implements Iterable<Address>
return first.column == last.column;
}
@Override
public Iterator<Address> iterator ()
{
return range.iterator ();
}
private void setRange (String text)
{
Matcher m = rangePattern.matcher (text);
if (m.find ())
{
from = new Address (m.group (1), m.group (2));
to = new Address (m.group (3), m.group (4));
addRange ();
return;
}
m = addressList.matcher (text);
if (m.find ())
{
System.out.printf ("Address list:%s%n", text);
String[] cells = m.group (1).split (",");
for (String s : cells)
range.add (new Address (s));
return;
}
int pos = text.indexOf ("...");
if (pos > 0)
{
String fromAddress = text.substring (0, pos);
String toAddress = text.substring (pos + 3);
from = new Address (fromAddress);
to = new Address (toAddress);
addRange ();
return;
}
System.out.printf ("null range [%s]%n", text);
}
@Override
public String toString ()
{
@ -67,10 +126,4 @@ class Range implements Iterable<Address>
}
return String.format (" %s -> %s", from.text, to.text);
}
@Override
public Iterator<Address> iterator ()
{
return range.iterator ();
}
}

View File

@ -1,58 +0,0 @@
package com.bytezone.diskbrowser.visicalc;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class RangeFunction extends Function
{
private static final Pattern rangePattern = Pattern
.compile ("\\(([A-B]?[A-Z])([0-9]{1,3})\\.\\.\\.([A-B]?[A-Z])([0-9]{1,3})\\)?");
private static final Pattern addressList = Pattern.compile ("\\(([^,]+(,[^,]+)*)\\)");
protected final Range range;
public RangeFunction (Sheet parent, String text)
{
super (parent, text);
range = getRange (text);
}
protected Range getRange (String text)
{
Range range = null;
Matcher m = rangePattern.matcher (text);
if (m.find ())
{
Address fromAddress = new Address (m.group (1), m.group (2));
Address toAddress = new Address (m.group (3), m.group (4));
range = new Range (fromAddress, toAddress);
}
if (range != null)
return range;
m = addressList.matcher (text);
if (m.find ())
{
String[] cells = m.group (1).split (",");
range = new Range (cells);
}
if (range != null)
return range;
int pos = text.indexOf ("...");
if (pos > 0)
{
String from = text.substring (0, pos);
String to = text.substring (pos + 3);
Address fromAddress = new Address (from);
Address toAddress = new Address (to);
range = new Range (fromAddress, toAddress);
}
if (range == null)
System.out.printf ("null range [%s]%n", text);
return range;
}
}

View File

@ -154,6 +154,8 @@ public class Sheet
ptr += length + 1; // +1 for end-of-line token
}
// might have to keep recalculating until nothing changes??
calculate (recalculationOrder);
calculate (recalculationOrder);
if (false)
@ -179,7 +181,6 @@ public class Sheet
private void processLine (String line)
{
assert !line.isEmpty ();
// System.out.println (line);
if (line.startsWith ("/"))
{

View File

@ -1,10 +1,13 @@
package com.bytezone.diskbrowser.visicalc;
class Sum extends RangeFunction
class Sum extends Function
{
private final Range range;
public Sum (Sheet parent, String text)
{
super (parent, text);
range = new Range (text);
}
@Override